Search code examples
ubuntuinode

To understand the same inode numbers for different objects in Ubuntu


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?


Solution

  • 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.