lkml.org 
[lkml]   [1997]   [Apr]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectCalling do_mknod() from init_module()
Date

We were wondering why no drivers use do_mknod() from
init_module() to automatically create the minor device
nodes when a loadable driver with dynamic major number
allocation is loaded.

It seems like a good idea to us -- no muss, no fuss, the
nodes just appear when the device gets loaded by insmod, and
disappear when the driver gets unloaded. Something like this:

if ((major = register_chrdev(0, "lala", &LalaFops)) <= 0) {
printk("Unable to get major for lala\n") ;
return(1) ;
}

do_unlink("/dev/lala0");
rc = do_mknod("/dev/lala0", S_IFCHR | 0666, MKDEV(major, 0) );
if (rc < 0)
{
printk("Unable to create device node for lala\n");
return (1);
}


To get this to work, we had to arrange to export do_mknod()
and also do_unlink() with the enclosed kernel patch.

So, I thought maybe I'd just pose the question here:

Calling do_mknod() from init_module() - a good idea or not???

-Rick

================= patch ============================
Note:
This device driver will make the device nodes
automatically on module loading. However, for the
time being you must hack your kernel to export
the proper symbols to enable this magic. I hope
to get the changes incorporated into the 2.0.30
kernel as well as the 2.1.X development kernels

The following patch will make the needed changes.
Tested on kernel 2.0.27

*** include/linux/fs.h.orig Wed Apr 2 12:31:11 1997
--- include/linux/fs.h Wed Apr 2 11:45:58 1997
***************
*** 617,622 ****
--- 617,623 ----
extern int open_namei(const char * pathname, int flag, int mode,
struct inode ** res_inode, struct inode * base);
extern int do_mknod(const char * filename, int mode, dev_t dev);
+ extern int do_unlink(const char * filename);
extern int do_pipe(int *);
extern void iput(struct inode * inode);
extern struct inode * __iget(struct super_block * sb,int nr,int crsmnt);
*** kernel/ksyms.c.orig Wed Apr 2 12:17:56 1997
--- kernel/ksyms.c Wed Apr 2 11:44:36 1997
***************
*** 170,175 ****
--- 170,177 ----
X(generic_file_read),
X(generic_file_mmap),
X(generic_readpage),
+ X(do_mknod),
+ X(do_unlink),

/* device registration */
X(register_chrdev),
*** fs/namei.c.orig Wed Apr 2 12:19:08 1997
--- fs/namei.c Wed Apr 2 11:45:13 1997
***************
*** 656,662 ****
return error;
}

! static int do_unlink(const char * name)
{
const char * basename;
int namelen, error;
--- 656,662 ----
return error;
}

! int do_unlink(const char * name)
{
const char * basename;
int namelen, error;

--
Rick Richardson Sr. Principal Engr. Can you be sure I'm really me
Digi Intl. Email: rick@dgii.com and not my clone??? Has anybody
11001 Bren Rd. East Fax: (612) 912-4955 seen The Leader's nose???
Minnetonka, MN 55343 Tel: (612) 912-3212 http://www.dgii.com/people/rick/

\
 
 \ /
  Last update: 2005-03-22 13:39    [W:0.133 / U:0.124 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site