[cs631apue] filemode and blocksize question
bzhang41
bzhang41 at stevens.edu
Thu Sep 29 23:47:47 EDT 2016
Dear Prof.
I came up another 2 questions:
1)
When I try the sticky bit, sometimes there will be a `+` char followed
bu the 'x' permission. What is that ?
bzhang41 at smurf:~/ReadAndTest$ ls -dl dummydir
drw-rwxrwT 3 bzhang41 student 4 Sep 29 17:36 dummydir
bzhang41 at smurf:~/ReadAndTest$ chmod 1007 dummydir
bzhang41 at smurf:~/ReadAndTest$ ls -dl dummydir
d------rwt 3 bzhang41 student 4 Sep 29 17:36 dummydir
bzhang41 at smurf:~/ReadAndTest$ chmod 1000 dummydir
bzhang41 at smurf:~/ReadAndTest$ ls -dl dummydir
d--------T 3 bzhang41 student 4 Sep 29 17:36 dummydir
bzhang41 at smurf:~/ReadAndTest$ chmod 1001 dummydir
bzhang41 at smurf:~/ReadAndTest$ ls -dl dummydir
d--------t+ 3 bzhang41 student 4 Sep 29 17:36 dummydir
bzhang41 at smurf:~/ReadAndTest$ chmod 1771 dummydir
bzhang41 at smurf:~/ReadAndTest$ ls -dl dummydir
drwxrwx--t+ 3 bzhang41 student 4 Sep 29 17:36 dummydir
bzhang41 at smurf:~/ReadAndTest$
2) When I try to calculat the block size of the directory, I found the
result is different from the
result by using ls. So I assume the default block size in 'stat' is 512
bytes. I wrote a test program just
print out the
blkcnt_t st_blocks; /* number of disk blocks allocated */
of each file. And if we add the block size of each file together, it
doesn't equal to the number showed by `ls -l` in the system. Here are
the two examples, I want to know what's wrong here ?
bzhang41 at smurf:~/dirblocksizetest$ ls -l
total 12
-rwxr-xr-x+ 1 bzhang41 student 8548 Sep 29 23:27 a.out
-rw-r--r--+ 1 bzhang41 student 0 Sep 29 23:00 foo1
-rw-r--r--+ 1 bzhang41 student 26 Sep 29 23:00 foo2
-rw-r--r--+ 1 bzhang41 student 530 Sep 29 23:01 ls.c
bzhang41 at smurf:~/dirblocksizetest$ ../trygit/a.out ./a.out
the size of ./a.out:8548 and blocksize:18
bzhang41 at smurf:~/dirblocksizetest$ ../trygit/a.out ./foo1
the size of ./foo1:0 and blocksize:1
bzhang41 at smurf:~/dirblocksizetest$ ../trygit/a.out ./foo2
the size of ./foo2:26 and blocksize:2
bzhang41 at smurf:~/dirblocksizetest$ ../trygit/a.out ./ls.c
the size of ./ls.c:530 and blocksize:3
So in dirblocksizetest dir, there are 4 files, the total block size is
18+1+2+3=24, it seems like it is 2 times of the 12 showed by 'ls -l'.
But I tried another one. Just copy ls.c to lsdup.c, so there becomes 5
files in the dir. See below:
bzhang41 at smurf:~/dirblocksizetest$ cp ls.c lsdup.c
bzhang41 at smurf:~/dirblocksizetest$ ls -l
total 13
-rwxr-xr-x+ 1 bzhang41 student 8548 Sep 29 23:27 a.out
-rw-r--r--+ 1 bzhang41 student 0 Sep 29 23:00 foo1
-rw-r--r--+ 1 bzhang41 student 26 Sep 29 23:00 foo2
-rw-r--r--+ 1 bzhang41 student 530 Sep 29 23:01 ls.c
-rw-r--r--+ 1 bzhang41 student 530 Sep 29 23:33 lsdup.c
bzhang41 at smurf:~/dirblocksizetest$ ../trygit/a.out ./a.out
the size of the dir:8548 and blocksize:18
bzhang41 at smurf:~/dirblocksizetest$ ../trygit/a.out ./foo1
the size of the dir:0 and blocksize:1
bzhang41 at smurf:~/dirblocksizetest$ ../trygit/a.out ./foo2
the size of the dir:26 and blocksize:2
bzhang41 at smurf:~/dirblocksizetest$ ../trygit/a.out ./ls.c
the size of the dir:530 and blocksize:3
bzhang41 at smurf:~/dirblocksizetest$ ../trygit/a.out ./lsdup.c
the size of the dir:530 and blocksize:3
bzhang41 at smurf:~/dirblocksizetest$
This time 18+1+2+3+3= 27 != 13 and also !=13*2
Why?
Thanks
Bo
More information about the cs631apue
mailing list