📄 fs.h
字号:
/** * @note Mandatory, may block. Appropriate locking MUST be implemented * @note Please call sos_fs_mark_dirty() if disk contents is changed */ sos_ret_t (*read)(struct sos_fs_opened_file *this, sos_uaddr_t dest_buf, sos_size_t * /* in/out */len); /** * @note Optional (might be NULL), may block. Appropriate locking * MUST be implemented * @note Please call sos_fs_mark_dirty() if disk contents is changed */ sos_ret_t (*write)(struct sos_fs_opened_file *this, sos_uaddr_t src_buf, sos_size_t * /* in/out */len); /** * @note Optional (might be NULL), may block. Appropriate locking * MUST be implemented * @note Please call sos_fs_mark_dirty() if disk contents is changed */ sos_ret_t (*mmap)(struct sos_fs_opened_file *this, sos_uaddr_t *uaddr, sos_size_t size, sos_ui32_t access_rights, sos_ui32_t flags, sos_luoffset_t offset); /** * @note Optional (might be NULL), may block. Appropriate locking * MUST be implemented * @note Please call sos_fs_mark_dirty() if disk contents is changed */ sos_ret_t (*fcntl)(struct sos_fs_opened_file *this, int req_id, sos_ui32_t req_arg /* Usually: sos_uaddr_t */);};/** Data structure that is to be filled by readdir */struct sos_fs_dirent{ sos_ui64_t storage_location; sos_si64_t offset_in_dirfile; sos_ui32_t type; sos_ui16_t namelen;#define SOS_FS_DIRENT_NAME_MAXLEN 128 char name[SOS_FS_DIRENT_NAME_MAXLEN];};/** * The list of methods implementing the basic VFS opened directory * operations * * @see sos_fs_opened_file::ops_file */struct sos_fs_ops_opened_dir{ /** * Each time it is called, responsible for filling the sos_fs_dirent * structure, return -SOS_ENOENT when done. * * @note Mandatory, may block. Appropriate locking MUST be implemented * @note Please call sos_fs_mark_dirty() if disk contents is changed */ sos_ret_t (*readdir)(struct sos_fs_opened_file *this, struct sos_fs_dirent * result);};/** * Used by the stat calls * * @see sos_fs_node_ops_file::stat */struct sos_fs_stat{ sos_fs_node_type_t st_type; sos_ui64_t st_storage_location; sos_ui32_t st_access_rights; sos_count_t st_nlink; sos_si64_t st_size;};/** * Used by the statvfs calls * * @see sos_fs_manager_instance::statfs */struct sos_fs_statfs{ sos_size_t f_sz_total; /**< Total size */ sos_size_t f_sz_free; /**< Size left on device */ sos_count_t f_node_total;/**< Total allocatable FS nodes */ sos_count_t f_node_avail;/**< Number of available free FS nodes */ sos_ui32_t f_flags;};/** * Must be called AFTER the FS manager types needed to mount the root * filesystem have been registered */sos_ret_t sos_fs_subsystem_setup(const char * root_device, const char * fs_type, const char * mount_args, struct sos_fs_manager_instance ** result_rootfs);/* *************************************************************** * The Following functions are relatively standard * * @see Unix manual pages for details *//** * mount a file system * * @param actor process calling mount * @param _src_path(len) may be NULL (as for virtfs or /proc) * @fsname the name of the filesystem type to mount * @args any args passed to the sos_fs_manager_type::mount method * @result_fs the resulting filesystem instance */sos_ret_t sos_fs_mount(struct sos_process * actor, const char * _src_path, sos_size_t _src_pathlen, const char * _dst_path, sos_size_t _dst_pathlen, const char * fsname, sos_ui32_t mountflags, const char * args, struct sos_fs_manager_instance ** /*out*/result_fs);/** * unmount the filesystem at the given location */sos_ret_t sos_fs_umount(struct sos_process * actor, const char * _mountpoint_path, sos_size_t _mountpoint_pathlen);/** * Flush all the dirty nodes of all the FS to disk */sos_ret_t sos_fs_sync_all_fs();/** * Retrieve filesystem status, or return -SOS_ENOSUP if filesystem * cannot report this */sos_ret_t sos_fs_vfstat(const struct sos_process * actor, const char * _path, sos_size_t _pathlen, struct sos_fs_statfs * result);/** * Open flags */#define SOS_FS_OPEN_EXCL (1 << 0)#define SOS_FS_OPEN_CREAT (1 << 1)#define SOS_FS_OPEN_NOFOLLOW (1 << 2)#define SOS_FS_OPEN_DIRECTORY (1 << 3) /* Incompatible with CREAT */#define SOS_FS_OPEN_SYNC (1 << 4)#define SOS_FS_OPEN_KEEPONEXEC (1 << 5) /* By default, files are closed upon an exec() */#define SOS_FS_OPEN_READ (1 << 16)#define SOS_FS_OPEN_WRITE (1 << 17)/** * FS access rights */#define SOS_FS_S_IRUSR 00400#define SOS_FS_S_IWUSR 00200#define SOS_FS_S_IXUSR 00100#define SOS_FS_S_IRWXALL 07777 /* For symlinks */sos_ret_t sos_fs_open(const struct sos_process *owner, const char *_path, sos_size_t _pathlen, sos_ui32_t open_flags, sos_ui32_t creat_access_rights, struct sos_fs_opened_file ** of);sos_ret_t sos_fs_close(struct sos_fs_opened_file * of);sos_ret_t sos_fs_read(struct sos_fs_opened_file * of, sos_uaddr_t dest_buf, sos_size_t * /* in/ou */len);sos_ret_t sos_fs_readdir(struct sos_fs_opened_file * of, struct sos_fs_dirent * result);sos_ret_t sos_fs_write(struct sos_fs_opened_file * of, sos_uaddr_t src_buf, sos_size_t * /* in/out */len);sos_ret_t sos_fs_seek(struct sos_fs_opened_file *of, sos_lsoffset_t offset, sos_seek_whence_t whence, sos_lsoffset_t * result_position);sos_ret_t sos_fs_ftruncate(struct sos_fs_opened_file *of, sos_lsoffset_t length);sos_ret_t sos_fs_mmap(struct sos_fs_opened_file *of, sos_uaddr_t *uaddr, sos_size_t size, sos_ui32_t access_rights, sos_ui32_t flags, sos_luoffset_t offset);sos_ret_t sos_fs_fsync(struct sos_fs_opened_file * of);sos_ret_t sos_fs_fcntl(struct sos_fs_opened_file *of, int req_id, sos_ui32_t req_arg /* Usually: sos_uaddr_t */);sos_ret_t sos_fs_creat(const struct sos_process * creator, const char * _path, sos_size_t _pathlen, sos_ui32_t access_rights);sos_ret_t sos_fs_link(const struct sos_process * creator, const char * _old_path, sos_size_t _old_pathlen, const char * _dest_path, sos_size_t _dest_pathlen);sos_ret_t sos_fs_rename(const struct sos_process * creator, const char * _old_path, sos_size_t _old_pathlen, const char * _dest_path, sos_size_t _dest_pathlen);sos_ret_t sos_fs_unlink(const struct sos_process * actor, const char * _path, sos_size_t _pathlen);sos_ret_t sos_fs_symlink(const struct sos_process * creator, const char * _path, sos_size_t _pathlen, sos_uaddr_t symlink_target, sos_size_t symlink_target_len);sos_ret_t sos_fs_mkdir(const struct sos_process * creator, const char * _path, sos_size_t _pathlen, sos_ui32_t access_rights);sos_ret_t sos_fs_rmdir(const struct sos_process * actor, const char * _path, sos_size_t _pathlen);sos_ret_t sos_fs_chmod(const struct sos_process * actor, const char * _path, sos_size_t _pathlen, sos_ui32_t access_rights);sos_ret_t sos_fs_stat(const struct sos_process * actor, const char * _path, sos_size_t _pathlen, int nofollow, struct sos_fs_stat * result);/* *************************************************************** * Restricted functions reserved to FS code and block/char devices *//** * Function to be called when proposing a new File system type */sos_ret_t sos_fs_register_fs_type(struct sos_fs_manager_type * fstype);sos_ret_t sos_fs_unregister_fs_type(struct sos_fs_manager_type * fstype);/** * Marthe given file as dirty, for FS supporting deferred write access * mode */sos_ret_t sos_fs_mark_dirty(struct sos_fs_opened_file * of);/** * Helper function to be called from the mount() method of the FS * instance code. Responsible for creating and updating the "root" * field of the FS instance structure and for connecting this FS in * the nscache * @param root_fsnode The root of the FS being mounted */sos_ret_t sos_fs_register_fs_instance(struct sos_fs_manager_instance * fs, struct sos_fs_node * root_fsnode);/** * Helper function to be called from the umount() method of the FS * instance code. Responsible for unregistering the instance from the * FS type's instances list and for disconnecting this mountpoint in * the nscache. */sos_ret_t sos_fs_unregister_fs_instance(struct sos_fs_manager_instance * fs);/* *************************************************************** * Restricted functions reserved to syscall.c */sos_ret_t sos_fs_ref_opened_file(struct sos_fs_opened_file * of);sos_ret_t _sos_fs_unref_opened_file(struct sos_fs_opened_file ** of);#define sos_fs_unref_opened_file(f) _sos_fs_unref_opened_file(&(f))/* *************************************************************** * Restricted functions to be used only by fs_nscache.c */sos_ret_t sos_fs_ref_fsnode(struct sos_fs_node * fsnode);sos_ret_t _sos_fs_unref_fsnode(struct sos_fs_node * fsnode);#define sos_fs_unref_fsnode(n) \ ({ sos_ret_t __retval = _sos_fs_unref_fsnode(n); (n)=NULL; __retval; })/* *************************************************************** * Restricted functions reserved to process.c and main.c:start_init() */sos_ret_t sos_fs_new_opened_file(const struct sos_process * proc, struct sos_fs_nscache_node * nsnode, sos_ui32_t open_flags, struct sos_fs_opened_file ** result_of);sos_ret_t sos_fs_duplicate_opened_file(struct sos_fs_opened_file * src_of, const struct sos_process * dst_proc, struct sos_fs_opened_file ** result_of);#endif /* _SOS_FS_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -