Updated get_fattime to use rtc and provide a date/time. This has been an annoying missing feature.

Dependents:   IoTGateway_Basic y_XBeeTest_5_read CameraC1098_picture LifeCam ... more

Committer:
SomeRandomBloke
Date:
Mon Apr 02 22:06:35 2012 +0000
Revision:
1:5baba5d5b728
Parent:
0:93acdd9f65f4

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
SomeRandomBloke 0:93acdd9f65f4 1 /* mbed Microcontroller Library - FATFileHandle
SomeRandomBloke 0:93acdd9f65f4 2 * Copyright (c) 2008, sford
SomeRandomBloke 0:93acdd9f65f4 3 */
SomeRandomBloke 0:93acdd9f65f4 4
SomeRandomBloke 0:93acdd9f65f4 5 #include "FATFileHandle.h"
SomeRandomBloke 0:93acdd9f65f4 6
SomeRandomBloke 0:93acdd9f65f4 7 #include <stdio.h>
SomeRandomBloke 0:93acdd9f65f4 8 #include <stdlib.h>
SomeRandomBloke 0:93acdd9f65f4 9 #include "ff.h"
SomeRandomBloke 0:93acdd9f65f4 10 #include "FATFileSystem.h"
SomeRandomBloke 0:93acdd9f65f4 11
SomeRandomBloke 0:93acdd9f65f4 12 namespace mbed {
SomeRandomBloke 0:93acdd9f65f4 13
SomeRandomBloke 0:93acdd9f65f4 14 #if FFSDEBUG_ENABLED
SomeRandomBloke 0:93acdd9f65f4 15 static const char *FR_ERRORS[] = {
SomeRandomBloke 0:93acdd9f65f4 16 "FR_OK = 0",
SomeRandomBloke 0:93acdd9f65f4 17 "FR_NOT_READY",
SomeRandomBloke 0:93acdd9f65f4 18 "FR_NO_FILE",
SomeRandomBloke 0:93acdd9f65f4 19 "FR_NO_PATH",
SomeRandomBloke 0:93acdd9f65f4 20 "FR_INVALID_NAME",
SomeRandomBloke 0:93acdd9f65f4 21 "FR_INVALID_DRIVE",
SomeRandomBloke 0:93acdd9f65f4 22 "FR_DENIED",
SomeRandomBloke 0:93acdd9f65f4 23 "FR_EXIST",
SomeRandomBloke 0:93acdd9f65f4 24 "FR_RW_ERROR",
SomeRandomBloke 0:93acdd9f65f4 25 "FR_WRITE_PROTECTED",
SomeRandomBloke 0:93acdd9f65f4 26 "FR_NOT_ENABLED",
SomeRandomBloke 0:93acdd9f65f4 27 "FR_NO_FILESYSTEM",
SomeRandomBloke 0:93acdd9f65f4 28 "FR_INVALID_OBJECT",
SomeRandomBloke 0:93acdd9f65f4 29 "FR_MKFS_ABORTED"
SomeRandomBloke 0:93acdd9f65f4 30 };
SomeRandomBloke 0:93acdd9f65f4 31 #endif
SomeRandomBloke 0:93acdd9f65f4 32
SomeRandomBloke 0:93acdd9f65f4 33 FATFileHandle::FATFileHandle(FIL fh) {
SomeRandomBloke 0:93acdd9f65f4 34 _fh = fh;
SomeRandomBloke 0:93acdd9f65f4 35 }
SomeRandomBloke 0:93acdd9f65f4 36
SomeRandomBloke 0:93acdd9f65f4 37 int FATFileHandle::close() {
SomeRandomBloke 0:93acdd9f65f4 38 FFSDEBUG("close\n");
SomeRandomBloke 0:93acdd9f65f4 39 int retval = f_close(&_fh);
SomeRandomBloke 0:93acdd9f65f4 40 delete this;
SomeRandomBloke 0:93acdd9f65f4 41 return retval;
SomeRandomBloke 0:93acdd9f65f4 42 }
SomeRandomBloke 0:93acdd9f65f4 43
SomeRandomBloke 0:93acdd9f65f4 44 ssize_t FATFileHandle::write(const void* buffer, size_t length) {
SomeRandomBloke 0:93acdd9f65f4 45 FFSDEBUG("write(%d)\n", length);
SomeRandomBloke 0:93acdd9f65f4 46 UINT n;
SomeRandomBloke 0:93acdd9f65f4 47 FRESULT res = f_write(&_fh, buffer, length, &n);
SomeRandomBloke 0:93acdd9f65f4 48 if(res) {
SomeRandomBloke 0:93acdd9f65f4 49 FFSDEBUG("f_write() failed (%d, %s)", res, FR_ERRORS[res]);
SomeRandomBloke 0:93acdd9f65f4 50 return -1;
SomeRandomBloke 0:93acdd9f65f4 51 }
SomeRandomBloke 0:93acdd9f65f4 52 return n;
SomeRandomBloke 0:93acdd9f65f4 53 }
SomeRandomBloke 0:93acdd9f65f4 54
SomeRandomBloke 0:93acdd9f65f4 55 ssize_t FATFileHandle::read(void* buffer, size_t length) {
SomeRandomBloke 0:93acdd9f65f4 56 FFSDEBUG("read(%d)\n", length);
SomeRandomBloke 0:93acdd9f65f4 57 UINT n;
SomeRandomBloke 0:93acdd9f65f4 58 FRESULT res = f_read(&_fh, buffer, length, &n);
SomeRandomBloke 0:93acdd9f65f4 59 if(res) {
SomeRandomBloke 0:93acdd9f65f4 60 FFSDEBUG("f_read() failed (%d, %s)\n", res, FR_ERRORS[res]);
SomeRandomBloke 0:93acdd9f65f4 61 return -1;
SomeRandomBloke 0:93acdd9f65f4 62 }
SomeRandomBloke 0:93acdd9f65f4 63 return n;
SomeRandomBloke 0:93acdd9f65f4 64 }
SomeRandomBloke 0:93acdd9f65f4 65
SomeRandomBloke 0:93acdd9f65f4 66 int FATFileHandle::isatty() {
SomeRandomBloke 0:93acdd9f65f4 67 return 0;
SomeRandomBloke 0:93acdd9f65f4 68 }
SomeRandomBloke 0:93acdd9f65f4 69
SomeRandomBloke 0:93acdd9f65f4 70 off_t FATFileHandle::lseek(off_t position, int whence) {
SomeRandomBloke 0:93acdd9f65f4 71 FFSDEBUG("lseek(%i,%i)\n",position,whence);
SomeRandomBloke 0:93acdd9f65f4 72 if(whence == SEEK_END) {
SomeRandomBloke 0:93acdd9f65f4 73 position += _fh.fsize;
SomeRandomBloke 0:93acdd9f65f4 74 } else if(whence==SEEK_CUR) {
SomeRandomBloke 0:93acdd9f65f4 75 position += _fh.fptr;
SomeRandomBloke 0:93acdd9f65f4 76 }
SomeRandomBloke 0:93acdd9f65f4 77 FRESULT res = f_lseek(&_fh, position);
SomeRandomBloke 0:93acdd9f65f4 78 if(res) {
SomeRandomBloke 0:93acdd9f65f4 79 FFSDEBUG("lseek failed (%d, %s)\n", res, FR_ERRORS[res]);
SomeRandomBloke 0:93acdd9f65f4 80 return -1;
SomeRandomBloke 0:93acdd9f65f4 81 } else {
SomeRandomBloke 0:93acdd9f65f4 82 FFSDEBUG("lseek OK, returning %i\n", _fh.fptr);
SomeRandomBloke 0:93acdd9f65f4 83 return _fh.fptr;
SomeRandomBloke 0:93acdd9f65f4 84 }
SomeRandomBloke 0:93acdd9f65f4 85 }
SomeRandomBloke 0:93acdd9f65f4 86
SomeRandomBloke 0:93acdd9f65f4 87 int FATFileHandle::fsync() {
SomeRandomBloke 0:93acdd9f65f4 88 FFSDEBUG("fsync()\n");
SomeRandomBloke 0:93acdd9f65f4 89 FRESULT res = f_sync(&_fh);
SomeRandomBloke 0:93acdd9f65f4 90 if (res) {
SomeRandomBloke 0:93acdd9f65f4 91 FFSDEBUG("f_sync() failed (%d, %s)\n", res, FR_ERRORS[res]);
SomeRandomBloke 0:93acdd9f65f4 92 return -1;
SomeRandomBloke 0:93acdd9f65f4 93 }
SomeRandomBloke 0:93acdd9f65f4 94 return 0;
SomeRandomBloke 0:93acdd9f65f4 95 }
SomeRandomBloke 0:93acdd9f65f4 96
SomeRandomBloke 0:93acdd9f65f4 97 off_t FATFileHandle::flen() {
SomeRandomBloke 0:93acdd9f65f4 98 FFSDEBUG("flen\n");
SomeRandomBloke 0:93acdd9f65f4 99 return _fh.fsize;
SomeRandomBloke 0:93acdd9f65f4 100 }
SomeRandomBloke 0:93acdd9f65f4 101
SomeRandomBloke 0:93acdd9f65f4 102 } // namespace mbed