LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-30-2009, 10:00 AM   #1
manavendra
LQ Newbie
 
Registered: May 2009
Location: Bangalore, India
Distribution: Kubuntu 2.6.31-14
Posts: 19

Rep: Reputation: 2
Why do inode numbers start from 1 and not 0 ?


The C language convention counts array indices from 0. Why do inode numbers start from 1 and not 0 ?

I am currently reading "The design of the Unix Operating System" by Maurice J Bach and was struck on this question from the exercises.
 
Old 12-30-2009, 10:50 AM   #2
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hint: what's the value of "null"?
 
Old 12-30-2009, 11:00 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
Quote:
Why do inode numbers start from 1 and not 0 ?
Why should they start with 0?

Quote:
The C language convention counts array indices from 0.
So what?

Why does GRUB count from 0?

Why does hard disk device numbering start with "a" and "1"?

Seriously---there are many kinds of computer utilities and conventions--there is no standard that says that numbering should start with 0 or 1. Unfortunately, you simply have to remember what convetion is followed for each situation.
 
Old 12-30-2009, 12:16 PM   #4
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: Debian lenny, Slackware 12
Posts: 808

Rep: Reputation: 178Reputation: 178
Quote:
Originally Posted by pixellany View Post
Why does GRUB count from 0?

Why does hard disk device numbering start with "a" and "1"?

Seriously---there are many kinds of computer utilities and conventions
Correct. But it's interesting to note that if you use inode=0 to mean that we're not referencing an inode (yet), that makes it easy to initialize a directory block: just smear it with 0x00 bytes.
 
Old 12-31-2009, 03:04 PM   #5
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,259

Rep: Reputation: 1078Reputation: 1078Reputation: 1078Reputation: 1078Reputation: 1078Reputation: 1078Reputation: 1078Reputation: 1078
Throughout the "C" world, an all-zero value is used to indicate "nothing." For instance, a value of zero in some inode-number slot would indicate that there is no inode associated with that slot.

Many Linux and Unix systems actually use inode numbers now that are random.
 
Old 12-31-2009, 08:03 PM   #6
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: Debian lenny, Slackware 12
Posts: 808

Rep: Reputation: 178Reputation: 178
Quote:
Originally Posted by sundialsvcs View Post
Many Linux and Unix systems actually use inode numbers now that are random.
Citation needed.
 
Old 12-31-2009, 09:20 PM   #7
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
Quote:
Originally Posted by wje_lq View Post
Citation needed.
Why? (We're not writing peer-reviewed papers here......)
 
Old 01-01-2010, 12:24 AM   #8
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: Debian lenny, Slackware 12
Posts: 808

Rep: Reputation: 178Reputation: 178
Quote:
Originally Posted by pixellany View Post
Why? (We're not writing peer-reviewed papers here......)
Not to prove the point, but to provide more information. I'd like to read about this random inode number assignment idea in more detail. Why would they do this? (for example)
 
Old 01-01-2010, 04:00 AM   #9
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Quote:
Originally Posted by wje_lq View Post
Not to prove the point, but to provide more information. I'd like to read about this random inode number assignment idea in more detail. Why would they do this? (for example)
Security? One might derive some useful information from a file system based on the ordering of the inodes. I totally made that up, but it seems like something the government would do.
Kevin Barry
 
Old 01-01-2010, 06:36 AM   #10
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,245
Blog Entries: 15

Rep: Reputation: 233Reputation: 233Reputation: 233
maybe for quicker inode searching algorithms?
Code:
for (n = x; n; ++n) {
    ...
    n = n->next;   # something similar?
}
 
Old 01-07-2010, 06:33 AM   #11
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Wheezy (Fluxbox WM)
Posts: 1,363
Blog Entries: 52

Rep: Reputation: 353Reputation: 353Reputation: 353Reputation: 353
Quote:
Originally Posted by sundialsvcs View Post
Many Linux and Unix systems actually use inode numbers now that are random.
That might be true of a particular filesystem. But on Linux filesystems at least, many of the inode numbering schemes are simply an incrementing counter (exceptions including things like the implementation of FAT). The inode number does get hashed for lookup purposes.

Last edited by neonsignal; 01-07-2010 at 06:34 AM.
 
1 members found this post helpful.
  


Reply

Tags
array, index, inode


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
manipulating 64 bit numbers using 32 bit numbers. rajesh_b Programming 3 09-15-2006 09:03 AM
sequence of numbers, how to extract which numbers are missing jonlake Programming 13 06-26-2006 03:28 AM
inode numbers are same 2147483647 ruleman Linux - Networking 3 08-16-2005 09:05 PM
about inode eshwar_ind Programming 3 04-24-2004 02:39 PM
Adding numbers, break on non-numbers... Cruger Programming 1 03-22-2004 09:18 AM


All times are GMT -5. The time now is 03:16 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration