RT-Thread RTOS 1.2.0
An open source embedded real-time operating system
载入中...
搜索中...
未找到
dfs.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-02-22 Bernard The first version.
9 * 2023-05-05 Bernard change to dfs v2.0
10 */
11
12#ifndef __DFS_H__
13#define __DFS_H__
14
15#include <stdio.h>
16#include <stdint.h>
17#include <stdlib.h>
18#include <string.h>
19#include "../../libc/compilers/common/include/dirent.h"
20#include <fcntl.h>
21#include <sys/stat.h>
22#include <sys/statfs.h>
23#include <sys/time.h>
24#include <sys/errno.h>
25#include <rtatomic.h>
26#include <rtdevice.h>
27
28#ifndef ATTR_MODE_SET
29#define ATTR_MODE_SET (1 << 6)
30#endif
31
32#ifndef ATTR_ATIME_SET
33#define ATTR_ATIME_SET (1 << 7)
34#endif
35
36#ifndef ATTR_MTIME_SET
37#define ATTR_MTIME_SET (1 << 8)
38#endif
39
40#ifndef ATTR_UID_SET
41#define ATTR_UID_SET (1 << 9)
42#endif
43
44#ifndef ATTR_GID_SET
45#define ATTR_GID_SET (1 << 10)
46#endif
47
48#ifndef AT_SYMLINK_NOFOLLOW
49#define AT_SYMLINK_NOFOLLOW 0x100
50#endif
51
52#ifndef UTIME_NOW
53#define UTIME_NOW 0x3fffffff
54#endif
55
56#ifndef UTIME_OMIT
57#define UTIME_OMIT 0x3ffffffe
58#endif
59
60#ifndef DFS_FD_MAX
61#define DFS_FD_MAX 16
62#endif
63
64/*
65 * skip stdin/stdout/stderr normally
66 */
67#ifndef DFS_STDIO_OFFSET
68#define DFS_STDIO_OFFSET 3
69#endif
70
71#ifndef DFS_PATH_MAX
72#define DFS_PATH_MAX 4096
73#endif
74
75#ifndef SECTOR_SIZE
76#define SECTOR_SIZE 512
77#endif
78
79#define DFS_FS_FLAG_DEFAULT 0x00 /* default flag */
80#define DFS_FS_FLAG_FULLPATH 0x01 /* set full path to underlaying file system */
81
82/* File flags */
83#define DFS_F_FREAD 0x01
84#define DFS_F_FWRITE 0x02
85
86#ifdef __cplusplus
87extern "C" {
88#endif
89
90rt_inline int dfs_fflags(int oflags)
91{
92 int rw = oflags & O_ACCMODE;
93
94 oflags &= ~O_ACCMODE;
95 return (rw + 1) | oflags;
96}
97
98rt_inline int dfs_oflags(int fflags)
99{
100 int rw = fflags & (DFS_F_FREAD | DFS_F_FWRITE);
101
102 fflags &= ~(DFS_F_FREAD | DFS_F_FWRITE);
103 return (rw - 1) | fflags;
104}
105
107{
108 uint32_t maxfd;
109 struct dfs_file **fds;
110};
111
112/* Initialization of dfs */
113int dfs_init(void);
114
115char *dfs_normalize_path(const char *directory, const char *filename);
116const char *dfs_subdir(const char *directory, const char *filename);
117
118rt_err_t dfs_lock(void);
119void dfs_unlock(void);
120
122void dfs_file_unlock(void);
123
124int dfs_fdtable_dup(struct dfs_fdtable *fdt_dst, struct dfs_fdtable *fdt_src, int fd_src);
125int dfs_fdtable_drop_fd(struct dfs_fdtable *fdtab, int fd);
126
127#ifdef DFS_USING_POSIX
128/* FD APIs */
129int fdt_fd_new(struct dfs_fdtable *fdt);
130struct dfs_file *fdt_get_file(struct dfs_fdtable* fdt, int fd);
131void fdt_fd_release(struct dfs_fdtable* fdt, int fd);
132int fd_new(void);
133int fdt_fd_associate_file(struct dfs_fdtable *fdt, int fd, struct dfs_file *file);
134struct dfs_file *fd_get(int fd);
135void fd_release(int fd);
136
137void fd_init(struct dfs_file *fd);
138
139struct dfs_fdtable *dfs_fdtable_get(void);
141int dfs_dup(int oldfd, int startfd);
142#endif /* DFS_USING_POSIX */
143
144#ifdef __cplusplus
145}
146#endif
147
148#endif
rt_inline int dfs_oflags(int fflags)
定义 dfs.h:98
#define DFS_F_FWRITE
定义 dfs.h:84
rt_err_t dfs_lock(void)
定义 dfs.c:120
void dfs_unlock(void)
定义 dfs.c:137
#define DFS_F_FREAD
定义 dfs.h:83
rt_inline int dfs_fflags(int oflags)
定义 dfs.h:90
struct dfs_fdtable * dfs_fdtable_get_global(void)
定义 dfs.c:420
int dfs_dup(int oldfd, int startfd)
定义 dfs.c:526
int dfs_init(void)
定义 dfs.c:172
int fd_new(void)
定义 dfs.c:345
char * dfs_normalize_path(const char *directory, const char *filename)
定义 dfs.c:779
void dfs_file_unlock(void)
定义 dfs.c:164
int fdt_fd_associate_file(struct dfs_fdtable *fdt, int fd, struct dfs_file *file)
定义 dfs.c:306
int dfs_fdtable_dup(struct dfs_fdtable *fdt_dst, struct dfs_fdtable *fdt_src, int fd_src)
Dup the specified fd_src from fdt_src to fdt_dst.
定义 dfs.c:436
void fdt_fd_release(struct dfs_fdtable *fdt, int fd)
定义 dfs.c:248
const char * dfs_subdir(const char *directory, const char *filename)
定义 dfs.c:753
rt_err_t dfs_file_lock(void)
定义 dfs.c:147
struct dfs_file * fd_get(int fd)
定义 dfs.c:367
struct dfs_fdtable * dfs_fdtable_get(void)
定义 dfs.c:379
int dfs_fdtable_drop_fd(struct dfs_fdtable *fdtab, int fd)
drop fd from the fd table.
定义 dfs.c:501
struct dfs_file * fdt_get_file(struct dfs_fdtable *fdt, int fd)
定义 dfs.c:286
void fd_release(int fd)
定义 dfs.c:359
int fdt_fd_new(struct dfs_fdtable *fdt)
定义 dfs.c:199
rt_base_t rt_err_t
uint32_t maxfd
定义 dfs.h:108
struct dfs_file ** fds
定义 dfs.h:109