[comp.unix.questions] Can you control the inode a file is assigned?

larry@focsys.uucp (Larry Williamson) (07/28/90)

Is there anyway to control the inode number a file is assigned,
assuming the inode is free?

For example...

If I think inode 1555 is not used in the root file system, and I want
to create a file say /etc/silly, can I do anything to ensure that
inode 1555 is used for this file?

I suppose one could create a temporary directory (on the appropriate
file system), start filling it with zero length files until the inode
of interest is assigned, then move that file to the desire place and
remove the temporary directory, but this sounds like too much of a
gross hack.

Any ideas?

-larry

mpledger@cti1.UUCP (Mark Pledger) (07/29/90)

You really can't do this under program control.  And now the reasons ...

The unix kernel determines when and how to assign inodes for newly created
files.  A (normally) 100 inode buffer is kept in the super block, which
is used to speed up inode allocation requests.  When a program requests a
new file to be created, the creat() of fopen() call results in an internal
kernal call to allocate a new inode block.  The kernel first  attempts to
get this new inode from the super block inode buffer.  If all is well the 
kernel returns the new inode block number.  If there is not any more inodes
available, the the kernel goes out and reads through the inode linked list
on disk, loading up the super block buffer with unused inode numbers.  After
which the kernel returns a new inode number from the freshly created buffer
list in the super block.

I also don't quite understand why you would want to do this in the first
place??

Mark Pledger
cti1!mpledger@uunet.uu.net
uunet!cti1!mpledger

guy@auspex.auspex.com (Guy Harris) (07/29/90)

>Is there anyway to control the inode number a file is assigned,
>assuming the inode is free?

No, not unless your vendor has added some special call to request that a
file be assigned a particular inode; standard UNIXes don't have any such
call.  The policy used to assign a given i-number to a file is file
system-dependent....