I'm running CentOS Linux.
I create a directory as follows using a proprietary filesystem:
$ mkdir fooDir
First, I check the inode value using "ls -ldi":
$ ls -ldi
total 4
9223372036854783200 drwxrwxrwx 2 root root 4096 Jan 6 20:58 fooDir
Then, I confirm same inode is being reported by 'stat':
$ stat /fooDir
File: `/fooDir'
Size: 4096 Blocks: 8 IO Block: 4096 directory
Device: 14h/20d Inode: 9223372036854783200 Links: 2
Access: (0777/drwxrwxrwx) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2016-01-06 20:58:13.000000000 +0000
Modify: 2016-01-06 20:58:13.000000000 +0000
Change: 2016-01-06 20:58:23.000000000 +0000
But then I switch over to run in python's interactive prompt and run om.stat against the directory:
$ python
Python 2.6.6 (r266:84292, Jun 18 2012, 14:18:47)
[GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.stat("/fooDir")
posix.stat_result(st_mode=16895, st_ino=-9223372036854768416, st_dev=20L, st_nlink=2, st_uid=0, st_gid=0, st_size=4096, st_atime=1452113893, st_mtime=1452113893, st_ctime=1452113903)
>>>
The inode value being returned by Python's om.stat does not match the value as reported by stat command.
The filesystem has assigned the inode value of 9223372036854783200 to the directory 'fooDir', however Python's om.stat is returning "-9223372036854768416".
I can handle that its treating it as a signed value and hence the negative sign, but I'm confused about why its a completely different value.
Any ideas on what's happening here? Why Python's os stat returning the wrong inode value? (or wrong according to 'stat' command)
I figured out the inode number was intended to be an unsigned long, but om.stat was interpreting as a negative number because the MSB was set.
So now that I know its supposed to be an unsigned, I can solve this issue as follows:
import ctypes
ctypes.c_ulong(os.stat(<dir here>).st_ino).value
An easier solution, without other dependencies:
if inode < 0 :
inode += 1 << 64