1 /* 2 * Copyright (c) 2020 Nordic Semiconductor ASA 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef ZEPHYR_INCLUDE_FS_FS_SYS_H_ 8 #define ZEPHYR_INCLUDE_FS_FS_SYS_H_ 9 10 #ifdef __cplusplus 11 extern "C" { 12 #endif 13 14 /** 15 * @ingroup file_system_api 16 * @{ 17 */ 18 19 /** 20 * @brief File System interface structure 21 * 22 * @param open Opens or creates a file, depending on flags given 23 * @param read Reads nbytes number of bytes 24 * @param write Writes nbytes number of bytes 25 * @param lseek Moves the file position to a new location in the file 26 * @param tell Retrieves the current position in the file 27 * @param truncate Truncates/expands the file to the new length 28 * @param sync Flushes the cache of an open file 29 * @param close Flushes the associated stream and closes the file 30 * @param opendir Opens an existing directory specified by the path 31 * @param readdir Reads directory entries of an open directory 32 * @param closedir Closes an open directory 33 * @param mount Mounts a file system 34 * @param unmount Unmounts a file system 35 * @param unlink Deletes the specified file or directory 36 * @param rename Renames a file or directory 37 * @param mkdir Creates a new directory using specified path 38 * @param stat Checks the status of a file or directory specified by the path 39 * @param statvfs Returns the total and available space on the file system 40 * volume 41 */ 42 struct fs_file_system_t { 43 /* File operations */ 44 int (*open)(struct fs_file_t *filp, const char *fs_path, 45 fs_mode_t flags); 46 ssize_t (*read)(struct fs_file_t *filp, void *dest, size_t nbytes); 47 ssize_t (*write)(struct fs_file_t *filp, 48 const void *src, size_t nbytes); 49 int (*lseek)(struct fs_file_t *filp, off_t off, int whence); 50 off_t (*tell)(struct fs_file_t *filp); 51 int (*truncate)(struct fs_file_t *filp, off_t length); 52 int (*sync)(struct fs_file_t *filp); 53 int (*close)(struct fs_file_t *filp); 54 /* Directory operations */ 55 int (*opendir)(struct fs_dir_t *dirp, const char *fs_path); 56 int (*readdir)(struct fs_dir_t *dirp, struct fs_dirent *entry); 57 int (*closedir)(struct fs_dir_t *dirp); 58 /* File system level operations */ 59 int (*mount)(struct fs_mount_t *mountp); 60 int (*unmount)(struct fs_mount_t *mountp); 61 int (*unlink)(struct fs_mount_t *mountp, const char *name); 62 int (*rename)(struct fs_mount_t *mountp, const char *from, 63 const char *to); 64 int (*mkdir)(struct fs_mount_t *mountp, const char *name); 65 int (*stat)(struct fs_mount_t *mountp, const char *path, 66 struct fs_dirent *entry); 67 int (*statvfs)(struct fs_mount_t *mountp, const char *path, 68 struct fs_statvfs *stat); 69 }; 70 71 /** 72 * @} 73 */ 74 75 #ifdef __cplusplus 76 } 77 #endif 78 79 #endif /* ZEPHYR_INCLUDE_FS_FS_SYS_H_ */ 80