Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!husc6!think!ames!ptsfa!hoptoad!academ!killer!jfh From: jfh@killer.UUCP (John Haugh) Newsgroups: comp.unix.questions Subject: Re: Identify file name given file descriptor Message-ID: <877@killer.UUCP> Date: Wed, 13-May-87 14:40:38 EDT Article-I.D.: killer.877 Posted: Wed May 13 14:40:38 1987 Date-Received: Tue, 19-May-87 06:34:01 EDT References: <710@twitch.UUCP> Organization: The Unix(tm) Connection, Dallas, Texas Lines: 48 Keywords: mount, ncheck, partly tested Summary: Metacode follows ... I opened my mouth and said it could be done. I refuse to write C code on my lunch hour so you will have to take what you get. Refer to ftw(3), fstat(2) and stat(2) for all of the information you should need. You don't REALLY need ncheck, find, /etc/mnttab or any of that other stuff. stat(2) and fstat(2) return plenty enough information. You _can_ make things go faster by finding the correct root directory. main find_file_name ("/", your_fstat_structure) -- start from root directory -- with fstat(2) values. end procedure find_file_name (current_directory, file_fstat) if current_directory.file_stat = file_fstat then -- was FD this directory? putstring (current_directory) return fi for each file_entry in current_directory -- stat(2) each slot if file_entry.file_type = directory_type then -- recursively call directories find_file_name (current_directory + file_entry.file_name, file_fstat) elif file_entry.file_stat = file_fstat then -- else check to see if it is the file -- by checking st_ino and st_dev fields. putstring (current_directory + file_entry.file_name) -- and print the name if you found one. return fi end There you have it. All accessible files are checked, which should include yourown since you should be able to read you own directory. The ones you can't access can't be accessed :-(. st_ino and st_dev are all you need to compare to see if the files are the same ones. This should (once written in C or something) be as fast or faster than find(1) since find(1) has atleast this much work to do. - John. Disclaimer - I speak for myself. My boss pays me money when he wants me to speak for him.