4 #include <sys/iosupport.h>
14 static int sdmc_open(
struct _reent *r,
void *fileStruct,
const char *path,
int flags,
int mode);
15 static int sdmc_close(
struct _reent *r,
int fd);
16 static ssize_t sdmc_write(
struct _reent *r,
int fd,
const char *ptr,
size_t len);
17 static ssize_t sdmc_read(
struct _reent *r,
int fd,
char *ptr,
size_t len);
18 static off_t sdmc_seek(
struct _reent *r,
int fd, off_t pos,
int dir);
19 static int sdmc_fstat(
struct _reent *r,
int fd,
struct stat *st);
20 static int sdmc_stat(
struct _reent *r,
const char *file,
struct stat *st);
21 static int sdmc_link(
struct _reent *r,
const char *existing,
const char *newLink);
22 static int sdmc_unlink(
struct _reent *r,
const char *name);
23 static int sdmc_chdir(
struct _reent *r,
const char *name);
24 static int sdmc_rename(
struct _reent *r,
const char *oldName,
const char *newName);
25 static int sdmc_mkdir(
struct _reent *r,
const char *path,
int mode);
26 static DIR_ITER* sdmc_diropen(
struct _reent *r, DIR_ITER *dirState,
const char *path);
27 static int sdmc_dirreset(
struct _reent *r, DIR_ITER *dirState);
28 static int sdmc_dirnext(
struct _reent *r, DIR_ITER *dirState,
char *filename,
struct stat *filestat);
29 static int sdmc_dirclose(
struct _reent *r, DIR_ITER *dirState);
30 static int sdmc_statvfs(
struct _reent *r,
const char *path,
struct statvfs *buf);
31 static int sdmc_ftruncate(
struct _reent *r,
int fd, off_t len);
32 static int sdmc_fsync(
struct _reent *r,
int fd);
33 static int sdmc_chmod(
struct _reent *r,
const char *path, mode_t mode);
34 static int sdmc_fchmod(
struct _reent *r,
int fd, mode_t mode);
58 .structSize =
sizeof(sdmc_file_t),
60 .close_r = sdmc_close,
61 .write_r = sdmc_write,
64 .fstat_r = sdmc_fstat,
67 .unlink_r = sdmc_unlink,
68 .chdir_r = sdmc_chdir,
69 .rename_r = sdmc_rename,
70 .mkdir_r = sdmc_mkdir,
71 .dirStateSize =
sizeof(sdmc_dir_t),
72 .diropen_r = sdmc_diropen,
73 .dirreset_r = sdmc_dirreset,
74 .dirnext_r = sdmc_dirnext,
75 .dirclose_r = sdmc_dirclose,
76 .statvfs_r = sdmc_statvfs,
77 .ftruncate_r = sdmc_ftruncate,
78 .fsync_r = sdmc_fsync,
80 .chmod_r = sdmc_chmod,
81 .fchmod_r = sdmc_fchmod,
105 AddDevice(&sdmc_devoptab);
117 RemoveDevice(
"sdmc");
134 sdmc_open(
struct _reent *r,
144 char *pathptr = NULL;
146 pathptr = strchr(path,
'/');
147 if(pathptr==NULL)pathptr = (
char*)path;
150 sdmc_file_t *file = (sdmc_file_t*)fileStruct;
153 switch(flags & O_ACCMODE)
193 sdmc_flags, attributes);
197 file->flags = (flags & (O_ACCMODE|O_APPEND|O_SYNC));
215 sdmc_close(
struct _reent *r,
221 sdmc_file_t *file = (sdmc_file_t*)fd;
242 sdmc_write(
struct _reent *r,
253 sdmc_file_t *file = (sdmc_file_t*)fd;
256 if((file->flags & O_ACCMODE) == O_RDONLY)
263 if(file->flags & O_SYNC)
267 offset = file->offset;
268 if(file->flags & O_APPEND)
290 file->offset = offset + bytes;
291 return (ssize_t)bytes;
309 sdmc_read(
struct _reent *r,
318 sdmc_file_t *file = (sdmc_file_t*)fd;
321 if((file->flags & O_ACCMODE) == O_WRONLY)
332 file->offset += bytes;
333 return (ssize_t)bytes;
351 sdmc_seek(
struct _reent *r,
360 sdmc_file_t *file = (sdmc_file_t*)fd;
372 offset = file->offset;
392 if(pos < 0 && offset < -pos)
400 file->offset = offset + pos;
414 sdmc_fstat(
struct _reent *r,
432 sdmc_stat(
struct _reent *r,
450 sdmc_link(
struct _reent *r,
451 const char *existing,
467 sdmc_unlink(
struct _reent *r,
483 sdmc_chdir(
struct _reent *r,
500 sdmc_rename(
struct _reent *r,
518 sdmc_mkdir(
struct _reent *r,
523 char *pathptr = NULL;
525 pathptr = strchr(path,
'/');
526 if(pathptr==NULL)pathptr = (
char*)path;
548 sdmc_diropen(
struct _reent *r,
554 char *pathptr = NULL;
556 pathptr = strchr(path,
'/');
557 if(pathptr==NULL)pathptr = (
char*)path;
560 sdmc_dir_t *dir = (sdmc_dir_t*)(dirState->dirStruct);
567 memset(&dir->entry_data, 0,
sizeof(dir->entry_data));
584 sdmc_dirreset(
struct _reent *r,
602 sdmc_dirnext(
struct _reent *r,
605 struct stat *filestat)
612 sdmc_dir_t *dir = (sdmc_dir_t*)(dirState->dirStruct);
615 rc =
FSDIR_Read(dir->fd, &entries, 1, &dir->entry_data);
626 filestat->st_ino = 0;
627 if(dir->entry_data.isDirectory)
628 filestat->st_mode = S_IFDIR;
630 filestat->st_mode = S_IFREG;
633 name = dir->entry_data.name;
635 *filename++ = *name++;
654 sdmc_dirclose(
struct _reent *r,
660 sdmc_dir_t *dir = (sdmc_dir_t*)(dirState->dirStruct);
681 sdmc_statvfs(
struct _reent *r,
686 u32 clusterSize, numClusters, freeClusters;
697 buf->f_bsize = clusterSize;
698 buf->f_frsize = clusterSize;
699 buf->f_blocks = numClusters;
700 buf->f_bfree = freeClusters;
701 buf->f_bavail = freeClusters;
703 buf->f_ffree = freeClusters;
704 buf->f_favail = freeClusters;
706 buf->f_flag = ST_NOSUID;
710 if(rc != 0 || !writable)
711 buf->f_flag |= ST_RDONLY;
730 sdmc_ftruncate(
struct _reent *r,
737 sdmc_file_t *file = (sdmc_file_t*)fd;
764 sdmc_fsync(
struct _reent *r,
770 sdmc_file_t *file = (sdmc_file_t*)fd;
790 sdmc_chmod(
struct _reent *r,
808 sdmc_fchmod(
struct _reent *r,
Result FSUSER_IsSdmcWritable(Handle *handle, u32 *writable)
Result FSDIR_Close(Handle handle)
Result FSUSER_OpenArchive(Handle *handle, FS_archive *archive)
Result FSDIR_Read(Handle handle, u32 *entriesRead, u32 entrycount, FS_dirent *buffer)
Result FSFILE_Flush(Handle handle)
Result FSFILE_Close(Handle handle)
Result FSFILE_SetSize(Handle handle, u64 size)
Result FSUSER_OpenDirectory(Handle *handle, Handle *out, FS_archive archive, FS_path dirLowPath)
Result FSFILE_GetSize(Handle handle, u64 *size)
Result FSUSER_CloseArchive(Handle *handle, FS_archive *archive)
Result FSFILE_Write(Handle handle, u32 *bytesWritten, u64 offset, const void *buffer, u32 size, u32 flushFlags)
Result FSUSER_GetSdmcArchiveResource(Handle *handle, u32 *sectorSize, u32 *clusterSize, u32 *numClusters, u32 *freeClusters)
Result FSUSER_OpenFile(Handle *handle, Handle *out, FS_archive archive, FS_path fileLowPath, u32 openflags, u32 attributes)
Result FSFILE_Read(Handle handle, u32 *bytesRead, u64 offset, void *buffer, u32 size)
u16 name[0x106]
UTF-16 encoded name.
Result FSUSER_CreateDirectory(Handle *handle, FS_archive archive, FS_path dirLowPath)
Specifies a text based path with a 8-bit byte per character.
#define FS_ATTRIBUTE_NONE