Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Can anyone tell me if this is true or false?

Does the inode of a file have the addresses of blocks containing the file's content?

Also for the permission command, there was a question asking that I have the right to change permissions for existing file, where the owner (r,w) g(r) condition. So I thought it's applicable for chmod 640 filename.txt and chmod u+rw g+r filename.txt, but apparently only the 640 is correct. Anyone know why the u+rw is not part of the answer?

share|improve this question

3 Answers 3

If I understand your question correctly then I would say it depends. An Inode typically can link to 12 data blocks, from wikipedia article:

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)

So as long as the file is < 12 data blocks * (the block size) then the Inode directly links to the data blocks. If the file is > 12 blocks then it will be using a combination of indirect blocks and double indirect blocks.

                     ss of inode structure

You can see how many blocks a file is consuming using the stat command:

sample stat command #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

sample stat command #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 question

As to your problem with chmod, I believe you need to separate your symbolic permissions (u+r g+r) with a comma, not a space, like so:

% chmod u+rw,g+r filename.txt

references

Here are some additional resources regarding inodes that you may want to read to gain a better understanding about inodes.

share|improve this answer

The inode normally stores pointers to the data blocks with direct pointers. If those do not suffice then indirect and doubly indirect pointers are used.

So arguably only for smaller files (12 blocks) does it actually have the addresses of the blocks with the file content.

share|improve this answer

Yes, the inode contains the list of the blocks "hosting" the file on the disk. Basically the inode contains all information about a file, except it's name - the name is "paired" together with inode-numbers in the directories (one type of so-called "special files").

You're a bit unclear on the 2nd question... Are you the owner of the file or not? If you're the owner; yes then you can change the permission of the file.

Depending on how the permissions are set prior (the umask), you may be right or you may be wrong. You add rw-permission to the owner and read permission to the group, but you don't remove any existing permission from others. Nor do you remove any execute-permissions. It may be better to use "=" instead of "+" (or "-"), as "=" sets the permission to something explicit.

A more correct way would be:

chmod u=rw,g=r,o= file

or alternatively:

chmod a=,u+rw,g+r file (Here you first set all rights to nothing)

Though in this case, it's probably simplest to just use:

chmod 640 file

With a bit of practice, it's not that difficult to calculate a permission in octal...

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.