Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of F12RFileSystem by
F32RFileHandle.cpp
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2016 ARM Limited 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a copy 00005 * of this software and associated documentation files (the "Software"), to deal 00006 * in the Software without restriction, including without limitation the rights 00007 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00008 * copies of the Software, and to permit persons to whom the Software is 00009 * furnished to do so, subject to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included in 00012 * all copies or substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00015 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00016 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00017 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00018 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00019 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 00020 * SOFTWARE. 00021 */ 00022 #include <algorithm> 00023 #include "F32RFileHandle.h" 00024 #include "fsdebug.h" 00025 00026 F32RFileHandle::F32RFileHandle(F32RFileSystem& fs_, uint32_t d):fs(fs_) { 00027 pos = 0; 00028 cluster = fs.storage_peek(d + 20, 2)<<16|fs.storage_peek(d + 26, 2); 00029 file_length = fs.storage_peek(d + 28, 4); 00030 FS_DBG("cluster=%d", cluster); 00031 FS_DBG("file_length=%d", file_length); 00032 } 00033 00034 int F32RFileHandle::close() { 00035 delete this; 00036 return 0; 00037 } 00038 00039 ssize_t F32RFileHandle::write(const void* buffer, size_t length) { 00040 return -1; 00041 } 00042 00043 ssize_t F32RFileHandle::read(void* buffer, size_t length) { 00044 FS_DBG("length=%d", length); 00045 ssize_t n = 0; 00046 while(n < length && pos < file_length) { 00047 uint32_t chunk = std::min((filesize_t)length - n, file_length - pos); 00048 chunk = std::min(chunk, fs.cluster_tail(pos)); 00049 FS_TEST_ASSERT(cluster >= 2 && cluster < 0x0ffffff8); 00050 fs.storage->Read(fs.base_data + (uint64_t)(cluster-2)*fs.cluster_size + fs.cluster_head(pos), (uint8_t*)buffer + n, chunk); 00051 pos += chunk; 00052 if (fs.cluster_head(pos) == 0) { 00053 cluster = fs.fat_read(cluster); 00054 } 00055 n += chunk; 00056 } 00057 return n; 00058 } 00059 00060 int F32RFileHandle::isatty() { 00061 return 0; 00062 } 00063 00064 off_t F32RFileHandle::lseek(off_t position, int whence) { 00065 FS_DBG("position=%d whence=%d", (uint32_t)position, whence); 00066 return -1; 00067 } 00068 00069 int F32RFileHandle::fsync() { 00070 return 0; 00071 } 00072 00073 off_t F32RFileHandle::flen() { 00074 FS_DBG("file_length=%d", file_length); 00075 return file_length; 00076 }
Generated on Tue Jul 12 2022 15:15:05 by
1.7.2
