next up previous
Next: remove_proc_entry Up: General proc functions Previous: proc_symlink

proc_mknod

proc_mknod is used to create device special files below /proc. Basically it can be used just like mknod is used. The only real usage is that creating device files below /proc is convenient if the file system was a read-only file system ( romfs or the like). Originally this seems to have been introduced in order to provide an initial console device via /proc during system startup, probably because devfs provides this in a cleaner way. For embedded systems enabling devfs is fairly expensive ( vmlinuz size of increase of 11k), so this somewhat brutal substitution can be interesting for resource constraint systems.


extern struct proc_dir_entry *proc_mknod(
   const char            *name,
   mode_t                 mode,
   struct proc_dir_entry *parent,
   kdev_t                 rdev);

It is possible to create all device files for an embedded system below /proc and link /dev to /proc. This eliminates the file system overhead of /dev and allows to set the permissions tightly (it's not trivial to modify the permissions of these files even as root). Generally it's probably better to use devfs for dynamically created device files than to misuse /proc.


   if (register_chrdev(SIMPLE_MAJOR,
      "simple_dev", &simple_dev_fops) == 0)
   {
      printk("driver (major %d) registered\n",
         SIMPLE_MAJOR);

      /* create the device */
      mydevice = proc_mknod(
         "simple_dev", S_IFCHR | 0666,
         &proc_root, MKDEV(17, 0));
      if (mydevice == NULL) {
         ret=-ENODEV;
      }

      mydevice->owner = THIS_MODULE;
      return ret;
   }

Now the user-space can access this character device via /proc/simple_dev, just as it would via /dev. For embedded systems this might be a way to "`emulate"' devfs without requiring the full size overhead of devfs.


next up previous
Next: remove_proc_entry Up: General proc functions Previous: proc_symlink
Der Herr Hofrat
2003-03-26