?

Log in

No account? Create an account
entries friends calendar profile My Website Previous Previous Next Next
Mark Atwood
fallenpegasus
fallenpegasus
Dear Lazyweb. Open by inode.
For the past twenty years, I've always assumed that, given knowledge of a file's inode number, there was some efficient way to open(2) that file by inode instead of name, and I've just never felt the need to use it.

Now I feel the desire to do that, and cannot find how. Searching google for "open by inode" just gives me references to stuff on how to implement Linux VFS, and/or how to open a file from inside kernel space, not from user space.

The openat(2) looks like a half-assed way to get some but not all of the same optimization.

So, is there a way to "open by inode" from user space, and how do I do it?

Tags: , ,
Current Location: IBM, Rochester MN

3 comments or Leave a comment
Comments
From: vatine Date: January 8th, 2008 10:18 pm (UTC) (Link)
As far as I am aware, there is no convenient way of opening a file by inode from unix userspace. There might, possibly, be *ux-specific ways of doing it, depening on *ux, but your best bet would probably be HURD.
krow From: krow Date: January 8th, 2008 10:28 pm (UTC) (Link)
Why do I think you are trying to do something with a temporary file?
lishablog From: lishablog Date: January 14th, 2008 11:45 pm (UTC) (Link)
An answer from my partner, M:

Answer 1: No, because inodes are specific to a file system (ie are handled differently in different file systsms). The way open in Unix is designed is that it transforms a name into a handle. An inode may or may not have a name. (You open a file, write to it, and then delete it. It's still on the disk. It still has an inode. It does not have any name.)

There are ways to do close things depending on what you need to do really. Do you want to bypass the time it takes to do name resolving? Do you want to make sure you access the same handle you opened before?

To use the same handle you can use dup(2). For bypassing the time it takes to do name resolving, it would depend on your intended end and the filesystem you are using.

Answer 2: There are some kernel hacks which will allow you to open by inode for specific file systems, but because different file systems deal with inodes differently, there is no one-size-fits-all solution to this issue. These kernel patches may give you what you want, but at a cost of causing possible other problems.

M recommends looking at what your goal is and finding another way to deal with it.
3 comments or Leave a comment