1 /* 2 * Copyright (c) 2006-2018, 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 19 #include <time.h> 20 #include <rtthread.h> 21 #include <rtdevice.h> 22 23 #ifndef DFS_FILESYSTEMS_MAX 24 #define DFS_FILESYSTEMS_MAX 2 25 #endif 26 27 #ifndef DFS_FD_MAX 28 #define DFS_FD_MAX 4 29 #endif 30 31 /* 32 * skip stdin/stdout/stderr normally 33 */ 34 #ifndef DFS_FD_OFFSET 35 #define DFS_FD_OFFSET 3 36 #endif 37 38 #ifndef DFS_PATH_MAX 39 #define DFS_PATH_MAX 256 40 #endif 41 42 #ifndef SECTOR_SIZE 43 #define SECTOR_SIZE 512 44 #endif 45 46 #ifndef DFS_FILESYSTEM_TYPES_MAX 47 #define DFS_FILESYSTEM_TYPES_MAX 2 48 #endif 49 50 #define DFS_FS_FLAG_DEFAULT 0x00 /* default flag */ 51 #define DFS_FS_FLAG_FULLPATH 0x01 /* set full path to underlaying file system */ 52 53 /* File types */ 54 #define FT_REGULAR 0 /* regular file */ 55 #define FT_SOCKET 1 /* socket file */ 56 #define FT_DIRECTORY 2 /* directory */ 57 #define FT_USER 3 /* user defined */ 58 59 /* File flags */ 60 #define DFS_F_OPEN 0x01000000 61 #define DFS_F_DIRECTORY 0x02000000 62 #define DFS_F_EOF 0x04000000 63 #define DFS_F_ERR 0x08000000 64 65 #ifdef __cplusplus 66 extern "C" { 67 #endif 68 69 struct statfs 70 { 71 size_t f_bsize; /* block size */ 72 size_t f_blocks; /* total data blocks in file system */ 73 size_t f_bfree; /* free blocks in file system */ 74 }; 75 76 struct dirent 77 { 78 uint8_t d_type; /* The type of the file */ 79 uint8_t d_namlen; /* The length of the not including the terminating null file name */ 80 uint16_t d_reclen; /* length of this record */ 81 char d_name[DFS_PATH_MAX]; /* The null-terminated file name */ 82 }; 83 84 struct dfs_fdtable 85 { 86 uint32_t maxfd; 87 struct dfs_fd **fds; 88 }; 89 90 /* Initialization of dfs */ 91 int dfs_init(void); 92 93 char *dfs_normalize_path(const char *directory, const char *filename); 94 const char *dfs_subdir(const char *directory, const char *filename); 95 96 void dfs_lock(void); 97 void dfs_unlock(void); 98 99 /* FD APIs */ 100 int fd_new(void); 101 struct dfs_fd *fd_get(int fd); 102 void fd_put(struct dfs_fd *fd); 103 int fd_is_open(const char *pathname); 104 105 struct dfs_fdtable* dfs_fdtable_get(void); 106 107 #ifdef __cplusplus 108 } 109 #endif 110 111 #endif 112