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.
virtual_fs.h
00001 /** 00002 * @file virtual_fs.h 00003 * @brief FAT 12/16 filesystem handling 00004 * 00005 * DAPLink Interface Firmware 00006 * Copyright (c) 2009-2016, ARM Limited, All Rights Reserved 00007 * SPDX-License-Identifier: Apache-2.0 00008 * 00009 * Licensed under the Apache License, Version 2.0 (the "License"); you may 00010 * not use this file except in compliance with the License. 00011 * You may obtain a copy of the License at 00012 * 00013 * http://www.apache.org/licenses/LICENSE-2.0 00014 * 00015 * Unless required by applicable law or agreed to in writing, software 00016 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 00017 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00018 * See the License for the specific language governing permissions and 00019 * limitations under the License. 00020 */ 00021 00022 #ifndef VIRTUAL_FS_H 00023 #define VIRTUAL_FS_H 00024 00025 #include <stdint.h> 00026 00027 #ifdef __cplusplus 00028 extern "C" { 00029 #endif 00030 00031 #define VFS_CLUSTER_SIZE 0x1000 00032 #define VFS_SECTOR_SIZE 512 00033 #define VFS_INVALID_SECTOR 0xFFFFFFFF 00034 #define VFS_FILE_INVALID 0 00035 #define VFS_MAX_FILES 16 00036 00037 typedef char vfs_filename_t[11]; 00038 00039 typedef enum { 00040 VFS_FILE_ATTR_READ_ONLY = (1 << 0), 00041 VFS_FILE_ATTR_HIDDEN = (1 << 1), 00042 VFS_FILE_ATTR_SYSTEM = (1 << 2), 00043 VFS_FILE_ATTR_VOLUME_LABEL = (1 << 3), 00044 VFS_FILE_ATTR_SUB_DIR = (1 << 4), 00045 VFS_FILE_ATTR_ARCHIVE = (1 << 5), 00046 } vfs_file_attr_bit_t; 00047 00048 typedef enum { 00049 VFS_FILE_CREATED = 0, /*!< A new file was created */ 00050 VFS_FILE_DELETED , /*!< An existing file was deleted */ 00051 VFS_FILE_CHANGED , /*!< Some attribute of the file changed. 00052 Note: when a file is deleted or 00053 created a file changed 00054 notification will also occur*/ 00055 } vfs_file_change_t ; 00056 00057 typedef void *vfs_file_t; 00058 typedef uint32_t vfs_sector_t; 00059 00060 // Callback for when data is written to a file on the virtual filesystem 00061 typedef void (*vfs_write_cb_t)(uint32_t sector_offset, const uint8_t *data, uint32_t num_sectors); 00062 // Callback for when data is ready from the virtual filesystem 00063 typedef uint32_t (*vfs_read_cb_t)(uint32_t sector_offset, uint8_t *data, uint32_t num_sectors); 00064 // Callback for when a file's attributes are changed on the virtual filesystem. Note that the 'file' parameter 00065 // can be saved and compared to other files to see if they are referencing the same object. The 00066 // same cannot be done with new_file_data since it points to a temporary buffer. 00067 typedef void (*vfs_file_change_cb_t)(const vfs_filename_t filename, vfs_file_change_t change, 00068 vfs_file_t file, vfs_file_t new_file_data); 00069 00070 // Initialize the filesystem with the given size and name 00071 void vfs_init(const vfs_filename_t drive_name, uint32_t disk_size); 00072 00073 // Get the total size of the virtual filesystem 00074 uint32_t vfs_get_total_size(void); 00075 00076 // Add a file to the virtual FS and return a handle to this file. 00077 // This must be called before vfs_read or vfs_write are called. 00078 // Adding a new file after vfs_read or vfs_write have been called results in undefined behavior. 00079 vfs_file_t vfs_create_file(const vfs_filename_t filename, vfs_read_cb_t read_cb, vfs_write_cb_t write_cb, uint32_t len); 00080 00081 // Set the attributes of a file 00082 void vfs_file_set_attr(vfs_file_t file, vfs_file_attr_bit_t attr); 00083 00084 // Get the starting sector of this file. 00085 // NOTE - If the file size is 0 there is no starting 00086 // sector so VFS_INVALID_SECTOR will be returned. 00087 vfs_sector_t vfs_file_get_start_sector(vfs_file_t file); 00088 00089 // Get the size of the file. 00090 uint32_t vfs_file_get_size(vfs_file_t file); 00091 00092 // Get the attributes of a file 00093 vfs_file_attr_bit_t vfs_file_get_attr(vfs_file_t file); 00094 00095 // Set the callback when a file is created, deleted or has atributes changed. 00096 void vfs_set_file_change_callback(vfs_file_change_cb_t cb); 00097 00098 // Read one or more sectors from the virtual filesystem 00099 void vfs_read(uint32_t sector, uint8_t *buf, uint32_t num_of_sectors); 00100 00101 // Write one or more sectors to the virtual filesystem 00102 void vfs_write(uint32_t sector, const uint8_t *buf, uint32_t num_of_sectors); 00103 00104 #ifdef __cplusplus 00105 } 00106 #endif 00107 00108 #endif
Generated on Tue Jul 12 2022 15:37:28 by
1.7.2