mirror of
https://github.com/Ai-Thinker-Open/Ai-Thinker-Open_RTL8710BX_ALIOS_SDK.git
synced 2026-08-29 01:31:32 +00:00
rel_1.6.0 init
This commit is contained in:
commit
27b3e2883d
19359 changed files with 8093121 additions and 0 deletions
64
Living_SDK/kernel/vfs/vfs_file.c
Executable file
64
Living_SDK/kernel/vfs/vfs_file.c
Executable file
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <aos/aos.h>
|
||||
#include <vfs_conf.h>
|
||||
#include <vfs_err.h>
|
||||
#include <vfs_inode.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define MAX_FILE_NUM (AOS_CONFIG_VFS_DEV_NODES * 2)
|
||||
static file_t files[MAX_FILE_NUM];
|
||||
|
||||
file_t *new_file(inode_t *node)
|
||||
{
|
||||
file_t *f;
|
||||
int idx;
|
||||
|
||||
for (idx = 0; idx < MAX_FILE_NUM; idx++) {
|
||||
f = &files[idx];
|
||||
|
||||
if (f->node == NULL) {
|
||||
goto got_file;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
got_file:
|
||||
f->node = node;
|
||||
f->f_arg = NULL;
|
||||
f->offset = 0;
|
||||
inode_ref(node);
|
||||
return f;
|
||||
}
|
||||
|
||||
void del_file(file_t *file)
|
||||
{
|
||||
inode_unref(file->node);
|
||||
file->node = NULL;
|
||||
}
|
||||
|
||||
int get_fd(file_t *file)
|
||||
{
|
||||
return (file - files) + AOS_CONFIG_VFS_FD_OFFSET;
|
||||
}
|
||||
|
||||
file_t *get_file(int fd)
|
||||
{
|
||||
file_t *f;
|
||||
|
||||
fd -= AOS_CONFIG_VFS_FD_OFFSET;
|
||||
|
||||
if (fd < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (fd >= MAX_FILE_NUM) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
f = &files[fd];
|
||||
return f->node ? f : NULL;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue