RT-Thread RTOS 1.2.0
An open source embedded real-time operating system
载入中...
搜索中...
未找到
dfs_file.h
浏览该文件的文档.
1/*
2 * Copyright (c) 2006-2023, RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 * 2005-01-26 Bernard The first version.
9 * 2023-05-05 Bernard Change to dfs v2.0
10 */
11
12#ifndef __DFS_FILE_H__
13#define __DFS_FILE_H__
14
15#include <dfs.h>
16#include <dfs_fs.h>
17
18#ifdef __cplusplus
19extern "C"
20{
21#endif
22
23#define STDIN_FILENO 0 /* standard input file descriptor */
24#define STDOUT_FILENO 1 /* standard output file descriptor */
25#define STDERR_FILENO 2 /* standard error file descriptor */
26
27struct dfs_file;
28struct dfs_vnode;
29struct dfs_dentry;
30struct dfs_attr;
31
32struct rt_pollreq;
33struct dirent;
34struct lwp_avl_struct;
35struct file_lock;
36struct dfs_aspace;
37
39{
40 int (*open)(struct dfs_file *file);
41 int (*close)(struct dfs_file *file);
42 int (*ioctl)(struct dfs_file *file, int cmd, void *arg);
43 ssize_t (*read)(struct dfs_file *file, void *buf, size_t count, off_t *pos);
44 ssize_t (*write)(struct dfs_file *file, const void *buf, size_t count, off_t *pos);
45 int (*flush)(struct dfs_file *file);
46 off_t (*lseek)(struct dfs_file *file, off_t offset, int wherece);
47 int (*truncate)(struct dfs_file *file, off_t offset);
48 int (*getdents)(struct dfs_file *file, struct dirent *dirp, uint32_t count);
49 int (*poll)(struct dfs_file *file, struct rt_pollreq *req);
50
51 int (*mmap)(struct dfs_file *file, struct lwp_avl_struct *mmap);
52 int (*lock)(struct dfs_file *file, struct file_lock *flock);
53 int (*flock)(struct dfs_file *file, int, struct file_lock *flock);
54};
55
57{
58 uint32_t flags;
59 uint32_t mode;
60 int type; /* node type */
61
62 rt_atomic_t ref_count; /* reference count */
63
64 struct dfs_mnt *mnt; /* which mounted file system does this vnode belong to */
65
66 size_t size;
67 uint32_t nlink;
68
69 const struct dfs_file_ops *fops;
70
71 unsigned int uid;
72 unsigned int gid;
73 struct timespec atime;
74 struct timespec mtime;
75 struct timespec ctime;
76
77 struct dfs_aspace *aspace;
78 struct rt_mutex lock;
79
80 void *data; /* private data of this file system */
81};
82
83/* file descriptor */
84#define DFS_FD_MAGIC 0xfdfd
86{
87 uint16_t magic;
88 uint16_t mode;
89
90 uint32_t flags;
92
93 off_t fpos;
95
96 const struct dfs_file_ops *fops;
97 struct dfs_dentry *dentry; /* dentry of this file */
98 struct dfs_vnode *vnode; /* vnode of this file */
99
100 void *mmap_context; /* used by mmap routine */
101
102 void *data;
103};
104#define DFS_FILE_POS(dfs_file) ((dfs_file)->fpos)
105
106/* file is open for reading */
107#define FMODE_READ 0x1
108/* file is open for writing */
109#define FMODE_WRITE 0x2
110/* file is seekable */
111#define FMODE_LSEEK 0x4
112/* file can be accessed using pread */
113#define FMODE_PREAD 0x8
114/* file can be accessed using pwrite */
115#define FMODE_PWRITE 0x10
116/* File is opened for execution with sys_execve / sys_uselib */
117#define FMODE_EXEC 0x20
118/* File is opened with O_NDELAY (only set for block devices) */
119#define FMODE_NDELAY 0x40
120/* File is opened with O_EXCL (only set for block devices) */
121#define FMODE_EXCL 0x80
122
123/* dfs_vnode.c */
124int dfs_vnode_init(struct dfs_vnode *vnode, int type, const struct dfs_file_ops *fops);
125struct dfs_vnode *dfs_vnode_create(void);
126int dfs_vnode_destroy(struct dfs_vnode* vnode);
127
128struct dfs_vnode *dfs_vnode_ref(struct dfs_vnode *vnode);
129void dfs_vnode_unref(struct dfs_vnode *vnode);
130
131/*dfs_file.c*/
132#ifdef RT_USING_SMART
133struct dfs_mmap2_args
134{
135 void *addr;
136 size_t length;
137 int prot;
138 int flags;
139 off_t pgoffset;
140
141 struct rt_lwp *lwp;
142 void *ret;
143};
144#endif
145
146void dfs_file_init(struct dfs_file *file);
147void dfs_file_deinit(struct dfs_file *file);
148
149int dfs_file_open(struct dfs_file *file, const char *path, int flags, mode_t mode);
150int dfs_file_close(struct dfs_file *file);
151
152off_t dfs_file_get_fpos(struct dfs_file *file);
153void dfs_file_set_fpos(struct dfs_file *file, off_t fpos);
154ssize_t dfs_file_pread(struct dfs_file *file, void *buf, size_t len, off_t offset);
155ssize_t dfs_file_read(struct dfs_file *file, void *buf, size_t len);
156ssize_t dfs_file_pwrite(struct dfs_file *file, const void *buf, size_t len, off_t offset);
157ssize_t dfs_file_write(struct dfs_file *file, const void *buf, size_t len);
158off_t generic_dfs_lseek(struct dfs_file *file, off_t offset, int whence);
159off_t dfs_file_lseek(struct dfs_file *file, off_t offset, int wherece);
160int dfs_file_stat(const char *path, struct stat *buf);
161int dfs_file_lstat(const char *path, struct stat *buf);
162int dfs_file_setattr(const char *path, struct dfs_attr *attr);
163int dfs_file_fstat(struct dfs_file *file, struct stat *buf);
164int dfs_file_ioctl(struct dfs_file *file, int cmd, void *args);
165int dfs_file_fcntl(int fd, int cmd, unsigned long arg);
166int dfs_file_fsync(struct dfs_file *file);
167int dfs_file_unlink(const char *path);
168int dfs_file_link(const char *oldname, const char *newname);
169int dfs_file_symlink(const char *oldname, const char *name);
170int dfs_file_readlink(const char *path, char *buf, int bufsize);
171int dfs_file_rename(const char *old_file, const char *new_file);
172int dfs_file_ftruncate(struct dfs_file *file, off_t length);
173int dfs_file_getdents(struct dfs_file *file, struct dirent *dirp, size_t nbytes);
174int dfs_file_mkdir(const char *path, mode_t mode);
175int dfs_file_rmdir(const char *pathname);
176int dfs_file_isdir(const char *path);
177int dfs_file_access(const char *path, mode_t mode);
178int dfs_file_chdir(const char *path);
179char *dfs_file_getcwd(char *buf, size_t size);
180
181#ifdef RT_USING_SMART
182int dfs_file_mmap2(struct dfs_file *file, struct dfs_mmap2_args *mmap2);
183
184int dfs_file_mmap(struct dfs_file *file, struct dfs_mmap2_args *mmap2);
185#endif
186
187/* 0x5254 is just a magic number to make these relatively unique ("RT") */
188#define RT_FIOFTRUNCATE 0x52540000U
189#define RT_FIOGETADDR 0x52540001U
190#define RT_FIOMMAP2 0x52540002U
191
192/* dfs_file_realpath mode */
193#define DFS_REALPATH_EXCEPT_LAST 0
194#define DFS_REALPATH_EXCEPT_NONE 1
195#define DFS_REALPATH_ONLY_LAST 3
196
197char *dfs_file_realpath(struct dfs_mnt **mnt, const char *fullpath, int mode);
198
199#ifdef __cplusplus
200}
201#endif
202
203#endif
int dfs_vnode_destroy(struct dfs_vnode *vnode)
int dfs_file_open(struct dfs_file *file, const char *path, int flags, mode_t mode)
int dfs_file_getdents(struct dfs_file *file, struct dirent *dirp, size_t nbytes)
int dfs_file_lstat(const char *path, struct stat *buf)
int dfs_file_access(const char *path, mode_t mode)
void dfs_vnode_unref(struct dfs_vnode *vnode)
int dfs_file_symlink(const char *oldname, const char *name)
int dfs_vnode_init(struct dfs_vnode *vnode, int type, const struct dfs_file_ops *fops)
off_t dfs_file_get_fpos(struct dfs_file *file)
int dfs_file_unlink(const char *path)
int dfs_file_ftruncate(struct dfs_file *file, off_t length)
char * dfs_file_getcwd(char *buf, size_t size)
void dfs_file_init(struct dfs_file *file)
ssize_t dfs_file_pwrite(struct dfs_file *file, const void *buf, size_t len, off_t offset)
off_t dfs_file_lseek(struct dfs_file *file, off_t offset, int wherece)
int dfs_file_setattr(const char *path, struct dfs_attr *attr)
int dfs_file_ioctl(struct dfs_file *file, int cmd, void *args)
ssize_t dfs_file_read(struct dfs_file *file, void *buf, size_t len)
ssize_t dfs_file_pread(struct dfs_file *file, void *buf, size_t len, off_t offset)
int dfs_file_fsync(struct dfs_file *file)
struct dfs_vnode * dfs_vnode_create(void)
int dfs_file_fcntl(int fd, int cmd, unsigned long arg)
int dfs_file_chdir(const char *path)
int dfs_file_mkdir(const char *path, mode_t mode)
int dfs_file_isdir(const char *path)
int dfs_file_close(struct dfs_file *file)
int dfs_file_rmdir(const char *pathname)
off_t generic_dfs_lseek(struct dfs_file *file, off_t offset, int whence)
char * dfs_file_realpath(struct dfs_mnt **mnt, const char *fullpath, int mode)
int dfs_file_readlink(const char *path, char *buf, int bufsize)
void dfs_file_set_fpos(struct dfs_file *file, off_t fpos)
void dfs_file_deinit(struct dfs_file *file)
int dfs_file_stat(const char *path, struct stat *buf)
int dfs_file_rename(const char *old_file, const char *new_file)
struct dfs_vnode * dfs_vnode_ref(struct dfs_vnode *vnode)
int dfs_file_link(const char *oldname, const char *newname)
ssize_t dfs_file_write(struct dfs_file *file, const void *buf, size_t len)
int dfs_file_fstat(struct dfs_file *file, struct stat *buf)
int dfs_file_mmap(struct dfs_file *file, struct dfs_mmap2_args *mmap2)
int stat(const char *file, struct stat *buf)
rt_base_t rt_atomic_t
int(* truncate)(struct dfs_file *file, off_t offset)
int(* flock)(struct dfs_file *file, int, struct file_lock *flock)
ssize_t(* write)(struct dfs_file *file, const void *buf, size_t count, off_t *pos)
int(* mmap)(struct dfs_file *file, struct lwp_avl_struct *mmap)
off_t(* lseek)(struct dfs_file *file, off_t offset, int wherece)
int(* flush)(struct dfs_file *file)
ssize_t(* read)(struct dfs_file *file, void *buf, size_t count, off_t *pos)
int(* ioctl)(struct dfs_file *file, int cmd, void *arg)
int(* open)(struct dfs_file *file)
int(* close)(struct dfs_file *file)
int(* poll)(struct dfs_file *file, struct rt_pollreq *req)
int(* getdents)(struct dfs_file *file, struct dirent *dirp, uint32_t count)
int(* lock)(struct dfs_file *file, struct file_lock *flock)
struct dfs_vnode * vnode
struct dfs_dentry * dentry
const struct dfs_file_ops * fops
uint16_t magic
struct rt_mutex pos_lock
rt_atomic_t ref_count
void * mmap_context
uint32_t flags
uint16_t mode
struct timespec ctime
uint32_t nlink
struct dfs_aspace * aspace
unsigned int uid
struct timespec atime
uint32_t flags
uint32_t mode
unsigned int gid
struct dfs_mnt * mnt
struct timespec mtime
const struct dfs_file_ops * fops
struct rt_mutex lock
rt_atomic_t ref_count