mbed-os for GR-LYCHEE

Dependents:   mbed-os-example-blinky-gr-lychee GR-Boads_Camera_sample GR-Boards_Audio_Recoder GR-Boads_Camera_DisplayApp ... more

Committer:
dkato
Date:
Fri Feb 02 05:42:23 2018 +0000
Revision:
0:f782d9c66c49
mbed-os for GR-LYCHEE

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dkato 0:f782d9c66c49 1
dkato 0:f782d9c66c49 2 /* mbed Microcontroller Library
dkato 0:f782d9c66c49 3 * Copyright (c) 2006-2013 ARM Limited
dkato 0:f782d9c66c49 4 *
dkato 0:f782d9c66c49 5 * Licensed under the Apache License, Version 2.0 (the "License");
dkato 0:f782d9c66c49 6 * you may not use this file except in compliance with the License.
dkato 0:f782d9c66c49 7 * You may obtain a copy of the License at
dkato 0:f782d9c66c49 8 *
dkato 0:f782d9c66c49 9 * http://www.apache.org/licenses/LICENSE-2.0
dkato 0:f782d9c66c49 10 *
dkato 0:f782d9c66c49 11 * Unless required by applicable law or agreed to in writing, software
dkato 0:f782d9c66c49 12 * distributed under the License is distributed on an "AS IS" BASIS,
dkato 0:f782d9c66c49 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
dkato 0:f782d9c66c49 14 * See the License for the specific language governing permissions and
dkato 0:f782d9c66c49 15 * limitations under the License.
dkato 0:f782d9c66c49 16 */
dkato 0:f782d9c66c49 17
dkato 0:f782d9c66c49 18 #include "mbed.h"
dkato 0:f782d9c66c49 19 #include "filesystem/FileSystem.h"
dkato 0:f782d9c66c49 20 #include <errno.h>
dkato 0:f782d9c66c49 21
dkato 0:f782d9c66c49 22
dkato 0:f782d9c66c49 23 FileSystem::FileSystem(const char *name)
dkato 0:f782d9c66c49 24 : FileBase(name, FileSystemPathType)
dkato 0:f782d9c66c49 25 {
dkato 0:f782d9c66c49 26 }
dkato 0:f782d9c66c49 27
dkato 0:f782d9c66c49 28 int FileSystem::file_sync(fs_file_t file)
dkato 0:f782d9c66c49 29 {
dkato 0:f782d9c66c49 30 return 0;
dkato 0:f782d9c66c49 31 }
dkato 0:f782d9c66c49 32
dkato 0:f782d9c66c49 33 int FileSystem::file_isatty(fs_file_t file)
dkato 0:f782d9c66c49 34 {
dkato 0:f782d9c66c49 35 return false;
dkato 0:f782d9c66c49 36 }
dkato 0:f782d9c66c49 37
dkato 0:f782d9c66c49 38 off_t FileSystem::file_tell(fs_file_t file)
dkato 0:f782d9c66c49 39 {
dkato 0:f782d9c66c49 40 return file_seek(file, 0, SEEK_CUR);
dkato 0:f782d9c66c49 41 }
dkato 0:f782d9c66c49 42
dkato 0:f782d9c66c49 43 void FileSystem::file_rewind(fs_file_t file)
dkato 0:f782d9c66c49 44 {
dkato 0:f782d9c66c49 45 file_seek(file, 0, SEEK_SET);
dkato 0:f782d9c66c49 46 }
dkato 0:f782d9c66c49 47
dkato 0:f782d9c66c49 48 size_t FileSystem::file_size(fs_file_t file)
dkato 0:f782d9c66c49 49 {
dkato 0:f782d9c66c49 50 off_t off = file_tell(file);
dkato 0:f782d9c66c49 51 size_t size = file_seek(file, 0, SEEK_END);
dkato 0:f782d9c66c49 52 file_seek(file, off, SEEK_SET);
dkato 0:f782d9c66c49 53 return size;
dkato 0:f782d9c66c49 54 }
dkato 0:f782d9c66c49 55
dkato 0:f782d9c66c49 56 int FileSystem::mkdir(const char *path, mode_t mode)
dkato 0:f782d9c66c49 57 {
dkato 0:f782d9c66c49 58 return -ENOSYS;
dkato 0:f782d9c66c49 59 }
dkato 0:f782d9c66c49 60
dkato 0:f782d9c66c49 61 int FileSystem::dir_open(fs_dir_t *dir, const char *path)
dkato 0:f782d9c66c49 62 {
dkato 0:f782d9c66c49 63 return -ENOSYS;
dkato 0:f782d9c66c49 64 }
dkato 0:f782d9c66c49 65
dkato 0:f782d9c66c49 66 int FileSystem::dir_close(fs_dir_t dir)
dkato 0:f782d9c66c49 67 {
dkato 0:f782d9c66c49 68 return -ENOSYS;
dkato 0:f782d9c66c49 69 }
dkato 0:f782d9c66c49 70
dkato 0:f782d9c66c49 71 ssize_t FileSystem::dir_read(fs_dir_t dir, struct dirent *ent)
dkato 0:f782d9c66c49 72 {
dkato 0:f782d9c66c49 73 return -ENOSYS;
dkato 0:f782d9c66c49 74 }
dkato 0:f782d9c66c49 75
dkato 0:f782d9c66c49 76 void FileSystem::dir_seek(fs_dir_t dir, off_t offset)
dkato 0:f782d9c66c49 77 {
dkato 0:f782d9c66c49 78 }
dkato 0:f782d9c66c49 79
dkato 0:f782d9c66c49 80 off_t FileSystem::dir_tell(fs_dir_t dir)
dkato 0:f782d9c66c49 81 {
dkato 0:f782d9c66c49 82 return 0;
dkato 0:f782d9c66c49 83 }
dkato 0:f782d9c66c49 84
dkato 0:f782d9c66c49 85 void FileSystem::dir_rewind(fs_dir_t dir)
dkato 0:f782d9c66c49 86 {
dkato 0:f782d9c66c49 87 // Note, the may not satisfy rewind on all filesystems
dkato 0:f782d9c66c49 88 dir_seek(dir, 0);
dkato 0:f782d9c66c49 89 }
dkato 0:f782d9c66c49 90
dkato 0:f782d9c66c49 91 size_t FileSystem::dir_size(fs_dir_t dir)
dkato 0:f782d9c66c49 92 {
dkato 0:f782d9c66c49 93 off_t off = dir_tell(dir);
dkato 0:f782d9c66c49 94 size_t size = 0;
dkato 0:f782d9c66c49 95 struct dirent *ent = new struct dirent;
dkato 0:f782d9c66c49 96
dkato 0:f782d9c66c49 97 dir_rewind(dir);
dkato 0:f782d9c66c49 98 while (true) {
dkato 0:f782d9c66c49 99 int res = dir_read(dir, ent);
dkato 0:f782d9c66c49 100 if (res <= 0) {
dkato 0:f782d9c66c49 101 break;
dkato 0:f782d9c66c49 102 }
dkato 0:f782d9c66c49 103
dkato 0:f782d9c66c49 104 size += 1;
dkato 0:f782d9c66c49 105 }
dkato 0:f782d9c66c49 106 dir_seek(dir, off);
dkato 0:f782d9c66c49 107
dkato 0:f782d9c66c49 108 delete ent;
dkato 0:f782d9c66c49 109 return size;
dkato 0:f782d9c66c49 110 }
dkato 0:f782d9c66c49 111