linux - Regarding Hard Link -


can please explain me why kernel doesn't allow make hard link directory. whether because breaks rule of directed acyclic graph structure of file-system or because of other reason. other complications come if allows that?

back in days of 7th edition (or version 7) unix, there no system calls mkdir(2) , rmdir(2). mkdir(1) program suid root, , used mknod(2) system call create directory , link(2) system call make entries . , .. in new directory. link(2) system call allowed root that. consequently, way (circa 1978), possible superuser create links directories, superuser permitted ensure there no problems cycles or other missing links. there diagnostic programs pick pieces if system crashed while directory partly created, example.


you can find unix 7th edition manuals @ bell labs. sections 2 , 3 devoid of mkdir(2) , rmdir(2). used mknod(2) system call make directory:

name

mknod – make directory or special file

synopsis

mknod(name, mode, addr) char *name; 

description

mknod creates new file name null-terminated string pointed name. mode of new file (including directory , special file bits) initialized mode. (the protection part of mode modified process’s mode mask; see umask(2)). first block pointer of i-node initialized addr. ordinary files , directories addr zero. in case of special file, addr specifies special file.

mknod may invoked super-user.

see also

mkdir(1), mknod(1), filsys(5)

diagnostics

zero returned if file has been made; – 1 if file exists or if user not superuser.

the entry link(2) states:

diagnostics

zero returned when link made; – 1 returned when name1 cannot found; when name2 exists; when directory of name2 cannot written; when attempt made link directory user other super-user; when attempt made link file on file system; when file has many links.

the entry unlink(2) states:

diagnostics

zero returned; – 1 indicates file not exist, directory cannot written, or file contains pure procedure text in use. write permission not required on file itself. illegal unlink directory (except super-user).

the manual page ln(1) command noted:

it forbidden link directory or link across file systems.

the manual page mkdir(1) command notes:

standard entries, '.', directory itself, , '..' parent, made automatically.

this not worthy of comment not possible create directories without links.


nowadays, mkdir(2) , rmdir(2) system calls standard , permit user create , remove directories, preserving correct semantics. there no longer need permit users create hard links directories. doubly true since symbolic links introduced - not in 7th edition unix, in bsd versions of unix quite on.


with normal directories, .. entry unambiguously links the (single, solitary) parent directory. if have 2 hard links (two names) same directory in different directories, .. entry point? presumably, original parent directory - , presumably there no way 'other' parent directory linked directory. that's asymmetry can cause trouble. normally, if do:

chdir("./subdir"); chdir(".."); 

(where ./subdir not symbolic link), in directory started from. if ./subdir hard link directory somewhere else, in different directory started after second chdir(). you'd have show pair of stat() calls before , after chdir() operations shown.


Comments