2011-10-08 22:50:08 +08:00
|
|
|
/*
|
2021-03-08 18:19:04 +08:00
|
|
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
2011-12-23 10:11:55 +08:00
|
|
|
*
|
2018-10-29 11:06:58 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2011-12-23 10:11:55 +08:00
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2005-01-26 Bernard The first version.
|
|
|
|
*/
|
2011-10-08 22:50:08 +08:00
|
|
|
|
2012-12-26 09:12:13 +08:00
|
|
|
#ifndef __DFS_FILE_H__
|
|
|
|
#define __DFS_FILE_H__
|
2011-10-08 22:50:08 +08:00
|
|
|
|
|
|
|
#include <dfs.h>
|
|
|
|
#include <dfs_fs.h>
|
|
|
|
|
2017-10-15 22:44:53 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct rt_pollreq;
|
|
|
|
|
|
|
|
struct dfs_file_ops
|
|
|
|
{
|
2023-04-08 22:25:51 +08:00
|
|
|
int (*open) (struct dfs_file *fd);
|
|
|
|
int (*close) (struct dfs_file *fd);
|
|
|
|
int (*ioctl) (struct dfs_file *fd, int cmd, void *args);
|
|
|
|
int (*read) (struct dfs_file *fd, void *buf, size_t count);
|
|
|
|
int (*write) (struct dfs_file *fd, const void *buf, size_t count);
|
|
|
|
int (*flush) (struct dfs_file *fd);
|
|
|
|
int (*lseek) (struct dfs_file *fd, off_t offset);
|
|
|
|
int (*getdents) (struct dfs_file *fd, struct dirent *dirp, uint32_t count);
|
|
|
|
|
|
|
|
int (*poll) (struct dfs_file *fd, struct rt_pollreq *req);
|
2017-10-15 22:44:53 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* file descriptor */
|
|
|
|
#define DFS_FD_MAGIC 0xfdfd
|
2022-12-03 12:07:44 +08:00
|
|
|
|
2023-04-08 22:25:51 +08:00
|
|
|
struct dfs_vnode
|
2017-10-15 22:44:53 +08:00
|
|
|
{
|
|
|
|
uint16_t type; /* Type (regular or socket) */
|
|
|
|
|
|
|
|
char *path; /* Name (below mount point) */
|
2022-12-03 12:07:44 +08:00
|
|
|
char *fullpath; /* Full path is hash key */
|
2017-10-15 22:44:53 +08:00
|
|
|
int ref_count; /* Descriptor reference count */
|
2022-12-03 12:07:44 +08:00
|
|
|
rt_list_t list; /* The node of vnode hash table */
|
2017-10-15 22:44:53 +08:00
|
|
|
|
2019-01-09 17:40:32 +08:00
|
|
|
struct dfs_filesystem *fs;
|
2017-10-15 22:44:53 +08:00
|
|
|
const struct dfs_file_ops *fops;
|
2022-12-03 12:07:44 +08:00
|
|
|
uint32_t flags; /* self flags, is dir etc.. */
|
2017-10-15 22:44:53 +08:00
|
|
|
|
|
|
|
size_t size; /* Size in bytes */
|
2022-12-03 12:07:44 +08:00
|
|
|
void *data; /* Specific file system data */
|
|
|
|
};
|
|
|
|
|
2023-04-08 22:25:51 +08:00
|
|
|
struct dfs_file
|
2022-12-03 12:07:44 +08:00
|
|
|
{
|
|
|
|
uint16_t magic; /* file descriptor magic number */
|
|
|
|
uint32_t flags; /* Descriptor flags */
|
|
|
|
int ref_count; /* Descriptor reference count */
|
2017-10-15 22:44:53 +08:00
|
|
|
off_t pos; /* Current file position */
|
2023-04-08 22:25:51 +08:00
|
|
|
struct dfs_vnode *vnode; /* file node struct */
|
2022-12-03 12:07:44 +08:00
|
|
|
void *data; /* Specific fd data */
|
|
|
|
};
|
2017-10-15 22:44:53 +08:00
|
|
|
|
2022-12-03 12:07:44 +08:00
|
|
|
struct dfs_mmap2_args
|
|
|
|
{
|
|
|
|
void *addr;
|
|
|
|
size_t length;
|
|
|
|
int prot;
|
|
|
|
int flags;
|
|
|
|
off_t pgoffset;
|
|
|
|
|
|
|
|
void *ret;
|
2017-10-15 22:44:53 +08:00
|
|
|
};
|
|
|
|
|
2023-04-08 22:25:51 +08:00
|
|
|
void dfs_vnode_mgr_init(void);
|
2022-12-03 12:07:44 +08:00
|
|
|
int dfs_file_is_open(const char *pathname);
|
2023-04-08 22:25:51 +08:00
|
|
|
int dfs_file_open(struct dfs_file *fd, const char *path, int flags);
|
|
|
|
int dfs_file_close(struct dfs_file *fd);
|
|
|
|
int dfs_file_ioctl(struct dfs_file *fd, int cmd, void *args);
|
|
|
|
int dfs_file_read(struct dfs_file *fd, void *buf, size_t len);
|
|
|
|
int dfs_file_getdents(struct dfs_file *fd, struct dirent *dirp, size_t nbytes);
|
2011-10-08 22:50:08 +08:00
|
|
|
int dfs_file_unlink(const char *path);
|
2023-04-08 22:25:51 +08:00
|
|
|
int dfs_file_write(struct dfs_file *fd, const void *buf, size_t len);
|
|
|
|
int dfs_file_flush(struct dfs_file *fd);
|
|
|
|
int dfs_file_lseek(struct dfs_file *fd, off_t offset);
|
2017-10-15 22:44:53 +08:00
|
|
|
|
2011-10-08 22:50:08 +08:00
|
|
|
int dfs_file_stat(const char *path, struct stat *buf);
|
2011-12-23 10:11:55 +08:00
|
|
|
int dfs_file_rename(const char *oldpath, const char *newpath);
|
2023-04-08 22:25:51 +08:00
|
|
|
int dfs_file_ftruncate(struct dfs_file *fd, off_t length);
|
|
|
|
int dfs_file_mmap2(struct dfs_file *fd, struct dfs_mmap2_args *mmap2);
|
2019-09-26 10:22:33 +08:00
|
|
|
|
|
|
|
/* 0x5254 is just a magic number to make these relatively unique ("RT") */
|
2022-12-03 12:07:44 +08:00
|
|
|
#define RT_FIOFTRUNCATE 0x52540000U
|
|
|
|
#define RT_FIOGETADDR 0x52540001U
|
|
|
|
#define RT_FIOMMAP2 0x52540002U
|
2011-10-08 22:50:08 +08:00
|
|
|
|
2017-10-15 22:44:53 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
2011-10-08 22:50:08 +08:00
|
|
|
#endif
|
|
|
|
|
2017-10-15 22:44:53 +08:00
|
|
|
#endif
|