RetroArch
fatfile.h
Go to the documentation of this file.
1 /*
2  fatfile.h
3 
4  Functions used by the newlib disc stubs to interface with
5  this library
6 
7  Copyright (c) 2006 Michael "Chishm" Chisholm
8 
9  Redistribution and use in source and binary forms, with or without modification,
10  are permitted provided that the following conditions are met:
11 
12  1. Redistributions of source code must retain the above copyright notice,
13  this list of conditions and the following disclaimer.
14  2. Redistributions in binary form must reproduce the above copyright notice,
15  this list of conditions and the following disclaimer in the documentation and/or
16  other materials provided with the distribution.
17  3. The name of the author may not be used to endorse or promote products derived
18  from this software without specific prior written permission.
19 
20  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
21  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22  AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
23  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30 
31 
32 #ifndef _FATFILE_H
33 #define _FATFILE_H
34 
35 #include <sys/reent.h>
36 #include <sys/stat.h>
37 
38 #include "common.h"
39 #include "partition.h"
40 #include "directory.h"
41 
42 #define FILE_MAX_SIZE ((uint32_t)0xFFFFFFFF) // 4GiB - 1B
43 
44 typedef struct {
45  u32 cluster;
46  sec_t sector;
47  s32 byte;
49 
50 struct _FILE_STRUCT;
51 
52 struct _FILE_STRUCT {
58  DIR_ENTRY_POSITION dirEntryStart; // Points to the start of the LFN entries of a file, or the alias for no LFN
59  DIR_ENTRY_POSITION dirEntryEnd; // Always points to the file's alias entry
61  struct _FILE_STRUCT* prevOpenFile; // The previous entry in a double-linked list of open files
62  struct _FILE_STRUCT* nextOpenFile; // The next entry in a double-linked list of open files
63  bool read;
64  bool write;
65  bool append;
66  bool inUse;
67  bool modified;
68 };
69 
70 typedef struct _FILE_STRUCT FILE_STRUCT;
71 
72 int _FAT_open_r (struct _reent *r, void *fileStruct, const char *path, int flags, int mode);
73 
74 int _FAT_close_r (struct _reent *r, void *fd);
75 
76 ssize_t _FAT_write_r (struct _reent *r,void *fd, const char *ptr, size_t len);
77 
78 ssize_t _FAT_read_r (struct _reent *r, void *fd, char *ptr, size_t len);
79 
80 off_t _FAT_seek_r (struct _reent *r, void *fd, off_t pos, int dir);
81 
82 int _FAT_fstat_r (struct _reent *r, void *fd, struct stat *st);
83 
84 int _FAT_stat_r (struct _reent *r, const char *path, struct stat *st);
85 
86 int _FAT_link_r (struct _reent *r, const char *existing, const char *newLink);
87 
88 int _FAT_unlink_r (struct _reent *r, const char *name);
89 
90 int _FAT_chdir_r (struct _reent *r, const char *name);
91 
92 int _FAT_rename_r (struct _reent *r, const char *oldName, const char *newName);
93 
94 int _FAT_ftruncate_r (struct _reent *r, void *fd, off_t len);
95 
96 int _FAT_fsync_r (struct _reent *r, void *fd);
97 
98 /*
99 Synchronizes the file data to disc.
100 Does no locking of its own -- lock the partition before calling.
101 Returns 0 on success, an error code on failure.
102 */
103 extern int _FAT_syncToDisc (FILE_STRUCT* file);
104 
105 #endif // _FATFILE_H
struct _FILE_STRUCT * nextOpenFile
Definition: fatfile.h:62
Definition: fatfile.h:52
GLuint const GLchar * name
Definition: glext.h:6671
const GLvoid * ptr
Definition: nx_glsym.h:242
int32_t s32
32bit signed integer
Definition: gctypes.h:24
GLenum mode
Definition: glext.h:6857
struct _FILE_STRUCT * prevOpenFile
Definition: fatfile.h:61
ssize_t _FAT_read_r(struct _reent *r, void *fd, char *ptr, size_t len)
Definition: fatfile.c:444
int _FAT_chdir_r(struct _reent *r, const char *name)
Definition: fatdir.c:186
int _FAT_ftruncate_r(struct _reent *r, void *fd, off_t len)
Definition: fatfile.c:1103
GLdouble GLdouble GLdouble r
Definition: glext.h:6406
GLsizei const GLchar ** path
Definition: glext.h:7901
GLenum GLsizei len
Definition: glext.h:7389
PARTITION * partition
Definition: fatfile.h:60
unsigned char byte
Definition: jsonsax_full.c:47
DIR_ENTRY_POSITION dirEntryStart
Definition: fatfile.h:58
FILE_POSITION appendPosition
Definition: fatfile.h:57
uint32_t startCluster
Definition: fatfile.h:54
int _FAT_rename_r(struct _reent *r, const char *oldName, const char *newName)
Definition: fatdir.c:223
uint32_t sec_t
Definition: iosuhax_disc_interface.h:40
bool modified
Definition: fatfile.h:67
bool inUse
Definition: fatfile.h:66
int _FAT_unlink_r(struct _reent *r, const char *name)
Definition: fatdir.c:93
uint32_t currentPosition
Definition: fatfile.h:55
int _FAT_open_r(struct _reent *r, void *fileStruct, const char *path, int flags, int mode)
Definition: fatfile.c:127
Definition: partition.h:52
ssize_t _FAT_write_r(struct _reent *r, void *fd, const char *ptr, size_t len)
Definition: fatfile.c:738
bool write
Definition: fatfile.h:64
int _FAT_stat_r(struct _reent *r, const char *path, struct stat *st)
Definition: fatdir.c:48
off_t _FAT_seek_r(struct _reent *r, void *fd, off_t pos, int dir)
Definition: fatfile.c:966
int _FAT_link_r(struct _reent *r, const char *existing, const char *newLink)
Definition: fatdir.c:87
Definition: fatfile.h:44
bool append
Definition: fatfile.h:65
int _FAT_fstat_r(struct _reent *r, void *fd, struct stat *st)
Definition: fatfile.c:1068
DIR_ENTRY_POSITION dirEntryEnd
Definition: fatfile.h:59
Definition: civetweb.c:1024
bool read
Definition: fatfile.h:63
GLbitfield flags
Definition: glext.h:7828
uint32_t u32
32bit unsigned integer
Definition: gctypes.h:19
Definition: directory.h:65
uint32_t filesize
Definition: fatfile.h:53
unsigned int uint32_t
Definition: stdint.h:126
int _FAT_close_r(struct _reent *r, void *fd)
Definition: fatfile.c:407
int _FAT_fsync_r(struct _reent *r, void *fd)
Definition: fatfile.c:1215
FILE_POSITION rwPosition
Definition: fatfile.h:56
int _FAT_syncToDisc(FILE_STRUCT *file)
Definition: fatfile.c:359