
谁能告诉我这是真的还是假的?
文件的索引节点是否具有包含文件内容的块的地址?
另外对于权限命令,有一个问题询问我是否有权更改现有文件的权限,其中所有者 (r,w) g(r) 条件。所以我认为它适用于chmod 640 filename.txt
和chmod u+rw g+r filename.txt
,但显然只有 640 是正确的。有人知道为什么 u+rw 不是答案的一部分吗?
答案1
如果我正确理解你的问题,那么我会说这要看情况。一个 Inode 通常可以链接到 12 个数据块,来自维基百科文章:
In the past, the structure may have consisted of eleven or thirteen
pointers, but most modern file systems use fifteen pointers. These
pointers consist of (assuming 15 pointers in the inode):
- Twelve pointers that directly point to blocks of the file's data
(direct pointers)
- One singly indirect pointer (a pointer that points to a block of
pointers that then point to blocks of the file's data)
- One doubly indirect pointer (a pointer that points to a block of
pointers that point to other blocks of pointers that then point to
blocks of the file's data)
- One triply indirect pointer (a pointer that points to a block of
pointers that point to other blocks of pointers that point to other
blocks of pointers that then point to blocks of the file's data)
因此,只要文件 < 12 个数据块 *(块大小),那么 Inode 就会直接链接到数据块。如果文件> 12 个块,则它将使用间接块和双间接块的组合。
您可以使用以下命令查看文件消耗了多少块stat
:
示例 stat 命令 #1
% stat /bin/ls
File: `/bin/ls'
Size: 117144 Blocks: 232 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 2496176 Links: 1
Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2013-04-17 16:24:20.593606056 -0400
Modify: 2010-11-03 07:43:02.000000000 -0400
Change: 2011-09-09 20:25:22.133239242 -0400
示例 stat 命令 #2
% stat /etc/httpd/conf/httpd.conf
File: `/etc/httpd/conf/httpd.conf'
Size: 34417 Blocks: 72 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 3147109 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2012-09-26 21:04:47.303641015 -0400
Modify: 2010-10-27 06:01:44.000000000 -0400
Change: 2010-12-18 19:30:00.719999998 -0500
chmod 问题
至于您的问题chmod
,我相信您需要用逗号而不是空格分隔符号权限(u + r g + r),如下所示:
% chmod u+rw,g+r filename.txt
参考
以下是一些有关 inode 的其他资源,您可能需要阅读这些资源,以更好地了解 inode。
答案2
索引节点通常使用直接指针存储指向数据块的指针。如果这些还不够,则使用间接和双重间接指针。
因此,可以说仅适用于较小的文件(12 个块)有包含文件内容的块的地址。
答案3
是的,索引节点包含磁盘上“托管”文件的块列表。基本上,索引节点包含有关文件的所有信息,除了它的名称 - 该名称与目录中的索引节点号“配对”在一起(一种所谓的“特殊文件”)。
你对第二个问题有点不清楚......你是文件的所有者吗?如果您是业主;是的,那么您可以更改文件的权限。
根据之前设置权限的方式(umask),您可能是对的,也可能是错的。你添加所有者的 rw 权限和组的读取权限,但您不删除任何现存的他人的许可。您也不会删除任何执行权限。最好使用“=”而不是“+”(或“-”),因为“=”将权限设置为明确的内容。
更正确的方法是:
chmod u=rw,g=r,o= 文件
或者:
chmod a=,u+rw,g+r file (这里首先将所有权限设置为空)
尽管在这种情况下,最简单的方法可能是使用:
chmod 640 文件
通过一些练习,计算八进制的权限并不困难......