Hi,
is there a way to retrieve a file’s path by inode number? Basically
the opposite of:
File.stat("/tmp/test").ino
=> 2178494
Background: I want to track files in a database, and want to keep
track of them even when they’re moved or renamed.
Apple is doing something similar on MacOS with Aliases. Internally, a
path and a fileID (=inode) is stored. When an alias is to be
resolved, it first tries to find it by path and falls back to
locating it by fileID.
Timo
On Jul 4, 2006, at 12:13 PM, Timo H. wrote:
Apple is doing something similar on MacOS with Aliases. Internally,
a path and a fileID (=inode) is stored. When an alias is to be
resolved, it first tries to find it by path and falls back to
locating it by fileID.
Timo
No. File paths are not associated with the i-node data structure in
an inode based fs. (An inode does not know the file name, only the
associated blocks). The file name is stored in the directory entry.
You’d have to search every directory entry on disk to see if it’s
inode was the one you were trying to keep track of.
On Jul 4, 2006, at 9:13 AM, Timo H. wrote:
Hi,
is there a way to retrieve a file’s path by inode number? Basically
the opposite of:
In principle, this is may be a bad idea. To start with, in nx
filesystems, a file can have lots of different pathnames, via hard
and soft links. -Tim
2006/7/4, Tim B. [email protected]:
and soft links. -Tim
Also, these file systems store only forward mappings, i.e. from file
name to inode number but not the reverse. So retrieving a file name
from an inode number basically means scanning the complete file system
and checking each file’s inode number. Definitively something that
does not fall into the category “efficient”.
Kind regards
robert
On 04/07/06, Tim B. [email protected] wrote:
In principle, this is may be a bad idea. To start with, in nx
filesystems, a file can have lots of different pathnames, via hard
and soft links. -Tim
Perhaps that’s a good solution to the problem (‘to keep
track of them even when they’re moved or renamed’): make a hard link.
% echo Hello > foo
% ln foo bar
% cat bar
Hello
% mv foo baz
cat: foo: No such file or directory
% cat bar
Hello
% rm baz
% cat bar
Hello
Paul.
Also, these file systems store only forward mappings, i.e. from file
name to inode number but not the reverse. So retrieving a file name
from an inode number basically means scanning the complete file system
and checking each file’s inode number. Definitively something that
does not fall into the category “efficient”.
Actually, when Linux crashes, it might store orphaned files in the
lost+found directory with the filename listed as the original inode of
the file. That’s why it’d be helpful to have that in Ruby.
Cody
On Fri, Aug 19, 2011 at 5:22 PM, Cody F. [email protected] wrote:
Also, these file systems store only forward mappings, i.e. from file
name to inode number but not the reverse. So retrieving a file name
from an inode number basically means scanning the complete file system
and checking each file’s inode number. Definitively something that
does not fall into the category “efficient”.
Actually, when Linux crashes, it might store orphaned files in the
lost+found directory with the filename listed as the original inode of
the file. That’s why it’d be helpful to have that in Ruby.
Now you just have to explain where that information should come from…
Cheers
robert