147 "Operation not permitted",
148 "No such file or directory",
150 "Interrupted system call",
152 "No such device or address",
153 "Argument list too long",
156 "No child processes",
161 "Block device required",
162 "Device or resource busy",
169 "File table overflow",
170 "Too many open files",
174 "No space left on device",
176 "Read-only file system",
179 "Math argument out of domain of func",
180 "Math result not representable",
199 if(fileno >= 0 && fileno <= 2)
237 return stream->
unget;
251 printf(
"fgetc stream->get NULL\n");
255 c = stream->
get(stream);
305 if (stream->
len < stream->
size)
312 printf(
"fputc stream->put NULL\n");
315 ret = stream->
put(c, stream);
403 return(
fputc(c, stream));
524 long offset =
ftell(stream);
553 ret =
lseek(fn, offset, whence);
642 position += fh->
fptr;
650 if(position !=
f_tell(fh) )
736 if ( __iob[fileno] == stream)
803 size_t fread(
void *ptr,
size_t size,
size_t nmemb,
FILE *stream)
805 size_t count = size * nmemb;
810 ret =
read(fn, ptr, count);
814 return((
size_t) ret);
868 size_t fwrite(
const void *ptr,
size_t size,
size_t nmemb,
FILE *stream)
870 size_t count = size * nmemb;
875 ret =
write(fn, ptr, count);
880 return((
size_t) ret);
895 int open(
const char *pathname,
int flags)
919 else if((flags & O_ACCMODE) ==
O_RDONLY)
950 res =
f_open(fh, pathname, (
BYTE) (fatfs_modes & 0xff));
970 if((flags & O_ACCMODE) ==
O_RDWR)
977 else if((flags & O_ACCMODE) ==
O_RDONLY)
1025 char *ptr = (
char *) buf;
1031 ret =
fgetc(stream);
1053 res =
f_read(fh, (
void *) buf, bytes, &size);
1193 char *ptr = (
char *) buf;
1199 ret =
fputc(c, stream);
1220 res =
f_write(fh, buf, bytes, &size);
1245 return(
close(fn) );
1299 int fstat(
int fd,
struct stat *buf)
1326 char *ptr = (
char *)
ctime_gm(&timev);
1329 if(len && ptr[len-1] ==
'\n')
1365 res =
f_stat(name, &info);
1580 int fchmod(
int fd,
mode_t mode)
1625 if(
chmod(pathname, mode))
1648 int rename(
const char *oldpath,
const char *newpath)
1744 return ((
DIR *) &_dp);
1816 const char *ptr =
NULL;
1825 printf(
"%s: %s\n", s, ptr);
1880 if (put == 0 &&
get == 0)
1931 len =
MATCH(name,
"/dev/sd");
1934 printf(
"Expected /dev/sda .. /dev/sdj\n");
1941 if(c >=
'a' && c <= (
'a' + 9))
2008 if( res !=
FR_OK || size != 1)
2044 if(res !=
FR_OK || size != 1)
2095 if( res !=
FR_OK || size != 1)
2232 memset(&tp, 0,
sizeof(
struct tm));
2234 tp.
tm_sec = (time << 1) & 0x3e;
2235 tp.
tm_min = ((time >> 5) & 0x3f);
2236 tp.
tm_hour = ((time >> 11) & 0x1f);
2238 tp.
tm_mon = ((date >> 5) & 0x0f) - 1;
2239 tp.
tm_year = ((date >> 9) & 0x7f) + 80;
2289 if( stream ==
NULL )
2365 if( __iob[i] ==
NULL)
2493 va_start(va, format);
2497 return ((
int)fn.
sent);
#define fdev_set_udata(stream, u)
device IO udata
MEMSPACE int new_file_descriptor(void)
Allocate a POSIX FILE descriptor. NOT POSIX.
MEMSPACE FRESULT f_closedir(DIR *dp)
MEMSPACE int putc(int c, FILE *stream)
Put a character to a stream See fdevopen() sets stream->put get for TTY devices.
char d_name[MAX_NAME_LEN]
MEMSPACE int isatty(int fileno)
Test POSIX fileno if it is a Serial Console/TTY.
MEMSPACE int WEAK_ATR strcmp(const char *str, const char *pat)
Compare two strings.
MEMSPACE FIL * fileno_to_fatfs(int fileno)
Convert POSIX fileno to FatFS handle NOT POSIX.
MEMSPACE off_t lseek(int fileno, off_t position, int whence)
POSIX seek to file position.
MEMSPACE size_t WEAK_ATR strlen(const char *str)
String Length.
MEMSPACE char * baseext(char *str)
File extention of a file name. NOT POSIX.
MEMSPACE void dump_stat(struct stat *sp)
Display struct stat, from POSIX stat(0 or fstat(), in ASCII. NOT POSIX.
int(* get)(struct __file *)
MEMSPACE int open(const char *pathname, int flags)
POSIX Open a file with integer mode flags.
MEMSPACE void clrerror(FILE *stream)
clrerror resets stream EOF and error flags
MEMSPACE FRESULT f_write(FIL *fp, const void *buff, UINT btw, UINT *bw)
MEMSPACE void sync(void)
POSIX Sync all pending file changes and metadata on ALL files.
dirent_t * readdir(DIR *dirp)
Master include file for project Includes all project includes and defines here.
MEMSPACE int fatfs_putc(char c, FILE *stream)
Private FatFs function called by fputc() to put a byte from file stream NOT POSIX open() assigns stre...
MEMSPACE int free_file_descriptor(int fileno)
Free POSIX fileno FILE descriptor. NOT POSIX.
MEMSPACE int close(int fileno)
POSIX Close a file with fileno handel.
MEMSPACE FRESULT f_chmod(const TCHAR *path, BYTE attr, BYTE mask)
MEMSPACE int fseek(FILE *stream, long offset, int whence)
POSIX seek to file possition.
#define FATFS_R
FATFS open modes.
MEMSPACE int putchar(int c)
put a character to stdout See fdevopen() sets stream->put get for TTY devices
MEMSPACE char * fgets(char *str, int size, FILE *stream)
get a string from stdin See fdevopen() sets stream->put get for TTY devices
MEMSPACE FILE * fopen(const char *path, const char *mode)
POSIX Open a file with path name and ascii file mode string.
#define O_ACCMODE
POSIX open modes - no other combination are allowed.
MEMSPACE FRESULT f_readdir(DIR *dp, FILINFO *fno)
MEMSPACE int rmdir(const char *pathname)
POSIX delete a directory.
static struct ip_info info
MEMSPACE FRESULT f_rename(const TCHAR *path_old, const TCHAR *path_new)
MEMSPACE void perror(const char *s)
POSIX perror() - convert POSIX errno to text with user message.
MEMSPACE int fgetpos(FILE *stream, size_t *pos)
POSIX get position of file stream.
MEMSPACE int fatfs_to_errno(FRESULT Result)
Convert FafFs error result to POSIX errno. NOT POSIX.
MEMSPACE WEAK_ATR char * strncpy(char *dest, const char *src, size_t size)
copy a string of at most N characters
MEMSPACE void _printf_fn(printf_t *fn, __memx const char *fmt, va_list va)
vsnprintf function
MEMSPACE FILE * fdevopen(int(*put)(char, FILE *), int(*get)(FILE *))
Device open functions.
MEMSPACE FRESULT f_read(FIL *fp, void *buff, UINT btr, UINT *br)
#define MAX_FILES
Maximum number of POSIX file handles.
MEMSPACE FRESULT f_close(FIL *fp)
MEMSPACE int fputc(int c, FILE *stream)
Put a byte to TTY device or FatFs file stream open() or fopen() sets stream->put = fatfs_outc() for F...
MEMSPACE int fprintf(FILE *fp, const char *format,...)
fprintf function Example user defined printf function using fputc for I/O This method allows I/O to d...
MEMSPACE FRESULT f_open(FIL *fp, const TCHAR *path, BYTE mode)
int mkfs(char *name)
Formt SD card.
MEMSPACE time_t timegm(tm_t *t)
Convert tm_t structure as GMT time into GMT seconds since 1900. All calculactions are in GMT regardle...
MEMSPACE ssize_t write(int fd, const void *buf, size_t count)
POSIX Write count bytes from *buf to fileno fd.
MEMSPACE int utime(const char *filename, const struct utimbuf *times)
Set Modification and Access time of a file.
MEMSPACE size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
POSIX read nmemb elements from buf, size bytes each, to the stream fd.
MEMSPACE int feof(FILE *stream)
feof reports if the stream is at EOF
MEMSPACE time_t time(time_t *t)
Return second from epoch - POSIX function.
MEMSPACE FRESULT f_opendir(DIR *dp, const TCHAR *path)
MEMSPACE FRESULT f_mkdir(const TCHAR *path)
void optimistic_yield(uint32_t interval_us)
MEMSPACE time_t fat_time_to_unix(uint16_t date, uint16_t time)
Convert FatFs file date and time to POSIX epoch seconds. NOT POSIX.
#define EOF
End of file or device read.
MEMSPACE FRESULT f_lseek(FIL *fp, FSIZE_t ofs)
MEMSPACE int fatfs_to_fileno(FIL *fh)
Convert FatFS file handle to POSIX fileno. NOT POSIX.
uint32_t time_t
type of EPOCH result.
MEMSPACE int dirname(char *str)
POSIX directory name of a filename. Return the index of the last '/' character.
MEMSPACE void put_rc(int rc)
display FatFs return code as ascii string
MEMSPACE char * ctime_gm(time_t *tp)
GMT version of POSIX ctime().
MEMSPACE void unix_time_to_fat(time_t epoch, uint16_t *date, uint16_t *time)
Convert Linux POSIX time_t to FAT32 date and time. NOT POSIX.
MEMSPACE int fputs(const char *str, FILE *stream)
put a string to stdout See fdevopen() sets stream->put get for TTY devices
MEMSPACE int syncfs(int fd)
POSIX Sync pending file changes and metadata for specified fileno.
MEMSPACE int truncate(const char *path, off_t length)
POSIX truncate named file to length.
MEMSPACE ssize_t read(int fd, const void *buf, size_t count)
POSIX read count bytes from *buf to fileno fd.
MEMSPACE int WEAK_ATR tolower(int c)
Convert character to lower case, only if it is upper case.
MEMSPACE void * safemalloc(size_t size)
Safe Malloc - Display Error message if Malloc fails.
MEMSPACE size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
POSIX write nmemb elements from buf, size bytes each, to the stream fd.
MEMSPACE int ftruncate(int fd, off_t length)
POSIX truncate open file to length.
MEMSPACE int unlink(const char *pathname)
POSIX delete a file.
MEMSPACE int posix_fopen_modes_to_open(const char *mode)
Convert POSIX fopen mode to POSIX open mode flags. NOT POSIX.
MEMSPACE int mmc_init(int verbose)
Initialize MMC and FatFs interface, display diagnostics.
#define _FDEV_SETUP_WRITE
MEMSPACE int fclose(FILE *stream)
POSIX close a file stream.
MEMSPACE tm_t * gmtime(time_t *tp)
Convert epoch GMT time_t *tp into POSIX static tm_t *t.
#define stdin
define stdin, stdout and stderr
#define modecmp(str, pat)
used in posix.c to compare to ascii file modes
Various string and character functions.
int(* put)(char, struct __file *)
MEMSPACE int fileno(FILE *stream)
Convert POSIX stream pointer to POSIX fileno (index of __iob[])
MEMSPACE FRESULT f_unlink(const TCHAR *path)
#define SEEK_SET
Seek offset macros.
static dirent_t _de
POSIX opendir.
MEMSPACE int fgetc(FILE *stream)
Get byte from a TTY device or FatFs file stream open() or fopen() sets stream->get = fatfs_getc() for...
MEMSPACE int puts(const char *str)
put a string to stdout See fdevopen() sets stream->put get for TTY devices
MEMSPACE void wdt_reset(void)
reset watchdog
MEMSPACE int fatfs_getc(FILE *stream)
Private FatFs function called by fgetc() to get a byte from file stream FIXME buffer this function ca...
MEMSPACE int mkdir(const char *pathname, mode_t mode)
POSIX make a directory.
MEMSPACE int ungetc(int c, FILE *stream)
Un-Get byte from a TTY device or FatFs file stream.
MEMSPACE char * strerror_r(int errnum, char *buf, size_t buflen)
POSIX strerror_r() - convert POSIX errno to text with user message.
int closedir(DIR *dirp)
POSIX closedir.
MEMSPACE int chmod(const char *pathname, mode_t mode)
POSIX chmod function - change file access permission Unfortunately file f_open modes and f_chmod mode...
MEMSPACE int printf(const char *format,...)
MEMSPACE long ftell(FILE *stream)
POSIX file position of open stream.
MEMSPACE FRESULT f_stat(const TCHAR *path, FILINFO *fno)
MEMSPACE int chdir(const char *pathname)
POSIX change directory.
MEMSPACE char * basename(char *str)
POSIX Basename of filename.
int errno
Note: fdevopen assigns stdin,stdout,stderr.
MEMSPACE FRESULT f_getcwd(TCHAR *buff, UINT len)
MEMSPACE int fsetpos(FILE *stream, size_t *pos)
POSIX set position of file stream.
MEMSPACE char * getcwd(char *pathname, int len)
POSIX get current working directory.
MEMSPACE int stat(char *name, struct stat *buf)
POSIX stat - get file status of named file.
MEMSPACE void safefree(void *p)
Safe free - Only free a pointer if it is in malloc memory range. We want to try to catch frees of sta...
MEMSPACE char * mctime(time_t timev)
Display Ascii formatted time from timev seconds NOT POSIX.
const char * sys_errlist[]
POSIX error messages for each errno value.
#define fdev_get_udata(stream)
MEMSPACE int getchar()
functions normally defined as macros
MEMSPACE FRESULT f_sync(FIL *fp)
FILE * __iob[MAX_FILES]
POSIX fileno to POSIX FILE stream table.
MEMSPACE void rewind(FILE *stream)
POSIX rewind file to the beginning.
DIR * opendir(const char *pathdir)
MEMSPACE int ferror(FILE *stream)
ferror reports if the stream has an error flag set
MEMSPACE FRESULT f_chdir(const TCHAR *path)
void(* put)(struct _printf_t *, char)
MEMSPACE FRESULT f_truncate(FIL *fp)
MEMSPACE FILE * fileno_to_stream(int fileno)
Convert POSIX fileno to POSIX FILE stream pointer. NOT POSIX.
static DIR _dp
POSIX opendir.
static MEMSPACE void _fprintf_putc(struct _printf_t *p, char ch)
fprintf character write function
MEMSPACE FRESULT f_mount(FATFS *fs, const TCHAR *path, BYTE opt)
MEMSPACE void * safecalloc(size_t nmemb, size_t size)
Safe Calloc - Display Error message if Calloc fails.
MEMSPACE FRESULT f_utime(const TCHAR *path, const FILINFO *fno)
MEMSPACE int rename(const char *oldpath, const char *newpath)
POSIX rename a file by name.
undefine any potential macro version of these functions
MEMSPACE FRESULT f_mkfs(const TCHAR *path, BYTE opt, DWORD au, void *work, UINT len)
MEMSPACE char WEAK_ATR * strerror(int errnum)
POSIX strerror() - convert POSIX errno to text with user message.