diff options
author | Stef Walter <stef@thewalter.net> | 2005-08-25 19:09:37 +0000 |
---|---|---|
committer | Stef Walter <stef@thewalter.net> | 2005-08-25 19:09:37 +0000 |
commit | 174d2c08409659a6a6f798b5e4bc0c6040f20712 (patch) | |
tree | 8c16c64041eeb3cfbb084bccd4c5cfda76da25a7 /src | |
parent | 6b61b72f4805ca2db09c5b0a496a29e82d162e16 (diff) |
Commit work on 0.8.7 (delayed commit)
Diffstat (limited to 'src')
-rw-r--r-- | src/ntfs.c | 16 | ||||
-rw-r--r-- | src/ntfsx.c | 42 | ||||
-rw-r--r-- | src/ntfsx.h | 1 |
3 files changed, 39 insertions, 20 deletions
@@ -101,25 +101,25 @@ bool ntfs_dofixups(byte* cluster, uint32 size) { ntfs_recordheader* record = (ntfs_recordheader*)cluster; byte numSectors; - uint16* updSeq; - uint16* sectorFooter; - byte i; + uint16* updSeq; + uint16* sectorFooter; + byte i; ASSERT(size % kSectorSize == 0); - numSectors = (byte)(size / kSectorSize); + numSectors = (byte)(size / kSectorSize); - /* Check the number of sectors against array */ + /* Check the number of sectors against array */ if(record->cwUpdSeq - 1 < numSectors) numSectors = record->cwUpdSeq - 1; - + updSeq = (uint16*)(cluster + record->offUpdSeq); for(i = 0; i < numSectors; i++) { - /* + /* * Check last 2 bytes in each sector against * first double byte value in update sequence - */ + */ sectorFooter = (uint16*)((cluster + (kSectorSize - 2)) + (i * kSectorSize)); if(*sectorFooter == updSeq[0]) *sectorFooter = updSeq[i + 1]; diff --git a/src/ntfsx.c b/src/ntfsx.c index 6008e1a..865199d 100644 --- a/src/ntfsx.c +++ b/src/ntfsx.c @@ -452,31 +452,49 @@ ntfsx_record* ntfsx_record_alloc(partitioninfo* info) void ntfsx_record_free(ntfsx_record* record) { - ntfsx_cluster_release(&(record->_clus)); - free(record); + ntfsx_cluster_release(&(record->_clus)); + free(record); } bool ntfsx_record_read(ntfsx_record* record, uint64 begSector, int dd) { - ntfs_recordheader* rechead; + ntfs_recordheader* rechead; - if(!ntfsx_cluster_read(&(record->_clus), record->info, begSector, dd)) - { - warn("couldn't read mft record from drive"); - return false; - } + if(!ntfsx_cluster_read(&(record->_clus), record->info, begSector, dd)) + { + warn("couldn't read mft record from drive"); + return false; + } /* Check and validate this record */ rechead = ntfsx_record_header(record); if(rechead->magic != kNTFS_RecMagic || + !ntfsx_record_validate(record) || !ntfs_dofixups(record->_clus.data, record->_clus.size)) { - warnx("invalid mft record"); - ntfsx_cluster_release(&(record->_clus)); - return false; + warnx("invalid mft record"); + ntfsx_cluster_release(&(record->_clus)); + return false; } - return true; + return true; +} + +bool ntfsx_record_validate(ntfsx_record* record) +{ + ntfs_recordheader* rechead; + rechead = ntfsx_record_header(record); + + /* + * TODO: We need more validation here + * In addition we should be validating attribute + * headers and anything else we read into memory + */ + + if(rechead->offUpdSeq > kSectorSize) + return false; + + return true; } ntfsx_cluster* ntfsx_record_cluster(ntfsx_record* record) diff --git a/src/ntfsx.h b/src/ntfsx.h index 2c1054c..45bcbdc 100644 --- a/src/ntfsx.h +++ b/src/ntfsx.h @@ -88,6 +88,7 @@ ntfsx_record* ntfsx_record_alloc(partitioninfo* info); ntfsx_cluster* ntfsx_record_cluster(ntfsx_record* record); void ntfsx_record_free(ntfsx_record* record); bool ntfsx_record_read(ntfsx_record* record, uint64 begSector, int dd); +bool ntfsx_record_validate(ntfsx_record* record); ntfs_recordheader* ntfsx_record_header(ntfsx_record* record); ntfsx_attribute* ntfsx_record_findattribute(ntfsx_record* record, uint32 attrType, int dd); |