*Allow sector sizes other than 512 bytes per sector

*Use internal NTFS-3G device sync function to sync the device
This commit is contained in:
dimok321 2011-02-16 20:11:53 +00:00
parent 520fc5f305
commit 86f2292aae
4 changed files with 28 additions and 15 deletions

View File

@ -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 // Check that there is a valid NTFS boot sector at the start of the device
NTFS_BOOT_SECTOR boot; NTFS_BOOT_SECTOR *boot = (NTFS_BOOT_SECTOR *) ntfs_malloc(MAX_SECTOR_SIZE);
if (interface->readSectors(fd->startSector, 1, &boot)) { if(boot == NULL) {
if (!ntfs_boot_sector_is_ntfs(&boot)) { errno = ENOMEM;
errno = EINVALPART;
return -1; return -1;
} }
} else {
if (!interface->readSectors(fd->startSector, 1, boot)) {
ntfs_log_perror("read failure @ sector %d\n", fd->startSector); ntfs_log_perror("read failure @ sector %d\n", fd->startSector);
errno = EIO; errno = EIO;
ntfs_free(boot);
return -1;
}
if (!ntfs_boot_sector_is_ntfs(boot)) {
errno = EINVALPART;
ntfs_free(boot);
return -1; return -1;
} }
// Parse the boot sector // Parse the boot sector
fd->hiddenSectors = le32_to_cpu(boot.bpb.hidden_sectors); fd->hiddenSectors = le32_to_cpu(boot->bpb.hidden_sectors);
fd->sectorSize = le16_to_cpu(boot.bpb.bytes_per_sector); fd->sectorSize = le16_to_cpu(boot->bpb.bytes_per_sector);
fd->sectorCount = sle64_to_cpu(boot.number_of_sectors); fd->sectorCount = sle64_to_cpu(boot->number_of_sectors);
fd->pos = 0; fd->pos = 0;
fd->len = (fd->sectorCount * fd->sectorSize); 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) // Mark the device as read-only (if required)
if (flags & O_RDONLY) { if (flags & O_RDONLY) {
@ -507,6 +517,7 @@ static int ntfs_device_gekko_io_sync(struct ntfs_device *dev)
// Mark the device as clean // Mark the device as clean
NDevClearDirty(dev); NDevClearDirty(dev);
NDevClearSync(dev);
// Flush any sectors in the disc cache (if required) // Flush any sectors in the disc cache (if required)
if (fd->cache) { if (fd->cache) {

View File

@ -30,6 +30,8 @@
#include <gccore.h> #include <gccore.h>
#include <ogc/disc_io.h> #include <ogc/disc_io.h>
#define MAX_SECTOR_SIZE 4096
/** /**
* gekko_fd - Gekko device driver descriptor * gekko_fd - Gekko device driver descriptor
*/ */

View File

@ -99,7 +99,7 @@ int ntfsFindPartitions (const DISC_INTERFACE *interface, sec_t **partitions)
int i; int i;
union { union {
u8 buffer[512]; u8 buffer[MAX_SECTOR_SIZE];
MASTER_BOOT_RECORD mbr; MASTER_BOOT_RECORD mbr;
EXTENDED_BOOT_RECORD ebr; EXTENDED_BOOT_RECORD ebr;
NTFS_BOOT_SECTOR boot; NTFS_BOOT_SECTOR boot;

View File

@ -247,7 +247,7 @@ void ntfsDeinitVolume (ntfs_vd *vd)
//} //}
// Force the underlying device to sync // Force the underlying device to sync
vd->dev->d_ops->sync(vd->dev); ntfs_device_sync(vd->dev);
// Unlock // Unlock
ntfsUnlock(vd); ntfsUnlock(vd);
@ -647,7 +647,7 @@ int ntfsUnlink (ntfs_vd *vd, const char *path)
} }
// Force the underlying device to sync // 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 // ntfs_delete() ALWAYS closes ni and dir_ni; so no need for us to anymore
dir_ni = ni = NULL; dir_ni = ni = NULL;
@ -696,7 +696,7 @@ int ntfsSync (ntfs_vd *vd, ntfs_inode *ni)
res = ntfs_inode_sync(ni); res = ntfs_inode_sync(ni);
// Force the underlying device to sync // Force the underlying device to sync
vd->dev->d_ops->sync(vd->dev); ntfs_device_sync(vd->dev);
// Unlock // Unlock
ntfsUnlock(vd); ntfsUnlock(vd);