/***************************************************************************** * Copyright (c) 2019, Nations Technologies Inc. * * All rights reserved. * **************************************************************************** * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistributions of source code must retain the above copyright notice, * this list of conditions and the disclaimer below. * * Nations' name may not be used to endorse or promote products derived from * this software without specific prior written permission. * * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE * DISCLAIMED. IN NO EVENT SHALL NATIONS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************/ /** * @file dfs_file.h * @author Nations * @version v1.0.0 * * @copyright Copyright (c) 2019, Nations Technologies Inc. All rights reserved. */ #ifndef __DFS_FILE_H__ #define __DFS_FILE_H__ #include #include #ifdef __cplusplus extern "C" { #endif struct rt_pollreq; struct dfs_file_ops { int (*open) (struct dfs_fd *fd); int (*close) (struct dfs_fd *fd); int (*ioctl) (struct dfs_fd *fd, int cmd, void *args); int (*read) (struct dfs_fd *fd, void *buf, size_t count); int (*write) (struct dfs_fd *fd, const void *buf, size_t count); int (*flush) (struct dfs_fd *fd); int (*lseek) (struct dfs_fd *fd, off_t offset); int (*getdents) (struct dfs_fd *fd, struct dirent *dirp, uint32_t count); int (*poll) (struct dfs_fd *fd, struct rt_pollreq *req); }; /* file descriptor */ #define DFS_FD_MAGIC 0xfdfd struct dfs_fd { uint16_t magic; /* file descriptor magic number */ uint16_t type; /* Type (regular or socket) */ char *path; /* Name (below mount point) */ int ref_count; /* Descriptor reference count */ struct dfs_filesystem *fs; const struct dfs_file_ops *fops; uint32_t flags; /* Descriptor flags */ size_t size; /* Size in bytes */ off_t pos; /* Current file position */ void *data; /* Specific file system data */ }; int dfs_file_open(struct dfs_fd *fd, const char *path, int flags); int dfs_file_close(struct dfs_fd *fd); int dfs_file_ioctl(struct dfs_fd *fd, int cmd, void *args); int dfs_file_read(struct dfs_fd *fd, void *buf, size_t len); int dfs_file_getdents(struct dfs_fd *fd, struct dirent *dirp, size_t nbytes); int dfs_file_unlink(const char *path); int dfs_file_write(struct dfs_fd *fd, const void *buf, size_t len); int dfs_file_flush(struct dfs_fd *fd); int dfs_file_lseek(struct dfs_fd *fd, off_t offset); int dfs_file_stat(const char *path, struct stat *buf); int dfs_file_rename(const char *oldpath, const char *newpath); int dfs_file_ftruncate(struct dfs_fd *fd, off_t length); /* 0x5254 is just a magic number to make these relatively unique ("RT") */ #define RT_FIOFTRUNCATE 0x52540000U #ifdef __cplusplus } #endif #endif