port libfat to PC and c++; use it in compactflash emulation; LFN are supported once more; files have been re-added, please run autogen.sh; there may be bugs in 64bit builds, let me know.
This commit is contained in:
parent
3795d559e0
commit
a41d8a4242
|
@ -49,6 +49,34 @@ libdesmume_a_SOURCES = \
|
|||
utils/decrypt/decrypt.h utils/decrypt/header.cpp utils/decrypt/header.h \
|
||||
utils/task.cpp utils/task.h \
|
||||
utils/dlditool.cpp \
|
||||
utils/libfat/bit_ops.h \
|
||||
utils/libfat/cache.cpp \
|
||||
utils/libfat/cache.h \
|
||||
utils/libfat/common.h \
|
||||
utils/libfat/directory.cpp \
|
||||
utils/libfat/directory.h \
|
||||
utils/libfat/disc.cpp \
|
||||
utils/libfat/disc.h \
|
||||
utils/libfat/disc_io.h \
|
||||
utils/libfat/fat.h \
|
||||
utils/libfat/fatdir.cpp \
|
||||
utils/libfat/fatdir.h \
|
||||
utils/libfat/fatfile.cpp \
|
||||
utils/libfat/fatfile.h \
|
||||
utils/libfat/filetime.cpp \
|
||||
utils/libfat/filetime.h \
|
||||
utils/libfat/file_allocation_table.cpp \
|
||||
utils/libfat/file_allocation_table.h \
|
||||
utils/libfat/libfat.cpp \
|
||||
utils/libfat/libfat_pc.h \
|
||||
utils/libfat/libfat_public_api.cpp \
|
||||
utils/libfat/libfat_public_api.h \
|
||||
utils/libfat/lock.cpp \
|
||||
utils/libfat/lock.h \
|
||||
utils/libfat/mem_allocate.h \
|
||||
utils/libfat/ndstypes.h \
|
||||
utils/libfat/partition.cpp \
|
||||
utils/libfat/partition.h \
|
||||
addons.cpp addons.h \
|
||||
addons/compactFlash.cpp addons/gbagame.cpp addons/none.cpp addons/rumblepak.cpp addons/guitarGrip.cpp addons/expMemory.cpp addons/piano.cpp addons/slot1_none.cpp addons/slot1_r4.cpp addons/slot1_retail.cpp fs.h \
|
||||
cheatSystem.cpp cheatSystem.h \
|
||||
|
|
|
@ -28,6 +28,9 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
#include "../emufat.h"
|
||||
|
||||
#include "../utils/libfat/libfat_public_api.h"
|
||||
|
||||
#include <stack>
|
||||
|
||||
#include <fcntl.h>
|
||||
|
@ -320,9 +323,9 @@ void count_ListCallback(FsEntry* fs, EListCallbackArg arg)
|
|||
}
|
||||
|
||||
static std::string currPath;
|
||||
static EmuFatFile currFatFile;
|
||||
static std::stack<EmuFatFile> fatStack;
|
||||
static std::stack<std::string> pathStack;
|
||||
static std::stack<std::string> virtPathStack;
|
||||
static std::string currVirtPath;
|
||||
void build_ListCallback(FsEntry* fs, EListCallbackArg arg)
|
||||
{
|
||||
char* fname = (strlen(fs->cAlternateFileName)>0) ? fs->cAlternateFileName : fs->cFileName;
|
||||
|
@ -332,10 +335,10 @@ void build_ListCallback(FsEntry* fs, EListCallbackArg arg)
|
|||
|
||||
if(arg == EListCallbackArg_Pop)
|
||||
{
|
||||
currFatFile = fatStack.top();
|
||||
fatStack.pop();
|
||||
currPath = pathStack.top();
|
||||
pathStack.pop();
|
||||
currVirtPath = virtPathStack.top();
|
||||
virtPathStack.pop();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -345,12 +348,13 @@ void build_ListCallback(FsEntry* fs, EListCallbackArg arg)
|
|||
if(!strcmp(fname,"..")) return;
|
||||
|
||||
pathStack.push(currPath);
|
||||
fatStack.push(currFatFile);
|
||||
virtPathStack.push(currVirtPath);
|
||||
|
||||
EmuFatFile newDir;
|
||||
newDir.makeDir(&currFatFile,fname);
|
||||
newDir.sync();
|
||||
currFatFile = newDir;
|
||||
currVirtPath = currVirtPath + "/" + fname;
|
||||
bool ok = LIBFAT::MkDir(currVirtPath.c_str());
|
||||
|
||||
if(!ok)
|
||||
printf("ERROR adding dir %s via libfat\n",currVirtPath.c_str());
|
||||
|
||||
currPath = currPath + std::string(1,FS_SEPARATOR) + fname;
|
||||
return;
|
||||
|
@ -369,10 +373,10 @@ void build_ListCallback(FsEntry* fs, EListCallbackArg arg)
|
|||
fread(buf,1,len,inf);
|
||||
fclose(inf);
|
||||
|
||||
EmuFatFile f;
|
||||
f.open(&currFatFile,fname,EO_RDWR | EO_CREAT);
|
||||
f.write(buf,len);
|
||||
f.close();
|
||||
std::string path = currVirtPath + "/" + fname;
|
||||
bool ok = LIBFAT::WriteFile(path.c_str(),buf,len);
|
||||
if(!ok)
|
||||
printf("ERROR adding file %s via libfat\n",path.c_str());
|
||||
delete[] buf;
|
||||
}
|
||||
}
|
||||
|
@ -385,6 +389,7 @@ static BOOL cflash_build_fat()
|
|||
{
|
||||
dataSectors = 0;
|
||||
currPath = sFlashPath;
|
||||
currVirtPath = "";
|
||||
list_files(sFlashPath.c_str(), count_ListCallback);
|
||||
|
||||
dataSectors += 8; //a few for reserved sectors, etc.
|
||||
|
@ -399,15 +404,25 @@ static BOOL cflash_build_fat()
|
|||
delete file;
|
||||
file = new EMUFILE_MEMORY(dataSectors*512);
|
||||
//file = new EMUFILE_FILE("c:\\temp.ima","rb+");
|
||||
|
||||
//format the disk
|
||||
{
|
||||
EmuFat fat(file);
|
||||
EmuFatVolume vol;
|
||||
u8 ok = vol.init(&fat);
|
||||
vol.formatNew(dataSectors);
|
||||
|
||||
reconstruct(&currFatFile);
|
||||
currFatFile.openRoot(&vol);
|
||||
//ensure we are working in memory, just in case we were testing with a disk file.
|
||||
//libfat will need to go straight to memory (for now; we could easily change it to work with the disk)
|
||||
file = file->memwrap();
|
||||
}
|
||||
EMUFILE_MEMORY* memf = (EMUFILE_MEMORY*)file;
|
||||
|
||||
//setup libfat and write all the files through it
|
||||
LIBFAT::Init(memf->buf(),memf->size());
|
||||
list_files(sFlashPath.c_str(), build_ListCallback);
|
||||
LIBFAT::Shutdown();
|
||||
|
||||
|
||||
//FILE* outf = fopen("d:\\test.ima","wb");
|
||||
//EMUFILE_MEMORY* memf = (EMUFILE_MEMORY*)file;
|
||||
|
|
|
@ -25,6 +25,11 @@
|
|||
//Copyright (C) 1998-2005 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
|
||||
|
||||
#include "emufat.h"
|
||||
#include <ctype.h>
|
||||
#include <wchar.h>
|
||||
#include <wctype.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#define LE16(x) (x)
|
||||
#define LE32(x) (x)
|
||||
|
@ -114,6 +119,7 @@ EmuFat::EmuFat(EMUFILE* fileNotToDelete)
|
|||
|
||||
EmuFat::~EmuFat()
|
||||
{
|
||||
cacheFlush();
|
||||
if(m_owns)
|
||||
delete m_pFile;
|
||||
}
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
//Copyright (C) 1998 H. Peter Anvin <hpa@zytor.com>
|
||||
//Copyright (C) 1998-2005 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
|
||||
|
||||
//based on libfat
|
||||
//Copyright (c) 2006 Michael "Chishm" Chisholm
|
||||
|
||||
#ifndef EMUFAT_H
|
||||
#define EMUFAT_H
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
bit_ops.h
|
||||
Functions for dealing with conversion of data between types
|
||||
|
||||
Copyright (c) 2006 Michael "Chishm" Chisholm
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
3. The name of the author may not be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _BIT_OPS_H
|
||||
#define _BIT_OPS_H
|
||||
|
||||
#ifndef _MSC_VER
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
/*-----------------------------------------------------------------
|
||||
Functions to deal with little endian values stored in uint8_t arrays
|
||||
-----------------------------------------------------------------*/
|
||||
static inline uint16_t u8array_to_u16 (const uint8_t* item, int offset) {
|
||||
return ( item[offset] | (item[offset + 1] << 8));
|
||||
}
|
||||
|
||||
static inline uint32_t u8array_to_u32 (const uint8_t* item, int offset) {
|
||||
return ( item[offset] | (item[offset + 1] << 8) | (item[offset + 2] << 16) | (item[offset + 3] << 24));
|
||||
}
|
||||
|
||||
static inline void u16_to_u8array (uint8_t* item, int offset, uint16_t value) {
|
||||
item[offset] = (uint8_t) value;
|
||||
item[offset + 1] = (uint8_t)(value >> 8);
|
||||
}
|
||||
|
||||
static inline void u32_to_u8array (uint8_t* item, int offset, uint32_t value) {
|
||||
item[offset] = (uint8_t) value;
|
||||
item[offset + 1] = (uint8_t)(value >> 8);
|
||||
item[offset + 2] = (uint8_t)(value >> 16);
|
||||
item[offset + 3] = (uint8_t)(value >> 24);
|
||||
}
|
||||
|
||||
#endif // _BIT_OPS_H
|
|
@ -0,0 +1,366 @@
|
|||
/*
|
||||
cache.c
|
||||
The cache is not visible to the user. It should be flushed
|
||||
when any file is closed or changes are made to the filesystem.
|
||||
|
||||
This cache implements a least-used-page replacement policy. This will
|
||||
distribute sectors evenly over the pages, so if less than the maximum
|
||||
pages are used at once, they should all eventually remain in the cache.
|
||||
This also has the benefit of throwing out old sectors, so as not to keep
|
||||
too many stale pages around.
|
||||
|
||||
Copyright (c) 2006 Michael "Chishm" Chisholm
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
3. The name of the author may not be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "cache.h"
|
||||
#include "disc.h"
|
||||
|
||||
#include "mem_allocate.h"
|
||||
#include "bit_ops.h"
|
||||
#include "file_allocation_table.h"
|
||||
|
||||
#define CACHE_FREE UINT_MAX
|
||||
|
||||
CACHE* _FAT_cache_constructor (unsigned int numberOfPages, unsigned int sectorsPerPage, const DISC_INTERFACE* discInterface, sec_t endOfPartition) {
|
||||
CACHE* cache;
|
||||
unsigned int i;
|
||||
CACHE_ENTRY* cacheEntries;
|
||||
|
||||
if (numberOfPages < 2) {
|
||||
numberOfPages = 2;
|
||||
}
|
||||
|
||||
if (sectorsPerPage < 8) {
|
||||
sectorsPerPage = 8;
|
||||
}
|
||||
|
||||
cache = (CACHE*) _FAT_mem_allocate (sizeof(CACHE));
|
||||
if (cache == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cache->disc = discInterface;
|
||||
cache->endOfPartition = endOfPartition;
|
||||
cache->numberOfPages = numberOfPages;
|
||||
cache->sectorsPerPage = sectorsPerPage;
|
||||
|
||||
|
||||
cacheEntries = (CACHE_ENTRY*) _FAT_mem_allocate ( sizeof(CACHE_ENTRY) * numberOfPages);
|
||||
if (cacheEntries == NULL) {
|
||||
_FAT_mem_free (cache);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i = 0; i < numberOfPages; i++) {
|
||||
cacheEntries[i].sector = CACHE_FREE;
|
||||
cacheEntries[i].count = 0;
|
||||
cacheEntries[i].last_access = 0;
|
||||
cacheEntries[i].dirty = false;
|
||||
cacheEntries[i].cache = (uint8_t*) _FAT_mem_align ( sectorsPerPage * BYTES_PER_READ );
|
||||
}
|
||||
|
||||
cache->cacheEntries = cacheEntries;
|
||||
|
||||
return cache;
|
||||
}
|
||||
|
||||
void _FAT_cache_destructor (CACHE* cache) {
|
||||
unsigned int i;
|
||||
// Clear out cache before destroying it
|
||||
_FAT_cache_flush(cache);
|
||||
|
||||
// Free memory in reverse allocation order
|
||||
for (i = 0; i < cache->numberOfPages; i++) {
|
||||
_FAT_mem_free (cache->cacheEntries[i].cache);
|
||||
}
|
||||
_FAT_mem_free (cache->cacheEntries);
|
||||
_FAT_mem_free (cache);
|
||||
}
|
||||
|
||||
|
||||
static u32 accessCounter = 0;
|
||||
|
||||
static u32 accessTime(){
|
||||
accessCounter++;
|
||||
return accessCounter;
|
||||
}
|
||||
|
||||
|
||||
static CACHE_ENTRY* _FAT_cache_getPage(CACHE *cache,sec_t sector)
|
||||
{
|
||||
unsigned int i;
|
||||
CACHE_ENTRY* cacheEntries = cache->cacheEntries;
|
||||
unsigned int numberOfPages = cache->numberOfPages;
|
||||
unsigned int sectorsPerPage = cache->sectorsPerPage;
|
||||
|
||||
bool foundFree = false;
|
||||
unsigned int oldUsed = 0;
|
||||
unsigned int oldAccess = UINT_MAX;
|
||||
|
||||
for(i=0;i<numberOfPages;i++) {
|
||||
if(sector>=cacheEntries[i].sector && sector<(cacheEntries[i].sector + cacheEntries[i].count)) {
|
||||
cacheEntries[i].last_access = accessTime();
|
||||
return &(cacheEntries[i]);
|
||||
}
|
||||
|
||||
if(foundFree==false && (cacheEntries[i].sector==CACHE_FREE || cacheEntries[i].last_access<oldAccess)) {
|
||||
if(cacheEntries[i].sector==CACHE_FREE) foundFree = true;
|
||||
oldUsed = i;
|
||||
oldAccess = cacheEntries[i].last_access;
|
||||
}
|
||||
}
|
||||
|
||||
if(foundFree==false && cacheEntries[oldUsed].dirty==true) {
|
||||
if(!_FAT_disc_writeSectors(cache->disc,cacheEntries[oldUsed].sector,cacheEntries[oldUsed].count,cacheEntries[oldUsed].cache)) return NULL;
|
||||
cacheEntries[oldUsed].dirty = false;
|
||||
}
|
||||
|
||||
sector = (sector/sectorsPerPage)*sectorsPerPage; // align base sector to page size
|
||||
sec_t next_page = sector + sectorsPerPage;
|
||||
if(next_page > cache->endOfPartition) next_page = cache->endOfPartition;
|
||||
|
||||
if(!_FAT_disc_readSectors(cache->disc,sector,next_page-sector,cacheEntries[oldUsed].cache)) return NULL;
|
||||
|
||||
cacheEntries[oldUsed].sector = sector;
|
||||
cacheEntries[oldUsed].count = next_page-sector;
|
||||
cacheEntries[oldUsed].last_access = accessTime();
|
||||
|
||||
return &(cacheEntries[oldUsed]);
|
||||
}
|
||||
|
||||
bool _FAT_cache_readSectors(CACHE *cache,sec_t sector,sec_t numSectors,void *buffer)
|
||||
{
|
||||
sec_t sec;
|
||||
sec_t secs_to_read;
|
||||
CACHE_ENTRY *entry;
|
||||
uint8_t *dest = (uint8_t *)buffer;
|
||||
|
||||
while(numSectors>0) {
|
||||
entry = _FAT_cache_getPage(cache,sector);
|
||||
if(entry==NULL) return false;
|
||||
|
||||
sec = sector - entry->sector;
|
||||
secs_to_read = entry->count - sec;
|
||||
if(secs_to_read>numSectors) secs_to_read = numSectors;
|
||||
|
||||
memcpy(dest,entry->cache + (sec*BYTES_PER_READ),(secs_to_read*BYTES_PER_READ));
|
||||
|
||||
dest += (secs_to_read*BYTES_PER_READ);
|
||||
sector += secs_to_read;
|
||||
numSectors -= secs_to_read;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
Reads some data from a cache page, determined by the sector number
|
||||
*/
|
||||
bool _FAT_cache_readPartialSector (CACHE* cache, void* buffer, sec_t sector, unsigned int offset, size_t size)
|
||||
{
|
||||
sec_t sec;
|
||||
CACHE_ENTRY *entry;
|
||||
|
||||
if (offset + size > BYTES_PER_READ) return false;
|
||||
|
||||
entry = _FAT_cache_getPage(cache,sector);
|
||||
if(entry==NULL) return false;
|
||||
|
||||
sec = sector - entry->sector;
|
||||
memcpy(buffer,entry->cache + ((sec*BYTES_PER_READ) + offset),size);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _FAT_cache_readLittleEndianValue (CACHE* cache, uint32_t *value, sec_t sector, unsigned int offset, int num_bytes) {
|
||||
uint8_t buf[4];
|
||||
if (!_FAT_cache_readPartialSector(cache, buf, sector, offset, num_bytes)) return false;
|
||||
|
||||
switch(num_bytes) {
|
||||
case 1: *value = buf[0]; break;
|
||||
case 2: *value = u8array_to_u16(buf,0); break;
|
||||
case 4: *value = u8array_to_u32(buf,0); break;
|
||||
default: return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
Writes some data to a cache page, making sure it is loaded into memory first.
|
||||
*/
|
||||
bool _FAT_cache_writePartialSector (CACHE* cache, const void* buffer, sec_t sector, unsigned int offset, size_t size)
|
||||
{
|
||||
sec_t sec;
|
||||
CACHE_ENTRY *entry;
|
||||
|
||||
if (offset + size > BYTES_PER_READ) return false;
|
||||
|
||||
entry = _FAT_cache_getPage(cache,sector);
|
||||
if(entry==NULL) return false;
|
||||
|
||||
sec = sector - entry->sector;
|
||||
memcpy(entry->cache + ((sec*BYTES_PER_READ) + offset),buffer,size);
|
||||
|
||||
entry->dirty = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _FAT_cache_writeLittleEndianValue (CACHE* cache, const uint32_t value, sec_t sector, unsigned int offset, int size) {
|
||||
uint8_t buf[4] = {0, 0, 0, 0};
|
||||
|
||||
switch(size) {
|
||||
case 1: buf[0] = value; break;
|
||||
case 2: u16_to_u8array(buf, 0, value); break;
|
||||
case 4: u32_to_u8array(buf, 0, value); break;
|
||||
default: return false;
|
||||
}
|
||||
|
||||
return _FAT_cache_writePartialSector(cache, buf, sector, offset, size);
|
||||
}
|
||||
|
||||
/*
|
||||
Writes some data to a cache page, zeroing out the page first
|
||||
*/
|
||||
bool _FAT_cache_eraseWritePartialSector (CACHE* cache, const void* buffer, sec_t sector, unsigned int offset, size_t size)
|
||||
{
|
||||
sec_t sec;
|
||||
CACHE_ENTRY *entry;
|
||||
|
||||
if (offset + size > BYTES_PER_READ) return false;
|
||||
|
||||
entry = _FAT_cache_getPage(cache,sector);
|
||||
if(entry==NULL) return false;
|
||||
|
||||
sec = sector - entry->sector;
|
||||
memset(entry->cache + (sec*BYTES_PER_READ),0,BYTES_PER_READ);
|
||||
memcpy(entry->cache + ((sec*BYTES_PER_READ) + offset),buffer,size);
|
||||
|
||||
entry->dirty = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static CACHE_ENTRY* _FAT_cache_findPage(CACHE *cache, sec_t sector, sec_t count) {
|
||||
|
||||
unsigned int i;
|
||||
CACHE_ENTRY* cacheEntries = cache->cacheEntries;
|
||||
unsigned int numberOfPages = cache->numberOfPages;
|
||||
CACHE_ENTRY *entry = NULL;
|
||||
sec_t lowest = UINT_MAX;
|
||||
|
||||
for(i=0;i<numberOfPages;i++) {
|
||||
if (cacheEntries[i].sector != CACHE_FREE) {
|
||||
bool intersect;
|
||||
if (sector > cacheEntries[i].sector) {
|
||||
intersect = sector - cacheEntries[i].sector < cacheEntries[i].count;
|
||||
} else {
|
||||
intersect = cacheEntries[i].sector - sector < count;
|
||||
}
|
||||
|
||||
if ( intersect && (cacheEntries[i].sector < lowest)) {
|
||||
lowest = cacheEntries[i].sector;
|
||||
entry = &cacheEntries[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
bool _FAT_cache_writeSectors (CACHE* cache, sec_t sector, sec_t numSectors, const void* buffer)
|
||||
{
|
||||
sec_t sec;
|
||||
sec_t secs_to_write;
|
||||
CACHE_ENTRY* entry;
|
||||
const uint8_t *src = (const uint8_t *)buffer;
|
||||
|
||||
while(numSectors>0)
|
||||
{
|
||||
entry = _FAT_cache_findPage(cache,sector,numSectors);
|
||||
|
||||
if(entry!=NULL) {
|
||||
|
||||
if ( entry->sector > sector) {
|
||||
|
||||
secs_to_write = entry->sector - sector;
|
||||
|
||||
_FAT_disc_writeSectors(cache->disc,sector,secs_to_write,src);
|
||||
src += (secs_to_write*BYTES_PER_READ);
|
||||
sector += secs_to_write;
|
||||
numSectors -= secs_to_write;
|
||||
}
|
||||
|
||||
sec = sector - entry->sector;
|
||||
secs_to_write = entry->count - sec;
|
||||
|
||||
if(secs_to_write>numSectors) secs_to_write = numSectors;
|
||||
|
||||
memcpy(entry->cache + (sec*BYTES_PER_READ),src,(secs_to_write*BYTES_PER_READ));
|
||||
|
||||
src += (secs_to_write*BYTES_PER_READ);
|
||||
sector += secs_to_write;
|
||||
numSectors -= secs_to_write;
|
||||
|
||||
entry->dirty = true;
|
||||
|
||||
} else {
|
||||
_FAT_disc_writeSectors(cache->disc,sector,numSectors,src);
|
||||
numSectors=0;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
Flushes all dirty pages to disc, clearing the dirty flag.
|
||||
*/
|
||||
bool _FAT_cache_flush (CACHE* cache) {
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < cache->numberOfPages; i++) {
|
||||
if (cache->cacheEntries[i].dirty) {
|
||||
if (!_FAT_disc_writeSectors (cache->disc, cache->cacheEntries[i].sector, cache->cacheEntries[i].count, cache->cacheEntries[i].cache)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
cache->cacheEntries[i].dirty = false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void _FAT_cache_invalidate (CACHE* cache) {
|
||||
unsigned int i;
|
||||
_FAT_cache_flush(cache);
|
||||
for (i = 0; i < cache->numberOfPages; i++) {
|
||||
cache->cacheEntries[i].sector = CACHE_FREE;
|
||||
cache->cacheEntries[i].last_access = 0;
|
||||
cache->cacheEntries[i].count = 0;
|
||||
cache->cacheEntries[i].dirty = false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,130 @@
|
|||
/*
|
||||
cache.h
|
||||
The cache is not visible to the user. It should be flushed
|
||||
when any file is closed or changes are made to the filesystem.
|
||||
|
||||
This cache implements a least-used-page replacement policy. This will
|
||||
distribute sectors evenly over the pages, so if less than the maximum
|
||||
pages are used at once, they should all eventually remain in the cache.
|
||||
This also has the benefit of throwing out old sectors, so as not to keep
|
||||
too many stale pages around.
|
||||
|
||||
Copyright (c) 2006 Michael "Chishm" Chisholm
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
3. The name of the author may not be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _CACHE_H
|
||||
#define _CACHE_H
|
||||
|
||||
#include "common.h"
|
||||
#include "disc.h"
|
||||
|
||||
#define PAGE_SECTORS 64
|
||||
#define CACHE_PAGE_SIZE (BYTES_PER_READ * PAGE_SECTORS)
|
||||
|
||||
typedef struct {
|
||||
sec_t sector;
|
||||
unsigned int count;
|
||||
unsigned int last_access;
|
||||
bool dirty;
|
||||
uint8_t* cache;
|
||||
} CACHE_ENTRY;
|
||||
|
||||
typedef struct {
|
||||
const DISC_INTERFACE* disc;
|
||||
sec_t endOfPartition;
|
||||
unsigned int numberOfPages;
|
||||
unsigned int sectorsPerPage;
|
||||
CACHE_ENTRY* cacheEntries;
|
||||
} CACHE;
|
||||
|
||||
/*
|
||||
Read data from a sector in the cache
|
||||
If the sector is not in the cache, it will be swapped in
|
||||
offset is the position to start reading from
|
||||
size is the amount of data to read
|
||||
Precondition: offset + size <= BYTES_PER_READ
|
||||
*/
|
||||
bool _FAT_cache_readPartialSector (CACHE* cache, void* buffer, sec_t sector, unsigned int offset, size_t size);
|
||||
|
||||
bool _FAT_cache_readLittleEndianValue (CACHE* cache, uint32_t *value, sec_t sector, unsigned int offset, int num_bytes);
|
||||
|
||||
/*
|
||||
Write data to a sector in the cache
|
||||
If the sector is not in the cache, it will be swapped in.
|
||||
When the sector is swapped out, the data will be written to the disc
|
||||
offset is the position to start writing to
|
||||
size is the amount of data to write
|
||||
Precondition: offset + size <= BYTES_PER_READ
|
||||
*/
|
||||
bool _FAT_cache_writePartialSector (CACHE* cache, const void* buffer, sec_t sector, unsigned int offset, size_t size);
|
||||
|
||||
bool _FAT_cache_writeLittleEndianValue (CACHE* cache, const uint32_t value, sec_t sector, unsigned int offset, int num_bytes);
|
||||
|
||||
/*
|
||||
Write data to a sector in the cache, zeroing the sector first
|
||||
If the sector is not in the cache, it will be swapped in.
|
||||
When the sector is swapped out, the data will be written to the disc
|
||||
offset is the position to start writing to
|
||||
size is the amount of data to write
|
||||
Precondition: offset + size <= BYTES_PER_READ
|
||||
*/
|
||||
bool _FAT_cache_eraseWritePartialSector (CACHE* cache, const void* buffer, sec_t sector, unsigned int offset, size_t size);
|
||||
|
||||
/*
|
||||
Read several sectors from the cache
|
||||
*/
|
||||
bool _FAT_cache_readSectors (CACHE* cache, sec_t sector, sec_t numSectors, void* buffer);
|
||||
|
||||
/*
|
||||
Read a full sector from the cache
|
||||
*/
|
||||
static inline bool _FAT_cache_readSector (CACHE* cache, void* buffer, sec_t sector) {
|
||||
return _FAT_cache_readPartialSector (cache, buffer, sector, 0, BYTES_PER_READ);
|
||||
}
|
||||
|
||||
/*
|
||||
Write a full sector to the cache
|
||||
*/
|
||||
static inline bool _FAT_cache_writeSector (CACHE* cache, const void* buffer, sec_t sector) {
|
||||
return _FAT_cache_writePartialSector (cache, buffer, sector, 0, BYTES_PER_READ);
|
||||
}
|
||||
|
||||
bool _FAT_cache_writeSectors (CACHE* cache, sec_t sector, sec_t numSectors, const void* buffer);
|
||||
|
||||
/*
|
||||
Write any dirty sectors back to disc and clear out the contents of the cache
|
||||
*/
|
||||
bool _FAT_cache_flush (CACHE* cache);
|
||||
|
||||
/*
|
||||
Clear out the contents of the cache without writing any dirty sectors first
|
||||
*/
|
||||
void _FAT_cache_invalidate (CACHE* cache);
|
||||
|
||||
CACHE* _FAT_cache_constructor (unsigned int numberOfPages, unsigned int sectorsPerPage, const DISC_INTERFACE* discInterface, sec_t endOfPartition);
|
||||
|
||||
void _FAT_cache_destructor (CACHE* cache);
|
||||
|
||||
#endif // _CACHE_H
|
||||
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
common.h
|
||||
Common definitions and included files for the FATlib
|
||||
|
||||
Copyright (c) 2006 Michael "Chishm" Chisholm
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
3. The name of the author may not be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _COMMON_H
|
||||
#define _COMMON_H
|
||||
|
||||
#define BYTES_PER_READ 512
|
||||
#include <stddef.h>
|
||||
#ifndef _MSC_VER
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
// When compiling for NDS, make sure NDS is defined
|
||||
#ifndef NDS
|
||||
#if defined ARM9 || defined ARM7
|
||||
#define NDS
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Platform specific includes
|
||||
#if defined(__gamecube__) || defined (__wii__)
|
||||
#include <gctypes.h>
|
||||
#include <ogc/disc_io.h>
|
||||
#include <gccore.h>
|
||||
#elif defined(NDS)
|
||||
#include <nds/ndstypes.h>
|
||||
#include <nds/system.h>
|
||||
#include <nds/disc_io.h>
|
||||
#elif defined(GBA)
|
||||
#include <gba_types.h>
|
||||
#include <disc_io.h>
|
||||
#endif
|
||||
|
||||
// Platform specific options
|
||||
#if defined (__wii__)
|
||||
#define DEFAULT_CACHE_PAGES 4
|
||||
#define DEFAULT_SECTORS_PAGE 64
|
||||
#define USE_LWP_LOCK
|
||||
#define USE_RTC_TIME
|
||||
#elif defined (__gamecube__)
|
||||
#define DEFAULT_CACHE_PAGES 4
|
||||
#define DEFAULT_SECTORS_PAGE 64
|
||||
#define USE_LWP_LOCK
|
||||
#define USE_RTC_TIME
|
||||
#elif defined (NDS)
|
||||
#define DEFAULT_CACHE_PAGES 4
|
||||
#define DEFAULT_SECTORS_PAGE 8
|
||||
#define USE_RTC_TIME
|
||||
#elif defined (GBA)
|
||||
#define DEFAULT_CACHE_PAGES 2
|
||||
#define DEFAULT_SECTORS_PAGE 8
|
||||
#define LIMIT_SECTORS 128
|
||||
#else
|
||||
#define LIBFAT_PC 1
|
||||
|
||||
//any particular reason for this?
|
||||
#define DEFAULT_CACHE_PAGES 4
|
||||
#define DEFAULT_SECTORS_PAGE 8
|
||||
#endif
|
||||
|
||||
#include "libfat_pc.h"
|
||||
|
||||
#include "fat.h"
|
||||
|
||||
#endif // _COMMON_H
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,178 @@
|
|||
/*
|
||||
directory.h
|
||||
Reading, writing and manipulation of the directory structure on
|
||||
a FAT partition
|
||||
|
||||
Copyright (c) 2006 Michael "Chishm" Chisholm
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
3. The name of the author may not be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _DIRECTORY_H
|
||||
#define _DIRECTORY_H
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "partition.h"
|
||||
|
||||
#define DIR_ENTRY_DATA_SIZE 0x20
|
||||
#define MAX_LFN_LENGTH 256
|
||||
#define MAX_FILENAME_LENGTH 768 // 256 UCS-2 characters encoded into UTF-8 can use up to 768 UTF-8 chars
|
||||
#define MAX_ALIAS_LENGTH 13
|
||||
#define LFN_ENTRY_LENGTH 13
|
||||
#define ALIAS_ENTRY_LENGTH 11
|
||||
#define MAX_ALIAS_EXT_LENGTH 3
|
||||
#define MAX_ALIAS_PRI_LENGTH 8
|
||||
#define MAX_NUMERIC_TAIL 999999
|
||||
#define FAT16_ROOT_DIR_CLUSTER 0
|
||||
|
||||
#define DIR_SEPARATOR '/'
|
||||
|
||||
// File attributes
|
||||
#define ATTRIB_ARCH 0x20 // Archive
|
||||
#define ATTRIB_DIR 0x10 // Directory
|
||||
#define ATTRIB_LFN 0x0F // Long file name
|
||||
#define ATTRIB_VOL 0x08 // Volume
|
||||
#define ATTRIB_SYS 0x04 // System
|
||||
#define ATTRIB_HID 0x02 // Hidden
|
||||
#define ATTRIB_RO 0x01 // Read only
|
||||
|
||||
typedef enum {FT_DIRECTORY, FT_FILE} FILE_TYPE;
|
||||
|
||||
typedef struct {
|
||||
uint32_t cluster;
|
||||
sec_t sector;
|
||||
int32_t offset;
|
||||
} DIR_ENTRY_POSITION;
|
||||
|
||||
typedef struct {
|
||||
uint8_t entryData[DIR_ENTRY_DATA_SIZE];
|
||||
DIR_ENTRY_POSITION dataStart; // Points to the start of the LFN entries of a file, or the alias for no LFN
|
||||
DIR_ENTRY_POSITION dataEnd; // Always points to the file/directory's alias entry
|
||||
char filename[MAX_FILENAME_LENGTH];
|
||||
} DIR_ENTRY;
|
||||
|
||||
// Directory entry offsets
|
||||
enum DIR_ENTRY_offset {
|
||||
DIR_ENTRY_name = 0x00,
|
||||
DIR_ENTRY_extension = 0x08,
|
||||
DIR_ENTRY_attributes = 0x0B,
|
||||
DIR_ENTRY_reserved = 0x0C,
|
||||
DIR_ENTRY_cTime_ms = 0x0D,
|
||||
DIR_ENTRY_cTime = 0x0E,
|
||||
DIR_ENTRY_cDate = 0x10,
|
||||
DIR_ENTRY_aDate = 0x12,
|
||||
DIR_ENTRY_clusterHigh = 0x14,
|
||||
DIR_ENTRY_mTime = 0x16,
|
||||
DIR_ENTRY_mDate = 0x18,
|
||||
DIR_ENTRY_cluster = 0x1A,
|
||||
DIR_ENTRY_fileSize = 0x1C
|
||||
};
|
||||
|
||||
/*
|
||||
Returns true if the file specified by entry is a directory
|
||||
*/
|
||||
static inline bool _FAT_directory_isDirectory (DIR_ENTRY* entry) {
|
||||
return ((entry->entryData[DIR_ENTRY_attributes] & ATTRIB_DIR) != 0);
|
||||
}
|
||||
|
||||
static inline bool _FAT_directory_isWritable (DIR_ENTRY* entry) {
|
||||
return ((entry->entryData[DIR_ENTRY_attributes] & ATTRIB_RO) == 0);
|
||||
}
|
||||
|
||||
static inline bool _FAT_directory_isDot (DIR_ENTRY* entry) {
|
||||
return ((entry->filename[0] == '.') && ((entry->filename[1] == '\0') ||
|
||||
((entry->filename[1] == '.') && entry->filename[2] == '\0')));
|
||||
}
|
||||
|
||||
/*
|
||||
Reads the first directory entry from the directory starting at dirCluster
|
||||
Places result in entry
|
||||
entry will be destroyed even if no directory entry is found
|
||||
Returns true on success, false on failure
|
||||
*/
|
||||
bool _FAT_directory_getFirstEntry (PARTITION* partition, DIR_ENTRY* entry, uint32_t dirCluster);
|
||||
|
||||
/*
|
||||
Reads the next directory entry after the one already pointed to by entry
|
||||
Places result in entry
|
||||
entry will be destroyed even if no directory entry is found
|
||||
Returns true on success, false on failure
|
||||
*/
|
||||
bool _FAT_directory_getNextEntry (PARTITION* partition, DIR_ENTRY* entry);
|
||||
|
||||
/*
|
||||
Gets the directory entry corrsponding to the supplied path
|
||||
entry will be destroyed even if no directory entry is found
|
||||
pathEnd specifies the end of the path string, for cutting strings short if needed
|
||||
specify NULL to use the full length of path
|
||||
pathEnd is only a suggestion, and the path string will be searched up until the next PATH_SEPARATOR
|
||||
after pathEND.
|
||||
Returns true on success, false on failure
|
||||
*/
|
||||
bool _FAT_directory_entryFromPath (PARTITION* partition, DIR_ENTRY* entry, const char* path, const char* pathEnd);
|
||||
|
||||
/*
|
||||
Changes the current directory to the one specified by path
|
||||
Returns true on success, false on failure
|
||||
*/
|
||||
bool _FAT_directory_chdir (PARTITION* partition, const char* path);
|
||||
|
||||
/*
|
||||
Removes the directory entry specified by entry
|
||||
Assumes that entry is valid
|
||||
Returns true on success, false on failure
|
||||
*/
|
||||
bool _FAT_directory_removeEntry (PARTITION* partition, DIR_ENTRY* entry);
|
||||
|
||||
/*
|
||||
Add a directory entry to the directory specified by dirCluster
|
||||
The fileData, dataStart and dataEnd elements of the DIR_ENTRY struct are
|
||||
updated with the new directory entry position and alias.
|
||||
Returns true on success, false on failure
|
||||
*/
|
||||
bool _FAT_directory_addEntry (PARTITION* partition, DIR_ENTRY* entry, uint32_t dirCluster);
|
||||
|
||||
/*
|
||||
Get the start cluster of a file from it's entry data
|
||||
*/
|
||||
uint32_t _FAT_directory_entryGetCluster (PARTITION* partition, const uint8_t* entryData);
|
||||
|
||||
/*
|
||||
Fill in the file name and entry data of DIR_ENTRY* entry.
|
||||
Assumes that the entry's dataStart and dataEnd are correct
|
||||
Returns true on success, false on failure
|
||||
*/
|
||||
bool _FAT_directory_entryFromPosition (PARTITION* partition, DIR_ENTRY* entry);
|
||||
|
||||
/*
|
||||
Fill in a stat struct based on a file entry
|
||||
*/
|
||||
void _FAT_directory_entryStat (PARTITION* partition, DIR_ENTRY* entry, struct stat *st);
|
||||
|
||||
/*
|
||||
Get volume label
|
||||
*/
|
||||
bool _FAT_directory_getVolumeLabel (PARTITION* partition, char *label);
|
||||
|
||||
#endif // _DIRECTORY_H
|
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
disc.c
|
||||
Interface to the low level disc functions. Used by the higher level
|
||||
file system code.
|
||||
|
||||
Copyright (c) 2008 Michael "Chishm" Chisholm
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
3. The name of the author may not be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "disc.h"
|
||||
|
||||
/*
|
||||
The list of interfaces consists of a series of name/interface pairs.
|
||||
The interface is returned via a simple function. This allows for
|
||||
platforms where the interface has to be "assembled" before it can
|
||||
be used, like DLDI on the NDS. For cases where a simple struct
|
||||
is available, wrapper functions are used.
|
||||
The list is terminated by a NULL/NULL entry.
|
||||
*/
|
||||
|
||||
/* ====================== Wii ====================== */
|
||||
#if defined (__wii__)
|
||||
#include <sdcard/wiisd_io.h>
|
||||
#include <ogc/usbstorage.h>
|
||||
#include <sdcard/gcsd.h>
|
||||
|
||||
static const DISC_INTERFACE* get_io_wiisd (void) {
|
||||
return &__io_wiisd;
|
||||
}
|
||||
static const DISC_INTERFACE* get_io_usbstorage (void) {
|
||||
return &__io_usbstorage;
|
||||
}
|
||||
|
||||
static const DISC_INTERFACE* get_io_gcsda (void) {
|
||||
return &__io_gcsda;
|
||||
}
|
||||
static const DISC_INTERFACE* get_io_gcsdb (void) {
|
||||
return &__io_gcsdb;
|
||||
}
|
||||
|
||||
const INTERFACE_ID _FAT_disc_interfaces[] = {
|
||||
{"sd", get_io_wiisd},
|
||||
{"usb", get_io_usbstorage},
|
||||
{"carda", get_io_gcsda},
|
||||
{"cardb", get_io_gcsdb},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
/* ==================== Gamecube ==================== */
|
||||
#elif defined (__gamecube__)
|
||||
#include <sdcard/gcsd.h>
|
||||
|
||||
static const DISC_INTERFACE* get_io_gcsda (void) {
|
||||
return &__io_gcsda;
|
||||
}
|
||||
static const DISC_INTERFACE* get_io_gcsdb (void) {
|
||||
return &__io_gcsdb;
|
||||
}
|
||||
|
||||
const INTERFACE_ID _FAT_disc_interfaces[] = {
|
||||
{"carda", get_io_gcsda},
|
||||
{"cardb", get_io_gcsdb},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
/* ====================== NDS ====================== */
|
||||
#elif defined (NDS)
|
||||
#include <nds/arm9/dldi.h>
|
||||
|
||||
const INTERFACE_ID _FAT_disc_interfaces[] = {
|
||||
{"fat", dldiGetInternal},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
/* ====================== GBA ====================== */
|
||||
#elif defined (GBA)
|
||||
#include <disc.h>
|
||||
|
||||
const INTERFACE_ID _FAT_disc_interfaces[] = {
|
||||
{"fat", discGetInterface},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
disc.h
|
||||
Interface to the low level disc functions. Used by the higher level
|
||||
file system code.
|
||||
|
||||
Copyright (c) 2006 Michael "Chishm" Chisholm
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
3. The name of the author may not be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef _DISC_H
|
||||
#define _DISC_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
/*
|
||||
A list of all default devices to try at startup,
|
||||
terminated by a {NULL,NULL} entry.
|
||||
*/
|
||||
typedef struct {
|
||||
const char* name;
|
||||
const DISC_INTERFACE* (*getInterface)(void);
|
||||
} INTERFACE_ID;
|
||||
extern const INTERFACE_ID _FAT_disc_interfaces[];
|
||||
|
||||
/*
|
||||
Check if a disc is inserted
|
||||
Return true if a disc is inserted and ready, false otherwise
|
||||
*/
|
||||
static inline bool _FAT_disc_isInserted (const DISC_INTERFACE* disc) {
|
||||
return disc->isInserted();
|
||||
}
|
||||
|
||||
/*
|
||||
Read numSectors sectors from a disc, starting at sector.
|
||||
numSectors is between 1 and LIMIT_SECTORS if LIMIT_SECTORS is defined,
|
||||
else it is at least 1
|
||||
sector is 0 or greater
|
||||
buffer is a pointer to the memory to fill
|
||||
*/
|
||||
static inline bool _FAT_disc_readSectors (const DISC_INTERFACE* disc, sec_t sector, sec_t numSectors, void* buffer) {
|
||||
return disc->readSectors (sector, numSectors, buffer);
|
||||
}
|
||||
|
||||
/*
|
||||
Write numSectors sectors to a disc, starting at sector.
|
||||
numSectors is between 1 and LIMIT_SECTORS if LIMIT_SECTORS is defined,
|
||||
else it is at least 1
|
||||
sector is 0 or greater
|
||||
buffer is a pointer to the memory to read from
|
||||
*/
|
||||
static inline bool _FAT_disc_writeSectors (const DISC_INTERFACE* disc, sec_t sector, sec_t numSectors, const void* buffer) {
|
||||
return disc->writeSectors (sector, numSectors, buffer);
|
||||
}
|
||||
|
||||
/*
|
||||
Reset the card back to a ready state
|
||||
*/
|
||||
static inline bool _FAT_disc_clearStatus (const DISC_INTERFACE* disc) {
|
||||
return disc->clearStatus();
|
||||
}
|
||||
|
||||
/*
|
||||
Initialise the disc to a state ready for data reading or writing
|
||||
*/
|
||||
static inline bool _FAT_disc_startup (const DISC_INTERFACE* disc) {
|
||||
return disc->startup();
|
||||
}
|
||||
|
||||
/*
|
||||
Put the disc in a state ready for power down.
|
||||
Complete any pending writes and disable the disc if necessary
|
||||
*/
|
||||
static inline bool _FAT_disc_shutdown (const DISC_INTERFACE* disc) {
|
||||
return disc->shutdown();
|
||||
}
|
||||
|
||||
/*
|
||||
Return a 32 bit value unique to each type of interface
|
||||
*/
|
||||
static inline uint32_t _FAT_disc_hostType (const DISC_INTERFACE* disc) {
|
||||
return disc->ioType;
|
||||
}
|
||||
|
||||
/*
|
||||
Return a 32 bit value that specifies the capabilities of the disc
|
||||
*/
|
||||
static inline uint32_t _FAT_disc_features (const DISC_INTERFACE* disc) {
|
||||
return disc->features;
|
||||
}
|
||||
|
||||
#endif // _DISC_H
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
disc_io.h
|
||||
Interface template for low level disc functions.
|
||||
|
||||
Copyright (c) 2006 Michael "Chishm" Chisholm
|
||||
Based on code originally written by MightyMax
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
3. The name of the author may not be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef NDS_DISC_IO_INCLUDE
|
||||
#define NDS_DISC_IO_INCLUDE
|
||||
|
||||
#include "ndstypes.h"
|
||||
|
||||
#define FEATURE_MEDIUM_CANREAD 0x00000001
|
||||
#define FEATURE_MEDIUM_CANWRITE 0x00000002
|
||||
#define FEATURE_SLOT_GBA 0x00000010
|
||||
#define FEATURE_SLOT_NDS 0x00000020
|
||||
|
||||
typedef uint32_t sec_t;
|
||||
|
||||
typedef bool (* FN_MEDIUM_STARTUP)(void) ;
|
||||
typedef bool (* FN_MEDIUM_ISINSERTED)(void) ;
|
||||
typedef bool (* FN_MEDIUM_READSECTORS)(sec_t sector, sec_t numSectors, void* buffer) ;
|
||||
typedef bool (* FN_MEDIUM_WRITESECTORS)(sec_t sector, sec_t numSectors, const void* buffer) ;
|
||||
typedef bool (* FN_MEDIUM_CLEARSTATUS)(void) ;
|
||||
typedef bool (* FN_MEDIUM_SHUTDOWN)(void) ;
|
||||
|
||||
struct DISC_INTERFACE_STRUCT {
|
||||
unsigned long ioType ;
|
||||
unsigned long features ;
|
||||
FN_MEDIUM_STARTUP startup ;
|
||||
FN_MEDIUM_ISINSERTED isInserted ;
|
||||
FN_MEDIUM_READSECTORS readSectors ;
|
||||
FN_MEDIUM_WRITESECTORS writeSectors ;
|
||||
FN_MEDIUM_CLEARSTATUS clearStatus ;
|
||||
FN_MEDIUM_SHUTDOWN shutdown ;
|
||||
} ;
|
||||
|
||||
typedef struct DISC_INTERFACE_STRUCT DISC_INTERFACE ;
|
||||
|
||||
#endif // define NDS_DISC_IO_INCLUDE
|
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
fat.h
|
||||
Simple functionality for startup, mounting and unmounting of FAT-based devices.
|
||||
|
||||
Copyright (c) 2006 - 2009
|
||||
Michael "Chishm" Chisholm
|
||||
Dave "WinterMute" Murphy
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
3. The name of the author may not be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _LIBFAT_H
|
||||
#define _LIBFAT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// When compiling for NDS, make sure NDS is defined
|
||||
#ifndef NDS
|
||||
#if defined ARM9 || defined ARM7
|
||||
#define NDS
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef _MSC_VER
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
#if defined(__gamecube__) || defined (__wii__)
|
||||
# include <ogc/disc_io.h>
|
||||
#else
|
||||
# ifdef NDS
|
||||
# include "nds/disc_io.h"
|
||||
# else
|
||||
# include "disc_io.h"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
Initialise any inserted block-devices.
|
||||
Add the fat device driver to the devoptab, making it available for standard file functions.
|
||||
cacheSize: The number of pages to allocate for each inserted block-device
|
||||
setAsDefaultDevice: if true, make this the default device driver for file operations
|
||||
*/
|
||||
extern bool fatInit (uint32_t cacheSize, bool setAsDefaultDevice);
|
||||
|
||||
/*
|
||||
Calls fatInit with setAsDefaultDevice = true and cacheSize optimised for the host system.
|
||||
*/
|
||||
extern bool fatInitDefault (void);
|
||||
|
||||
/*
|
||||
Mount the device pointed to by interface, and set up a devoptab entry for it as "name:".
|
||||
You can then access the filesystem using "name:/".
|
||||
This will mount the active partition or the first valid partition on the disc,
|
||||
and will use a cache size optimized for the host system.
|
||||
*/
|
||||
extern bool fatMountSimple (const char* name, const DISC_INTERFACE* interface);
|
||||
|
||||
/*
|
||||
Mount the device pointed to by interface, and set up a devoptab entry for it as "name:".
|
||||
You can then access the filesystem using "name:/".
|
||||
If startSector = 0, it will mount the active partition of the first valid partition on
|
||||
the disc. Otherwise it will try to mount the partition starting at startSector.
|
||||
cacheSize specifies the number of pages to allocate for the cache.
|
||||
This will not startup the disc, so you need to call interface->startup(); first.
|
||||
*/
|
||||
extern bool fatMount (const char* name, const DISC_INTERFACE* interface, sec_t startSector, uint32_t cacheSize, uint32_t SectorsPerPage);
|
||||
|
||||
/*
|
||||
Unmount the partition specified by name.
|
||||
If there are open files, it will attempt to synchronise them to disc.
|
||||
*/
|
||||
extern void fatUnmount (const char* name);
|
||||
|
||||
/*
|
||||
Get Volume Label
|
||||
*/
|
||||
extern void fatGetVolumeLabel (const char* name, char *label);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _LIBFAT_H
|
|
@ -0,0 +1,613 @@
|
|||
/*
|
||||
fatdir.c
|
||||
|
||||
Functions used by the newlib disc stubs to interface with
|
||||
this library
|
||||
|
||||
Copyright (c) 2006 Michael "Chishm" Chisholm
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
3. The name of the author may not be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#ifndef _MSC_VER
|
||||
#include <unistd.h>
|
||||
#include <sys/dir.h>
|
||||
#endif
|
||||
|
||||
#include "fatdir.h"
|
||||
|
||||
#include "cache.h"
|
||||
#include "file_allocation_table.h"
|
||||
#include "partition.h"
|
||||
#include "directory.h"
|
||||
#include "bit_ops.h"
|
||||
#include "filetime.h"
|
||||
#include "lock.h"
|
||||
|
||||
|
||||
int _FAT_stat_r (struct _reent *r, const char *path, struct stat *st) {
|
||||
PARTITION* partition = NULL;
|
||||
DIR_ENTRY dirEntry;
|
||||
|
||||
// Get the partition this file is on
|
||||
partition = _FAT_partition_getPartitionFromPath (path);
|
||||
if (partition == NULL) {
|
||||
r->_errno = ENODEV;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Move the path pointer to the start of the actual path
|
||||
if (strchr (path, ':') != NULL) {
|
||||
path = strchr (path, ':') + 1;
|
||||
}
|
||||
if (strchr (path, ':') != NULL) {
|
||||
r->_errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
_FAT_lock(&partition->lock);
|
||||
|
||||
// Search for the file on the disc
|
||||
if (!_FAT_directory_entryFromPath (partition, &dirEntry, path, NULL)) {
|
||||
_FAT_unlock(&partition->lock);
|
||||
r->_errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Fill in the stat struct
|
||||
_FAT_directory_entryStat (partition, &dirEntry, st);
|
||||
|
||||
_FAT_unlock(&partition->lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _FAT_link_r (struct _reent *r, const char *existing, const char *newLink) {
|
||||
r->_errno = ENOTSUP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _FAT_unlink_r (struct _reent *r, const char *path) {
|
||||
PARTITION* partition = NULL;
|
||||
DIR_ENTRY dirEntry;
|
||||
DIR_ENTRY dirContents;
|
||||
uint32_t cluster;
|
||||
bool nextEntry;
|
||||
bool errorOccured = false;
|
||||
|
||||
// Get the partition this directory is on
|
||||
partition = _FAT_partition_getPartitionFromPath (path);
|
||||
if (partition == NULL) {
|
||||
r->_errno = ENODEV;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Make sure we aren't trying to write to a read-only disc
|
||||
if (partition->readOnly) {
|
||||
r->_errno = EROFS;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Move the path pointer to the start of the actual path
|
||||
if (strchr (path, ':') != NULL) {
|
||||
path = strchr (path, ':') + 1;
|
||||
}
|
||||
if (strchr (path, ':') != NULL) {
|
||||
r->_errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
_FAT_lock(&partition->lock);
|
||||
|
||||
// Search for the file on the disc
|
||||
if (!_FAT_directory_entryFromPath (partition, &dirEntry, path, NULL)) {
|
||||
_FAT_unlock(&partition->lock);
|
||||
r->_errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
cluster = _FAT_directory_entryGetCluster (partition, dirEntry.entryData);
|
||||
|
||||
|
||||
// If this is a directory, make sure it is empty
|
||||
if (_FAT_directory_isDirectory (&dirEntry)) {
|
||||
nextEntry = _FAT_directory_getFirstEntry (partition, &dirContents, cluster);
|
||||
|
||||
while (nextEntry) {
|
||||
if (!_FAT_directory_isDot (&dirContents)) {
|
||||
// The directory had something in it that isn't a reference to itself or it's parent
|
||||
_FAT_unlock(&partition->lock);
|
||||
r->_errno = EPERM;
|
||||
return -1;
|
||||
}
|
||||
nextEntry = _FAT_directory_getNextEntry (partition, &dirContents);
|
||||
}
|
||||
}
|
||||
|
||||
if (_FAT_fat_isValidCluster(partition, cluster)) {
|
||||
// Remove the cluster chain for this file
|
||||
if (!_FAT_fat_clearLinks (partition, cluster)) {
|
||||
r->_errno = EIO;
|
||||
errorOccured = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove the directory entry for this file
|
||||
if (!_FAT_directory_removeEntry (partition, &dirEntry)) {
|
||||
r->_errno = EIO;
|
||||
errorOccured = true;
|
||||
}
|
||||
|
||||
// Flush any sectors in the disc cache
|
||||
if (!_FAT_cache_flush(partition->cache)) {
|
||||
r->_errno = EIO;
|
||||
errorOccured = true;
|
||||
}
|
||||
|
||||
_FAT_unlock(&partition->lock);
|
||||
if (errorOccured) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int _FAT_chdir_r (struct _reent *r, const char *path) {
|
||||
PARTITION* partition = NULL;
|
||||
|
||||
// Get the partition this directory is on
|
||||
partition = _FAT_partition_getPartitionFromPath (path);
|
||||
if (partition == NULL) {
|
||||
r->_errno = ENODEV;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Move the path pointer to the start of the actual path
|
||||
if (strchr (path, ':') != NULL) {
|
||||
path = strchr (path, ':') + 1;
|
||||
}
|
||||
if (strchr (path, ':') != NULL) {
|
||||
r->_errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
_FAT_lock(&partition->lock);
|
||||
|
||||
// Try changing directory
|
||||
if (_FAT_directory_chdir (partition, path)) {
|
||||
// Successful
|
||||
_FAT_unlock(&partition->lock);
|
||||
return 0;
|
||||
} else {
|
||||
// Failed
|
||||
_FAT_unlock(&partition->lock);
|
||||
r->_errno = ENOTDIR;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int _FAT_rename_r (struct _reent *r, const char *oldName, const char *newName) {
|
||||
PARTITION* partition = NULL;
|
||||
DIR_ENTRY oldDirEntry;
|
||||
DIR_ENTRY newDirEntry;
|
||||
const char *pathEnd;
|
||||
uint32_t dirCluster;
|
||||
|
||||
// Get the partition this directory is on
|
||||
partition = _FAT_partition_getPartitionFromPath (oldName);
|
||||
if (partition == NULL) {
|
||||
r->_errno = ENODEV;
|
||||
return -1;
|
||||
}
|
||||
|
||||
_FAT_lock(&partition->lock);
|
||||
|
||||
// Make sure the same partition is used for the old and new names
|
||||
if (partition != _FAT_partition_getPartitionFromPath (newName)) {
|
||||
_FAT_unlock(&partition->lock);
|
||||
r->_errno = EXDEV;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Make sure we aren't trying to write to a read-only disc
|
||||
if (partition->readOnly) {
|
||||
_FAT_unlock(&partition->lock);
|
||||
r->_errno = EROFS;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Move the path pointer to the start of the actual path
|
||||
if (strchr (oldName, ':') != NULL) {
|
||||
oldName = strchr (oldName, ':') + 1;
|
||||
}
|
||||
if (strchr (oldName, ':') != NULL) {
|
||||
_FAT_unlock(&partition->lock);
|
||||
r->_errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
if (strchr (newName, ':') != NULL) {
|
||||
newName = strchr (newName, ':') + 1;
|
||||
}
|
||||
if (strchr (newName, ':') != NULL) {
|
||||
_FAT_unlock(&partition->lock);
|
||||
r->_errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Search for the file on the disc
|
||||
if (!_FAT_directory_entryFromPath (partition, &oldDirEntry, oldName, NULL)) {
|
||||
_FAT_unlock(&partition->lock);
|
||||
r->_errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Make sure there is no existing file / directory with the new name
|
||||
if (_FAT_directory_entryFromPath (partition, &newDirEntry, newName, NULL)) {
|
||||
_FAT_unlock(&partition->lock);
|
||||
r->_errno = EEXIST;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Create the new file entry
|
||||
// Get the directory it has to go in
|
||||
pathEnd = strrchr (newName, DIR_SEPARATOR);
|
||||
if (pathEnd == NULL) {
|
||||
// No path was specified
|
||||
dirCluster = partition->cwdCluster;
|
||||
pathEnd = newName;
|
||||
} else {
|
||||
// Path was specified -- get the right dirCluster
|
||||
// Recycling newDirEntry, since it needs to be recreated anyway
|
||||
if (!_FAT_directory_entryFromPath (partition, &newDirEntry, newName, pathEnd) ||
|
||||
!_FAT_directory_isDirectory(&newDirEntry)) {
|
||||
_FAT_unlock(&partition->lock);
|
||||
r->_errno = ENOTDIR;
|
||||
return -1;
|
||||
}
|
||||
dirCluster = _FAT_directory_entryGetCluster (partition, newDirEntry.entryData);
|
||||
// Move the pathEnd past the last DIR_SEPARATOR
|
||||
pathEnd += 1;
|
||||
}
|
||||
|
||||
// Copy the entry data
|
||||
memcpy (&newDirEntry, &oldDirEntry, sizeof(DIR_ENTRY));
|
||||
|
||||
// Set the new name
|
||||
strncpy (newDirEntry.filename, pathEnd, MAX_FILENAME_LENGTH - 1);
|
||||
|
||||
// Write the new entry
|
||||
if (!_FAT_directory_addEntry (partition, &newDirEntry, dirCluster)) {
|
||||
_FAT_unlock(&partition->lock);
|
||||
r->_errno = ENOSPC;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Remove the old entry
|
||||
if (!_FAT_directory_removeEntry (partition, &oldDirEntry)) {
|
||||
_FAT_unlock(&partition->lock);
|
||||
r->_errno = EIO;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Flush any sectors in the disc cache
|
||||
if (!_FAT_cache_flush (partition->cache)) {
|
||||
_FAT_unlock(&partition->lock);
|
||||
r->_errno = EIO;
|
||||
return -1;
|
||||
}
|
||||
|
||||
_FAT_unlock(&partition->lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _FAT_mkdir_r (struct _reent *r, const char *path, int mode) {
|
||||
PARTITION* partition = NULL;
|
||||
bool fileExists;
|
||||
DIR_ENTRY dirEntry;
|
||||
const char* pathEnd;
|
||||
uint32_t parentCluster, dirCluster;
|
||||
uint8_t newEntryData[DIR_ENTRY_DATA_SIZE];
|
||||
|
||||
partition = _FAT_partition_getPartitionFromPath (path);
|
||||
if (partition == NULL) {
|
||||
r->_errno = ENODEV;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Move the path pointer to the start of the actual path
|
||||
if (strchr (path, ':') != NULL) {
|
||||
path = strchr (path, ':') + 1;
|
||||
}
|
||||
if (strchr (path, ':') != NULL) {
|
||||
r->_errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
_FAT_lock(&partition->lock);
|
||||
|
||||
// Search for the file/directory on the disc
|
||||
fileExists = _FAT_directory_entryFromPath (partition, &dirEntry, path, NULL);
|
||||
|
||||
// Make sure it doesn't exist
|
||||
if (fileExists) {
|
||||
_FAT_unlock(&partition->lock);
|
||||
r->_errno = EEXIST;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (partition->readOnly) {
|
||||
// We can't write to a read-only partition
|
||||
_FAT_unlock(&partition->lock);
|
||||
r->_errno = EROFS;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Get the directory it has to go in
|
||||
pathEnd = strrchr (path, DIR_SEPARATOR);
|
||||
if (pathEnd == NULL) {
|
||||
// No path was specified
|
||||
parentCluster = partition->cwdCluster;
|
||||
pathEnd = path;
|
||||
} else {
|
||||
// Path was specified -- get the right parentCluster
|
||||
// Recycling dirEntry, since it needs to be recreated anyway
|
||||
if (!_FAT_directory_entryFromPath (partition, &dirEntry, path, pathEnd) ||
|
||||
!_FAT_directory_isDirectory(&dirEntry)) {
|
||||
_FAT_unlock(&partition->lock);
|
||||
r->_errno = ENOTDIR;
|
||||
return -1;
|
||||
}
|
||||
parentCluster = _FAT_directory_entryGetCluster (partition, dirEntry.entryData);
|
||||
// Move the pathEnd past the last DIR_SEPARATOR
|
||||
pathEnd += 1;
|
||||
}
|
||||
// Create the entry data
|
||||
strncpy (dirEntry.filename, pathEnd, MAX_FILENAME_LENGTH - 1);
|
||||
memset (dirEntry.entryData, 0, DIR_ENTRY_DATA_SIZE);
|
||||
|
||||
// Set the creation time and date
|
||||
dirEntry.entryData[DIR_ENTRY_cTime_ms] = 0;
|
||||
u16_to_u8array (dirEntry.entryData, DIR_ENTRY_cTime, _FAT_filetime_getTimeFromRTC());
|
||||
u16_to_u8array (dirEntry.entryData, DIR_ENTRY_cDate, _FAT_filetime_getDateFromRTC());
|
||||
u16_to_u8array (dirEntry.entryData, DIR_ENTRY_mTime, _FAT_filetime_getTimeFromRTC());
|
||||
u16_to_u8array (dirEntry.entryData, DIR_ENTRY_mDate, _FAT_filetime_getDateFromRTC());
|
||||
u16_to_u8array (dirEntry.entryData, DIR_ENTRY_aDate, _FAT_filetime_getDateFromRTC());
|
||||
|
||||
// Set the directory attribute
|
||||
dirEntry.entryData[DIR_ENTRY_attributes] = ATTRIB_DIR;
|
||||
|
||||
// Get a cluster for the new directory
|
||||
dirCluster = _FAT_fat_linkFreeClusterCleared (partition, CLUSTER_FREE);
|
||||
if (!_FAT_fat_isValidCluster(partition, dirCluster)) {
|
||||
// No space left on disc for the cluster
|
||||
_FAT_unlock(&partition->lock);
|
||||
r->_errno = ENOSPC;
|
||||
return -1;
|
||||
}
|
||||
u16_to_u8array (dirEntry.entryData, DIR_ENTRY_cluster, dirCluster);
|
||||
u16_to_u8array (dirEntry.entryData, DIR_ENTRY_clusterHigh, dirCluster >> 16);
|
||||
|
||||
// Write the new directory's entry to it's parent
|
||||
if (!_FAT_directory_addEntry (partition, &dirEntry, parentCluster)) {
|
||||
_FAT_unlock(&partition->lock);
|
||||
r->_errno = ENOSPC;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Create the dot entry within the directory
|
||||
memset (newEntryData, 0, DIR_ENTRY_DATA_SIZE);
|
||||
memset (newEntryData, ' ', 11);
|
||||
newEntryData[DIR_ENTRY_name] = '.';
|
||||
newEntryData[DIR_ENTRY_attributes] = ATTRIB_DIR;
|
||||
u16_to_u8array (newEntryData, DIR_ENTRY_cluster, dirCluster);
|
||||
u16_to_u8array (newEntryData, DIR_ENTRY_clusterHigh, dirCluster >> 16);
|
||||
|
||||
// Write it to the directory, erasing that sector in the process
|
||||
_FAT_cache_eraseWritePartialSector ( partition->cache, newEntryData,
|
||||
_FAT_fat_clusterToSector (partition, dirCluster), 0, DIR_ENTRY_DATA_SIZE);
|
||||
|
||||
|
||||
// Create the double dot entry within the directory
|
||||
|
||||
// if ParentDir == Rootdir then ".."" always link to Cluster 0
|
||||
if(parentCluster == partition->rootDirCluster)
|
||||
parentCluster = FAT16_ROOT_DIR_CLUSTER;
|
||||
|
||||
newEntryData[DIR_ENTRY_name + 1] = '.';
|
||||
u16_to_u8array (newEntryData, DIR_ENTRY_cluster, parentCluster);
|
||||
u16_to_u8array (newEntryData, DIR_ENTRY_clusterHigh, parentCluster >> 16);
|
||||
|
||||
// Write it to the directory
|
||||
_FAT_cache_writePartialSector ( partition->cache, newEntryData,
|
||||
_FAT_fat_clusterToSector (partition, dirCluster), DIR_ENTRY_DATA_SIZE, DIR_ENTRY_DATA_SIZE);
|
||||
|
||||
// Flush any sectors in the disc cache
|
||||
if (!_FAT_cache_flush(partition->cache)) {
|
||||
_FAT_unlock(&partition->lock);
|
||||
r->_errno = EIO;
|
||||
return -1;
|
||||
}
|
||||
|
||||
_FAT_unlock(&partition->lock);
|
||||
return 0;
|
||||
}
|
||||
//
|
||||
//int _FAT_statvfs_r (struct _reent *r, const char *path, struct statvfs *buf)
|
||||
//{
|
||||
// PARTITION* partition = NULL;
|
||||
// unsigned int freeClusterCount;
|
||||
//
|
||||
// // Get the partition of the requested path
|
||||
// partition = _FAT_partition_getPartitionFromPath (path);
|
||||
// if (partition == NULL) {
|
||||
// r->_errno = ENODEV;
|
||||
// return -1;
|
||||
// }
|
||||
//
|
||||
// _FAT_lock(&partition->lock);
|
||||
//
|
||||
// freeClusterCount = _FAT_fat_freeClusterCount (partition);
|
||||
//
|
||||
// // FAT clusters = POSIX blocks
|
||||
// buf->f_bsize = partition->bytesPerCluster; // File system block size.
|
||||
// buf->f_frsize = partition->bytesPerCluster; // Fundamental file system block size.
|
||||
//
|
||||
// buf->f_blocks = partition->fat.lastCluster - CLUSTER_FIRST + 1; // Total number of blocks on file system in units of f_frsize.
|
||||
// buf->f_bfree = freeClusterCount; // Total number of free blocks.
|
||||
// buf->f_bavail = freeClusterCount; // Number of free blocks available to non-privileged process.
|
||||
//
|
||||
// // Treat requests for info on inodes as clusters
|
||||
// buf->f_files = partition->fat.lastCluster - CLUSTER_FIRST + 1; // Total number of file serial numbers.
|
||||
// buf->f_ffree = freeClusterCount; // Total number of free file serial numbers.
|
||||
// buf->f_favail = freeClusterCount; // Number of file serial numbers available to non-privileged process.
|
||||
//
|
||||
// // File system ID. 32bit ioType value
|
||||
// buf->f_fsid = _FAT_disc_hostType(partition->disc);
|
||||
//
|
||||
// // Bit mask of f_flag values.
|
||||
// buf->f_flag = ST_NOSUID /* No support for ST_ISUID and ST_ISGID file mode bits */
|
||||
// | (partition->readOnly ? ST_RDONLY /* Read only file system */ : 0 ) ;
|
||||
// // Maximum filename length.
|
||||
// buf->f_namemax = MAX_FILENAME_LENGTH;
|
||||
//
|
||||
// _FAT_unlock(&partition->lock);
|
||||
// return 0;
|
||||
//}
|
||||
|
||||
DIR_ITER* _FAT_diropen_r(struct _reent *r, DIR_ITER *dirState, const char *path) {
|
||||
DIR_ENTRY dirEntry;
|
||||
DIR_STATE_STRUCT* state = (DIR_STATE_STRUCT*) (dirState->dirStruct);
|
||||
bool fileExists;
|
||||
|
||||
state->partition = _FAT_partition_getPartitionFromPath (path);
|
||||
if (state->partition == NULL) {
|
||||
r->_errno = ENODEV;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Move the path pointer to the start of the actual path
|
||||
if (strchr (path, ':') != NULL) {
|
||||
path = strchr (path, ':') + 1;
|
||||
}
|
||||
if (strchr (path, ':') != NULL) {
|
||||
r->_errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
_FAT_lock(&state->partition->lock);
|
||||
|
||||
// Get the start cluster of the directory
|
||||
fileExists = _FAT_directory_entryFromPath (state->partition, &dirEntry, path, NULL);
|
||||
|
||||
if (!fileExists) {
|
||||
_FAT_unlock(&state->partition->lock);
|
||||
r->_errno = ENOENT;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Make sure it is a directory
|
||||
if (! _FAT_directory_isDirectory (&dirEntry)) {
|
||||
_FAT_unlock(&state->partition->lock);
|
||||
r->_errno = ENOTDIR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Save the start cluster for use when resetting the directory data
|
||||
state->startCluster = _FAT_directory_entryGetCluster (state->partition, dirEntry.entryData);
|
||||
|
||||
// Get the first entry for use with a call to dirnext
|
||||
state->validEntry =
|
||||
_FAT_directory_getFirstEntry (state->partition, &(state->currentEntry), state->startCluster);
|
||||
|
||||
// We are now using this entry
|
||||
state->inUse = true;
|
||||
_FAT_unlock(&state->partition->lock);
|
||||
return (DIR_ITER*) state;
|
||||
}
|
||||
|
||||
int _FAT_dirreset_r (struct _reent *r, DIR_ITER *dirState) {
|
||||
DIR_STATE_STRUCT* state = (DIR_STATE_STRUCT*) (dirState->dirStruct);
|
||||
|
||||
_FAT_lock(&state->partition->lock);
|
||||
|
||||
// Make sure we are still using this entry
|
||||
if (!state->inUse) {
|
||||
_FAT_unlock(&state->partition->lock);
|
||||
r->_errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Get the first entry for use with a call to dirnext
|
||||
state->validEntry =
|
||||
_FAT_directory_getFirstEntry (state->partition, &(state->currentEntry), state->startCluster);
|
||||
|
||||
_FAT_unlock(&state->partition->lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _FAT_dirnext_r (struct _reent *r, DIR_ITER *dirState, char *filename, struct stat *filestat) {
|
||||
DIR_STATE_STRUCT* state = (DIR_STATE_STRUCT*) (dirState->dirStruct);
|
||||
|
||||
_FAT_lock(&state->partition->lock);
|
||||
|
||||
// Make sure we are still using this entry
|
||||
if (!state->inUse) {
|
||||
_FAT_unlock(&state->partition->lock);
|
||||
r->_errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Make sure there is another file to report on
|
||||
if (! state->validEntry) {
|
||||
_FAT_unlock(&state->partition->lock);
|
||||
r->_errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Get the filename
|
||||
strncpy (filename, state->currentEntry.filename, MAX_FILENAME_LENGTH);
|
||||
// Get the stats, if requested
|
||||
if (filestat != NULL) {
|
||||
_FAT_directory_entryStat (state->partition, &(state->currentEntry), filestat);
|
||||
}
|
||||
|
||||
// Look for the next entry for use next time
|
||||
state->validEntry =
|
||||
_FAT_directory_getNextEntry (state->partition, &(state->currentEntry));
|
||||
|
||||
_FAT_unlock(&state->partition->lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _FAT_dirclose_r (struct _reent *r, DIR_ITER *dirState) {
|
||||
DIR_STATE_STRUCT* state = (DIR_STATE_STRUCT*) (dirState->dirStruct);
|
||||
|
||||
// We are no longer using this entry
|
||||
_FAT_lock(&state->partition->lock);
|
||||
state->inUse = false;
|
||||
_FAT_unlock(&state->partition->lock);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
fatdir.h
|
||||
|
||||
Functions used by the newlib disc stubs to interface with
|
||||
this library
|
||||
|
||||
Copyright (c) 2006 Michael "Chishm" Chisholm
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
3. The name of the author may not be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _FATDIR_H
|
||||
#define _FATDIR_H
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "directory.h"
|
||||
|
||||
#ifndef LIBFAT_PC
|
||||
#include <sys/statvfs.h>
|
||||
#include <sys/iosupport.h>
|
||||
#include <sys/reent.h>
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct {
|
||||
PARTITION* partition;
|
||||
DIR_ENTRY currentEntry;
|
||||
uint32_t startCluster;
|
||||
bool inUse;
|
||||
bool validEntry;
|
||||
} DIR_STATE_STRUCT;
|
||||
|
||||
extern int _FAT_stat_r (struct _reent *r, const char *path, struct stat *st);
|
||||
|
||||
extern int _FAT_link_r (struct _reent *r, const char *existing, const char *newLink);
|
||||
|
||||
extern int _FAT_unlink_r (struct _reent *r, const char *name);
|
||||
|
||||
extern int _FAT_chdir_r (struct _reent *r, const char *name);
|
||||
|
||||
extern int _FAT_rename_r (struct _reent *r, const char *oldName, const char *newName);
|
||||
|
||||
extern int _FAT_mkdir_r (struct _reent *r, const char *path, int mode);
|
||||
|
||||
extern int _FAT_statvfs_r (struct _reent *r, const char *path, struct statvfs *buf);
|
||||
|
||||
/*
|
||||
Directory iterator functions
|
||||
*/
|
||||
extern DIR_ITER* _FAT_diropen_r(struct _reent *r, DIR_ITER *dirState, const char *path);
|
||||
extern int _FAT_dirreset_r (struct _reent *r, DIR_ITER *dirState);
|
||||
extern int _FAT_dirnext_r (struct _reent *r, DIR_ITER *dirState, char *filename, struct stat *filestat);
|
||||
extern int _FAT_dirclose_r (struct _reent *r, DIR_ITER *dirState);
|
||||
|
||||
|
||||
#endif // _FATDIR_H
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,108 @@
|
|||
/*
|
||||
fatfile.h
|
||||
|
||||
Functions used by the newlib disc stubs to interface with
|
||||
this library
|
||||
|
||||
Copyright (c) 2006 Michael "Chishm" Chisholm
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
3. The name of the author may not be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _FATFILE_H
|
||||
#define _FATFILE_H
|
||||
|
||||
#include "common.h"
|
||||
#include "partition.h"
|
||||
#include "directory.h"
|
||||
|
||||
#ifndef LIBFAT_PC
|
||||
#include <sys/reent.h>
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
|
||||
#define FILE_MAX_SIZE ((uint32_t)0xFFFFFFFF) // 4GiB - 1B
|
||||
|
||||
typedef struct {
|
||||
u32 cluster;
|
||||
sec_t sector;
|
||||
s32 byte;
|
||||
} FILE_POSITION;
|
||||
|
||||
struct _FILE_STRUCT;
|
||||
|
||||
struct _FILE_STRUCT {
|
||||
uint32_t filesize;
|
||||
uint32_t startCluster;
|
||||
uint32_t currentPosition;
|
||||
FILE_POSITION rwPosition;
|
||||
FILE_POSITION appendPosition;
|
||||
DIR_ENTRY_POSITION dirEntryStart; // Points to the start of the LFN entries of a file, or the alias for no LFN
|
||||
DIR_ENTRY_POSITION dirEntryEnd; // Always points to the file's alias entry
|
||||
PARTITION* partition;
|
||||
struct _FILE_STRUCT* prevOpenFile; // The previous entry in a double-linked list of open files
|
||||
struct _FILE_STRUCT* nextOpenFile; // The next entry in a double-linked list of open files
|
||||
bool read;
|
||||
bool write;
|
||||
bool append;
|
||||
bool inUse;
|
||||
bool modified;
|
||||
};
|
||||
|
||||
typedef struct _FILE_STRUCT FILE_STRUCT;
|
||||
|
||||
intptr_t _FAT_open_r (struct _reent *r, void *fileStruct, const char *path, int flags, int mode);
|
||||
|
||||
intptr_t _FAT_close_r (struct _reent *r, intptr_t fd);
|
||||
|
||||
ssize_t _FAT_write_r (struct _reent *r,intptr_t fd, const char *ptr, size_t len);
|
||||
|
||||
ssize_t _FAT_read_r (struct _reent *r, intptr_t fd, char *ptr, size_t len);
|
||||
|
||||
off_t _FAT_seek_r (struct _reent *r, intptr_t fd, off_t pos, int dir);
|
||||
|
||||
int _FAT_fstat_r (struct _reent *r, intptr_t fd, struct stat *st);
|
||||
|
||||
int _FAT_stat_r (struct _reent *r, const char *path, struct stat *st);
|
||||
|
||||
int _FAT_link_r (struct _reent *r, const char *existing, const char *newLink);
|
||||
|
||||
int _FAT_unlink_r (struct _reent *r, const char *name);
|
||||
|
||||
int _FAT_chdir_r (struct _reent *r, const char *name);
|
||||
|
||||
int _FAT_rename_r (struct _reent *r, const char *oldName, const char *newName);
|
||||
|
||||
int _FAT_ftruncate_r (struct _reent *r, intptr_t fd, off_t len);
|
||||
|
||||
int _FAT_fsync_r (struct _reent *r, intptr_t fd);
|
||||
|
||||
/*
|
||||
Synchronizes the file data to disc.
|
||||
Does no locking of its own -- lock the partition before calling.
|
||||
Returns 0 on success, an error code on failure.
|
||||
*/
|
||||
extern int _FAT_syncToDisc (FILE_STRUCT* file);
|
||||
|
||||
#endif // _FATFILE_H
|
|
@ -0,0 +1,383 @@
|
|||
/*
|
||||
file_allocation_table.c
|
||||
Reading, writing and manipulation of the FAT structure on
|
||||
a FAT partition
|
||||
|
||||
Copyright (c) 2006 Michael "Chishm" Chisholm
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
3. The name of the author may not be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
#include "file_allocation_table.h"
|
||||
#include "partition.h"
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
Gets the cluster linked from input cluster
|
||||
*/
|
||||
uint32_t _FAT_fat_nextCluster(PARTITION* partition, uint32_t cluster)
|
||||
{
|
||||
uint32_t nextCluster = CLUSTER_FREE;
|
||||
sec_t sector;
|
||||
int offset;
|
||||
|
||||
if (cluster == CLUSTER_FREE) {
|
||||
return CLUSTER_FREE;
|
||||
}
|
||||
|
||||
switch (partition->filesysType)
|
||||
{
|
||||
case FS_UNKNOWN:
|
||||
return CLUSTER_ERROR;
|
||||
break;
|
||||
|
||||
case FS_FAT12:
|
||||
{
|
||||
u32 nextCluster_h;
|
||||
sector = partition->fat.fatStart + (((cluster * 3) / 2) / BYTES_PER_READ);
|
||||
offset = ((cluster * 3) / 2) % BYTES_PER_READ;
|
||||
|
||||
|
||||
_FAT_cache_readLittleEndianValue (partition->cache, &nextCluster, sector, offset, sizeof(u8));
|
||||
|
||||
offset++;
|
||||
|
||||
if (offset >= BYTES_PER_READ) {
|
||||
offset = 0;
|
||||
sector++;
|
||||
}
|
||||
nextCluster_h = 0;
|
||||
|
||||
_FAT_cache_readLittleEndianValue (partition->cache, &nextCluster_h, sector, offset, sizeof(u8));
|
||||
nextCluster |= (nextCluster_h << 8);
|
||||
|
||||
if (cluster & 0x01) {
|
||||
nextCluster = nextCluster >> 4;
|
||||
} else {
|
||||
nextCluster &= 0x0FFF;
|
||||
}
|
||||
|
||||
if (nextCluster >= 0x0FF7)
|
||||
{
|
||||
nextCluster = CLUSTER_EOF;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case FS_FAT16:
|
||||
sector = partition->fat.fatStart + ((cluster << 1) / BYTES_PER_READ);
|
||||
offset = (cluster % (BYTES_PER_READ >> 1)) << 1;
|
||||
|
||||
_FAT_cache_readLittleEndianValue (partition->cache, &nextCluster, sector, offset, sizeof(u16));
|
||||
|
||||
if (nextCluster >= 0xFFF7) {
|
||||
nextCluster = CLUSTER_EOF;
|
||||
}
|
||||
break;
|
||||
|
||||
case FS_FAT32:
|
||||
sector = partition->fat.fatStart + ((cluster << 2) / BYTES_PER_READ);
|
||||
offset = (cluster % (BYTES_PER_READ >> 2)) << 2;
|
||||
|
||||
_FAT_cache_readLittleEndianValue (partition->cache, &nextCluster, sector, offset, sizeof(u32));
|
||||
|
||||
if (nextCluster >= 0x0FFFFFF7) {
|
||||
nextCluster = CLUSTER_EOF;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return CLUSTER_ERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
return nextCluster;
|
||||
}
|
||||
|
||||
/*
|
||||
writes value into the correct offset within a partition's FAT, based
|
||||
on the cluster number.
|
||||
*/
|
||||
static bool _FAT_fat_writeFatEntry (PARTITION* partition, uint32_t cluster, uint32_t value) {
|
||||
sec_t sector;
|
||||
int offset;
|
||||
uint32_t oldValue;
|
||||
|
||||
if ((cluster < CLUSTER_FIRST) || (cluster > partition->fat.lastCluster /* This will catch CLUSTER_ERROR */))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (partition->filesysType)
|
||||
{
|
||||
case FS_UNKNOWN:
|
||||
return false;
|
||||
break;
|
||||
|
||||
case FS_FAT12:
|
||||
sector = partition->fat.fatStart + (((cluster * 3) / 2) / BYTES_PER_READ);
|
||||
offset = ((cluster * 3) / 2) % BYTES_PER_READ;
|
||||
|
||||
if (cluster & 0x01) {
|
||||
|
||||
_FAT_cache_readLittleEndianValue (partition->cache, &oldValue, sector, offset, sizeof(u8));
|
||||
|
||||
value = (value << 4) | (oldValue & 0x0F);
|
||||
|
||||
_FAT_cache_writeLittleEndianValue (partition->cache, value & 0xFF, sector, offset, sizeof(u8));
|
||||
|
||||
offset++;
|
||||
if (offset >= BYTES_PER_READ) {
|
||||
offset = 0;
|
||||
sector++;
|
||||
}
|
||||
|
||||
_FAT_cache_writeLittleEndianValue (partition->cache, (value >> 8) & 0xFF, sector, offset, sizeof(u8));
|
||||
|
||||
} else {
|
||||
|
||||
_FAT_cache_writeLittleEndianValue (partition->cache, value, sector, offset, sizeof(u8));
|
||||
|
||||
offset++;
|
||||
if (offset >= BYTES_PER_READ) {
|
||||
offset = 0;
|
||||
sector++;
|
||||
}
|
||||
|
||||
_FAT_cache_readLittleEndianValue (partition->cache, &oldValue, sector, offset, sizeof(u8));
|
||||
|
||||
value = ((value >> 8) & 0x0F) | (oldValue & 0xF0);
|
||||
|
||||
_FAT_cache_writeLittleEndianValue (partition->cache, value, sector, offset, sizeof(u8));
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case FS_FAT16:
|
||||
sector = partition->fat.fatStart + ((cluster << 1) / BYTES_PER_READ);
|
||||
offset = (cluster % (BYTES_PER_READ >> 1)) << 1;
|
||||
|
||||
_FAT_cache_writeLittleEndianValue (partition->cache, value, sector, offset, sizeof(u16));
|
||||
|
||||
break;
|
||||
|
||||
case FS_FAT32:
|
||||
sector = partition->fat.fatStart + ((cluster << 2) / BYTES_PER_READ);
|
||||
offset = (cluster % (BYTES_PER_READ >> 2)) << 2;
|
||||
|
||||
_FAT_cache_writeLittleEndianValue (partition->cache, value, sector, offset, sizeof(u32));
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------
|
||||
gets the first available free cluster, sets it
|
||||
to end of file, links the input cluster to it then returns the
|
||||
cluster number
|
||||
If an error occurs, return CLUSTER_ERROR
|
||||
-----------------------------------------------------------------*/
|
||||
uint32_t _FAT_fat_linkFreeCluster(PARTITION* partition, uint32_t cluster) {
|
||||
uint32_t firstFree;
|
||||
uint32_t curLink;
|
||||
uint32_t lastCluster;
|
||||
bool loopedAroundFAT = false;
|
||||
|
||||
lastCluster = partition->fat.lastCluster;
|
||||
|
||||
if (cluster > lastCluster) {
|
||||
return CLUSTER_ERROR;
|
||||
}
|
||||
|
||||
// Check if the cluster already has a link, and return it if so
|
||||
curLink = _FAT_fat_nextCluster(partition, cluster);
|
||||
if ((curLink >= CLUSTER_FIRST) && (curLink <= lastCluster)) {
|
||||
return curLink; // Return the current link - don't allocate a new one
|
||||
}
|
||||
|
||||
// Get a free cluster
|
||||
firstFree = partition->fat.firstFree;
|
||||
// Start at first valid cluster
|
||||
if (firstFree < CLUSTER_FIRST) {
|
||||
firstFree = CLUSTER_FIRST;
|
||||
}
|
||||
|
||||
// Search until a free cluster is found
|
||||
while (_FAT_fat_nextCluster(partition, firstFree) != CLUSTER_FREE) {
|
||||
firstFree++;
|
||||
if (firstFree > lastCluster) {
|
||||
if (loopedAroundFAT) {
|
||||
// If couldn't get a free cluster then return an error
|
||||
partition->fat.firstFree = firstFree;
|
||||
return CLUSTER_ERROR;
|
||||
} else {
|
||||
// Try looping back to the beginning of the FAT
|
||||
// This was suggested by loopy
|
||||
firstFree = CLUSTER_FIRST;
|
||||
loopedAroundFAT = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
partition->fat.firstFree = firstFree;
|
||||
|
||||
if ((cluster >= CLUSTER_FIRST) && (cluster < lastCluster))
|
||||
{
|
||||
// Update the linked from FAT entry
|
||||
_FAT_fat_writeFatEntry (partition, cluster, firstFree);
|
||||
}
|
||||
// Create the linked to FAT entry
|
||||
_FAT_fat_writeFatEntry (partition, firstFree, CLUSTER_EOF);
|
||||
|
||||
return firstFree;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------
|
||||
gets the first available free cluster, sets it
|
||||
to end of file, links the input cluster to it, clears the new
|
||||
cluster to 0 valued bytes, then returns the cluster number
|
||||
If an error occurs, return CLUSTER_ERROR
|
||||
-----------------------------------------------------------------*/
|
||||
uint32_t _FAT_fat_linkFreeClusterCleared (PARTITION* partition, uint32_t cluster) {
|
||||
uint32_t newCluster;
|
||||
uint32_t i;
|
||||
uint8_t emptySector[BYTES_PER_READ];
|
||||
|
||||
// Link the cluster
|
||||
newCluster = _FAT_fat_linkFreeCluster(partition, cluster);
|
||||
|
||||
if (newCluster == CLUSTER_FREE || newCluster == CLUSTER_ERROR) {
|
||||
return CLUSTER_ERROR;
|
||||
}
|
||||
|
||||
// Clear all the sectors within the cluster
|
||||
memset (emptySector, 0, BYTES_PER_READ);
|
||||
for (i = 0; i < partition->sectorsPerCluster; i++) {
|
||||
_FAT_cache_writeSectors (partition->cache,
|
||||
_FAT_fat_clusterToSector (partition, newCluster) + i,
|
||||
1, emptySector);
|
||||
}
|
||||
|
||||
return newCluster;
|
||||
}
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------
|
||||
_FAT_fat_clearLinks
|
||||
frees any cluster used by a file
|
||||
-----------------------------------------------------------------*/
|
||||
bool _FAT_fat_clearLinks (PARTITION* partition, uint32_t cluster) {
|
||||
uint32_t nextCluster;
|
||||
|
||||
if ((cluster < CLUSTER_FIRST) || (cluster > partition->fat.lastCluster /* This will catch CLUSTER_ERROR */))
|
||||
return false;
|
||||
|
||||
// If this clears up more space in the FAT before the current free pointer, move it backwards
|
||||
if (cluster < partition->fat.firstFree) {
|
||||
partition->fat.firstFree = cluster;
|
||||
}
|
||||
|
||||
while ((cluster != CLUSTER_EOF) && (cluster != CLUSTER_FREE) && (cluster != CLUSTER_ERROR)) {
|
||||
// Store next cluster before erasing the link
|
||||
nextCluster = _FAT_fat_nextCluster (partition, cluster);
|
||||
|
||||
// Erase the link
|
||||
_FAT_fat_writeFatEntry (partition, cluster, CLUSTER_FREE);
|
||||
|
||||
// Move onto next cluster
|
||||
cluster = nextCluster;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------
|
||||
_FAT_fat_trimChain
|
||||
Drop all clusters past the chainLength.
|
||||
If chainLength is 0, all clusters are dropped.
|
||||
If chainLength is 1, the first cluster is kept and the rest are
|
||||
dropped, and so on.
|
||||
Return the last cluster left in the chain.
|
||||
-----------------------------------------------------------------*/
|
||||
uint32_t _FAT_fat_trimChain (PARTITION* partition, uint32_t startCluster, unsigned int chainLength) {
|
||||
uint32_t nextCluster;
|
||||
|
||||
if (chainLength == 0) {
|
||||
// Drop the entire chain
|
||||
_FAT_fat_clearLinks (partition, startCluster);
|
||||
return CLUSTER_FREE;
|
||||
} else {
|
||||
// Find the last cluster in the chain, and the one after it
|
||||
chainLength--;
|
||||
nextCluster = _FAT_fat_nextCluster (partition, startCluster);
|
||||
while ((chainLength > 0) && (nextCluster != CLUSTER_FREE) && (nextCluster != CLUSTER_EOF)) {
|
||||
chainLength--;
|
||||
startCluster = nextCluster;
|
||||
nextCluster = _FAT_fat_nextCluster (partition, startCluster);
|
||||
}
|
||||
|
||||
// Drop all clusters after the last in the chain
|
||||
if (nextCluster != CLUSTER_FREE && nextCluster != CLUSTER_EOF) {
|
||||
_FAT_fat_clearLinks (partition, nextCluster);
|
||||
}
|
||||
|
||||
// Mark the last cluster in the chain as the end of the file
|
||||
_FAT_fat_writeFatEntry (partition, startCluster, CLUSTER_EOF);
|
||||
|
||||
return startCluster;
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------
|
||||
_FAT_fat_lastCluster
|
||||
Trace the cluster links until the last one is found
|
||||
-----------------------------------------------------------------*/
|
||||
uint32_t _FAT_fat_lastCluster (PARTITION* partition, uint32_t cluster) {
|
||||
while ((_FAT_fat_nextCluster(partition, cluster) != CLUSTER_FREE) && (_FAT_fat_nextCluster(partition, cluster) != CLUSTER_EOF)) {
|
||||
cluster = _FAT_fat_nextCluster(partition, cluster);
|
||||
}
|
||||
return cluster;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------
|
||||
_FAT_fat_freeClusterCount
|
||||
Return the number of free clusters available
|
||||
-----------------------------------------------------------------*/
|
||||
unsigned int _FAT_fat_freeClusterCount (PARTITION* partition) {
|
||||
unsigned int count = 0;
|
||||
uint32_t curCluster;
|
||||
|
||||
for (curCluster = CLUSTER_FIRST; curCluster <= partition->fat.lastCluster; curCluster++) {
|
||||
if (_FAT_fat_nextCluster(partition, curCluster) == CLUSTER_FREE) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
file_allocation_table.h
|
||||
Reading, writing and manipulation of the FAT structure on
|
||||
a FAT partition
|
||||
|
||||
Copyright (c) 2006 Michael "Chishm" Chisholm
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
3. The name of the author may not be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _FAT_H
|
||||
#define _FAT_H
|
||||
|
||||
#include "common.h"
|
||||
#include "partition.h"
|
||||
|
||||
#define CLUSTER_EOF_16 0xFFFF
|
||||
#define CLUSTER_EOF 0x0FFFFFFF
|
||||
#define CLUSTER_FREE 0x00000000
|
||||
#define CLUSTER_ROOT 0x00000000
|
||||
#define CLUSTER_FIRST 0x00000002
|
||||
#define CLUSTER_ERROR 0xFFFFFFFF
|
||||
|
||||
#define CLUSTERS_PER_FAT12 4085
|
||||
#define CLUSTERS_PER_FAT16 65525
|
||||
|
||||
|
||||
uint32_t _FAT_fat_nextCluster(PARTITION* partition, uint32_t cluster);
|
||||
|
||||
uint32_t _FAT_fat_linkFreeCluster(PARTITION* partition, uint32_t cluster);
|
||||
uint32_t _FAT_fat_linkFreeClusterCleared (PARTITION* partition, uint32_t cluster);
|
||||
|
||||
bool _FAT_fat_clearLinks (PARTITION* partition, uint32_t cluster);
|
||||
|
||||
uint32_t _FAT_fat_trimChain (PARTITION* partition, uint32_t startCluster, unsigned int chainLength);
|
||||
|
||||
uint32_t _FAT_fat_lastCluster (PARTITION* partition, uint32_t cluster);
|
||||
|
||||
unsigned int _FAT_fat_freeClusterCount (PARTITION* partition);
|
||||
|
||||
static inline sec_t _FAT_fat_clusterToSector (PARTITION* partition, uint32_t cluster) {
|
||||
return (cluster >= CLUSTER_FIRST) ?
|
||||
((cluster - CLUSTER_FIRST) * (sec_t)partition->sectorsPerCluster) + partition->dataStart :
|
||||
partition->rootDirStart;
|
||||
}
|
||||
|
||||
static inline bool _FAT_fat_isValidCluster (PARTITION* partition, uint32_t cluster) {
|
||||
return (cluster >= CLUSTER_FIRST) && (cluster <= partition->fat.lastCluster /* This will catch CLUSTER_ERROR */);
|
||||
}
|
||||
|
||||
#endif // _FAT_H
|
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
filetime.c
|
||||
Conversion of file time and date values to various other types
|
||||
|
||||
Copyright (c) 2006 Michael "Chishm" Chisholm
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
3. The name of the author may not be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
#include <time.h>
|
||||
#include "filetime.h"
|
||||
#include "common.h"
|
||||
|
||||
#define MAX_HOUR 23
|
||||
#define MAX_MINUTE 59
|
||||
#define MAX_SECOND 59
|
||||
|
||||
#define MAX_MONTH 11
|
||||
#define MIN_MONTH 0
|
||||
#define MAX_DAY 31
|
||||
#define MIN_DAY 1
|
||||
|
||||
uint16_t _FAT_filetime_getTimeFromRTC (void) {
|
||||
#ifdef USE_RTC_TIME
|
||||
struct tm timeParts;
|
||||
time_t epochTime;
|
||||
|
||||
if (time(&epochTime) == (time_t)-1) {
|
||||
return 0;
|
||||
}
|
||||
localtime_r(&epochTime, &timeParts);
|
||||
|
||||
// Check that the values are all in range.
|
||||
// If they are not, return 0 (no timestamp)
|
||||
if ((timeParts.tm_hour < 0) || (timeParts.tm_hour > MAX_HOUR)) return 0;
|
||||
if ((timeParts.tm_min < 0) || (timeParts.tm_min > MAX_MINUTE)) return 0;
|
||||
if ((timeParts.tm_sec < 0) || (timeParts.tm_sec > MAX_SECOND)) return 0;
|
||||
|
||||
return (
|
||||
((timeParts.tm_hour & 0x1F) << 11) |
|
||||
((timeParts.tm_min & 0x3F) << 5) |
|
||||
((timeParts.tm_sec >> 1) & 0x1F)
|
||||
);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
uint16_t _FAT_filetime_getDateFromRTC (void) {
|
||||
#ifdef USE_RTC_TIME
|
||||
struct tm timeParts;
|
||||
time_t epochTime;
|
||||
|
||||
if (time(&epochTime) == (time_t)-1) {
|
||||
return 0;
|
||||
}
|
||||
localtime_r(&epochTime, &timeParts);
|
||||
|
||||
if ((timeParts.tm_mon < MIN_MONTH) || (timeParts.tm_mon > MAX_MONTH)) return 0;
|
||||
if ((timeParts.tm_mday < MIN_DAY) || (timeParts.tm_mday > MAX_DAY)) return 0;
|
||||
|
||||
return (
|
||||
(((timeParts.tm_year - 80) & 0x7F) <<9) | // Adjust for MS-FAT base year (1980 vs 1900 for tm_year)
|
||||
(((timeParts.tm_mon + 1) & 0xF) << 5) |
|
||||
(timeParts.tm_mday & 0x1F)
|
||||
);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
time_t _FAT_filetime_to_time_t (uint16_t t, uint16_t d) {
|
||||
struct tm timeParts;
|
||||
|
||||
timeParts.tm_hour = t >> 11;
|
||||
timeParts.tm_min = (t >> 5) & 0x3F;
|
||||
timeParts.tm_sec = (t & 0x1F) << 1;
|
||||
|
||||
timeParts.tm_mday = d & 0x1F;
|
||||
timeParts.tm_mon = ((d >> 5) & 0x0F) - 1;
|
||||
timeParts.tm_year = (d >> 9) + 80;
|
||||
|
||||
timeParts.tm_isdst = 0;
|
||||
|
||||
return mktime(&timeParts);
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
filetime.h
|
||||
Conversion of file time and date values to various other types
|
||||
|
||||
Copyright (c) 2006 Michael "Chishm" Chisholm
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
3. The name of the author may not be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _FILETIME_H
|
||||
#define _FILETIME_H
|
||||
|
||||
#include "common.h"
|
||||
#include <sys/types.h>
|
||||
|
||||
uint16_t _FAT_filetime_getTimeFromRTC (void);
|
||||
uint16_t _FAT_filetime_getDateFromRTC (void);
|
||||
|
||||
time_t _FAT_filetime_to_time_t (uint16_t t, uint16_t d);
|
||||
|
||||
|
||||
#endif // _FILETIME_H
|
|
@ -0,0 +1,276 @@
|
|||
/*
|
||||
libfat.c
|
||||
Simple functionality for startup, mounting and unmounting of FAT-based devices.
|
||||
|
||||
Copyright (c) 2006 Michael "Chishm" Chisholm
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
3. The name of the author may not be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "partition.h"
|
||||
#include "fatfile.h"
|
||||
#include "fatdir.h"
|
||||
#include "lock.h"
|
||||
#include "mem_allocate.h"
|
||||
#include "disc.h"
|
||||
|
||||
#ifndef LIBFAT_PC
|
||||
#include <sys/iosupport.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
|
||||
static const devoptab_t dotab_fat = {
|
||||
"fat",
|
||||
sizeof (FILE_STRUCT),
|
||||
_FAT_open_r,
|
||||
_FAT_close_r,
|
||||
_FAT_write_r,
|
||||
_FAT_read_r,
|
||||
_FAT_seek_r,
|
||||
_FAT_fstat_r,
|
||||
_FAT_stat_r,
|
||||
_FAT_link_r,
|
||||
_FAT_unlink_r,
|
||||
_FAT_chdir_r,
|
||||
_FAT_rename_r,
|
||||
_FAT_mkdir_r,
|
||||
sizeof (DIR_STATE_STRUCT),
|
||||
_FAT_diropen_r,
|
||||
_FAT_dirreset_r,
|
||||
_FAT_dirnext_r,
|
||||
_FAT_dirclose_r,
|
||||
#ifndef LIBFAT_PC
|
||||
_FAT_statvfs_r,
|
||||
#endif
|
||||
_FAT_ftruncate_r,
|
||||
_FAT_fsync_r,
|
||||
NULL, /* Device data */
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
#ifdef LIBFAT_PC
|
||||
static devoptab_t* _sole_device = NULL;
|
||||
devoptab_t* GetDeviceOpTab(const char* name)
|
||||
{
|
||||
return _sole_device;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
bool fatMount (const char* name, const DISC_INTERFACE* interface, sec_t startSector, uint32_t cacheSize, uint32_t SectorsPerPage) {
|
||||
PARTITION* partition;
|
||||
devoptab_t* devops;
|
||||
//char* nameCopy;
|
||||
|
||||
if(!name || strlen(name) > 8 || !interface)
|
||||
return false;
|
||||
|
||||
if(!interface->startup())
|
||||
return false;
|
||||
|
||||
if(!interface->isInserted())
|
||||
return false;
|
||||
|
||||
//char devname[10];
|
||||
//sprintf(devname, "%s:", name);
|
||||
//if(FindDevice(devname) >= 0)
|
||||
// return true;
|
||||
|
||||
devops = (devoptab_t*)_FAT_mem_allocate (sizeof(devoptab_t) + strlen(name) + 1);
|
||||
if (!devops) {
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef LIBFAT_PC
|
||||
_sole_device = devops;
|
||||
#endif
|
||||
|
||||
// Use the space allocated at the end of the devoptab struct for storing the name
|
||||
//nameCopy = (char*)(devops+1);
|
||||
|
||||
// Initialize the file system
|
||||
partition = _FAT_partition_constructor (interface, cacheSize, SectorsPerPage, startSector);
|
||||
if (!partition) {
|
||||
_FAT_mem_free (devops);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Add an entry for this device to the devoptab table
|
||||
memcpy (devops, &dotab_fat, sizeof(dotab_fat));
|
||||
//strcpy (nameCopy, name);
|
||||
//devops->name = nameCopy;
|
||||
devops->deviceData = partition;
|
||||
|
||||
//AddDevice (devops);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool fatMountSimple (const char* name, const DISC_INTERFACE* interface) {
|
||||
return fatMount (name, interface, 0, DEFAULT_CACHE_PAGES, DEFAULT_SECTORS_PAGE);
|
||||
}
|
||||
|
||||
void fatUnmountDirect (devoptab_t *devops) {
|
||||
PARTITION* partition = (PARTITION*)devops->deviceData;
|
||||
_FAT_partition_destructor (partition);
|
||||
_FAT_mem_free (devops);
|
||||
_sole_device = NULL;
|
||||
}
|
||||
|
||||
//void fatUnmount (const char* name) {
|
||||
// devoptab_t *devops;
|
||||
// PARTITION* partition;
|
||||
//
|
||||
// if(!name)
|
||||
// return;
|
||||
//
|
||||
// devops = (devoptab_t*)GetDeviceOpTab (name);
|
||||
// if (!devops) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// // Perform a quick check to make sure we're dealing with a libfat controlled device
|
||||
// //if (devops->open_r != dotab_fat.open_r) {
|
||||
// // return;
|
||||
// //}
|
||||
//
|
||||
// if (RemoveDevice (name) == -1) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// partition = (PARTITION*)devops->deviceData;
|
||||
// _FAT_partition_destructor (partition);
|
||||
// _FAT_mem_free (devops);
|
||||
//}
|
||||
|
||||
//bool fatInit (uint32_t cacheSize, bool setAsDefaultDevice) {
|
||||
// int i;
|
||||
// int defaultDevice = -1;
|
||||
// const DISC_INTERFACE *disc;
|
||||
//
|
||||
// for (i = 0;
|
||||
// _FAT_disc_interfaces[i].name != NULL && _FAT_disc_interfaces[i].getInterface != NULL;
|
||||
// i++)
|
||||
// {
|
||||
// disc = _FAT_disc_interfaces[i].getInterface();
|
||||
// if (fatMount (_FAT_disc_interfaces[i].name, disc, 0, cacheSize, DEFAULT_SECTORS_PAGE)) {
|
||||
// // The first device to successfully mount is set as the default
|
||||
// if (defaultDevice < 0) {
|
||||
// defaultDevice = i;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (defaultDevice < 0) {
|
||||
// // None of our devices mounted
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// if (setAsDefaultDevice) {
|
||||
// char filePath[MAXPATHLEN * 2];
|
||||
// strcpy (filePath, _FAT_disc_interfaces[defaultDevice].name);
|
||||
// strcat (filePath, ":/");
|
||||
//#ifdef ARGV_MAGIC
|
||||
// if ( __system_argv->argvMagic == ARGV_MAGIC && __system_argv->argc >= 1 && strrchr( __system_argv->argv[0], '/' )!=NULL ) {
|
||||
// // Check the app's path against each of our mounted devices, to see
|
||||
// // if we can support it. If so, change to that path.
|
||||
// for (i = 0;
|
||||
// _FAT_disc_interfaces[i].name != NULL && _FAT_disc_interfaces[i].getInterface != NULL;
|
||||
// i++)
|
||||
// {
|
||||
// if ( !strncasecmp( __system_argv->argv[0], _FAT_disc_interfaces[i].name,
|
||||
// strlen(_FAT_disc_interfaces[i].name)))
|
||||
// {
|
||||
// char *lastSlash;
|
||||
// strcpy(filePath, __system_argv->argv[0]);
|
||||
// lastSlash = strrchr( filePath, '/' );
|
||||
//
|
||||
// if ( NULL != lastSlash) {
|
||||
// if ( *(lastSlash - 1) == ':') lastSlash++;
|
||||
// *lastSlash = 0;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//#endif
|
||||
// chdir (filePath);
|
||||
// }
|
||||
//
|
||||
// return true;
|
||||
//}
|
||||
|
||||
//bool fatInitDefault (void) {
|
||||
// return fatInit (DEFAULT_CACHE_PAGES, true);
|
||||
//}
|
||||
|
||||
//void fatGetVolumeLabel (const char* name, char *label) {
|
||||
// devoptab_t *devops;
|
||||
// PARTITION* partition;
|
||||
// char *buf;
|
||||
// int namelen,i;
|
||||
//
|
||||
// if(!name || !label)
|
||||
// return;
|
||||
//
|
||||
// namelen = strlen(name);
|
||||
// buf=(char*)_FAT_mem_allocate(sizeof(char)*namelen+2);
|
||||
// strcpy(buf,name);
|
||||
//
|
||||
// if (name[namelen-1] == '/') {
|
||||
// buf[namelen-1]='\0';
|
||||
// namelen--;
|
||||
// }
|
||||
//
|
||||
// if (name[namelen-1] != ':') {
|
||||
// buf[namelen]=':';
|
||||
// buf[namelen+1]='\0';
|
||||
// }
|
||||
//
|
||||
// devops = (devoptab_t*)GetDeviceOpTab(buf);
|
||||
//
|
||||
// for(i=0;buf[i]!='\0' && buf[i]!=':';i++);
|
||||
// if (!devops || strncasecmp(buf,devops->name,i)) {
|
||||
// _FAT_mem_free(buf);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// _FAT_mem_free(buf);
|
||||
//
|
||||
// // Perform a quick check to make sure we're dealing with a libfat controlled device
|
||||
// if (devops->open_r != dotab_fat.open_r) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// partition = (PARTITION*)devops->deviceData;
|
||||
//
|
||||
// if(!_FAT_directory_getVolumeLabel(partition, label)) {
|
||||
// strncpy(label,partition->label,11);
|
||||
// label[11]='\0';
|
||||
// }
|
||||
// if(!strncmp(label, "NO NAME", 7)) label[0]='\0';
|
||||
//}
|
|
@ -0,0 +1,114 @@
|
|||
#ifndef _LIBFAT_PC_H
|
||||
#define _LIBFAT_PC_H
|
||||
|
||||
#ifdef LIBFAT_PC
|
||||
|
||||
#include "../../types.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
#define ENOTSUP 0
|
||||
#define EOVERFLOW 0
|
||||
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define strcasecmp(x,y) _stricmp(x,y)
|
||||
#define strncasecmp(x, y, l) strnicmp(x, y, l)
|
||||
|
||||
typedef unsigned __int64 uint64_t;
|
||||
typedef __int64 int64_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef int int32_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef short int16_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef char int8_t;
|
||||
|
||||
typedef int32_t ssize_t;
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#define S_IRUSR S_IREAD
|
||||
#define S_IRGRP S_IREAD
|
||||
#define S_IROTH S_IREAD
|
||||
#define S_IWUSR S_IWRITE
|
||||
#define S_IWGRP S_IWRITE
|
||||
#define S_IWOTH S_IWRITE
|
||||
|
||||
//struct stat {
|
||||
// u32 st_dev;
|
||||
// u32 st_ino;
|
||||
// u32 st_mode;
|
||||
// u32 st_nlink;
|
||||
// u32 st_uid;
|
||||
// u32 st_gid;
|
||||
// u32 st_rdev;
|
||||
// s64 st_size;
|
||||
// time_t st_atime;
|
||||
// time_t st_mtime;
|
||||
// time_t st_ctime;
|
||||
// s32 st_blksize;
|
||||
// s32 st_blocks;
|
||||
// u32 st_attr;
|
||||
//};
|
||||
|
||||
#else // (!_MSC_VER)
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#endif //_MSC_VER
|
||||
|
||||
struct _reent {
|
||||
intptr_t _errno;
|
||||
};
|
||||
|
||||
typedef uint32_t mode_t;
|
||||
|
||||
struct DIR_ITER {
|
||||
void* dirStruct;
|
||||
};
|
||||
|
||||
struct devoptab_t {
|
||||
const char *name;
|
||||
int structSize;
|
||||
intptr_t (*open_r)(struct _reent *r, void *fileStruct, const char *path, int flags, int mode);
|
||||
intptr_t (*close_r)(struct _reent *r, intptr_t fd);
|
||||
ssize_t (*write_r)(struct _reent *r, intptr_t fd, const char *ptr, size_t len);
|
||||
ssize_t (*read_r)(struct _reent *r, intptr_t fd, char *ptr, size_t len);
|
||||
off_t (*seek_r)(struct _reent *r, intptr_t fd, off_t pos, int dir);
|
||||
int (*fstat_r)(struct _reent *r, intptr_t fd, struct stat *st);
|
||||
int (*stat_r)(struct _reent *r, const char *file, struct stat *st);
|
||||
int (*link_r)(struct _reent *r, const char *existing, const char *newLink);
|
||||
int (*unlink_r)(struct _reent *r, const char *name);
|
||||
int (*chdir_r)(struct _reent *r, const char *name);
|
||||
int (*rename_r) (struct _reent *r, const char *oldName, const char *newName);
|
||||
int (*mkdir_r) (struct _reent *r, const char *path, int mode);
|
||||
|
||||
int dirStateSize;
|
||||
|
||||
DIR_ITER* (*diropen_r)(struct _reent *r, DIR_ITER *dirState, const char *path);
|
||||
int (*dirreset_r)(struct _reent *r, DIR_ITER *dirState);
|
||||
int (*dirnext_r)(struct _reent *r, DIR_ITER *dirState, char *filename, struct stat *filestat);
|
||||
int (*dirclose_r)(struct _reent *r, DIR_ITER *dirState);
|
||||
#ifndef LIBFAT_PC
|
||||
int (*statvfs_r)(struct _reent *r, const char *path, struct statvfs *buf);
|
||||
#endif
|
||||
int (*ftruncate_r)(struct _reent *r, intptr_t fd, off_t len);
|
||||
int (*fsync_r)(struct _reent *r, intptr_t fd);
|
||||
|
||||
void *deviceData;
|
||||
|
||||
int (*chmod_r)(struct _reent *r, const char *path, mode_t mode);
|
||||
int (*fchmod_r)(struct _reent *r, int fd, mode_t mode);
|
||||
|
||||
};
|
||||
|
||||
|
||||
devoptab_t* GetDeviceOpTab(const char* name);
|
||||
|
||||
#define _ATTR_WEAK_
|
||||
|
||||
#endif //LIBFAT_PC
|
||||
|
||||
#endif //_LIBFAT_PC_H
|
|
@ -0,0 +1,116 @@
|
|||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
|
||||
#include "libfat_public_api.h"
|
||||
#include "common.h"
|
||||
#include "disc_io.h"
|
||||
#include "fatfile.h"
|
||||
|
||||
|
||||
struct Instance
|
||||
{
|
||||
void* buffer;
|
||||
int size_bytes;
|
||||
devoptab_t* devops;
|
||||
};
|
||||
|
||||
Instance sInstance;
|
||||
Instance* gInstance = NULL;
|
||||
|
||||
bool MEDIUM_STARTUP(void)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool MEDIUM_ISINSERTED(void)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool MEDIUM_io(bool write, sec_t sector, sec_t numSectors, void* buffer)
|
||||
{
|
||||
int todo = (int)numSectors*512;
|
||||
int loc = (int)sector*512;
|
||||
int have = gInstance->size_bytes - loc;
|
||||
if(todo>have)
|
||||
return false;
|
||||
if(write)
|
||||
memcpy((u8*)gInstance->buffer + loc,buffer,todo);
|
||||
else
|
||||
memcpy(buffer,(u8*)gInstance->buffer + loc,todo);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MEDIUM_READSECTORS(sec_t sector, sec_t numSectors, void* buffer)
|
||||
{
|
||||
return MEDIUM_io(false,sector,numSectors,buffer);
|
||||
}
|
||||
bool MEDIUM_WRITESECTORS(sec_t sector, sec_t numSectors, const void* buffer)
|
||||
{
|
||||
return MEDIUM_io(true,sector,numSectors,(void*)buffer);
|
||||
}
|
||||
bool MEDIUM_CLEARSTATUS(void)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool MEDIUM_SHUTDOWN(void)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
DISC_INTERFACE_STRUCT discio = {
|
||||
0, //unsigned long ioType ;
|
||||
FEATURE_MEDIUM_CANWRITE | FEATURE_MEDIUM_CANREAD, //unsigned long features ;
|
||||
MEDIUM_STARTUP, // FN_MEDIUM_STARTUP startup ;
|
||||
MEDIUM_ISINSERTED, //FN_MEDIUM_ISINSERTED isInserted ;
|
||||
MEDIUM_READSECTORS, //FN_MEDIUM_READSECTORS readSectors ;
|
||||
MEDIUM_WRITESECTORS, //FN_MEDIUM_WRITESECTORS writeSectors ;
|
||||
MEDIUM_CLEARSTATUS, //FN_MEDIUM_CLEARSTATUS clearStatus ;
|
||||
MEDIUM_SHUTDOWN, //FN_MEDIUM_SHUTDOWN shutdown ;
|
||||
} ;
|
||||
|
||||
|
||||
//not declared in any libfat headers...?
|
||||
bool fatMountSimple (const char* name, const DISC_INTERFACE* interface);
|
||||
void fatUnmountDirect (devoptab_t *devops);
|
||||
|
||||
namespace LIBFAT
|
||||
{
|
||||
void Init(void* buffer, int size_bytes)
|
||||
{
|
||||
gInstance = &sInstance;
|
||||
gInstance->buffer = buffer;
|
||||
gInstance->size_bytes = size_bytes;
|
||||
fatMountSimple("fat",&discio);
|
||||
gInstance->devops = GetDeviceOpTab(NULL);
|
||||
|
||||
|
||||
int zzz=9;
|
||||
}
|
||||
|
||||
bool MkDir(const char *path)
|
||||
{
|
||||
_reent r;
|
||||
return gInstance->devops->mkdir_r(&r,path,0) == 0;
|
||||
}
|
||||
|
||||
bool WriteFile(const char *path, const void* data, int len)
|
||||
{
|
||||
_reent r;
|
||||
FILE_STRUCT file;
|
||||
intptr_t fd = gInstance->devops->open_r(&r,&file,path,O_CREAT | O_RDWR,0);
|
||||
if(fd != -1)
|
||||
{
|
||||
ssize_t ret = gInstance->devops->write_r(&r, fd, (char*)data, len);
|
||||
gInstance->devops->close_r(&r, fd);
|
||||
if(ret == len)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Shutdown()
|
||||
{
|
||||
fatUnmountDirect(gInstance->devops);
|
||||
gInstance = NULL;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
#ifndef _LIBFAT_PUBLIC_API_H_
|
||||
#define _LIBFAT_PUBLIC_API_H_
|
||||
|
||||
namespace LIBFAT
|
||||
{
|
||||
void Init(void* buffer, int size_bytes);
|
||||
void Shutdown();
|
||||
bool MkDir(const char *path);
|
||||
bool WriteFile(const char *path, const void* data, int len);
|
||||
};
|
||||
|
||||
#endif //_LIBFAT_PUBLIC_API_H_
|
|
@ -0,0 +1,29 @@
|
|||
#include "common.h"
|
||||
|
||||
#ifndef USE_LWP_LOCK
|
||||
|
||||
#ifndef mutex_t
|
||||
typedef int mutex_t;
|
||||
#endif
|
||||
|
||||
void _ATTR_WEAK_ _FAT_lock_init(mutex_t *mutex)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void _ATTR_WEAK_ _FAT_lock_deinit(mutex_t *mutex)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void _ATTR_WEAK_ _FAT_lock(mutex_t *mutex)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void _ATTR_WEAK_ _FAT_unlock(mutex_t *mutex)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#endif // USE_LWP_LOCK
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
lock.h
|
||||
|
||||
Copyright (c) 2008 Sven Peter <svpe@gmx.net>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
3. The name of the author may not be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef _LOCK_H
|
||||
#define _LOCK_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#ifdef USE_LWP_LOCK
|
||||
|
||||
static inline void _FAT_lock_init(mutex_t *mutex)
|
||||
{
|
||||
LWP_MutexInit(mutex, false);
|
||||
}
|
||||
|
||||
static inline void _FAT_lock_deinit(mutex_t *mutex)
|
||||
{
|
||||
LWP_MutexDestroy(*mutex);
|
||||
}
|
||||
|
||||
static inline void _FAT_lock(mutex_t *mutex)
|
||||
{
|
||||
LWP_MutexLock(*mutex);
|
||||
}
|
||||
|
||||
static inline void _FAT_unlock(mutex_t *mutex)
|
||||
{
|
||||
LWP_MutexUnlock(*mutex);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// We still need a blank lock type
|
||||
#ifndef mutex_t
|
||||
typedef int mutex_t;
|
||||
#endif
|
||||
|
||||
void _FAT_lock_init(mutex_t *mutex);
|
||||
void _FAT_lock_deinit(mutex_t *mutex);
|
||||
void _FAT_lock(mutex_t *mutex);
|
||||
void _FAT_unlock(mutex_t *mutex);
|
||||
|
||||
#endif // USE_LWP_LOCK
|
||||
|
||||
|
||||
#endif // _LOCK_H
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
mem_allocate.h
|
||||
Memory allocation and destruction calls
|
||||
Replace these calls with custom allocators if
|
||||
malloc is unavailable
|
||||
|
||||
Copyright (c) 2006 Michael "Chishm" Chisholm
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
3. The name of the author may not be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _MEM_ALLOCATE_H
|
||||
#define _MEM_ALLOCATE_H
|
||||
|
||||
#include <malloc.h>
|
||||
|
||||
static inline void* _FAT_mem_allocate (size_t size) {
|
||||
return malloc (size);
|
||||
}
|
||||
|
||||
static inline void* _FAT_mem_align (size_t size) {
|
||||
#ifdef __wii__
|
||||
return memalign (32, size);
|
||||
#else
|
||||
return malloc (size);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void _FAT_mem_free (void* mem) {
|
||||
free (mem);
|
||||
}
|
||||
|
||||
#endif // _MEM_ALLOCATE_H
|
|
@ -0,0 +1,310 @@
|
|||
/*
|
||||
partition.c
|
||||
Functions for mounting and dismounting partitions
|
||||
on various block devices.
|
||||
|
||||
Copyright (c) 2006 Michael "Chishm" Chisholm
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
3. The name of the author may not be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "partition.h"
|
||||
#include "bit_ops.h"
|
||||
#include "file_allocation_table.h"
|
||||
#include "directory.h"
|
||||
#include "mem_allocate.h"
|
||||
#include "fatfile.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#ifndef LIBFAT_PC
|
||||
#include <sys/iosupport.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
This device name, as known by devkitPro toolchains
|
||||
*/
|
||||
const char* DEVICE_NAME = "fat";
|
||||
|
||||
/*
|
||||
Data offsets
|
||||
*/
|
||||
|
||||
// BIOS Parameter Block offsets
|
||||
enum BPB {
|
||||
BPB_jmpBoot = 0x00,
|
||||
BPB_OEMName = 0x03,
|
||||
// BIOS Parameter Block
|
||||
BPB_bytesPerSector = 0x0B,
|
||||
BPB_sectorsPerCluster = 0x0D,
|
||||
BPB_reservedSectors = 0x0E,
|
||||
BPB_numFATs = 0x10,
|
||||
BPB_rootEntries = 0x11,
|
||||
BPB_numSectorsSmall = 0x13,
|
||||
BPB_mediaDesc = 0x15,
|
||||
BPB_sectorsPerFAT = 0x16,
|
||||
BPB_sectorsPerTrk = 0x18,
|
||||
BPB_numHeads = 0x1A,
|
||||
BPB_numHiddenSectors = 0x1C,
|
||||
BPB_numSectors = 0x20,
|
||||
// Ext BIOS Parameter Block for FAT16
|
||||
BPB_FAT16_driveNumber = 0x24,
|
||||
BPB_FAT16_reserved1 = 0x25,
|
||||
BPB_FAT16_extBootSig = 0x26,
|
||||
BPB_FAT16_volumeID = 0x27,
|
||||
BPB_FAT16_volumeLabel = 0x2B,
|
||||
BPB_FAT16_fileSysType = 0x36,
|
||||
// Bootcode
|
||||
BPB_FAT16_bootCode = 0x3E,
|
||||
// FAT32 extended block
|
||||
BPB_FAT32_sectorsPerFAT32 = 0x24,
|
||||
BPB_FAT32_extFlags = 0x28,
|
||||
BPB_FAT32_fsVer = 0x2A,
|
||||
BPB_FAT32_rootClus = 0x2C,
|
||||
BPB_FAT32_fsInfo = 0x30,
|
||||
BPB_FAT32_bkBootSec = 0x32,
|
||||
// Ext BIOS Parameter Block for FAT32
|
||||
BPB_FAT32_driveNumber = 0x40,
|
||||
BPB_FAT32_reserved1 = 0x41,
|
||||
BPB_FAT32_extBootSig = 0x42,
|
||||
BPB_FAT32_volumeID = 0x43,
|
||||
BPB_FAT32_volumeLabel = 0x47,
|
||||
BPB_FAT32_fileSysType = 0x52,
|
||||
// Bootcode
|
||||
BPB_FAT32_bootCode = 0x5A,
|
||||
BPB_bootSig_55 = 0x1FE,
|
||||
BPB_bootSig_AA = 0x1FF
|
||||
};
|
||||
|
||||
static const char FAT_SIG[3] = {'F', 'A', 'T'};
|
||||
|
||||
|
||||
sec_t FindFirstValidPartition(const DISC_INTERFACE* disc)
|
||||
{
|
||||
uint8_t part_table[16*4];
|
||||
uint8_t *ptr;
|
||||
int i;
|
||||
|
||||
uint8_t sectorBuffer[BYTES_PER_READ] = {0};
|
||||
|
||||
// Read first sector of disc
|
||||
if (!_FAT_disc_readSectors (disc, 0, 1, sectorBuffer)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
memcpy(part_table,sectorBuffer+0x1BE,16*4);
|
||||
ptr = part_table;
|
||||
|
||||
for(i=0;i<4;i++,ptr+=16) {
|
||||
sec_t part_lba = u8array_to_u32(ptr, 0x8);
|
||||
|
||||
if (!memcmp(sectorBuffer + BPB_FAT16_fileSysType, FAT_SIG, sizeof(FAT_SIG)) ||
|
||||
!memcmp(sectorBuffer + BPB_FAT32_fileSysType, FAT_SIG, sizeof(FAT_SIG))) {
|
||||
return part_lba;
|
||||
}
|
||||
|
||||
if(ptr[4]==0) continue;
|
||||
|
||||
if(ptr[4]==0x0F) {
|
||||
sec_t part_lba2=part_lba;
|
||||
sec_t next_lba2=0;
|
||||
int n;
|
||||
|
||||
for(n=0;n<8;n++) // max 8 logic partitions
|
||||
{
|
||||
if(!_FAT_disc_readSectors (disc, part_lba+next_lba2, 1, sectorBuffer)) return 0;
|
||||
|
||||
part_lba2 = part_lba + next_lba2 + u8array_to_u32(sectorBuffer, 0x1C6) ;
|
||||
next_lba2 = u8array_to_u32(sectorBuffer, 0x1D6);
|
||||
|
||||
if(!_FAT_disc_readSectors (disc, part_lba2, 1, sectorBuffer)) return 0;
|
||||
|
||||
if (!memcmp(sectorBuffer + BPB_FAT16_fileSysType, FAT_SIG, sizeof(FAT_SIG)) ||
|
||||
!memcmp(sectorBuffer + BPB_FAT32_fileSysType, FAT_SIG, sizeof(FAT_SIG)))
|
||||
{
|
||||
return part_lba2;
|
||||
}
|
||||
|
||||
if(next_lba2==0) break;
|
||||
}
|
||||
} else {
|
||||
if(!_FAT_disc_readSectors (disc, part_lba, 1, sectorBuffer)) return 0;
|
||||
if (!memcmp(sectorBuffer + BPB_FAT16_fileSysType, FAT_SIG, sizeof(FAT_SIG)) ||
|
||||
!memcmp(sectorBuffer + BPB_FAT32_fileSysType, FAT_SIG, sizeof(FAT_SIG))) {
|
||||
return part_lba;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
PARTITION* _FAT_partition_constructor (const DISC_INTERFACE* disc, uint32_t cacheSize, uint32_t sectorsPerPage, sec_t startSector) {
|
||||
PARTITION* partition;
|
||||
uint8_t sectorBuffer[BYTES_PER_READ] = {0};
|
||||
|
||||
// Read first sector of disc
|
||||
if (!_FAT_disc_readSectors (disc, startSector, 1, sectorBuffer)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Make sure it is a valid MBR or boot sector
|
||||
if ( (sectorBuffer[BPB_bootSig_55] != 0x55) || (sectorBuffer[BPB_bootSig_AA] != 0xAA)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (startSector != 0) {
|
||||
// We're told where to start the partition, so just accept it
|
||||
} else if (!memcmp(sectorBuffer + BPB_FAT16_fileSysType, FAT_SIG, sizeof(FAT_SIG))) {
|
||||
// Check if there is a FAT string, which indicates this is a boot sector
|
||||
startSector = 0;
|
||||
} else if (!memcmp(sectorBuffer + BPB_FAT32_fileSysType, FAT_SIG, sizeof(FAT_SIG))) {
|
||||
// Check for FAT32
|
||||
startSector = 0;
|
||||
} else {
|
||||
startSector = FindFirstValidPartition(disc);
|
||||
if (!_FAT_disc_readSectors (disc, startSector, 1, sectorBuffer)) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// Now verify that this is indeed a FAT partition
|
||||
if (memcmp(sectorBuffer + BPB_FAT16_fileSysType, FAT_SIG, sizeof(FAT_SIG)) &&
|
||||
memcmp(sectorBuffer + BPB_FAT32_fileSysType, FAT_SIG, sizeof(FAT_SIG)))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
partition = (PARTITION*) _FAT_mem_allocate (sizeof(PARTITION));
|
||||
if (partition == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Init the partition lock
|
||||
_FAT_lock_init(&partition->lock);
|
||||
|
||||
if (!memcmp(sectorBuffer + BPB_FAT16_fileSysType, FAT_SIG, sizeof(FAT_SIG)))
|
||||
strncpy(partition->label, (char*)(sectorBuffer + BPB_FAT16_volumeLabel), 11);
|
||||
else
|
||||
strncpy(partition->label, (char*)(sectorBuffer + BPB_FAT32_volumeLabel), 11);
|
||||
partition->label[11] = '\0';
|
||||
|
||||
// Set partition's disc interface
|
||||
partition->disc = disc;
|
||||
|
||||
// Store required information about the file system
|
||||
partition->fat.sectorsPerFat = u8array_to_u16(sectorBuffer, BPB_sectorsPerFAT);
|
||||
if (partition->fat.sectorsPerFat == 0) {
|
||||
partition->fat.sectorsPerFat = u8array_to_u32( sectorBuffer, BPB_FAT32_sectorsPerFAT32);
|
||||
}
|
||||
|
||||
partition->numberOfSectors = u8array_to_u16( sectorBuffer, BPB_numSectorsSmall);
|
||||
if (partition->numberOfSectors == 0) {
|
||||
partition->numberOfSectors = u8array_to_u32( sectorBuffer, BPB_numSectors);
|
||||
}
|
||||
|
||||
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->bytesPerCluster = partition->bytesPerSector * partition->sectorsPerCluster;
|
||||
partition->fat.fatStart = startSector + u8array_to_u16(sectorBuffer, BPB_reservedSectors);
|
||||
|
||||
partition->rootDirStart = partition->fat.fatStart + (sectorBuffer[BPB_numFATs] * partition->fat.sectorsPerFat);
|
||||
partition->dataStart = partition->rootDirStart +
|
||||
(( 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;
|
||||
|
||||
// Store info about FAT
|
||||
uint32_t clusterCount = (partition->numberOfSectors - (uint32_t)(partition->dataStart - startSector)) / partition->sectorsPerCluster;
|
||||
partition->fat.lastCluster = clusterCount + CLUSTER_FIRST - 1;
|
||||
partition->fat.firstFree = CLUSTER_FIRST;
|
||||
|
||||
if (clusterCount < CLUSTERS_PER_FAT12) {
|
||||
partition->filesysType = FS_FAT12; // FAT12 volume
|
||||
} else if (clusterCount < CLUSTERS_PER_FAT16) {
|
||||
partition->filesysType = FS_FAT16; // FAT16 volume
|
||||
} else {
|
||||
partition->filesysType = FS_FAT32; // FAT32 volume
|
||||
}
|
||||
|
||||
if (partition->filesysType != FS_FAT32) {
|
||||
partition->rootDirCluster = FAT16_ROOT_DIR_CLUSTER;
|
||||
} else {
|
||||
// Set up for the FAT32 way
|
||||
partition->rootDirCluster = u8array_to_u32(sectorBuffer, BPB_FAT32_rootClus);
|
||||
// Check if FAT mirroring is enabled
|
||||
if (!(sectorBuffer[BPB_FAT32_extFlags] & 0x80)) {
|
||||
// Use the active FAT
|
||||
partition->fat.fatStart = partition->fat.fatStart + ( partition->fat.sectorsPerFat * (sectorBuffer[BPB_FAT32_extFlags] & 0x0F));
|
||||
}
|
||||
}
|
||||
|
||||
// Create a cache to use
|
||||
partition->cache = _FAT_cache_constructor (cacheSize, sectorsPerPage, partition->disc, startSector+partition->numberOfSectors);
|
||||
|
||||
// Set current directory to the root
|
||||
partition->cwdCluster = partition->rootDirCluster;
|
||||
|
||||
// Check if this disc is writable, and set the readOnly property appropriately
|
||||
partition->readOnly = !(_FAT_disc_features(disc) & FEATURE_MEDIUM_CANWRITE);
|
||||
|
||||
// There are currently no open files on this partition
|
||||
partition->openFileCount = 0;
|
||||
partition->firstOpenFile = NULL;
|
||||
|
||||
return partition;
|
||||
}
|
||||
|
||||
void _FAT_partition_destructor (PARTITION* partition) {
|
||||
FILE_STRUCT* nextFile;
|
||||
|
||||
_FAT_lock(&partition->lock);
|
||||
|
||||
// Synchronize open files
|
||||
nextFile = partition->firstOpenFile;
|
||||
while (nextFile) {
|
||||
_FAT_syncToDisc (nextFile);
|
||||
nextFile = nextFile->nextOpenFile;
|
||||
}
|
||||
|
||||
// Free memory used by the cache, writing it to disc at the same time
|
||||
_FAT_cache_destructor (partition->cache);
|
||||
|
||||
// Unlock the partition and destroy the lock
|
||||
_FAT_unlock(&partition->lock);
|
||||
_FAT_lock_deinit(&partition->lock);
|
||||
|
||||
// Free memory used by the partition
|
||||
_FAT_mem_free (partition);
|
||||
}
|
||||
|
||||
PARTITION* _FAT_partition_getPartitionFromPath (const char* path) {
|
||||
const devoptab_t *devops;
|
||||
|
||||
devops = GetDeviceOpTab (path);
|
||||
|
||||
if (!devops) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (PARTITION*)devops->deviceData;
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
partition.h
|
||||
Functions for mounting and dismounting partitions
|
||||
on various block devices.
|
||||
|
||||
Copyright (c) 2006 Michael "Chishm" Chisholm
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
3. The name of the author may not be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _PARTITION_H
|
||||
#define _PARTITION_H
|
||||
|
||||
#include "common.h"
|
||||
#include "cache.h"
|
||||
#include "lock.h"
|
||||
|
||||
// Device name
|
||||
extern const char* DEVICE_NAME;
|
||||
|
||||
// Filesystem type
|
||||
typedef enum {FS_UNKNOWN, FS_FAT12, FS_FAT16, FS_FAT32} FS_TYPE;
|
||||
|
||||
typedef struct {
|
||||
sec_t fatStart;
|
||||
uint32_t sectorsPerFat;
|
||||
uint32_t lastCluster;
|
||||
uint32_t firstFree;
|
||||
} FAT;
|
||||
|
||||
typedef struct {
|
||||
const DISC_INTERFACE* disc;
|
||||
CACHE* cache;
|
||||
// Info about the partition
|
||||
FS_TYPE filesysType;
|
||||
uint64_t totalSize;
|
||||
sec_t rootDirStart;
|
||||
uint32_t rootDirCluster;
|
||||
uint32_t numberOfSectors;
|
||||
sec_t dataStart;
|
||||
uint32_t bytesPerSector;
|
||||
uint32_t sectorsPerCluster;
|
||||
uint32_t bytesPerCluster;
|
||||
FAT fat;
|
||||
// Values that may change after construction
|
||||
uint32_t cwdCluster; // Current working directory cluster
|
||||
int openFileCount;
|
||||
struct _FILE_STRUCT* firstOpenFile; // The start of a linked list of files
|
||||
mutex_t lock; // A lock for partition operations
|
||||
bool readOnly; // If this is set, then do not try writing to the disc
|
||||
char label[12]; // Volume label
|
||||
} PARTITION;
|
||||
|
||||
/*
|
||||
Mount the supplied device and return a pointer to the struct necessary to use it
|
||||
*/
|
||||
PARTITION* _FAT_partition_constructor (const DISC_INTERFACE* disc, uint32_t cacheSize, uint32_t SectorsPerPage, sec_t startSector);
|
||||
|
||||
/*
|
||||
Dismount the device and free all structures used.
|
||||
Will also attempt to synchronise all open files to disc.
|
||||
*/
|
||||
void _FAT_partition_destructor (PARTITION* partition);
|
||||
|
||||
/*
|
||||
Return the partition specified in a path, as taken from the devoptab.
|
||||
*/
|
||||
PARTITION* _FAT_partition_getPartitionFromPath (const char* path);
|
||||
|
||||
#endif // _PARTITION_H
|
|
@ -1387,14 +1387,6 @@
|
|||
RelativePath="..\utils\md5.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\mkgmtime.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\mkgmtime.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\task.cpp"
|
||||
>
|
||||
|
@ -1497,6 +1489,122 @@
|
|||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="libfat"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\bit_ops.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\cache.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\cache.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\common.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\directory.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\directory.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\disc.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\disc.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\disc_io.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\fat.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\fatdir.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\fatdir.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\fatfile.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\fatfile.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\file_allocation_table.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\file_allocation_table.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\filetime.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\filetime.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\libfat.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\libfat_pc.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\libfat_public_api.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\libfat_public_api.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\lock.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\lock.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\mem_allocate.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\ndstypes.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\partition.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\partition.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="addons"
|
||||
|
|
|
@ -1130,6 +1130,122 @@
|
|||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="libfat"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\bit_ops.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\cache.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\cache.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\common.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\directory.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\directory.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\disc.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\disc.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\disc_io.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\fat.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\fatdir.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\fatdir.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\fatfile.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\fatfile.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\file_allocation_table.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\file_allocation_table.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\filetime.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\filetime.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\libfat.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\libfat_pc.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\libfat_public_api.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\libfat_public_api.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\lock.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\lock.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\mem_allocate.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\ndstypes.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\partition.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\utils\libfat\partition.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="metaspu"
|
||||
|
|
|
@ -472,6 +472,17 @@
|
|||
<ClCompile Include="..\thumb_instructions.cpp" />
|
||||
<ClCompile Include="..\utils\datetime.cpp" />
|
||||
<ClCompile Include="..\utils\dlditool.cpp" />
|
||||
<ClCompile Include="..\utils\libfat\cache.cpp" />
|
||||
<ClCompile Include="..\utils\libfat\directory.cpp" />
|
||||
<ClCompile Include="..\utils\libfat\disc.cpp" />
|
||||
<ClCompile Include="..\utils\libfat\fatdir.cpp" />
|
||||
<ClCompile Include="..\utils\libfat\fatfile.cpp" />
|
||||
<ClCompile Include="..\utils\libfat\filetime.cpp" />
|
||||
<ClCompile Include="..\utils\libfat\file_allocation_table.cpp" />
|
||||
<ClCompile Include="..\utils\libfat\libfat.cpp" />
|
||||
<ClCompile Include="..\utils\libfat\libfat_public_api.cpp" />
|
||||
<ClCompile Include="..\utils\libfat\lock.cpp" />
|
||||
<ClCompile Include="..\utils\libfat\partition.cpp" />
|
||||
<ClCompile Include="..\version.cpp" />
|
||||
<ClCompile Include="..\wifi.cpp" />
|
||||
<ClCompile Include="..\addons\compactFlash.cpp" />
|
||||
|
@ -595,6 +606,23 @@
|
|||
<ClInclude Include="..\thumb_instructions.h" />
|
||||
<ClInclude Include="..\types.h" />
|
||||
<ClInclude Include="..\utils\datetime.h" />
|
||||
<ClInclude Include="..\utils\libfat\bit_ops.h" />
|
||||
<ClInclude Include="..\utils\libfat\cache.h" />
|
||||
<ClInclude Include="..\utils\libfat\common.h" />
|
||||
<ClInclude Include="..\utils\libfat\directory.h" />
|
||||
<ClInclude Include="..\utils\libfat\disc.h" />
|
||||
<ClInclude Include="..\utils\libfat\disc_io.h" />
|
||||
<ClInclude Include="..\utils\libfat\fat.h" />
|
||||
<ClInclude Include="..\utils\libfat\fatdir.h" />
|
||||
<ClInclude Include="..\utils\libfat\fatfile.h" />
|
||||
<ClInclude Include="..\utils\libfat\filetime.h" />
|
||||
<ClInclude Include="..\utils\libfat\file_allocation_table.h" />
|
||||
<ClInclude Include="..\utils\libfat\libfat_pc.h" />
|
||||
<ClInclude Include="..\utils\libfat\libfat_public_api.h" />
|
||||
<ClInclude Include="..\utils\libfat\lock.h" />
|
||||
<ClInclude Include="..\utils\libfat\mem_allocate.h" />
|
||||
<ClInclude Include="..\utils\libfat\ndstypes.h" />
|
||||
<ClInclude Include="..\utils\libfat\partition.h" />
|
||||
<ClInclude Include="..\version.h" />
|
||||
<ClInclude Include="..\wifi.h" />
|
||||
<ClInclude Include="..\utils\xstring.h" />
|
||||
|
|
|
@ -46,6 +46,9 @@
|
|||
<Filter Include="Windows\libs">
|
||||
<UniqueIdentifier>{42b6ff9b-c9ff-4006-b2f7-f3e3268b8c31}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Core\utils\libfat">
|
||||
<UniqueIdentifier>{c751e37c-54da-44e2-9be8-0399cb02467a}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\addons.cpp">
|
||||
|
@ -399,6 +402,39 @@
|
|||
<ClCompile Include="..\utils\datetime.cpp">
|
||||
<Filter>Core\utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\utils\libfat\partition.cpp">
|
||||
<Filter>Core\utils\libfat</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\utils\libfat\cache.cpp">
|
||||
<Filter>Core\utils\libfat</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\utils\libfat\directory.cpp">
|
||||
<Filter>Core\utils\libfat</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\utils\libfat\disc.cpp">
|
||||
<Filter>Core\utils\libfat</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\utils\libfat\fatdir.cpp">
|
||||
<Filter>Core\utils\libfat</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\utils\libfat\fatfile.cpp">
|
||||
<Filter>Core\utils\libfat</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\utils\libfat\file_allocation_table.cpp">
|
||||
<Filter>Core\utils\libfat</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\utils\libfat\filetime.cpp">
|
||||
<Filter>Core\utils\libfat</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\utils\libfat\libfat.cpp">
|
||||
<Filter>Core\utils\libfat</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\utils\libfat\libfat_public_api.cpp">
|
||||
<Filter>Core\utils\libfat</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\utils\libfat\lock.cpp">
|
||||
<Filter>Core\utils\libfat</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\addons.h">
|
||||
|
@ -735,6 +771,57 @@
|
|||
<ClInclude Include="..\utils\datetime.h">
|
||||
<Filter>Core\utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\utils\libfat\ndstypes.h">
|
||||
<Filter>Core\utils\libfat</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\utils\libfat\partition.h">
|
||||
<Filter>Core\utils\libfat</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\utils\libfat\bit_ops.h">
|
||||
<Filter>Core\utils\libfat</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\utils\libfat\cache.h">
|
||||
<Filter>Core\utils\libfat</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\utils\libfat\common.h">
|
||||
<Filter>Core\utils\libfat</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\utils\libfat\directory.h">
|
||||
<Filter>Core\utils\libfat</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\utils\libfat\disc.h">
|
||||
<Filter>Core\utils\libfat</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\utils\libfat\disc_io.h">
|
||||
<Filter>Core\utils\libfat</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\utils\libfat\fat.h">
|
||||
<Filter>Core\utils\libfat</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\utils\libfat\fatdir.h">
|
||||
<Filter>Core\utils\libfat</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\utils\libfat\fatfile.h">
|
||||
<Filter>Core\utils\libfat</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\utils\libfat\file_allocation_table.h">
|
||||
<Filter>Core\utils\libfat</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\utils\libfat\filetime.h">
|
||||
<Filter>Core\utils\libfat</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\utils\libfat\libfat_pc.h">
|
||||
<Filter>Core\utils\libfat</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\utils\libfat\libfat_public_api.h">
|
||||
<Filter>Core\utils\libfat</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\utils\libfat\lock.h">
|
||||
<Filter>Core\utils\libfat</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\utils\libfat\mem_allocate.h">
|
||||
<Filter>Core\utils\libfat</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\instruction_tabdef.inc">
|
||||
|
|
Loading…
Reference in New Issue