Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    How to call ioctl function

    hai friend,
    I have a doubt in ioctl function..The function is
    int device_ioctl(struct inode *inode,struct file *file,unsigned int ioctl_num,unsigned long ioctl_param)......
    when its called in our program and what purpose it is used and also give me a detail about ioctl function with an simple example..

    Thanks in advance..

  2. #2
    // user space program for ioctl

    #define CDROMEJECT 1
    int main (int argc, char* argv[])
    /* Open a file descriptor to the device specified on the command line. */
    int fd = open (argv[1], O_RDONLY); //argv[1] is /dev/cdrom
    /* Eject the CD-ROM. */
    ioctl (fd, CDROMEJECT); /*CDROMEJECT become device_ioctl.. int cmd parameter */
    /* Close the file descriptor. */
    close (fd);
    return 0;

    device driver ioctl
    static int device_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg)
    case CDROMEJECT:
    printk("CD-ROM EJECTED\n");
    return 0;

    hope this helps you

    Ashok Athukuri

  3. #3

    Unhappy ioctl user app didn't work for me

    Hi above,

    I tried your sample user space application but it didn't work for me.
    i compiled successfully the userapp and ran in tha way as:

    ./a.out /dev/cdrom
    but after hitting enter nothing happened.
    I want to see the practical example of ioctl like this e.g. but it's not working can you tell waht is problem?

    I am using ubuntu9.10 ang gcc4.4.1

  4. $spacer_open

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts