Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Back in the days of 7th Edition (or Version 7) UNIX, there were no system calls <code>mkdir(2)</code> and <code>rmdir(2)</code>. The <code>mkdir(1)</code> program was SUID root, and used the <code>mknod(2)</code> system call to create the directory and the <code>link(2)</code> system call to make the entries for <code>.</code> and <code>..</code> in the new directory. The <code>link(2)</code> system call only allowed root to do that. Consequently, way back then (circa 1978), it was possible for the superuser to create links to directories, but only the superuser was permitted to do so to ensure that there were no problems with cycles or other missing links. There were diagnostic programs to pick up the pieces if the system crashed while a directory was partly created, for example.</p> <hr> <p>You can find the Unix 7th Edition manuals at <a href="http://www.cs.bell-labs.com/7thEdMan/" rel="nofollow">Bell Labs</a>. Sections 2 and 3 are devoid of <code>mkdir(2)</code> and <code>rmdir(2)</code>. You used the <code>mknod(2)</code> system call to make the directory:</p> <blockquote> <h3>NAME</h3> <p>mknod – make a directory or a special file </p> <h3>SYNOPSIS</h3> <pre><code>mknod(name, mode, addr) char *name; </code></pre> <h3>DESCRIPTION</h3> <p>Mknod creates a new file whose name is the null-terminated string pointed to by name. The mode of the new file (including directory and special file bits) is initialized from mode. (The protection part of the mode is modified by the process’s mode mask; see umask(2)). The first block pointer of the i-node is initialized from addr. For ordinary files and directories addr is normally zero. In the case of a special file, addr specifies which special file.</p> <p>Mknod may be invoked only by the super-user. </p> <h3>SEE ALSO</h3> <p>mkdir(1), mknod(1), filsys(5) </p> <h3>DIAGNOSTICS</h3> <p>Zero is returned if the file has been made; – 1 if the file already exists or if the user is not the superuser.</p> </blockquote> <p>The entry for <code>link(2)</code> states:</p> <blockquote> <h3>DIAGNOSTICS</h3> <p>Zero is returned when a link is made; – 1 is returned when name1 cannot be found; when name2 already exists; when the directory of name2 cannot be written; when an attempt is made to link to a directory by a user other than the super-user; when an attempt is made to link to a file on another file system; when a file has too many links.</p> </blockquote> <p>The entry for <code>unlink(2)</code> states:</p> <blockquote> <h3>DIAGNOSTICS</h3> <p>Zero is normally returned; – 1 indicates that the file does not exist, that its directory cannot be written, or that the file contains pure procedure text that is currently in use. Write permission is not required on the file itself. It is also illegal to unlink a directory (except for the super-user).</p> </blockquote> <p>The manual page for the <code>ln(1)</code> command noted:</p> <blockquote> <p>It is forbidden to link to a directory or to link across file systems.</p> </blockquote> <p>The manual page for the <code>mkdir(1)</code> command notes:</p> <blockquote> <p>Standard entries, '.', for the directory itself, and '..' for its parent, are made automatically.</p> </blockquote> <p>This would not be worthy of comment were it not that it was possible to create directories without those links.</p> <hr> <p>Nowadays, the <code>mkdir(2)</code> and <code>rmdir(2)</code> system calls are standard and permit any user to create and remove directories, preserving the correct semantics. There is no longer a need to permit users to create hard links to directories. This is doubly true since symbolic links were introduced - they were not in 7th Edition UNIX, but were in the BSD versions of UNIX from quite early on.</p> <hr> <p>With normal directories, the <code>..</code> entry unambiguously links back to <em>the</em> (single, solitary) parent directory. If you have two hard links (two names) for the same directory in different directories, where does the <code>..</code> entry point? Presumably, to the original parent directory - and presumably there is no way to get to the 'other' parent directory from the linked directory. That's an asymmetry that can cause trouble. Normally, if you do:</p> <pre><code>chdir("./subdir"); chdir(".."); </code></pre> <p>(where <code>./subdir</code> is not a symbolic link), then you will be back in the directory you started from. If <code>./subdir</code> is a hard link to a directory somewhere else, then you will be in a different directory from where you started after the second <code>chdir()</code>. You'd have to show that with a pair of <code>stat()</code> calls before and after the <code>chdir()</code> operations shown.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload