Questions about the ext2 filesystem.......

Questions about the ext2 filesystem.......

Post by Steven J. Hil » Sun, 09 Aug 1998 04:00:00



I apologize if this is the wrong group for this question. Just
direct me to the right place, thanks. The questions concerns
symbolic links. A file entry keeps track of how many symbolic links
are attached to it. Am I correct in assuming that it has no
information on where those links are located? I am trying to write
a little utility that takes a file and tells me if and where all
the links to it are located. Any help is greatly appreciated.

Steve

 
 
 

Questions about the ext2 filesystem.......

Post by Travis Geiselbrech » Sun, 09 Aug 1998 04:00:00


Well, actually the inode of the file only stores how many hard links are
pointing at it. It does not know how many symbolic links are pointing at it
at all. A symbolic link is a directory link to a inode that stores the
symlink path in the inode instead of a list of file blocks. It's up to the
layers above the filesystem to resolve it.

If you're talking about hard links, well, you're right. A hard link is just
a directory entry that happens to point at the same inode as another one.
The inode does store the number of hard links, but not which directory entry
points to it. To find all of the directory entries, you're probably going to
have to search the entire filesystem. :(

Travis Geiselbrecht


>I apologize if this is the wrong group for this question. Just
>direct me to the right place, thanks. The questions concerns
>symbolic links. A file entry keeps track of how many symbolic links
>are attached to it. Am I correct in assuming that it has no
>information on where those links are located? I am trying to write
>a little utility that takes a file and tells me if and where all
>the links to it are located. Any help is greatly appreciated.

>Steve


 
 
 

Questions about the ext2 filesystem.......

Post by Robert Nicho » Mon, 10 Aug 1998 04:00:00


Note: E-mailed *and* posted.



:I apologize if this is the wrong group for this question. Just
:direct me to the right place, thanks. The questions concerns
:symbolic links. A file entry keeps track of how many symbolic links
:are attached to it.

No.  There is nothing that keeps track of the number of symbolic links.
The st_nlink field in the stat structure counts only hard links.
Maintaining a count of symbolic links would be sort of like trying to
keep track of how many people have a record of your e-mail address.

: Am I correct in assuming that it has no
:information on where those links are located? I am trying to write
:a little utility that takes a file and tells me if and where all
:the links to it are located.

Good luck.  The only way to do it is to traverse the entire directory
tree starting from the root file system.  Also, keep in mind that if the
file system is exported, e.g. via NFS, the symlink might be on
another system.  Or, the symlink might be on a file system that is not
currently mounted, such as a floppy disk in someone's desk drawer.

--


PGP public key 1024/9A9C7955
Key fingerprint = 2F E5 82 F8 5D 06 A2 59  20 65 44 68 87 EC A7 D7

 
 
 

Questions about the ext2 filesystem.......

Post by bill davids » Tue, 11 Aug 1998 04:00:00




| I apologize if this is the wrong group for this question. Just
| direct me to the right place, thanks. The questions concerns
| symbolic links. A file entry keeps track of how many symbolic links
| are attached to it.

Stop. No it doesn't. There is a count of hard links in the inode. There
is nothing in the file entry. Either you don't understand the UNIX
filesystem model or you type even worse than I do ;-)

Hard links point to an inode. An inode counts the links. The inode
describes the file. Symbolic links contain a pathname, it may point to
a file, directory, device, pipe or be invalid, and nothing keeps track
of where slinks point. Slinks are only evaluated when used, and then
only in the forward lookup direction, with absolutely no back pointers
at all.

--

 "If I were a diplomat, in the best case I'd go hungry.  In the worst
  case, people would die."
                -- Robert Lipe

 
 
 

Questions about the ext2 filesystem.......

Post by Jürgen Exne » Tue, 11 Aug 1998 04:00:00



>I apologize if this is the wrong group for this question. Just
>direct me to the right place, thanks. The questions concerns
>symbolic links. A file entry keeps track of how many symbolic links
>are attached to it.

Actually that's not correct. The number of symbolic links pointing to a
specific file is not counted for anywhere. For hardlink however you are
right.

Quote:>Am I correct in assuming that it has no
>information on where those links are located? I am trying to write
>a little utility that takes a file and tells me if and where all
>the links to it are located. Any help is greatly appreciated.

To the best of my knowlegde you will have to do it the other way round (for
both, symbolic and hard links). Create your private cross-reference matrix
of files and where they point to.

jue
--
Jrgen Exner; jurgenex AT microsoft.com
Sorry for this anti-spam inconvenience

 
 
 

Questions about the ext2 filesystem.......

Post by Kurt Harder » Wed, 12 Aug 1998 04:00:00



> I apologize if this is the wrong group for this question. Just
> direct me to the right place, thanks. The questions concerns
> symbolic links. A file entry keeps track of how many symbolic links
> are attached to it. Am I correct in assuming that it has no
> information on where those links are located? I am trying to write
> a little utility that takes a file and tells me if and where all
> the links to it are located. Any help is greatly appreciated.

Hallo Steven,

there is no chance to find all symlinks pointing to a file. Assume a NFS
mounted filesystem from machine A mounted on machine B (/nfsmount/.....)
and a symlink on a local disk of B pointing to some file in
/nfsmount/... A will NEVER find out about this link, because its not
accessible for A.

Regards, Kurt

 
 
 

Questions about the ext2 filesystem.......

Post by bill davids » Wed, 12 Aug 1998 04:00:00




| >I apologize if this is the wrong group for this question. Just
| >direct me to the right place, thanks. The questions concerns
| >symbolic links. A file entry keeps track of how many symbolic links
| >are attached to it.
|
| Actually that's not correct. The number of symbolic links pointing to a
| specific file is not counted for anywhere. For hardlink however you are
| right.

Sorry, the number of hard links is not kept in "A file entry," it lives
in the inode. people have this vision of "a file" and "a link to the
file," but all directory links to an inode are equal.

--

 "If I were a diplomat, in the best case I'd go hungry.  In the worst
  case, people would die."
                -- Robert Lipe

 
 
 

Questions about the ext2 filesystem.......

Post by Michael Bro » Thu, 13 Aug 1998 04:00:00





>>Am I correct in assuming that it has no
>>information on where those links are located? I am trying to write
>>a little utility that takes a file and tells me if and where all
>>the links to it are located. Any help is greatly appreciated.

>To the best of my knowlegde you will have to do it the other way round (for
>both, symbolic and hard links). Create your private cross-reference matrix
>of files and where they point to.

Yada yada yada, only hard links work like this. As all the responses
mentioned... but searching for the hard links is relatively easy.

It can be done on the fly. Find the inode number of the file in question:

 518231 stuff

/home/michael/stuff

find <mount point of filesystem> -inum <inum of file> -print
prints all the files with the corresponding inode number.

HTH, M.

--
Michael ``M.'' Brown
Computer Science, University of Waterloo
SIGSIG -- signature too long (core dumped)

 
 
 

Questions about the ext2 filesystem.......

Post by Jürgen Exne » Thu, 13 Aug 1998 04:00:00






>>>Am I correct in assuming that it has no
>>>information on where those links are located? I am trying to write
>>>a little utility that takes a file and tells me if and where all
>>>the links to it are located. Any help is greatly appreciated.

>>To the best of my knowlegde you will have to do it the other way round
(for
>>both, symbolic and hard links). Create your private cross-reference matrix
>>of files and where they point to.
>Yada yada yada, only hard links work like this. As all the responses
>mentioned... but searching for the hard links is relatively easy.

>It can be done on the fly. Find the inode number of the file in question:

> 518231 stuff

>/home/michael/stuff

>find <mount point of filesystem> -inum <inum of file> -print
>prints all the files with the corresponding inode number.

Sure, you're right. I'm well aware of find and how to search for inodes.

However if I'm not mistaken the original poster was looking for a general
approach that will allow him to get all filenames for _every_ file.
Using your suggestion with find will require a cost of O(n^2).
Using some programming and your own cross-reference matrix can get this cost
of HD access down to a linear factor of O(n).

On a filesystem with let's say 5000 files this is the difference between 1
minute and 3 1/2 days!!!

jue
--
Jrgen Exner; jurgenex AT microsoft.com
Sorry for this anti-spam inconvenience

 
 
 

Questions about the ext2 filesystem.......

Post by bill davids » Sat, 15 Aug 1998 04:00:00



| It can be done on the fly. Find the inode number of the file in question:

|  518231 stuff

| /home/michael/stuff
|
| find <mount point of filesystem> -inum <inum of file> -print
| prints all the files with the corresponding inode number.

And you can use the -lname option on everything to find symbolic links,
although there's obviously no promise that you will find ALL slinks,
since some may be in filesystems not mounted on your system.

Oh, and you might use "df" as a convenient cheat to find that mount
point.

--

 "If I were a diplomat, in the best case I'd go hungry.  In the worst
  case, people would die."
                -- Robert Lipe

 
 
 

1. Questions about the ext2 filesystem.......

I apologize if this is the wrong group for this question. Just
direct me to the right place, thanks. The questions concerns
symbolic links. A file entry keeps track of how many symbolic links
are attached to it. Am I correct in assuming that it has no
information on where those links are located? I am trying to write
a little utility that takes a file and tells me if and where all
the links to it are located. Any help is greatly appreciated.

Steve

2. make: *** No rule to make target `config'. Stop.

3. Severe problems with ftape/Conner 420Mb

4. How come I can't mount an ext2 filesystem as ext2?

5. Virtual Terminal Help...

6. Filesystem Question - FAT/NTFS/EXT2?

7. router - 2.2 kernel

8. Linux ext2 filesystem question

9. Problem with 2nd SCSI drive and ext2 filesystem (oops)

10. Corrupted ext2 filesystem - retry

11. XWIN causes ext2 filesystem meltdown!

12. ext2 filesystem vs. xfs