Domanda

Devo scrivere un dispositivo Char Linux, che gestisce le funzioni IOCTL (senza BKL) per sblocchi_ioctl. Al momento posso ricevere un argomento dal comando IOCTL dello spazio utenti

__get_user(myint, (int __user *) arg);

Come posso ricevere più argomenti int (ad esempio questa chiamata)?:

ioctl(fp, SZ_NEW_DEV_FORMAT, 0, 1, 30);
È stato utile?

Soluzione

Yes, you have to use structures. For a particular ioctl command there will be some predefined arguments. You need to wrap these all arguments into a structure object and pass in the address of the object. In side the kernel, you need to type cast the given arg to structure pointer and access the arguments. For instance.

 struct mesg {
         int size;
         char buf[100];
 };

 struct mesg msg1;

 /*Fill in the structure object here and call ioctl like this*/
 ret = ioctl(fd, SZ_NEW_DEV_FORMAT, &msg1);

Inside the kernel you access it like this:

      struct mesg *msg;
      copy_from_user((char *)msg, (char *)arg, sizeof(*msg));
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top