1 /* 2 * Copyright (C) 2015-2017 Alibaba Group Holding Limited 3 */ 4 5 #ifndef VFS_TYPES_H 6 #define VFS_TYPES_H 7 8 #include <stdint.h> 9 #include <time.h> 10 11 typedef struct { 12 time_t actime; /* time of last access */ 13 time_t modtime; /* time of last modification */ 14 } vfs_utimbuf_t; 15 16 typedef struct { 17 uint16_t st_mode; /* mode of file */ 18 uint32_t st_size; /* bytes of file */ 19 time_t st_actime; /* time of last access */ 20 time_t st_modtime; /* time of last modification */ 21 } vfs_stat_t; 22 23 typedef struct { 24 int32_t d_ino; /* file number */ 25 uint8_t d_type; /* type of file */ 26 char d_name[]; /* file name */ 27 } vfs_dirent_t; 28 29 typedef struct { 30 int32_t dd_vfs_fd; 31 int32_t dd_rsv; 32 } vfs_dir_t; 33 34 typedef struct { 35 int32_t f_type; /* fs type */ 36 int32_t f_bsize; /* optimized transport block size */ 37 int32_t f_blocks; /* total blocks */ 38 int32_t f_bfree; /* available blocks */ 39 int32_t f_bavail; /* number of blocks that non-super users can acquire */ 40 int32_t f_files; /* total number of file nodes */ 41 int32_t f_ffree; /* available file nodes */ 42 int32_t f_fsid; /* fs id */ 43 int32_t f_namelen; /* max file name length */ 44 } vfs_statfs_t; 45 46 typedef void (*vfs_poll_notify_t)(void *fds, void *arg); 47 48 typedef struct vfs_file_ops vfs_file_ops_t; 49 typedef struct vfs_filesystem_ops vfs_filesystem_ops_t; 50 51 union vfs_inode_ops_t { 52 const vfs_file_ops_t *i_ops; 53 const vfs_filesystem_ops_t *i_fops; 54 }; 55 56 typedef enum { 57 VFS_INODE_VALID, /* node is available*/ 58 VFS_INODE_INVALID, /* Node is ready to be deleted, unavailable*/ 59 VFS_INODE_DETACHED, /* Node is ready to be deleted, and Wait for the operation to complete */ 60 VFS_INODE_MAX 61 } vfs_inode_status_t; 62 63 typedef struct { 64 union vfs_inode_ops_t ops; /* inode operations */ 65 66 void *i_arg; /* per inode private data */ 67 char *i_name; /* name of inode */ 68 int32_t i_flags; /* flags for inode */ 69 uint8_t type; /* type for inode */ 70 uint8_t refs; /* refs for inode */ 71 void *lock; /* lock for inode operations */ 72 vfs_inode_status_t status; /* valid or invalid status for this inode */ 73 } vfs_inode_t; 74 75 typedef struct { 76 vfs_inode_t *node; /* node for file or device */ 77 void *f_arg; /* arguments for file or device */ 78 uint32_t offset; /* offset of the file */ 79 #ifdef CONFIG_VFS_LSOPEN 80 char filename[VFS_CONFIG_PATH_MAX]; 81 #endif 82 int32_t redirect_fd; /* the target FD that it's redirected to, optionally used. */ 83 } vfs_file_t; 84 85 typedef enum { 86 VFS_LIST_TYPE_FS, 87 VFS_LIST_TYPE_DEVICE 88 } vfs_list_type_t; 89 90 struct vfs_file_ops { 91 int32_t (*open) (vfs_inode_t *node, vfs_file_t *fp); 92 int32_t (*close) (vfs_file_t *fp); 93 int32_t (*read) (vfs_file_t *fp, void *buf, uint32_t nbytes); 94 int32_t (*write) (vfs_file_t *fp, const void *buf, uint32_t nbytes); 95 int32_t (*ioctl) (vfs_file_t *fp, int32_t cmd, uint32_t arg); 96 int32_t (*poll) (vfs_file_t *fp, int32_t flag, vfs_poll_notify_t notify, void *fds, void *arg); 97 uint32_t (*lseek) (vfs_file_t *fp, int64_t off, int32_t whence); 98 #ifdef AOS_PROCESS_SUPPORT 99 void* (*mmap)(vfs_file_t *fp, void *addr, size_t length, int prot, int flags, 100 int fd, off_t offset); 101 #endif 102 103 }; 104 105 struct vfs_filesystem_ops { 106 int32_t (*open) (vfs_file_t *fp, const char *path, int32_t flags); 107 int32_t (*close) (vfs_file_t *fp); 108 int32_t (*read) (vfs_file_t *fp, char *buf, uint32_t len); 109 int32_t (*write) (vfs_file_t *fp, const char *buf, uint32_t len); 110 uint32_t (*lseek) (vfs_file_t *fp, int64_t off, int32_t whence); 111 int32_t (*sync) (vfs_file_t *fp); 112 int32_t (*stat) (vfs_file_t *fp, const char *path, vfs_stat_t *st); 113 int32_t (*fstat) (vfs_file_t *fp, vfs_stat_t *st); 114 int32_t (*link) (vfs_file_t *fp, const char *path1, const char *path2); 115 int32_t (*unlink) (vfs_file_t *fp, const char *path); 116 int32_t (*remove) (vfs_file_t *fp, const char *path); 117 int32_t (*rename) (vfs_file_t *fp, const char *oldpath, const char *newpath); 118 vfs_dir_t *(*opendir) (vfs_file_t *fp, const char *path); 119 vfs_dirent_t *(*readdir) (vfs_file_t *fp, vfs_dir_t *dir); 120 int32_t (*closedir) (vfs_file_t *fp, vfs_dir_t *dir); 121 int32_t (*mkdir) (vfs_file_t *fp, const char *path); 122 int32_t (*rmdir) (vfs_file_t *fp, const char *path); 123 void (*rewinddir) (vfs_file_t *fp, vfs_dir_t *dir); 124 int32_t (*telldir) (vfs_file_t *fp, vfs_dir_t *dir); 125 void (*seekdir) (vfs_file_t *fp, vfs_dir_t *dir, int32_t loc); 126 int32_t (*ioctl) (vfs_file_t *fp, int32_t cmd, uint32_t arg); 127 int32_t (*statfs) (vfs_file_t *fp, const char *path, vfs_statfs_t *suf); 128 int32_t (*access) (vfs_file_t *fp, const char *path, int32_t amode); 129 int32_t (*pathconf) (vfs_file_t *fp, const char *path, int name); 130 int32_t (*fpathconf) (vfs_file_t *fp, int name); 131 int32_t (*utime) (vfs_file_t *fp, const char *path, const vfs_utimbuf_t *times); 132 }; 133 134 #if VFS_CONFIG_DEBUG > 0 135 #define VFS_ERROR printf 136 #else 137 #define VFS_ERROR(x, ...) do { } while (0) 138 #endif 139 140 #endif /* VFS_TYPES_H */ 141 142