/bin/pwd

Conor P. Cahill cpcahil at virtech.uucp
Fri Sep 14 10:22:32 AEST 1990


In article <2488 at idunno.Princeton.EDU> pfalstad at phoenix.Princeton.EDU (Paul John Falstad) writes:
>Can anyone tell me how /bin/pwd works?  I thought it was a trivial

On BSD style systems /bin/pwd calls the library function (I think it is 
getcwd(), but don't have the manual nearby).

On System V style systems, getcwd(3) popen(3)'s "/bin/pwd" to get 
the current workind directory.

Anyway, the way pwd works is something like the following:

	Stat the current directory (".") and get the inode number and
		device number

	Open ".." and read each entry
		if you find an entry with the same inode number
			stat it
			if it is the same device number
				you got a match, save name portion
				close this directory
				start again one directory higher
		
		if you don't find an entry with the right inode number
			go back and stat each entry looking for the one
				with the correct device number
		

This goes on and on until you get to the top of the filesystem. (you get
to the top when a stat of . & .. return the exact same stuff.

-- 
Conor P. Cahill            (703)430-9247        Virtual Technologies, Inc.,
uunet!virtech!cpcahil                           46030 Manekin Plaza, Suite 160
                                                Sterling, VA 22170 



More information about the Comp.unix.questions mailing list