7 . 9
S U M M A R Y
125
with the new name, it is first deleted and the old file is then renamed. Con-
sequently, a rename may touch as many blocks as a delete does, in addition
to all the blocks necessary to delete the old file name from the directory (and
indices) and then to reinsert the new name in the directory (and indices).
Change a File Size
In comparison to rename, changing the size of a file is a trivial operation. Ad-
justing the size of a file involves modifying the i-node of the file, any indirect
blocks written with the addresses of new data blocks, and the bitmap blocks
the allocation happened in. A large allocation that involves double-indirect
blocks may touch many blocks as part of the transaction. The number of
blocks that may be touched in a file creation is easy to calculate by know-
ing the allocation policy of BFS. First, the default allocation size for indirect
and double-indirect
block run
s is 4K. That is, the indirect block is 4K, and
the double-indirect block is 4K and points to 512 indirect
block run
s (each
of 4K). Knowing these numbers, the maximum number of blocks touched by
growing a file is
1 for the i-node
4 for the indirect block
4 for the first-level double-indirect block
512
4 for the second-level double-indirect blocks
2057 total blocks
This situation would occur if a program created a file, seeked to a file
position 9 GB out, and then wrote a byte. Alternatively, on a perfectly frag-
mented file system (i.e., every other disk block allocated), this would occur
with a 1 GB file. Both of these situations are extremely unlikely.
The Rest
The remaining operations decompose into one of the above operations. For
example, creating an index is equivalent to creating a directory in the in-
dex directory. Adding attributes to a file is equivalent to creating a file in
the attribute directory attached to the file. Because the other operations are
equivalent in nature to the preceding basic operations, we will not consider
them further.
7.9
Summary
Journaling is a technique borrowed from the database community and ap-
plied to file systems. A journaling file system prevents corruption of its data
structures by collecting modifications made during an operation and batching
those modifications into a single transaction that the file system records in
Practical File System Design:The Be File System
, Dominic Giampaolo
page 125