Functions use st_dev and st_inode to get the file name and directory path out?


 
Thread Tools Search this Thread
Top Forums Programming Functions use st_dev and st_inode to get the file name and directory path out?
# 1  
Old 09-18-2005
Question Functions use st_dev and st_inode to get the file name and directory path out?

Hi.
A questions on unix sytem's directory inode and file inode. Unix have system function's that can get the following stat information out to user ( readdir, lstat.etc)
struct stat {
dev_t st_dev; /* device */
ino_t st_ino; /* inode */
mode_t st_mode; /* protection */
nlink_t st_nlink; /* number of hard links */
uid_t st_uid; /* user ID of owner */
gid_t st_gid; /* group ID of owner */
dev_t st_rdev; /* device type (if inode device) */ off_t st_size; /* total size, in bytes */
blksize_t st_blksize; /* blocksize for filesystem I/O */
blkcnt_t st_blocks; /* number of blocks allocated */
time_t st_atime; /* time of last access */
time_t st_mtime; /* time of last modification */
time_t st_ctime; /* time of last change */
};
I am wondering are there functions, I can pass in the st_dev and st_ino information and then get the file name and directory absolute path out, like a reversed function.

Thank you.
# 2  
Old 09-18-2005
No such function, you would need to search for it. And bear in mind that a file can have zero or more paths that point to it. There may be no answer or there may be many.
# 3  
Old 09-18-2005
"And bear in mind that a file can have zero or more paths that point to it."

More path means there are simbolic links, right? what is zero path mean? Thank you.
# 4  
Old 09-18-2005
Not soft links, hard links.
Code:
$ cd dir
$ touch a
$ ln a b
$ ln a c
$ ls -i1
288735 a
288735 b
288735 c
$

a, b, and c are all links to the same file. Same device number and same inode number.

As for zero links, when you remove the last hard link to a file, the file will not be freed if a program has it open. So a program can create a file and then unlink it. The file will disappear when the program exits. Very handy for temp files. It is a problem for newbie admins though. A file system will get full, they locate a large file, rm the large file, and then wonder why the space is still allocated. example
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

What is the difference ../directory path and ./directory path in ksh?

What is the difference ../directory path and ./directory path in ksh? (1 Reply)
Discussion started by: TestKing
1 Replies

2. UNIX for Beginners Questions & Answers

Convert Relative path to Absolute path, without changing directory to the file location.

Hello, I am creating a file with all the source folders included in my git branch, when i grep for the used source, i found source included as relative path instead of absolute path, how can convert relative path to absolute path without changing directory to that folder and using readlink -f ? ... (4 Replies)
Discussion started by: Sekhar419
4 Replies

3. UNIX for Beginners Questions & Answers

A file or directory in the path does not exist

I'm brand new to AIX and I looked up how to print this file and it was working but now I'm not able to do it all of a sudden. the file name is rom1.txt so this is what i wrote in the command line and I know I'm in the right directory. In bold is what I seem to be messing up with. prod @ root... (3 Replies)
Discussion started by: Dark0Prince
3 Replies

4. Shell Programming and Scripting

Sizeof a file from directory path in perl

Hai how to find size of a file?? ex : /home/kiran/pdk/sample/calibre this is a path In that I have to find size of a files in side a calibre(it is the folder) like .results or .summary (1 Reply)
Discussion started by: kiran425
1 Replies

5. Shell Programming and Scripting

print all filenames in directory with path to another file

hi, i have a directory at /path/unix with the following files 1.txt 2.txt 3.txt 4.txt I want to make another file called filenames.txt at a different location called /path/home. So, my output file would be /path/home/filenames.txt with contents /path/unix/1.txt... (1 Reply)
Discussion started by: jacobs.smith
1 Replies

6. Shell Programming and Scripting

How to remove a directory path in a file using sed

Hi, I want to remove a directory path from a file starting with the bracket using sed command. eg. (cd /man/abc/def ; \ aaaaa bbbb (cd /man/aaaa/aa; \ op. aaaaa bbbb The "(cd /man" is to be consideres as the start. I tries the below thing, but it didnt worked. Can anyone help.... (3 Replies)
Discussion started by: vdhingra123
3 Replies

7. UNIX for Advanced & Expert Users

Find exact path of a file/directory

Hello Folks, A wrapper takes an argument of file or directory name. I want to allow paths that reside within the current directory only. Can simply discard the paths like "/A" & "../" as they go outside the current by looking at the path beginning. How to validate this one: A/../../../b... (4 Replies)
Discussion started by: vibhor_agarwali
4 Replies

8. Shell Programming and Scripting

Retrieve directory path from full file path through sh

Hi, I have a file abcd.txt which has contents in the form of full path file names i.e. $home> vi abcd.txt /a/b/c/r1.txt /q/w/e/r2.txt /z/x/c/r3.txt Now I want to retrieve only the directory path name for each row i.e /a/b/c/ /q/w/e/ How to get the same through shell script?... (7 Replies)
Discussion started by: royzlife
7 Replies

9. Shell Programming and Scripting

Extract directory from a file path

Im trying to extract a directory from a path entered by the user Lets say the path is path=/home/bliss/files/myfile.txt i wanna extract "/home/bliss/files" from $path ... how can i do this? (4 Replies)
Discussion started by: mrudula009
4 Replies

10. Shell Programming and Scripting

Replace a Directory path with another in a file

Hi, I have abt 20-30 scripts using a directory structure. I have to replace a directory structure in a file for example "/i01/proc" with "/dwftp/scripts" using sed. The command :- cat filename | sed 's/"i01/proc"/"dwftp/scripts"' is not working. Can someone help me in this regard? ... (3 Replies)
Discussion started by: venkatajay_18
3 Replies
Login or Register to Ask a Question