mirror of
https://github.com/Ai-Thinker-Open/Ai-Thinker-Open_RTL8710BX_ALIOS_SDK.git
synced 2025-07-31 19:31:05 +00:00
rel_1.6.0 init
This commit is contained in:
commit
27b3e2883d
19359 changed files with 8093121 additions and 0 deletions
118
Living_SDK/kernel/vfs/vfs_register.c
Normal file
118
Living_SDK/kernel/vfs/vfs_register.c
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <aos/aos.h>
|
||||
#include <vfs_conf.h>
|
||||
#include <vfs_err.h>
|
||||
#include <vfs_register.h>
|
||||
|
||||
extern aos_mutex_t g_vfs_mutex;
|
||||
|
||||
int aos_register_driver(const char *path, file_ops_t *ops, void *arg)
|
||||
{
|
||||
inode_t *node = NULL;
|
||||
int err, ret;
|
||||
|
||||
err = aos_mutex_lock(&g_vfs_mutex, AOS_WAIT_FOREVER);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
|
||||
ret = inode_reserve(path, &node);
|
||||
if (ret == VFS_SUCCESS) {
|
||||
/* now populate it with char specific information */
|
||||
INODE_SET_CHAR(node);
|
||||
|
||||
node->ops.i_ops = ops;
|
||||
node->i_arg = arg;
|
||||
|
||||
/* creat device lock. */
|
||||
ret = aos_mutex_new(&node->mutex);
|
||||
}
|
||||
|
||||
/* step out critical area for type is allocated */
|
||||
err = aos_mutex_unlock(&g_vfs_mutex);
|
||||
if (err != 0) {
|
||||
if (node->i_name != NULL) {
|
||||
aos_free(node->i_name);
|
||||
}
|
||||
|
||||
memset(node, 0, sizeof(inode_t));
|
||||
return err;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int aos_unregister_driver(const char *path)
|
||||
{
|
||||
int err, ret;
|
||||
|
||||
err = aos_mutex_lock(&g_vfs_mutex, AOS_WAIT_FOREVER);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
|
||||
ret = inode_release(path);
|
||||
|
||||
err = aos_mutex_unlock(&g_vfs_mutex);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int aos_register_fs(const char *path, fs_ops_t *ops, void *arg)
|
||||
{
|
||||
inode_t *node = NULL;
|
||||
int err, ret;
|
||||
|
||||
err = aos_mutex_lock(&g_vfs_mutex, AOS_WAIT_FOREVER);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
|
||||
ret = inode_reserve(path, &node);
|
||||
if (ret == VFS_SUCCESS) {
|
||||
INODE_SET_FS(node);
|
||||
|
||||
node->ops.i_fops = ops;
|
||||
node->i_arg = arg;
|
||||
}
|
||||
|
||||
err = aos_mutex_unlock(&g_vfs_mutex );
|
||||
if (err != 0) {
|
||||
if (node->i_name != NULL) {
|
||||
aos_free(node->i_name);
|
||||
}
|
||||
|
||||
memset(node, 0, sizeof(inode_t));
|
||||
return err;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int aos_unregister_fs(const char *path)
|
||||
{
|
||||
int err, ret;
|
||||
|
||||
err = aos_mutex_lock(&g_vfs_mutex, AOS_WAIT_FOREVER);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
|
||||
ret = inode_release(path);
|
||||
|
||||
err = aos_mutex_unlock(&g_vfs_mutex);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue