【发布时间】:2016-04-11 03:26:22
【问题描述】:
我正在运行 CentOS Linux。
我使用专有文件系统创建如下目录:
$ mkdir fooDir
首先,我使用“ls -ldi”检查 inode 值:
$ ls -ldi
total 4
9223372036854783200 drwxrwxrwx 2 root root 4096 Jan 6 20:58 fooDir
然后,我确认 'stat' 报告了相同的 inode:
$ 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
但随后我切换到在 python 的交互式提示中运行并针对目录运行 om.stat:
$ 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)
>>>
Python 的 om.stat 返回的 inode 值与 stat 命令报告的值不匹配。
文件系统已将 inode 值 9223372036854783200 分配给目录“fooDir”,但 Python 的 om.stat 返回“-9223372036854768416”。
我可以将其视为有符号值并因此视为负号,但我很困惑为什么它是一个完全不同的值。
对这里发生的事情有任何想法吗?为什么 Python 的 os stat 返回错误的 inode 值? (或根据'stat'命令错误)
【问题讨论】:
-
您说您使用的是专有文件系统。也许这就是问题所在?这个 inode 数字看起来非常大。
-
这些数字相当于 mod 2**64
-
“我可以处理它把它当作一个有符号值,因此是负号,”。从有符号转换为无符号不仅仅是添加/删除符号前缀。如果您进行正确的转换,这两个数字是相同的。阅读其中一些资源:What is “2's Complement”? 和 wikipedia Two's complement page。
-
这发生在 python 2.x 中,因为在 python 3.8.6 中它可以正常工作
标签: python linux filesystems stat inode