Re: Anyway to mknod from kernel?

Adam D. Bradley (artdodge@cs.bu.edu)
Tue, 26 Oct 1999 16:25:09 -0400 (EDT)


On Tue, 26 Oct 1999, Bret Indrelee wrote:

> Is there any way for the kernel module to do the 'mknod' commands from
> within the module? I would rather have the code create the inode rather than
> needing a separate script that creates each of the minor device numbers.

You _can_ do it, but it's generally frowned upon. There are two other
approaches you can take:

1) devfs - Richard Gooch posts notifications about updates to the list all
the time, check an archive for the URL...

2) create the nodes in a /proc directory, and pre-populate /dev with
symlinks to wherever the nodes will go. I.e., your driver creates:
/proc/magicdriver/pipe1 (char device X,Y)
and you, prior to ever installing or loading your module, have already
created:
/dev/magicpipe1 (symlink) -> /proc/magicdriver/pipe1

That's how I've done it in the past. It's pretty easy, requires a
dirt-simple setup script to be run one time (instead of after every
install of the module, which I gather is what you want to avoid), and the
code is dirt simple: (snipped from something I was working back in late
2.1 days)

struct proc_dir_entry *node = malloc(sizeof(struct proc_dir_entry));
*node = (struct proc_dir_entry) {
0, strlen("device"), "device",
S_IFBLK | S_IWUSR | S_IRUGO |
MKDEV(device_major, device_minor),
1, 0, 0, 0,
&blkdev_inode_operations,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, 0, 0 };
proc_register(parent_proc_directory, node);

Good luck,
Adam
-- Adam D. Bradley -- artdodge@cs.bu.edu -- BU x8921 MCS211 --- <>< ---
This message has been infected with a .signature virus. \ www.adbp.org
Copy it into your .signature file or the turnip dies!!! \ 2Cor6:12-13

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/