diff options
Diffstat (limited to 'src/Core/FatFormatter.cpp')
-rw-r--r-- | src/Core/FatFormatter.cpp | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/Core/FatFormatter.cpp b/src/Core/FatFormatter.cpp index fa327837..c8115f9b 100644 --- a/src/Core/FatFormatter.cpp +++ b/src/Core/FatFormatter.cpp @@ -122,61 +122,61 @@ namespace VeraCrypt do { ft->reserved++; fatsecs = ft->num_sectors - ft->reserved; ft->size_root_dir = ft->cluster_size * ft->sector_size; ft->cluster_count = (int) (((int64) fatsecs * ft->sector_size) / (ft->cluster_size * ft->sector_size)); ft->fat_length = (ft->cluster_count * 4 + ft->sector_size - 1) / ft->sector_size; // Align data area on TC_MAX_VOLUME_SECTOR_SIZE } while (ft->sector_size == TC_SECTOR_SIZE_LEGACY && (ft->reserved * ft->sector_size + ft->fat_length * ft->fats * ft->sector_size) % TC_MAX_VOLUME_SECTOR_SIZE != 0); } ft->cluster_count -= ft->fat_length * ft->fats / ft->cluster_size; if (ft->num_sectors >= 65536 || ft->size_fat == 32) { ft->sectors = 0; ft->total_sect = ft->num_sectors; } else { ft->sectors = (uint16) ft->num_sectors; ft->total_sect = 0; } } - static void PutBoot (fatparams * ft, byte *boot, uint32 volumeId) + static void PutBoot (fatparams * ft, uint8 *boot, uint32 volumeId) { int cnt = 0; boot[cnt++] = 0xeb; /* boot jump */ boot[cnt++] = (ft->size_fat == 32)? 0x58: 0x3c; boot[cnt++] = 0x90; memcpy (boot + cnt, "MSDOS5.0", 8); /* system id */ cnt += 8; *(int16 *)(boot + cnt) = Endian::Little (ft->sector_size); /* bytes per sector */ cnt += 2; boot[cnt++] = (int8) ft->cluster_size; /* sectors per cluster */ *(int16 *)(boot + cnt) = Endian::Little (ft->reserved); /* reserved sectors */ cnt += 2; boot[cnt++] = (int8) ft->fats; /* 2 fats */ if(ft->size_fat == 32) { boot[cnt++] = 0x00; boot[cnt++] = 0x00; } else { *(int16 *)(boot + cnt) = Endian::Little (ft->dir_entries); /* 512 root entries */ cnt += 2; } *(int16 *)(boot + cnt) = Endian::Little (ft->sectors); /* # sectors */ cnt += 2; boot[cnt++] = (int8) ft->media; /* media byte */ @@ -217,170 +217,170 @@ namespace VeraCrypt boot[cnt++] = 0x00; memset(boot+cnt, 0, 12); cnt+=12; /* Reserved */ } boot[cnt++] = 0x00; /* drive number */ // FIXED 80 > 00 boot[cnt++] = 0x00; /* reserved */ boot[cnt++] = 0x29; /* boot sig */ *(int32 *)(boot + cnt) = volumeId; cnt += 4; memcpy (boot + cnt, ft->volume_name, 11); /* vol title */ cnt += 11; switch(ft->size_fat) /* filesystem type */ { case 12: memcpy (boot + cnt, "FAT12 ", 8); break; case 16: memcpy (boot + cnt, "FAT16 ", 8); break; case 32: memcpy (boot + cnt, "FAT32 ", 8); break; } cnt += 8; memset (boot + cnt, 0, ft->size_fat==32 ? 420:448); /* boot code */ cnt += ft->size_fat==32 ? 420:448; boot[cnt++] = 0x55; boot[cnt++] = 0xaa; /* boot sig */ } /* FAT32 FSInfo */ - static void PutFSInfo (byte *sector, fatparams *ft) + static void PutFSInfo (uint8 *sector, fatparams *ft) { memset (sector, 0, ft->sector_size); sector[3] = 0x41; /* LeadSig */ sector[2] = 0x61; sector[1] = 0x52; sector[0] = 0x52; sector[484+3] = 0x61; /* StrucSig */ sector[484+2] = 0x41; sector[484+1] = 0x72; sector[484+0] = 0x72; // Free cluster count *(uint32 *)(sector + 488) = Endian::Little (ft->cluster_count - ft->size_root_dir / ft->sector_size / ft->cluster_size); // Next free cluster *(uint32 *)(sector + 492) = Endian::Little ((uint32) 2); sector[508+3] = 0xaa; /* TrailSig */ sector[508+2] = 0x55; sector[508+1] = 0x00; sector[508+0] = 0x00; } void FatFormatter::Format (WriteSectorCallback &writeSector, uint64 deviceSize, uint32 clusterSize, uint32 sectorSize) { fatparams fatParams; #if TC_MAX_VOLUME_SECTOR_SIZE > 0xFFFF #error TC_MAX_VOLUME_SECTOR_SIZE > 0xFFFF #endif fatParams.sector_size = (uint16) sectorSize; if (deviceSize / fatParams.sector_size > 0xffffFFFF) throw ParameterIncorrect (SRC_POS); fatParams.num_sectors = (uint32) (deviceSize / fatParams.sector_size); fatParams.cluster_size = clusterSize / fatParams.sector_size; memcpy (fatParams.volume_name, "NO NAME ", 11); GetFatParams (&fatParams); fatparams *ft = &fatParams; SecureBuffer sector (ft->sector_size); uint32 sectorNumber = 0; /* Write the data area */ sector.Zero(); uint32 volumeId; - RandomNumberGenerator::GetDataFast (BufferPtr ((byte *) &volumeId, sizeof (volumeId))); + RandomNumberGenerator::GetDataFast (BufferPtr ((uint8 *) &volumeId, sizeof (volumeId))); - PutBoot (ft, (byte *) sector, volumeId); + PutBoot (ft, (uint8 *) sector, volumeId); writeSector (sector); ++sectorNumber; /* fat32 boot area */ if (ft->size_fat == 32) { /* fsinfo */ - PutFSInfo((byte *) sector, ft); + PutFSInfo((uint8 *) sector, ft); writeSector (sector); ++sectorNumber; /* reserved */ while (sectorNumber < 6) { sector.Zero(); sector[508+3] = 0xaa; /* TrailSig */ sector[508+2] = 0x55; writeSector (sector); ++sectorNumber; } /* bootsector backup */ sector.Zero(); - PutBoot (ft, (byte *) sector, volumeId); + PutBoot (ft, (uint8 *) sector, volumeId); writeSector (sector); ++sectorNumber; - PutFSInfo((byte *) sector, ft); + PutFSInfo((uint8 *) sector, ft); writeSector (sector); ++sectorNumber; } /* reserved */ while (sectorNumber < (uint32)ft->reserved) { sector.Zero(); writeSector (sector); ++sectorNumber; } /* write fat */ for (uint32 x = 1; x <= ft->fats; x++) { for (uint32 n = 0; n < ft->fat_length; n++) { sector.Zero(); if (n == 0) { - byte fat_sig[12]; + uint8 fat_sig[12]; if (ft->size_fat == 32) { - fat_sig[0] = (byte) ft->media; + fat_sig[0] = (uint8) ft->media; fat_sig[1] = fat_sig[2] = 0xff; fat_sig[3] = 0x0f; fat_sig[4] = fat_sig[5] = fat_sig[6] = 0xff; fat_sig[7] = 0x0f; fat_sig[8] = fat_sig[9] = fat_sig[10] = 0xff; fat_sig[11] = 0x0f; memcpy (sector, fat_sig, 12); } else if (ft->size_fat == 16) { - fat_sig[0] = (byte) ft->media; + fat_sig[0] = (uint8) ft->media; fat_sig[1] = 0xff; fat_sig[2] = 0xff; fat_sig[3] = 0xff; memcpy (sector, fat_sig, 4); } else if (ft->size_fat == 12) { - fat_sig[0] = (byte) ft->media; + fat_sig[0] = (uint8) ft->media; fat_sig[1] = 0xff; fat_sig[2] = 0xff; fat_sig[3] = 0x00; memcpy (sector, fat_sig, 4); } } if (!writeSector (sector)) return; } } /* write rootdir */ for (uint32 x = 0; x < ft->size_root_dir / ft->sector_size; x++) { sector.Zero(); if (!writeSector (sector)) return; } } } |