1 /* 2 * Copyright (c) 2006-2021, RT-Thread Development Team 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Change Logs: 7 * Date Author Notes 8 * 2005-02-22 Bernard The first version. 9 */ 10 11 #ifndef __DFS_H__ 12 #define __DFS_H__ 13 14 #include <stdio.h> 15 #include <stdint.h> 16 #include <stdlib.h> 17 #include <string.h> 18 #include <dirent.h> 19 #include <fcntl.h> 20 #include <sys/stat.h> 21 #include <sys/statfs.h> 22 #include <sys/time.h> 23 #include <rtdevice.h> 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 #ifndef DFS_FILESYSTEMS_MAX 30 #define DFS_FILESYSTEMS_MAX 4 31 #endif 32 33 #ifndef DFS_FD_MAX 34 #define DFS_FD_MAX 16 35 #endif 36 37 /* 38 * skip stdin/stdout/stderr normally 39 */ 40 #ifndef DFS_STDIO_OFFSET 41 #define DFS_STDIO_OFFSET 3 42 #endif 43 44 #ifndef DFS_PATH_MAX 45 #define DFS_PATH_MAX DIRENT_NAME_MAX 46 #endif 47 48 #ifndef SECTOR_SIZE 49 #define SECTOR_SIZE 512 50 #endif 51 52 #ifndef DFS_FILESYSTEM_TYPES_MAX 53 #define DFS_FILESYSTEM_TYPES_MAX 2 54 #endif 55 56 #define DFS_FS_FLAG_DEFAULT 0x00 /* default flag */ 57 #define DFS_FS_FLAG_FULLPATH 0x01 /* set full path to underlaying file system */ 58 59 /* File types */ 60 #define FT_REGULAR 0 /* regular file */ 61 #define FT_SOCKET 1 /* socket file */ 62 #define FT_DIRECTORY 2 /* directory */ 63 #define FT_USER 3 /* user defined */ 64 #define FT_DEVICE 4 /* device */ 65 66 /* File flags */ 67 #define DFS_F_OPEN 0x01000000 68 #define DFS_F_DIRECTORY 0x02000000 69 #define DFS_F_EOF 0x04000000 70 #define DFS_F_ERR 0x08000000 71 72 struct dfs_fdtable 73 { 74 uint32_t maxfd; 75 struct dfs_file **fds; 76 }; 77 78 /* Initialization of dfs */ 79 int dfs_init(void); 80 81 char *dfs_normalize_path(const char *directory, const char *filename); 82 const char *dfs_subdir(const char *directory, const char *filename); 83 84 int fd_is_open(const char *pathname); 85 struct dfs_fdtable *dfs_fdtable_get(void); 86 87 void dfs_lock(void); 88 void dfs_unlock(void); 89 90 void dfs_file_lock(void); 91 void dfs_file_unlock(void); 92 93 void dfs_fm_lock(void); 94 void dfs_fm_unlock(void); 95 96 #ifdef DFS_USING_POSIX 97 98 /* FD APIs */ 99 int fdt_fd_new(struct dfs_fdtable *fdt); 100 struct dfs_file *fdt_fd_get(struct dfs_fdtable* fdt, int fd); 101 void fdt_fd_release(struct dfs_fdtable* fdt, int fd); 102 103 int fd_new(void); 104 struct dfs_file *fd_get(int fd); 105 void fd_release(int fd); 106 107 void fd_init(struct dfs_file *fd); 108 int fd_associate(struct dfs_fdtable *fdt, int fd, struct dfs_file *file); 109 int fd_get_fd_index(struct dfs_file *file); 110 111 struct dfs_fdtable *dfs_fdtable_get(void); 112 struct dfs_fdtable *dfs_fdtable_get_global(void); 113 #endif /* DFS_USING_POSIX */ 114 115 #ifdef __cplusplus 116 } 117 #endif 118 119 #endif 120