Home > Software design >  UNIX: Is the i-number same as the file descriptor?
UNIX: Is the i-number same as the file descriptor?

Time:10-02

Dennis Ritchie and Ken Thompson's paper UNIX Time-Sharing System mentions the following points

  1. About i-number: A directory entry contains only a name for the associated file and a pointer to the file itself. This pointer is an integer called the i-number (for index number) of the file
  2. About open and create system-calls: The returned value (of open and create) is called a file descriptor. It is a small integer used to identify the file in subsequent calls
  3. Purpose of open/create: The purpose of an open or create system call is to turn the path name given by the user into an i-number by searching the explicitly or implicitly named directories

Does this mean that the file descriptor is just the i-number of a file? Or am I missing something?

CodePudding user response:

A file descriptor in UNIX is basically just an index into the array of open files for the current process.

An inode number is an index into the inode table for the file system.

So they're basically just integers, indexes into an array, but they are indexes into completely different, unrelated arrays. So there is no connection between them.

CodePudding user response:

To add to Chris Dodd's answer, not only are inode numbers and file descriptor numbers not directly related, it wouldn't be practical for them to be.

Inode numbers are unique to each file system. Imagine if you opened fileA on a file system (say, /mnt) with inode number 100, and in the same process also opened fileB on another filesystem (say, /mnt2) which also happened to have inode number 100. What should the file descriptors be in that case?

  • Related