Problem in Reading the Device file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



with the following code for registration of a character device->
int scullv_init(void)
{
    int result, i,err;
    dev_t dev;
    if((result = alloc_chrdev_region(&dev, 0, 1, "scullv")))
        printk("Couldnt find a major number");

    scullv_major = MAJOR(dev);
    scullv_minor = MINOR(dev);
    scullv_device = kmalloc(sizeof (struct scullv_dev), GFP_KERNEL);
    if (!scullv_device) {
        result = -ENOMEM;
        goto fail_malloc;
    }
    memset(scullv_device, 0, sizeof (struct scullv_dev));
    cdev_init(&scullv_device->cdev, &scullv_fops);
    scullv_device->cdev.owner = THIS_MODULE;
    scullv_device->cdev.ops = &scullv_fops;
    err = cdev_add (&scullv_device->cdev, dev, 1);
    /* Fail gracefully if need be */
    if (err)
        printk(KERN_NOTICE "Error %d adding scull", err);
    return 0; /* succeed */

 fail_malloc:
    unregister_chrdev_region(dev, 1);
    return result;
}



...when i run a user prog on corresponding device file to open and read the file
the read function is not executing. I checked with the help of dmesg.
int scullv_open (struct inode *inode, struct file *filp)
{
    printk("Hi open called");
    return 0;
}
ssize_t scullv_read (struct file *filp, const char __user *buf, size_t count,
                loff_t *f_pos)
{
    printk("Hi read called");
    return 0;
}

the user level code is
int main()
{
int fd;
    if(fd=open("/dev/kanishk",O_RDWR)<=0)
    {
        printf("Error in opening file\n");
    }
    printf("Hi open done\n");
    char *buff=(char *) malloc(10);
    while(1);
    printf("Data Returned is :%d",read(fd,buff,5));
   
    buff[6]='\0';
    printf("Data Entered is :%s",buff);
    return 0;
}

thanks in advance



Yahoo! Photos
Ring in the New Year with Photo Calendars. Add photos, events, holidays, whatever.

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux