This is SDFileSystem which corrected the bug for MiMicSDK.

Dependents:   MbedFileServer_1768MiniDK2 RedWireBridge IssueDebug_gcc MiMicRemoteMCU-for-Mbed ... more

Fork of SDFileSystem by mbed official

Committer:
nyatla
Date:
Tue Nov 12 03:41:14 2013 +0000
Revision:
9:b2ca0e66c1f7
Parent:
8:22ce3449b224
fix warning.;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nyatla 5:2c7b6bd5b079 1 /* mbed Microcontroller Library
nyatla 5:2c7b6bd5b079 2 * Copyright (c) 2006-2012 ARM Limited
nyatla 5:2c7b6bd5b079 3 *
nyatla 5:2c7b6bd5b079 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
nyatla 5:2c7b6bd5b079 5 * of this software and associated documentation files (the "Software"), to deal
nyatla 5:2c7b6bd5b079 6 * in the Software without restriction, including without limitation the rights
nyatla 5:2c7b6bd5b079 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
nyatla 5:2c7b6bd5b079 8 * copies of the Software, and to permit persons to whom the Software is
nyatla 5:2c7b6bd5b079 9 * furnished to do so, subject to the following conditions:
nyatla 5:2c7b6bd5b079 10 *
nyatla 5:2c7b6bd5b079 11 * The above copyright notice and this permission notice shall be included in
nyatla 5:2c7b6bd5b079 12 * all copies or substantial portions of the Software.
nyatla 5:2c7b6bd5b079 13 *
nyatla 5:2c7b6bd5b079 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
nyatla 5:2c7b6bd5b079 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
nyatla 5:2c7b6bd5b079 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
nyatla 5:2c7b6bd5b079 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
nyatla 5:2c7b6bd5b079 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
nyatla 5:2c7b6bd5b079 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
nyatla 5:2c7b6bd5b079 20 * SOFTWARE.
nyatla 5:2c7b6bd5b079 21 */
nyatla 5:2c7b6bd5b079 22 #include "ff.h"
nyatla 5:2c7b6bd5b079 23 #include "ffconf.h"
nyatla 5:2c7b6bd5b079 24
nyatla 5:2c7b6bd5b079 25 #include "FATFileHandle.h"
nyatla 5:2c7b6bd5b079 26
nyatla 8:22ce3449b224 27
nyatla 7:5429e81addde 28
nyatla 5:2c7b6bd5b079 29 FATFileHandle::FATFileHandle(FIL fh) {
nyatla 5:2c7b6bd5b079 30 _fh = fh;
nyatla 5:2c7b6bd5b079 31 }
nyatla 5:2c7b6bd5b079 32
nyatla 5:2c7b6bd5b079 33 int FATFileHandle::close() {
nyatla 5:2c7b6bd5b079 34 int retval = f_close(&_fh);
nyatla 5:2c7b6bd5b079 35 delete this;
nyatla 5:2c7b6bd5b079 36 return retval;
nyatla 5:2c7b6bd5b079 37 }
nyatla 5:2c7b6bd5b079 38
nyatla 5:2c7b6bd5b079 39 ssize_t FATFileHandle::write(const void* buffer, size_t length) {
nyatla 5:2c7b6bd5b079 40 UINT n;
nyatla 5:2c7b6bd5b079 41 FRESULT res = f_write(&_fh, buffer, length, &n);
nyatla 5:2c7b6bd5b079 42 if (res) {
nyatla 5:2c7b6bd5b079 43 return -1;
nyatla 5:2c7b6bd5b079 44 }
nyatla 5:2c7b6bd5b079 45 return n;
nyatla 5:2c7b6bd5b079 46 }
nyatla 5:2c7b6bd5b079 47
nyatla 5:2c7b6bd5b079 48 ssize_t FATFileHandle::read(void* buffer, size_t length) {
nyatla 5:2c7b6bd5b079 49 UINT n;
nyatla 5:2c7b6bd5b079 50 FRESULT res = f_read(&_fh, buffer, length, &n);
nyatla 5:2c7b6bd5b079 51 if (res) {
nyatla 5:2c7b6bd5b079 52 return -1;
nyatla 5:2c7b6bd5b079 53 }
nyatla 5:2c7b6bd5b079 54 return n;
nyatla 5:2c7b6bd5b079 55 }
nyatla 5:2c7b6bd5b079 56
nyatla 5:2c7b6bd5b079 57 int FATFileHandle::isatty() {
nyatla 5:2c7b6bd5b079 58 return 0;
nyatla 5:2c7b6bd5b079 59 }
nyatla 5:2c7b6bd5b079 60
nyatla 5:2c7b6bd5b079 61 off_t FATFileHandle::lseek(off_t position, int whence) {
nyatla 5:2c7b6bd5b079 62 if (whence == SEEK_END) {
nyatla 5:2c7b6bd5b079 63 position += _fh.fsize;
nyatla 5:2c7b6bd5b079 64 } else if(whence==SEEK_CUR) {
nyatla 5:2c7b6bd5b079 65 position += _fh.fptr;
nyatla 5:2c7b6bd5b079 66 }
nyatla 5:2c7b6bd5b079 67 FRESULT res = f_lseek(&_fh, position);
nyatla 5:2c7b6bd5b079 68 if (res) {
nyatla 5:2c7b6bd5b079 69 return -1;
nyatla 5:2c7b6bd5b079 70 } else {
nyatla 5:2c7b6bd5b079 71 return _fh.fptr;
nyatla 5:2c7b6bd5b079 72 }
nyatla 5:2c7b6bd5b079 73 }
nyatla 5:2c7b6bd5b079 74
nyatla 5:2c7b6bd5b079 75 int FATFileHandle::fsync() {
nyatla 5:2c7b6bd5b079 76 FRESULT res = f_sync(&_fh);
nyatla 5:2c7b6bd5b079 77 if (res) {
nyatla 5:2c7b6bd5b079 78 return -1;
nyatla 5:2c7b6bd5b079 79 }
nyatla 5:2c7b6bd5b079 80 return 0;
nyatla 5:2c7b6bd5b079 81 }
nyatla 5:2c7b6bd5b079 82
nyatla 5:2c7b6bd5b079 83 off_t FATFileHandle::flen() {
nyatla 5:2c7b6bd5b079 84 return _fh.fsize;
nyatla 5:2c7b6bd5b079 85 }