diff --git a/source/gekko_io.c b/source/gekko_io.c index 48ca90d..8ee8260 100644 --- a/source/gekko_io.c +++ b/source/gekko_io.c @@ -112,25 +112,35 @@ static int ntfs_device_gekko_io_open(struct ntfs_device *dev, int flags) } // Check that there is a valid NTFS boot sector at the start of the device - NTFS_BOOT_SECTOR boot; - if (interface->readSectors(fd->startSector, 1, &boot)) { - if (!ntfs_boot_sector_is_ntfs(&boot)) { - errno = EINVALPART; - return -1; - } - } else { + NTFS_BOOT_SECTOR *boot = (NTFS_BOOT_SECTOR *) ntfs_malloc(MAX_SECTOR_SIZE); + if(boot == NULL) { + errno = ENOMEM; + return -1; + } + + if (!interface->readSectors(fd->startSector, 1, boot)) { ntfs_log_perror("read failure @ sector %d\n", fd->startSector); errno = EIO; + ntfs_free(boot); + return -1; + } + + if (!ntfs_boot_sector_is_ntfs(boot)) { + errno = EINVALPART; + ntfs_free(boot); return -1; } // Parse the boot sector - fd->hiddenSectors = le32_to_cpu(boot.bpb.hidden_sectors); - fd->sectorSize = le16_to_cpu(boot.bpb.bytes_per_sector); - fd->sectorCount = sle64_to_cpu(boot.number_of_sectors); + fd->hiddenSectors = le32_to_cpu(boot->bpb.hidden_sectors); + fd->sectorSize = le16_to_cpu(boot->bpb.bytes_per_sector); + fd->sectorCount = sle64_to_cpu(boot->number_of_sectors); fd->pos = 0; fd->len = (fd->sectorCount * fd->sectorSize); - fd->ino = le64_to_cpu(boot.volume_serial_number); + fd->ino = le64_to_cpu(boot->volume_serial_number); + + // Free memory for boot sector + ntfs_free(boot); // Mark the device as read-only (if required) if (flags & O_RDONLY) { @@ -507,6 +517,7 @@ static int ntfs_device_gekko_io_sync(struct ntfs_device *dev) // Mark the device as clean NDevClearDirty(dev); + NDevClearSync(dev); // Flush any sectors in the disc cache (if required) if (fd->cache) { diff --git a/source/gekko_io.h b/source/gekko_io.h index d5018e8..bc5516a 100644 --- a/source/gekko_io.h +++ b/source/gekko_io.h @@ -30,6 +30,8 @@ #include #include +#define MAX_SECTOR_SIZE 4096 + /** * gekko_fd - Gekko device driver descriptor */ diff --git a/source/ntfs.c b/source/ntfs.c index 0ec3ad7..9beb31f 100644 --- a/source/ntfs.c +++ b/source/ntfs.c @@ -99,7 +99,7 @@ int ntfsFindPartitions (const DISC_INTERFACE *interface, sec_t **partitions) int i; union { - u8 buffer[512]; + u8 buffer[MAX_SECTOR_SIZE]; MASTER_BOOT_RECORD mbr; EXTENDED_BOOT_RECORD ebr; NTFS_BOOT_SECTOR boot; diff --git a/source/ntfsinternal.c b/source/ntfsinternal.c index c4db493..c2de094 100644 --- a/source/ntfsinternal.c +++ b/source/ntfsinternal.c @@ -247,7 +247,7 @@ void ntfsDeinitVolume (ntfs_vd *vd) //} // Force the underlying device to sync - vd->dev->d_ops->sync(vd->dev); + ntfs_device_sync(vd->dev); // Unlock ntfsUnlock(vd); @@ -647,7 +647,7 @@ int ntfsUnlink (ntfs_vd *vd, const char *path) } // Force the underlying device to sync - vd->dev->d_ops->sync(vd->dev); + ntfs_device_sync(vd->dev); // ntfs_delete() ALWAYS closes ni and dir_ni; so no need for us to anymore dir_ni = ni = NULL; @@ -696,7 +696,7 @@ int ntfsSync (ntfs_vd *vd, ntfs_inode *ni) res = ntfs_inode_sync(ni); // Force the underlying device to sync - vd->dev->d_ops->sync(vd->dev); + ntfs_device_sync(vd->dev); // Unlock ntfsUnlock(vd);