I am writing a device driver for Linux. He creates a device with 4 minor numbers. Whenever we try to write a device to a minor number 3, we have to kill the device, and currently it should not do anything else except what it writes to the booga device. Here are some of my current codes, and if necessary, I can send more code:
Recording Method:
static ssize_t booga_write (struct file *filp, const char *buf, size_t count, loff_t *f_pose) { printk("Attempting to write to booga device\n"); if (down_interruptible (&booga_device_stats->sem)) return (-ERESTARTSYS); booga_device_stats->num_bytes_written += count; up(&booga_device_stats->sem); return count;
How it is tested:
static void run_write_test(char *device, int bufsize) { char *buf; int src; int out; src = open(device, O_WRONLY); if (src < 0) { perror("Open for write failed:"); exit(1); } buf = (char *) malloc(sizeof(char)*(bufsize+1)); fprintf(stderr, "Attempting to write to booga device\n"); out = write(src, buf, bufsize); fprintf(stderr, "Wrote %d bytes.\n", out); free(buf); close(src); }
I am wondering if there is a way to get the lowest number. I looked in linux / fs.h and saw that there is a member with the name private_data in the file structure, but whenever I try to call this it will crash my system since it is currently set to null.
Or do I not need to try to get the lowest number from the structure file and try to track it when I first open the device?
Kat
source share