mangaluve wrote:Thanks!
Yeah I also thought that cluster_size should be replaced by sector_size, then the code makes much more sense. Is a cluster an entry in the fat-table, or a chunk in the data area? (terminology question). Is this correct?:
The FAT-table is a table of 4-bytes entries. Each entry points to a new entry (or it could be marked as free / EOF and so on). After the FAT table comes the data area, which is divided into clusters? Each entry in the fat-table corresponds to one of these data-chunks?
A cluster is a run of continuous sectors in the data area. Each entry in the FAT table corresponds to one cluster in the data area (hence, entries in the FAT table are sometimes also called clusters). After the FAT comes the root directory, and after the root directory comes the data area. The first sector of the data area corresponds to sector zero of cluster two.
mangaluve wrote:
And why does this limit the file size to 4 GB? The FAT-table entries are 28 bits, so I can have 2^28 of them. Each of them corresponds to a chunk of, say, 512 bytes in the data area. That would give me, if the entire disk is used for one large file, to 2^(28+37) bytes and not 4 GB?
The four gigabyte limitation comes from the file size field of the directory entry, which is thirty-two bits, and thus cannot store a value larger than 2^32-1. This field stores the length of the file measures in bytes, not in clusters. Think about it: if the file length was measured in clusters, how would you store how many bytes are there in a partially-filled last cluster?