mirror of
https://github.com/wiiu-env/libfat.git
synced 2025-02-19 18:52:48 +01:00
clean
This commit is contained in:
parent
38528ce18f
commit
8ad45f1556
@ -4,7 +4,7 @@
|
|||||||
on various block devices.
|
on various block devices.
|
||||||
|
|
||||||
Copyright (c) 2006 Michael "Chishm" Chisholm
|
Copyright (c) 2006 Michael "Chishm" Chisholm
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without modification,
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
are permitted provided that the following conditions are met:
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
@ -38,7 +38,7 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <sys/iosupport.h>
|
#include <sys/iosupport.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This device name, as known by devkitPro toolchains
|
This device name, as known by devkitPro toolchains
|
||||||
*/
|
*/
|
||||||
const char* DEVICE_NAME = "fat";
|
const char* DEVICE_NAME = "fat";
|
||||||
@ -128,7 +128,7 @@ PARTITION* _FAT_partition_constructor (const DISC_INTERFACE* disc, uint32_t cach
|
|||||||
if (i == 0x1FE) {
|
if (i == 0x1FE) {
|
||||||
for (i=0x1BE; (i < 0x1FE) && (sectorBuffer[i+0x04] == 0x00); i+= 0x10);
|
for (i=0x1BE; (i < 0x1FE) && (sectorBuffer[i+0x04] == 0x00); i+= 0x10);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( i != 0x1FE) {
|
if ( i != 0x1FE) {
|
||||||
// Go to first valid partition
|
// Go to first valid partition
|
||||||
startSector = u8array_to_u32(sectorBuffer, 0x8 + i);
|
startSector = u8array_to_u32(sectorBuffer, 0x8 + i);
|
||||||
@ -147,7 +147,7 @@ PARTITION* _FAT_partition_constructor (const DISC_INTERFACE* disc, uint32_t cach
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now verify that this is indeed a FAT partition
|
// Now verify that this is indeed a FAT partition
|
||||||
if (memcmp(sectorBuffer + BPB_FAT16_fileSysType, FAT_SIG, sizeof(FAT_SIG)) &&
|
if (memcmp(sectorBuffer + BPB_FAT16_fileSysType, FAT_SIG, sizeof(FAT_SIG)) &&
|
||||||
memcmp(sectorBuffer + BPB_FAT32_fileSysType, FAT_SIG, sizeof(FAT_SIG)))
|
memcmp(sectorBuffer + BPB_FAT32_fileSysType, FAT_SIG, sizeof(FAT_SIG)))
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -167,28 +167,28 @@ PARTITION* _FAT_partition_constructor (const DISC_INTERFACE* disc, uint32_t cach
|
|||||||
|
|
||||||
// Init the partition lock
|
// Init the partition lock
|
||||||
_FAT_lock_init(&partition->lock);
|
_FAT_lock_init(&partition->lock);
|
||||||
|
|
||||||
// Set partition's disc interface
|
// Set partition's disc interface
|
||||||
partition->disc = disc;
|
partition->disc = disc;
|
||||||
|
|
||||||
// Store required information about the file system
|
// Store required information about the file system
|
||||||
partition->fat.sectorsPerFat = u8array_to_u16(sectorBuffer, BPB_sectorsPerFAT);
|
partition->fat.sectorsPerFat = u8array_to_u16(sectorBuffer, BPB_sectorsPerFAT);
|
||||||
if (partition->fat.sectorsPerFat == 0) {
|
if (partition->fat.sectorsPerFat == 0) {
|
||||||
partition->fat.sectorsPerFat = u8array_to_u32( sectorBuffer, BPB_FAT32_sectorsPerFAT32);
|
partition->fat.sectorsPerFat = u8array_to_u32( sectorBuffer, BPB_FAT32_sectorsPerFAT32);
|
||||||
}
|
}
|
||||||
|
|
||||||
partition->numberOfSectors = u8array_to_u16( sectorBuffer, BPB_numSectorsSmall);
|
partition->numberOfSectors = u8array_to_u16( sectorBuffer, BPB_numSectorsSmall);
|
||||||
if (partition->numberOfSectors == 0) {
|
if (partition->numberOfSectors == 0) {
|
||||||
partition->numberOfSectors = u8array_to_u32( sectorBuffer, BPB_numSectors);
|
partition->numberOfSectors = u8array_to_u32( sectorBuffer, BPB_numSectors);
|
||||||
}
|
}
|
||||||
|
|
||||||
partition->bytesPerSector = BYTES_PER_READ; // Sector size is redefined to be 512 bytes
|
partition->bytesPerSector = BYTES_PER_READ; // Sector size is redefined to be 512 bytes
|
||||||
partition->sectorsPerCluster = sectorBuffer[BPB_sectorsPerCluster] * u8array_to_u16(sectorBuffer, BPB_bytesPerSector) / BYTES_PER_READ;
|
partition->sectorsPerCluster = sectorBuffer[BPB_sectorsPerCluster] * u8array_to_u16(sectorBuffer, BPB_bytesPerSector) / BYTES_PER_READ;
|
||||||
partition->bytesPerCluster = partition->bytesPerSector * partition->sectorsPerCluster;
|
partition->bytesPerCluster = partition->bytesPerSector * partition->sectorsPerCluster;
|
||||||
partition->fat.fatStart = startSector + u8array_to_u16(sectorBuffer, BPB_reservedSectors);
|
partition->fat.fatStart = startSector + u8array_to_u16(sectorBuffer, BPB_reservedSectors);
|
||||||
|
|
||||||
partition->rootDirStart = partition->fat.fatStart + (sectorBuffer[BPB_numFATs] * partition->fat.sectorsPerFat);
|
partition->rootDirStart = partition->fat.fatStart + (sectorBuffer[BPB_numFATs] * partition->fat.sectorsPerFat);
|
||||||
partition->dataStart = partition->rootDirStart +
|
partition->dataStart = partition->rootDirStart +
|
||||||
(( u8array_to_u16(sectorBuffer, BPB_rootEntries) * DIR_ENTRY_DATA_SIZE) / partition->bytesPerSector);
|
(( u8array_to_u16(sectorBuffer, BPB_rootEntries) * DIR_ENTRY_DATA_SIZE) / partition->bytesPerSector);
|
||||||
|
|
||||||
partition->totalSize = ((uint64_t)partition->numberOfSectors - (partition->dataStart - startSector)) * (uint64_t)partition->bytesPerSector;
|
partition->totalSize = ((uint64_t)partition->numberOfSectors - (partition->dataStart - startSector)) * (uint64_t)partition->bytesPerSector;
|
||||||
@ -210,7 +210,7 @@ PARTITION* _FAT_partition_constructor (const DISC_INTERFACE* disc, uint32_t cach
|
|||||||
partition->rootDirCluster = FAT16_ROOT_DIR_CLUSTER;
|
partition->rootDirCluster = FAT16_ROOT_DIR_CLUSTER;
|
||||||
} else {
|
} else {
|
||||||
// Set up for the FAT32 way
|
// Set up for the FAT32 way
|
||||||
partition->rootDirCluster = u8array_to_u32(sectorBuffer, BPB_FAT32_rootClus);
|
partition->rootDirCluster = u8array_to_u32(sectorBuffer, BPB_FAT32_rootClus);
|
||||||
// Check if FAT mirroring is enabled
|
// Check if FAT mirroring is enabled
|
||||||
if (!(sectorBuffer[BPB_FAT32_extFlags] & 0x80)) {
|
if (!(sectorBuffer[BPB_FAT32_extFlags] & 0x80)) {
|
||||||
// Use the active FAT
|
// Use the active FAT
|
||||||
@ -223,10 +223,10 @@ PARTITION* _FAT_partition_constructor (const DISC_INTERFACE* disc, uint32_t cach
|
|||||||
|
|
||||||
// Set current directory to the root
|
// Set current directory to the root
|
||||||
partition->cwdCluster = partition->rootDirCluster;
|
partition->cwdCluster = partition->rootDirCluster;
|
||||||
|
|
||||||
// Check if this disc is writable, and set the readOnly property appropriately
|
// Check if this disc is writable, and set the readOnly property appropriately
|
||||||
partition->readOnly = !(_FAT_disc_features(disc) & FEATURE_MEDIUM_CANWRITE);
|
partition->readOnly = !(_FAT_disc_features(disc) & FEATURE_MEDIUM_CANWRITE);
|
||||||
|
|
||||||
// There are currently no open files on this partition
|
// There are currently no open files on this partition
|
||||||
partition->openFileCount = 0;
|
partition->openFileCount = 0;
|
||||||
partition->firstOpenFile = NULL;
|
partition->firstOpenFile = NULL;
|
||||||
@ -236,7 +236,7 @@ PARTITION* _FAT_partition_constructor (const DISC_INTERFACE* disc, uint32_t cach
|
|||||||
|
|
||||||
void _FAT_partition_destructor (PARTITION* partition) {
|
void _FAT_partition_destructor (PARTITION* partition) {
|
||||||
FILE_STRUCT* nextFile;
|
FILE_STRUCT* nextFile;
|
||||||
|
|
||||||
_FAT_lock(&partition->lock);
|
_FAT_lock(&partition->lock);
|
||||||
|
|
||||||
// Synchronize open files
|
// Synchronize open files
|
||||||
@ -245,27 +245,26 @@ void _FAT_partition_destructor (PARTITION* partition) {
|
|||||||
_FAT_syncToDisc (nextFile);
|
_FAT_syncToDisc (nextFile);
|
||||||
nextFile = nextFile->nextOpenFile;
|
nextFile = nextFile->nextOpenFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Free memory used by the cache, writing it to disc at the same time
|
// Free memory used by the cache, writing it to disc at the same time
|
||||||
_FAT_cache_destructor (partition->cache);
|
_FAT_cache_destructor (partition->cache);
|
||||||
|
|
||||||
// Unlock the partition and destroy the lock
|
// Unlock the partition and destroy the lock
|
||||||
_FAT_unlock(&partition->lock);
|
_FAT_unlock(&partition->lock);
|
||||||
_FAT_lock_deinit(&partition->lock);
|
_FAT_lock_deinit(&partition->lock);
|
||||||
|
|
||||||
// Free memory used by the partition
|
// Free memory used by the partition
|
||||||
_FAT_mem_free (partition);
|
_FAT_mem_free (partition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PARTITION* _FAT_partition_getPartitionFromPath (const char* path) {
|
PARTITION* _FAT_partition_getPartitionFromPath (const char* path) {
|
||||||
const devoptab_t *devops;
|
const devoptab_t *devops;
|
||||||
|
|
||||||
devops = GetDeviceOpTab (path);
|
devops = GetDeviceOpTab (path);
|
||||||
|
|
||||||
if (!devops) {
|
if (!devops) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (PARTITION*)devops->deviceData;
|
return (PARTITION*)devops->deviceData;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user