Understanding the concept of Inodes
I am referring to the link about concepts of Inodes
I am confused on parts:
- 12 direct block pointers
- 1 single indirect block pointer
- 1 double indirect block pointer
- 1 triple indirect block pointer
Now the diagram says that each pointer is 32/64 bits.
- [Query]: Why and how are these values inferred? I mean why specifically have开发者_JAVA百科 only 32 or 64 bit pointers?
The diagram says, One data block {8 KB} for each pointer {4 bytes/8 bytes}
- [Query]: How does this actually work out? i.e. 8*1024 bytes / 8 bytes = 1024 bytes? What is the logic behind having a 8 bytes pointer for 8KB block?
Sample calculation of maximum file size
* Assume that there are 10 direct pointers to data blocks, 1 indirect pointer, 1 double indirect pointer, and 1 triple indirect pointer
* Assume that the size of the data blocks is 1024 bytes = 1Kb, i.e., BlockSize = 1Kb
* Assume that the block numbers are represented as 4 byte unsigned integers, i.e., BlockNumberSize = 4b
* Some data blocks are used as index blocks. They store 1024 bytes / 4 bytes/entry = 256 entries
* Maximum number of bytes addressed by 10 direct pointers is
= Number of direct pointers * Blocksize
= 10 * 1Kb
= 10Kb
* Maximum number of bytes addressed by single indirect pointer is
= NumberOfEntries * BlockSize
= (Blocksize / BlockNumberSize) * BlockSize
= (1Kb / 4b) * 1Kb
= 256 * 1Kb
= 256Kb
* Maximum number of bytes addressed by double indirect pointer is
= NumberOfEntries^2 * BlockSize
= (Blocksize / BlockNumberSize)^2 * BlockSize
= (1Kb / 4b)^2 * 1Kb
= (2^10 / 2^2)^2 * (2^10b)
= (2^8)^2 * (2^10)b
= (2^16) * (2^10)b
= 2^6 * 2^20 b
= 64 Mb
* Maximum number of bytes addressed by triple indirect pointer is
= NumberOfEntries^3 * BlockSize
= (Blocksize / BlockNumberSize)^3 * BlockSize
= (1Kb / 4b)^3 * 1Kb
= (2^10 / 2^2)^3 * (2^10b)
= (2^8)^3 * (2^10)b
= (2^24) * (2^10)b
= 2^4 * 2^30 b
= 16 Gb
* Maximum file size is 16Gb + 64Mb + 266Kb
The pointers referred to are disk block addresses - each pointer contains the information necessary to identify a block on disk. Since each disk block is at least 512 bytes (sometimes 4096 or 8192 bytes), using 32-bit addresses the disk can address up to 512 * 4 * 10243 = 2 TiB (Tebibytes - more commonly called Terabytes) assuming 1/2 KiB blocks; correspondingly larger sizes as the block size grows (so 32 TiB at 8 KiB block size). For an addressing scheme for larger disks, you would have to move to larger block sizes or larger disk addresses - hence 48-bit or 64-bit addresses might be plausible.
So, to answer Q1, 32-bits is a common size for lots of things. Very often, when 32 bits are no longer big enough, the next sensible size is 64 bits.
Answering Q2:
With 8 KiB data blocks, if the file is 96 KiB or smaller, then it uses 12 blocks or less on disk, and all those block addresses are stored directly in the inode itself.
When the file grows bigger, the disk driver allocates a single indirect block, and records that in the inode. When the driver needs to get a block, it reads the indirect block into memory, and then finds the address for the block it needs from the indirect block. Thus, it requires (nominally) two reads to get to the data, though of course the indirect tends to be cached in memory.
With an 8 KiB block size and 4-byte disk addresses, you can fit 2048 disk addresses in the single indirect block. So, for files from 96 KiB + 1 byte to 16 MiB or so, there is only a single indirect block.
If a file grows still bigger, then the driver allocates a double indirect block. Each pointer in the double indirect block points to a single indirect block. So, you can have 2048 more indirect blocks, each of which can effectively point at 16 MiB, leading to files of up to 32 GiB (approx) being storable.
If a file grows still larger, then the driver allocates a triple indirect block. Each of the 2048 pointers in a triple indirect block points to a double block. So, under the 32-bit addressing scheme with 32-bit addresses, files up to about 64 TiB could be addressed. Except that you've run out of disk addresses before that (32 TiB maximum because of the 32-bit addresses to 8 KiB blocks).
So, the inode structure can handle files bigger than 32-bit disk addresses can handle.
I'll leave it as an exercise for the reader to see how things change with 64-bit disk addresses.
Before giving the answers, you should understand how file system works:
Whenever a user or a program refers to a file by name, the operating system uses that name to look up the corresponding inode, which then enables the system to obtain the information it needs about the file to perform further operations. That is, a file name in a Unix-like operating system is merely an entry in a table with inode numbers, rather than being associated directly with a file (in contrast to other operating systems such as the Microsoft Windows systems). The inode numbers and their corresponding inodes are held in inode tables, which are stored in strategic locations in a filesystem, including near its beginning.
Answer for the first question is that bit space covers the total 32 or 64 bit. simply it makes 2^32 and it is large enough define the all these variables.Also, for further uses it has to know the size of the bits for operations.In your example they just defined in that way.
Second each pointer (size depends on your disk capacity) reference a data block(8KB on disk, disk has blocks) but keep in mind that unix file system has an hierarchical structure. A table that points many other tables and finally the last table point to the data block.
i offer you to go over this book, very useful to understand the Unix file system.
精彩评论