Performing File operations using File Inode number

This is a discussion on Performing File operations using File Inode number within the C Programming forums, part of the General Programming Boards category; Hi all, Is it possible to perform file I/O operations in Unix like open,read,write etc. using the file inode number? ...

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    22

    Performing File operations using File Inode number

    Hi all,
    Is it possible to perform file I/O operations in Unix like open,read,write etc. using the file inode number?

    Thanks

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Sure. But in what way are you wanting such a task to be performed? Are you desiring a function that takes an inode as an input and spits a FILE* or file descriptor as its output? You are going to have some work to do with the inode before having a useful handle of any sort.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I am 99% sure that there are no user-mode functions in Linux or Unix that take an inode as an input. There are ways (such as stat()) to find out which inode belongs to a particular file/directory, but that's it.

    Of course, inside the kernel, inodes are used for many purposes, because the kernel uses inodes instead of filenames to reference a particular file. Even FAT filesystems which do not natively have an inode, have a way to provide a "fake" inode in Linux, because the upper layers of the filesystem requires all filesystems to have something like an inode that is unique for each file. [I seem to remember that FAT uses the first cluster of the file as an inode, and since no two files can use the same cluser, there's no problem with that].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Registered User
    Join Date
    Aug 2008
    Posts
    22
    I want to use file inodes to open, read, write, seek files etc. This can be used for file copying. The reason why I asked whether these FILE I/O operations can be performed using Inode number instead of file names is that it might give better performance since inode numbers are unique.

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by rak1986 View Post
    I want to use file inodes to open, read, write, seek files etc. This can be used for file copying. The reason why I asked whether these FILE I/O operations can be performed using Inode number instead of file names is that it might give better performance since inode numbers are unique.
    And my answer is that you can not do this (from user-mode, at the very least). In the whole scheme of things, finding the file is generally a small portion of the time needed to copy the file. If the file is bigger than a few kilobytes, it is almost certainly going to take 100x times longer to reach the files physical location on the hard-disk, than it takes to find the file within the directory. The inode would have to be validated (you wouldn't be allowed to just pass in any random number), so reading the directory for the relevant file would still be needed (even if that process also is about 100x slower than parsing through the directory to find the name).

    So you are shooting mosquito's with a cannon, really.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  2. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 07:51 PM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21