tags:

views:

324

answers:

4

Why does /cdrom has the same inode -number than /sys/devices/platform/power in Ubuntu?

The following have the same inode number in my Ubuntu

./media/BACKUP_1/MISC
./cdrom
./sys/devices/platform/power

I get them by running the following at root

find . -inum 12 2> /dev/null


Reply to Leffler's answer

I run

stat cdrom

I get

  File: `cdrom' -> `media/cdrom'
  Size: 11              Blocks: 0          IO Block: 4096   symbolic link
Device: 801h/2049d      Inode: 12          Links: 1
Access: (0777/lrwxrwxrwx)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2009-08-03 04:25:35.000000000 +0300
Modify: 2009-08-03 04:19:05.000000000 +0300
Change: 2009-08-03 04:19:05.000000000 +0300

What does this info tell you?

Reply to Leffler's edit

Often, you can dissect the device number into a major and minor device number which is what 'ls -l' prints for a device.

This command ls -l cdrom gives me this

lrwxrwxrwx 1 root root 11 2009-08-03 04:19 cdrom -> media/cdrom

How can you see the major and minor device number from this?

+4  A: 

The devices are probably on different file systems - and it is the combination of the file system and the inode number that is unique.

If you use the stat() system call, the relevant fields are the st_ino and st_dev (and st_rdev identifies special devices).


The question was extended - asking what information can be gleaned from:

  File: `cdrom' -> `media/cdrom'
  Size: 11              Blocks: 0          IO Block: 4096   symbolic link
Device: 801h/2049d      Inode: 12          Links: 1

There are many things that can be gleaned from this. The key ones are that this symbolic link is on the file system with device number (st_rdev) of 0x0801 (or 2049), and the inode number is 12. Often, you can dissect the device number into a major and minor device number which is what 'ls -l' prints for a device. There's a decent chance (but I have not formally verified this) that the major device number is 8 and the minor device is 1 (based on the hex representation 0x0801).


The question was extended a second time:

This command ls -l cdrom gives me this

lrwxrwxrwx 1 root root 11 2009-08-03 04:19 cdrom -> media/cdrom

How can you see the major and minor device number from this?

The short answer is "you can't". The output from one of these might be appropriately informative:

ls -l media/cdrom
ls -lL cdrom

The device shown in the previous question (the output from the stat command) has, I suggested, major device 8 and minor device 1. You'd find that by running 'ls -l' on the device that is mounted as the file system for '.'. You might use 'df .' to find the name of the mounted device - there are probably other mechanisms that would work too.

Jonathan Leffler
Please, see my edit in the question for the output of stat.
Masi
Please, see the second edit in my question about the command `ls -l`.
Masi
+1  A: 

/sys/ is a separate filesystem, named sysfs. Inode numbers are only unique within a particular filesystem, not within the global file tree.

John Millikin
+2  A: 
Jörg W Mittag
Great answer! - For reference, one byte is 8 bits.
Masi
One Byte is the smallest addressable unit of memory. On some computers it is 8 Bits, on some it is 6, 7, 9 or 12. Some even have a variable Byte size that can be selected during boot, on some it can even be selected per instruction and some don't even have Bytes at all. (I know that there is some ISO specification out there which defines a Byte to be 8 Bits, but that is only applicable *within* that specification.)
Jörg W Mittag
There was a Cray for which the C compiler defined `sizeof(char) == sizeof(int) == sizeof(long)` and `CHAR_BITS == 32`. On that machine, a byte was 32-bits.
Jonathan Leffler
Interesting. In that case I would actually argue that the machine doesn't have bytes at all, because to me, a byte implies a unit smaller than a word. But that depends on exactly how you define "byte" and "word", which I won't be attempting to do :-)
Jörg W Mittag
A: 

To verify the Hex and Dec numbers, use:

$ echo "obase=16; 2049"|bc 
801
Masi