fallenpegasus: amazon (Default)
[personal profile] fallenpegasus
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?

Date: 2008-01-08 10:18 pm (UTC)
vatine: Generated with some CL code and a hand-designed blackletter font (Default)
From: [personal profile] vatine
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.

Date: 2008-01-08 10:28 pm (UTC)
From: [identity profile] krow.livejournal.com
Why do I think you are trying to do something with a temporary file?

Date: 2008-01-14 11:45 pm (UTC)
From: [identity profile] lishablog.livejournal.com
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.

Profile

fallenpegasus: amazon (Default)
Mark Atwood

October 2017

S M T W T F S
1 234567
891011121314
1516 1718192021
22232425262728
293031    

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Oct. 21st, 2017 08:44 am
Powered by Dreamwidth Studios