goto out_idr;
list_add_tail(&bd->device_list, &b_dev_list);
+ bic->minor = bd->minor;
spin_unlock(&b_dev_lock);
return 0;
out_idr:
{
int __user *uarg = (int __user *) arg;
struct b_ioctl_cmd bic;
+ int ret = -ENOTTY;
if (copy_from_user(&bic, uarg, sizeof(bic)))
return -EFAULT;
switch (cmd) {
case 0:
- return b_add_dev(&bic);
+ ret = b_add_dev(&bic);
+ if (!ret && copy_to_user(uarg, &bic, sizeof(bic))) {
+ b_del_dev(&bic);
+ ret = -EFAULT;
+ }
+ break;
case 1:
- return b_del_dev(&bic);
+ ret = b_del_dev(&bic);
+ break;
default:
break;
}
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
+#include <linux/types.h>
#include <sys/ioctl.h>
-#define B_NAME_LEN 32
-
-struct b_ioctl_cmd {
- int fd;
- char name[B_NAME_LEN];
-};
+#include "../binject.h"
int main(int argc, char *argv[])
{
}
bic.fd = fd;
- strcpy(bic.name, argv[1]);
- if (ioctl(fdb, 0, &bic) < 0)
+ if (ioctl(fdb, 0, &bic) < 0) {
perror("ioctl");
+ return 1;
+ }
+ printf("%s mapped to binject minor %u\n", argv[1], bic.minor);
return 0;
}
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
+#include <linux/types.h>
-struct b_ioctl_cmd {
- int fd;
- int minor;
-};
+#include "../binject.h"
int main(int argc, char *argv[])
{