static int apple_open(struct inode *inode,struct file *file)
{
printk("This is open(skull)\n");
return 0;
}
static int apple_release(struct inode *inode,struct file *file)
{
printk("This is released\n");
return 0;
}
static int apple_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg)
{
switch(cmd)
{
case 1: printk("There is 1 apple.\n"); break;
case 2: printk("There is 2 apples\n"); break;
case 3: printk("There is 3 apples\n"); break;
}
int main(int argc, char *argv)
{
int fd,num;
char label[10];
fd = open("/dev/apple",O_RDWR);
if(fd != -1)
{
printf("Please enter the label attached to the Apple\n");
scanf("%s",&label);
write(fd,&label,10*sizeof(char));
read(fd,&label,10*sizeof(char));
printf("Please enter the number of apples\n");
scanf("%d",&num);
ioctl(fd,num);
close(fd);
}
else
{
printf("Device open failure\n");
}
}