RT-Thread RTOS 1.2.0
An open source embedded real-time operating system
载入中...
搜索中...
未找到
+ File Descriptor 的协作图:

函数

int fdt_fd_new (struct dfs_fdtable *fdt)
 
struct dfs_filefdt_get_file (struct dfs_fdtable *fdt, int fd)
 
void fd_release (int fd)
 

详细描述

函数说明

◆ fdt_fd_new()

int fdt_fd_new ( struct dfs_fdtable * fdt)

This function will allocate a file descriptor.

返回
-1 on failed or the allocated file descriptor.

在文件 dfs.c199 行定义.

200{
201 int idx = -1;
202
203 /* lock filesystem */
204 if (dfs_file_lock() != RT_EOK)
205 {
206 return -RT_ENOSYS;
207 }
208
209 /* find an empty fd entry */
210 idx = _fdt_fd_alloc(fdt, (fdt == &_fdtab) ? DFS_STDIO_OFFSET : 0);
211 /* can't find an empty fd entry */
212 if (idx < 0)
213 {
214 LOG_E("DFS fd new is failed! Could not found an empty fd entry.");
215 }
216 else if (!fdt->fds[idx])
217 {
218 struct dfs_file *file;
219
220 file = (struct dfs_file *)rt_calloc(1, sizeof(struct dfs_file));
221
222 if (file)
223 {
224 file->magic = DFS_FD_MAGIC;
225 file->ref_count = 1;
226 rt_mutex_init(&file->pos_lock, "fpos", RT_IPC_FLAG_PRIO);
227 fdt->fds[idx] = file;
228
229 LOG_D("allocate a new fd @ %d", idx);
230 }
231 else
232 {
233 fdt->fds[idx] = RT_NULL;
234 idx = -1;
235 }
236 }
237 else
238 {
239 LOG_E("DFS not found an empty fds entry.");
240 idx = -1;
241 }
242
244
245 return idx;
246}
#define DFS_STDIO_OFFSET
定义 dfs.h:68
#define DFS_FD_MAGIC
void dfs_file_unlock(void)
定义 dfs.c:164
rt_err_t dfs_file_lock(void)
定义 dfs.c:147
#define RT_IPC_FLAG_PRIO
rt_weak void * rt_calloc(rt_size_t count, rt_size_t size)
This function will contiguously allocate enough space for count objects that are size bytes of memory...
rt_err_t rt_mutex_init(rt_mutex_t mutex, const char *name, rt_uint8_t flag)
Initialize a static mutex object.
定义 ipc.c:1007
#define LOG_D(...)
#define LOG_E(fmt,...)
#define RT_NULL
struct dfs_file ** fds
定义 dfs.h:109
uint16_t magic
struct rt_mutex pos_lock
rt_atomic_t ref_count

引用了 DFS_FD_MAGIC, dfs_file_lock(), dfs_file_unlock(), DFS_STDIO_OFFSET, dfs_fdtable::fds, LOG_D, LOG_E, dfs_file::magic, dfs_file::pos_lock, dfs_file::ref_count, rt_calloc(), RT_IPC_FLAG_PRIO, rt_mutex_init() , 以及 RT_NULL.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ fdt_get_file()

struct dfs_file * fdt_get_file ( struct dfs_fdtable * fdt,
int fd )

This function will return a file descriptor structure according to file descriptor.

返回
NULL on on this file descriptor or the file descriptor structure pointer.

在文件 dfs.c286 行定义.

287{
288 struct dfs_file *f;
289
290 if (fd < 0 || fd >= (int)fdt->maxfd)
291 {
292 return NULL;
293 }
294
295 f = fdt->fds[fd];
296
297 /* check file valid or not */
298 if ((f == NULL) || (f->magic != DFS_FD_MAGIC))
299 {
300 return NULL;
301 }
302
303 return f;
304}
uint32_t maxfd
定义 dfs.h:108

引用了 DFS_FD_MAGIC, dfs_fdtable::fds, dfs_file::magic , 以及 dfs_fdtable::maxfd.

+ 这是这个函数的调用关系图:

◆ fd_release()

void fd_release ( int fd)

This function will put the file descriptor.

在文件 dfs.c359 行定义.

360{
361 struct dfs_fdtable *fdt;
362
363 fdt = dfs_fdtable_get();
364 fdt_fd_release(fdt, fd);
365}
void fdt_fd_release(struct dfs_fdtable *fdt, int fd)
定义 dfs.c:248
struct dfs_fdtable * dfs_fdtable_get(void)
定义 dfs.c:379

引用了 dfs_fdtable_get() , 以及 fdt_fd_release().

+ 函数调用图:
+ 这是这个函数的调用关系图: