Lines Matching refs:boot
48 readboot(int dosfs, struct bootblock *boot) in readboot() argument
65 memset(boot, 0, sizeof *boot); in readboot()
66 boot->ValidFat = -1; in readboot()
71 boot->bpbBytesPerSec = block[11] + (block[12] << 8); in readboot()
72 if (boot->bpbBytesPerSec < DOSBOOTBLOCKSIZE_REAL || in readboot()
73 boot->bpbBytesPerSec > DOSBOOTBLOCKSIZE || in readboot()
74 !powerof2(boot->bpbBytesPerSec)) { in readboot()
75 pfatal("Invalid sector size: %u", boot->bpbBytesPerSec); in readboot()
80 boot->bpbSecPerClust = block[13]; in readboot()
81 if (boot->bpbSecPerClust == 0 || !powerof2(boot->bpbSecPerClust)) { in readboot()
82 pfatal("Invalid cluster size: %u", boot->bpbSecPerClust); in readboot()
87 boot->bpbResSectors = block[14] + (block[15] << 8); in readboot()
88 if (boot->bpbResSectors < 1) { in readboot()
90 boot->bpbResSectors); in readboot()
95 boot->bpbFATs = block[16]; in readboot()
96 if (boot->bpbFATs == 0) { in readboot()
97 pfatal("Invalid number of FATs: %u", boot->bpbFATs); in readboot()
102 boot->bpbRootDirEnts = block[17] + (block[18] << 8); in readboot()
103 if (!boot->bpbRootDirEnts) { in readboot()
105 boot->flags |= FAT32; in readboot()
109 boot->bpbSectors = block[19] + (block[20] << 8); in readboot()
110 if (boot->bpbSectors != 0 && (boot->flags & FAT32)) { in readboot()
112 boot->bpbSectors); in readboot()
117 boot->bpbMedia = block[21]; in readboot()
120 boot->bpbFATsmall = block[22] + (block[23] << 8); in readboot()
121 if (boot->bpbFATsmall != 0 && (boot->flags & FAT32)) { in readboot()
123 boot->bpbFATsmall); in readboot()
128 boot->SecPerTrack = block[24] + (block[25] << 8); in readboot()
129 boot->bpbHeads = block[26] + (block[27] << 8); in readboot()
132 boot->bpbHiddenSecs = block[28] + (block[29] << 8) + in readboot()
136 boot->bpbHugeSectors = block[32] + (block[33] << 8) + in readboot()
138 if (boot->bpbHugeSectors == 0) { in readboot()
139 if (boot->flags & FAT32) { in readboot()
142 } else if (boot->bpbSectors == 0) { in readboot()
146 boot->NumSectors = boot->bpbSectors; in readboot()
148 if (boot->bpbSectors != 0) { in readboot()
152 boot->NumSectors = boot->bpbHugeSectors; in readboot()
155 if (boot->flags & FAT32) { in readboot()
163 boot->FATsecs = block[36] + (block[37] << 8) in readboot()
167 boot->ValidFat = block[40] & 0x0f; in readboot()
181 boot->bpbRootClust = block[44] + (block[45] << 8) in readboot()
185 boot->bpbFSInfo = block[48] + (block[49] << 8); in readboot()
188 boot->bpbBackup = block[50] + (block[51] << 8); in readboot()
191 if (boot->bpbFSInfo == 0) { in readboot()
202 if (lseek(dosfs, boot->bpbFSInfo * boot->bpbBytesPerSec, in readboot()
203 SEEK_SET) != boot->bpbFSInfo * boot->bpbBytesPerSec in readboot()
228 if (lseek(dosfs, boot->bpbFSInfo * in readboot()
229 boot->bpbBytesPerSec, SEEK_SET) in readboot()
230 != boot->bpbFSInfo * boot->bpbBytesPerSec in readboot()
238 boot->bpbFSInfo = 0; in readboot()
241 boot->FSFree = fsinfo[0x1e8] + (fsinfo[0x1e9] << 8) in readboot()
244 boot->FSNext = fsinfo[0x1ec] + (fsinfo[0x1ed] << 8) in readboot()
250 boot->FATsecs = boot->bpbFATsmall; in readboot()
253 if (boot->FATsecs < 1 || boot->FATsecs > UINT32_MAX / boot->bpbFATs) { in readboot()
255 boot->bpbFATs, (size_t)boot->FATsecs); in readboot()
259 boot->FirstCluster = (boot->bpbRootDirEnts * 32 + in readboot()
260 boot->bpbBytesPerSec - 1) / boot->bpbBytesPerSec + in readboot()
261 boot->bpbResSectors + boot->bpbFATs * boot->FATsecs; in readboot()
263 if (boot->FirstCluster + boot->bpbSecPerClust > boot->NumSectors) { in readboot()
265 boot->FirstCluster); in readboot()
273 boot->NumClusters = in readboot()
274 (boot->NumSectors - boot->FirstCluster) / boot->bpbSecPerClust; in readboot()
276 if (boot->flags & FAT32) { in readboot()
277 if (boot->NumClusters > (CLUST_RSRVD & CLUST32_MASK)) { in readboot()
279 boot->NumClusters); in readboot()
282 if (boot->NumClusters < (CLUST_RSRVD & CLUST16_MASK)) { in readboot()
284 boot->NumClusters); in readboot()
287 boot->ClustMask = CLUST32_MASK; in readboot()
289 if (boot->bpbRootClust < CLUST_FIRST || in readboot()
290 boot->bpbRootClust >= boot->NumClusters) { in readboot()
292 boot->bpbRootClust); in readboot()
295 } else if (boot->NumClusters < (CLUST_RSRVD&CLUST12_MASK)) { in readboot()
296 boot->ClustMask = CLUST12_MASK; in readboot()
297 } else if (boot->NumClusters < (CLUST_RSRVD&CLUST16_MASK)) { in readboot()
298 boot->ClustMask = CLUST16_MASK; in readboot()
301 boot->NumClusters); in readboot()
305 switch (boot->ClustMask) { in readboot()
307 boot->NumFatEntries = (boot->FATsecs * boot->bpbBytesPerSec) / 4; in readboot()
310 boot->NumFatEntries = (boot->FATsecs * boot->bpbBytesPerSec) / 2; in readboot()
313 boot->NumFatEntries = (boot->FATsecs * boot->bpbBytesPerSec * 2) / 3; in readboot()
317 if (boot->NumFatEntries < boot->NumClusters) { in readboot()
319 boot->NumClusters, boot->FATsecs); in readboot()
328 boot->NumClusters += CLUST_FIRST; in readboot()
330 boot->ClusterSize = boot->bpbBytesPerSec * boot->bpbSecPerClust; in readboot()
332 boot->NumFiles = 1; in readboot()
333 boot->NumFree = 0; in readboot()
339 writefsinfo(int dosfs, struct bootblock *boot) in writefsinfo() argument
343 if (lseek(dosfs, boot->bpbFSInfo * boot->bpbBytesPerSec, SEEK_SET) in writefsinfo()
344 != boot->bpbFSInfo * boot->bpbBytesPerSec in writefsinfo()
349 fsinfo[0x1e8] = (u_char)boot->FSFree; in writefsinfo()
350 fsinfo[0x1e9] = (u_char)(boot->FSFree >> 8); in writefsinfo()
351 fsinfo[0x1ea] = (u_char)(boot->FSFree >> 16); in writefsinfo()
352 fsinfo[0x1eb] = (u_char)(boot->FSFree >> 24); in writefsinfo()
353 fsinfo[0x1ec] = (u_char)boot->FSNext; in writefsinfo()
354 fsinfo[0x1ed] = (u_char)(boot->FSNext >> 8); in writefsinfo()
355 fsinfo[0x1ee] = (u_char)(boot->FSNext >> 16); in writefsinfo()
356 fsinfo[0x1ef] = (u_char)(boot->FSNext >> 24); in writefsinfo()
357 if (lseek(dosfs, boot->bpbFSInfo * boot->bpbBytesPerSec, SEEK_SET) in writefsinfo()
358 != boot->bpbFSInfo * boot->bpbBytesPerSec in writefsinfo()