Results 1 to 3 of 3
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 04-08-2008 #1Just Joined!
- Join Date
- Feb 2008
- Posts
- 18
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..
vivek
- 04-09-2008 #2Just Joined!
- Join Date
- Jun 2006
- Posts
- 29
// user space program for ioctl
Code:#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
Code:static int device_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg) { switch(cmd) { case CDROMEJECT: printk("CD-ROM EJECTED\n"); break; default: printk("IOCTL DEFAULT COMMAND EXECUTED\n"); } return 0; }
hope this helps you
Ashok Athukuri
- 01-30-2010 #3Just Joined!
- Join Date
- Jan 2010
- Posts
- 2
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



