Reputation
891
Top tag
Next privilege 1,000 Rep.
See votes, expandable usercard
Badges
4 4
Newest
 Yearling
Impact
~77k people reached

  • 0 posts edited
  • 0 helpful flags
  • 3 votes cast
Oct
6
revised Why size reporting for directories is different than other files?
added points raised by questioning in other answers
Oct
6
comment Why size reporting for directories is different than other files?
@Utku, that's as best as I can understand it as well.
Oct
6
comment Why size reporting for directories is different than other files?
The GNU coreutils (8.23) info ls documentation is much clearer as it only talks about "disk allocation", without file size calculations. I suspect that it's just the documentation making up for Unix madness. ls -s should be showing the same info as stat --format=%b does, which has a field for the number of data blocks. Also check stat and you'll see there is a general case difference between allocated blocks and file size.
Oct
6
comment Why size reporting for directories is different than other files?
@Utku the strategy on how to allocate blocks is the filesystem's prerogative. In practice, most files grow within certain thresholds so the FS can eager-allocate data blocks in intervals. However, when the FS starts to get fragmented/full, it may choose to change strategies on how blocks are assigned, and/or FS tools may reallocate blocks differently. So it helps if the FS knows that your file is only "really" using 200 blocks out of its 400 assigned when the optimizer program needs to run. OTOH, directories should always be optimized, thus always at parity with their allocation.
Oct
6
comment Why size reporting for directories is different than other files?
Yes. Traditionally, inodes have blocklists, and ls -s shows the size of that list. Symlinks have zero blocks and thus will always report zero unles you use low-level tools to edit their data blocks. I don't think filesystems are necessarily bound by the blocklist metaphor. RAM-based filesystems, or database filesystems, or other FUSE stuff can "cheat" this somehow. And I'm pretty sure reiserfs has "small files support" which can store the data of a small file inside the inode block if it will fit. Don't know how reiser reports ls -s for small files though. zero? 1?
Oct
6
comment Why size reporting for directories is different than other files?
The "inode" is an entity separate from the data blocks. The inode can be thought of as metadata with a pointer to the blocks (usually a list). In the case of a symlink, there are NO blocks - the inode itself contains the filename being pointed to.
Oct
6
comment Why size reporting for directories is different than other files?
(if the above clarifies it, I'll incorporate it into the answer)
Oct
6
comment Why size reporting for directories is different than other files?
Directories, however, are special files and may be treated differently by the filesystem with regards to filesize / block allocation. Space allocated on the disk for a directory is probably also exclusively owned by the directory for optimization purposes (to allow a directory's contents to be read/written faster). So I would think of the difference NOT as a reporting difference, but as an allocation difference. The directory "owns" the whole block when created, a regular file, not necessarily so. Which would explain why directory size differs depending on the filesystem.
Oct
6
comment Why size reporting for directories is different than other files?
I would make a difference between filesize and allocated size. Filesystems may, at their discretion, use different techniques for allocating blocks - in general case the inode contains a "block list" pointing to the data blocks, some filesystems can store the file data in the inode's block itself, some filesystems can have the inode state a starting / ending block, some may split / allocate blocks between files, etc. In other words, there is no guarantee in the general case that the file "owns" the whole block. The only size "owned" by the file is the actual content (not the inode).
Oct
6
answered Why size reporting for directories is different than other files?
May
11
awarded  Yearling
Aug
4
comment how to set crontab PATH variable
bash -lc starts a login shell which sources your user's profile. This means that it uses the PATH set in ~/.bash_profile, ~/.profile, or ~/.bashrc... do you have the path set there? If so and it works ill update my answer for it
Aug
3
awarded  Editor
Aug
3
revised how to set crontab PATH variable
added tip to include your normal profile using bash -lc
Aug
3
answered how to set crontab PATH variable
May
11
awarded  Yearling
May
11
awarded  Yearling
Mar
10
answered Is copying the root folder an adequate form of backup?
Mar
10
awarded  Supporter
Aug
7
awarded  Good Answer