home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / unix / wizards / 5296 < prev    next >
Encoding:
Text File  |  1992-12-22  |  4.0 KB  |  98 lines

  1. Newsgroups: comp.unix.wizards
  2. Path: sparky!uunet!krfiny!jeffj
  3. From: jeffj@krfiny.uucp (J. Jonas)
  4. Subject: Re: /dev/null and file locking
  5. Message-ID: <1992Dec21.202503.2953@krfiny.uucp>
  6. Summary: there are locks, then there are other locks (but no bagles)
  7. Organization: Jeff's house of computer pieces
  8. References: <15945@auspex-gw.auspex.com> <1992Dec18.182107.22098@zeus.ieee.org> <1gu11eINN4tn@early-bird.think.com>
  9. Date: Mon, 21 Dec 1992 20:25:03 GMT
  10. Lines: 86
  11.  
  12. In article <1gu11eINN4tn@early-bird.think.com> barmar@think.com (Barry Margolin) writes:
  13. >In article <1992Dec18.182107.22098@zeus.ieee.org> jbarth@ep.ieee.org writes:
  14. >>I recall reading in Bach's "The Design of the UNIX Operating System" that
  15. >>device inodes, unlike regular inodes, are never locked.  I don't remember
  16. >>what the rationale was -- perhaps someone more knowledgeable than me could
  17. >>comment.
  18.  
  19. Okay, let's look at an incore inode
  20. (look at /usr/include/sys/inode.h in system V, or
  21. /usr/include/sys/vnode.h for SUN OS).
  22.  
  23. For System V, there's a flag bit called ILOCK.
  24. The inode is locked when its being modified, so as to prevent
  25. two (or more) processes from altering the inode at the same time.
  26. This is necessary when adding blocks to a file or anything that's
  27. altering the inode with a complex sequence of operations.
  28. This lock should be very short in span since inode operations
  29. are quite short.
  30. Only the kernel inode manipulation routines may view/alter/test this bit.
  31.  
  32. There's another lock used for exclusion.
  33. Devices such as line printers don't allow more than one open to succeed.
  34. That lock doesn't seem to reside in the inode, but in a structure
  35. internal to the driver thus the driver is the only thing that may
  36. view/alter/test the bit.
  37. If the lock and status bits are indeed in a driver specific structure,
  38. then it does not matter how many inodes you have going to the same
  39. device (whether it be /dev/null or another), they're all pointing to the
  40. same major/minor number and the same driver using the same
  41. global data structures so there's no chance of confusion.
  42.  
  43. The File/Record lock is the one that allows processes to battle
  44. for file access privileges with the fcntl/read/write system calls.
  45.  
  46.  
  47. If I recall properly, the original question had to do with
  48. making more /dev/nulls on a system.
  49. /dev/null is not an exclusive device and should have no
  50. locking of any sort.  Ignoring data should be a fast operation :-)
  51.  
  52. There are 3 ways.  In my order of preference:
  53. 1) If the desired file is on the same file system as /dev then
  54. make a "hard link" with "ln /dev/null /dev/kr0".
  55. ls -li /dev/null /dev/kr0 shows:
  56.     80 crw-rw-rw-  2 root       3,   2 Dec 18 16:22 /dev/kr0
  57.     80 crw-rw-rw-  2 root       3,   2 Dec 18 16:22 /dev/null
  58.  
  59. This shows that there are 2 directory entries
  60. both pointing to inode 80 which is a character special device
  61. major number 3, minor number 2.
  62.  
  63. The nice thing about hard links is that you only create additional
  64. directory entries.  No additional inodes are created.
  65. The 'link count' in the 'ls -l' tells you how many names/directory
  66. entries are pointing to the file.
  67. But how do you find all the names (particularly since they may
  68. be in any directory in the file system)?  'find' them like this:
  69.     find / -inum 80 -mount -print
  70. prints
  71.     /dev/null
  72.     /dev/kr0
  73.  
  74. (the -mount option tells 'find' to not cross mount points,
  75. because every file system has inodes starting with 2).
  76. [this is due to historical reasons: on a System V file system,
  77. inode 0 means an unallocated/free inode,
  78. inode 1 is reserved for bad blocks
  79. inode 2 is the root directory]
  80.  
  81. 2) If the desired file is not on the same file system,
  82. make a symbolic link as such:
  83.     ln -s /dev/null null2
  84. ls -l shows:
  85.     lrwxrwxrwx  1 jeffj           9 Dec 21 14:59 null2 -> /dev/null
  86.  
  87.  
  88. 3) If the desired file is not on the same file system as /dev
  89. and the system does not support symbolic links (such as SVR3)
  90. then you have no choice but to make a duplicate character special inode
  91.     /etc/mknod null2 c 3 2
  92. The problem with this is tracking all the inodes pointing to the same
  93. device.  No single find/ncheck/ff will do this.
  94. -- 
  95. Jeffrey Jonas
  96.  
  97. jeffj@panix.com
  98.