2013-06-26 22:30:40 +08:00
|
|
|
/*
|
2021-03-08 18:19:04 +08:00
|
|
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
2013-06-26 22:30:40 +08:00
|
|
|
*
|
2018-10-15 01:46:07 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2013-06-26 22:30:40 +08:00
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
2018-02-11 13:57:51 +08:00
|
|
|
* 2018-02-11 Bernard Ignore O_CREAT flag in open.
|
2013-06-26 22:30:40 +08:00
|
|
|
*/
|
2022-12-03 12:07:44 +08:00
|
|
|
#include <rthw.h>
|
2011-10-08 22:50:08 +08:00
|
|
|
#include <rtthread.h>
|
2017-10-15 22:44:53 +08:00
|
|
|
#include <rtdevice.h>
|
|
|
|
|
2011-10-08 22:50:08 +08:00
|
|
|
#include <dfs.h>
|
|
|
|
#include <dfs_fs.h>
|
2017-10-15 22:44:53 +08:00
|
|
|
#include <dfs_file.h>
|
2011-10-08 22:50:08 +08:00
|
|
|
|
|
|
|
#include "devfs.h"
|
|
|
|
|
|
|
|
struct device_dirent
|
|
|
|
{
|
2013-06-26 22:30:40 +08:00
|
|
|
rt_device_t *devices;
|
|
|
|
rt_uint16_t read_index;
|
|
|
|
rt_uint16_t device_count;
|
2011-10-08 22:50:08 +08:00
|
|
|
};
|
|
|
|
|
2012-07-10 08:42:39 +08:00
|
|
|
int dfs_device_fs_mount(struct dfs_filesystem *fs, unsigned long rwflag, const void *data)
|
2011-10-08 22:50:08 +08:00
|
|
|
{
|
2017-10-15 22:44:53 +08:00
|
|
|
return RT_EOK;
|
2011-10-08 22:50:08 +08:00
|
|
|
}
|
|
|
|
|
2023-03-29 14:36:36 +08:00
|
|
|
int dfs_device_fs_statfs(struct dfs_filesystem *fs, struct statfs *buf)
|
|
|
|
{
|
|
|
|
buf->f_bsize = 512;
|
|
|
|
buf->f_blocks = 2048 * 64; // 64M
|
|
|
|
buf->f_bfree = buf->f_blocks;
|
|
|
|
buf->f_bavail = buf->f_bfree;
|
|
|
|
|
|
|
|
return RT_EOK;
|
|
|
|
}
|
|
|
|
|
2023-04-08 22:25:51 +08:00
|
|
|
int dfs_device_fs_ioctl(struct dfs_file *file, int cmd, void *args)
|
2011-10-08 22:50:08 +08:00
|
|
|
{
|
2013-06-26 22:30:40 +08:00
|
|
|
rt_err_t result;
|
|
|
|
rt_device_t dev_id;
|
2011-10-08 22:50:08 +08:00
|
|
|
|
2013-06-26 22:30:40 +08:00
|
|
|
RT_ASSERT(file != RT_NULL);
|
2011-10-08 22:50:08 +08:00
|
|
|
|
2013-06-26 22:30:40 +08:00
|
|
|
/* get device handler */
|
2022-12-03 12:07:44 +08:00
|
|
|
dev_id = (rt_device_t)file->vnode->data;
|
2013-06-26 22:30:40 +08:00
|
|
|
RT_ASSERT(dev_id != RT_NULL);
|
2011-10-08 22:50:08 +08:00
|
|
|
|
2023-03-29 11:13:35 +08:00
|
|
|
if ((file->vnode->path[0] == '/') && (file->vnode->path[1] == '\0'))
|
|
|
|
return -RT_ENOSYS;
|
|
|
|
|
2013-06-26 22:30:40 +08:00
|
|
|
/* close device handler */
|
|
|
|
result = rt_device_control(dev_id, cmd, args);
|
|
|
|
if (result == RT_EOK)
|
2017-10-15 22:44:53 +08:00
|
|
|
return RT_EOK;
|
2011-10-08 22:50:08 +08:00
|
|
|
|
2017-10-15 22:44:53 +08:00
|
|
|
return result;
|
2011-10-08 22:50:08 +08:00
|
|
|
}
|
|
|
|
|
2023-04-08 22:25:51 +08:00
|
|
|
int dfs_device_fs_read(struct dfs_file *file, void *buf, size_t count)
|
2011-10-08 22:50:08 +08:00
|
|
|
{
|
2013-06-26 22:30:40 +08:00
|
|
|
int result;
|
|
|
|
rt_device_t dev_id;
|
2011-10-08 22:50:08 +08:00
|
|
|
|
2013-06-26 22:30:40 +08:00
|
|
|
RT_ASSERT(file != RT_NULL);
|
2011-10-08 22:50:08 +08:00
|
|
|
|
2013-06-26 22:30:40 +08:00
|
|
|
/* get device handler */
|
2022-12-03 12:07:44 +08:00
|
|
|
dev_id = (rt_device_t)file->vnode->data;
|
2013-06-26 22:30:40 +08:00
|
|
|
RT_ASSERT(dev_id != RT_NULL);
|
2011-10-08 22:50:08 +08:00
|
|
|
|
2023-03-29 11:13:35 +08:00
|
|
|
if ((file->vnode->path[0] == '/') && (file->vnode->path[1] == '\0'))
|
|
|
|
return -RT_ENOSYS;
|
|
|
|
|
2013-06-26 22:30:40 +08:00
|
|
|
/* read device data */
|
|
|
|
result = rt_device_read(dev_id, file->pos, buf, count);
|
|
|
|
file->pos += result;
|
2011-10-08 22:50:08 +08:00
|
|
|
|
2013-06-26 22:30:40 +08:00
|
|
|
return result;
|
2011-10-08 22:50:08 +08:00
|
|
|
}
|
|
|
|
|
2023-04-08 22:25:51 +08:00
|
|
|
int dfs_device_fs_write(struct dfs_file *file, const void *buf, size_t count)
|
2011-10-08 22:50:08 +08:00
|
|
|
{
|
2013-06-26 22:30:40 +08:00
|
|
|
int result;
|
|
|
|
rt_device_t dev_id;
|
2011-10-08 22:50:08 +08:00
|
|
|
|
2013-06-26 22:30:40 +08:00
|
|
|
RT_ASSERT(file != RT_NULL);
|
2011-10-08 22:50:08 +08:00
|
|
|
|
2013-06-26 22:30:40 +08:00
|
|
|
/* get device handler */
|
2022-12-03 12:07:44 +08:00
|
|
|
dev_id = (rt_device_t)file->vnode->data;
|
2013-06-26 22:30:40 +08:00
|
|
|
RT_ASSERT(dev_id != RT_NULL);
|
2011-10-08 22:50:08 +08:00
|
|
|
|
2023-03-29 11:13:35 +08:00
|
|
|
if ((file->vnode->path[0] == '/') && (file->vnode->path[1] == '\0'))
|
|
|
|
return -RT_ENOSYS;
|
|
|
|
|
2013-06-26 22:30:40 +08:00
|
|
|
/* read device data */
|
|
|
|
result = rt_device_write(dev_id, file->pos, buf, count);
|
|
|
|
file->pos += result;
|
2011-10-08 22:50:08 +08:00
|
|
|
|
2013-06-26 22:30:40 +08:00
|
|
|
return result;
|
2011-10-08 22:50:08 +08:00
|
|
|
}
|
|
|
|
|
2023-04-08 22:25:51 +08:00
|
|
|
int dfs_device_fs_close(struct dfs_file *file)
|
2011-10-08 22:50:08 +08:00
|
|
|
{
|
2013-06-26 22:30:40 +08:00
|
|
|
rt_err_t result;
|
|
|
|
rt_device_t dev_id;
|
2011-10-08 22:50:08 +08:00
|
|
|
|
2013-06-26 22:30:40 +08:00
|
|
|
RT_ASSERT(file != RT_NULL);
|
2022-12-03 12:07:44 +08:00
|
|
|
RT_ASSERT(file->vnode->ref_count > 0);
|
|
|
|
|
|
|
|
if (file->vnode->ref_count > 1)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2011-10-08 22:50:08 +08:00
|
|
|
|
2023-03-29 11:13:35 +08:00
|
|
|
if (file->vnode->type == FT_DIRECTORY && (file->vnode->path[0] == '/') && (file->vnode->path[1] == '\0'))
|
2013-06-26 22:30:40 +08:00
|
|
|
{
|
|
|
|
struct device_dirent *root_dirent;
|
2011-10-08 22:50:08 +08:00
|
|
|
|
2022-12-03 12:07:44 +08:00
|
|
|
root_dirent = (struct device_dirent *)file->vnode->data;
|
2013-06-26 22:30:40 +08:00
|
|
|
RT_ASSERT(root_dirent != RT_NULL);
|
2019-04-03 18:09:52 +08:00
|
|
|
|
2013-06-26 22:30:40 +08:00
|
|
|
/* release dirent */
|
|
|
|
rt_free(root_dirent);
|
2017-10-15 22:44:53 +08:00
|
|
|
return RT_EOK;
|
2013-06-26 22:30:40 +08:00
|
|
|
}
|
2011-10-08 22:50:08 +08:00
|
|
|
|
2013-06-26 22:30:40 +08:00
|
|
|
/* get device handler */
|
2022-12-03 12:07:44 +08:00
|
|
|
dev_id = (rt_device_t)file->vnode->data;
|
2013-06-26 22:30:40 +08:00
|
|
|
RT_ASSERT(dev_id != RT_NULL);
|
2011-10-08 22:50:08 +08:00
|
|
|
|
2013-06-26 22:30:40 +08:00
|
|
|
/* close device handler */
|
|
|
|
result = rt_device_close(dev_id);
|
|
|
|
if (result == RT_EOK)
|
|
|
|
{
|
2022-12-03 12:07:44 +08:00
|
|
|
file->vnode->data = RT_NULL;
|
2012-07-10 08:42:39 +08:00
|
|
|
|
2017-10-15 22:44:53 +08:00
|
|
|
return RT_EOK;
|
2013-06-26 22:30:40 +08:00
|
|
|
}
|
2011-10-08 22:50:08 +08:00
|
|
|
|
2017-10-15 22:44:53 +08:00
|
|
|
return -EIO;
|
2011-10-08 22:50:08 +08:00
|
|
|
}
|
|
|
|
|
2023-04-08 22:25:51 +08:00
|
|
|
int dfs_device_fs_open(struct dfs_file *file)
|
2011-10-08 22:50:08 +08:00
|
|
|
{
|
2015-01-28 14:13:44 +08:00
|
|
|
rt_err_t result;
|
2013-06-26 22:30:40 +08:00
|
|
|
rt_device_t device;
|
|
|
|
|
2022-12-03 12:07:44 +08:00
|
|
|
RT_ASSERT(file->vnode->ref_count > 0);
|
|
|
|
if (file->vnode->ref_count > 1)
|
|
|
|
{
|
|
|
|
file->pos = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
2013-06-26 22:30:40 +08:00
|
|
|
/* open root directory */
|
2022-12-03 12:07:44 +08:00
|
|
|
if ((file->vnode->path[0] == '/') && (file->vnode->path[1] == '\0') &&
|
2017-10-15 22:44:53 +08:00
|
|
|
(file->flags & O_DIRECTORY))
|
2013-06-26 22:30:40 +08:00
|
|
|
{
|
|
|
|
struct rt_object *object;
|
|
|
|
struct rt_list_node *node;
|
|
|
|
struct rt_object_information *information;
|
|
|
|
struct device_dirent *root_dirent;
|
|
|
|
rt_uint32_t count = 0;
|
2019-04-03 18:09:52 +08:00
|
|
|
|
2013-06-26 22:30:40 +08:00
|
|
|
/* lock scheduler */
|
|
|
|
rt_enter_critical();
|
|
|
|
|
|
|
|
/* traverse device object */
|
2017-12-12 07:36:37 +08:00
|
|
|
information = rt_object_get_information(RT_Object_Class_Device);
|
|
|
|
RT_ASSERT(information != RT_NULL);
|
2013-06-26 22:30:40 +08:00
|
|
|
for (node = information->object_list.next; node != &(information->object_list); node = node->next)
|
|
|
|
{
|
|
|
|
count ++;
|
|
|
|
}
|
2022-01-26 16:02:24 +08:00
|
|
|
rt_exit_critical();
|
2013-06-26 22:30:40 +08:00
|
|
|
|
2019-04-03 18:09:52 +08:00
|
|
|
root_dirent = (struct device_dirent *)rt_malloc(sizeof(struct device_dirent) +
|
|
|
|
count * sizeof(rt_device_t));
|
2013-06-26 22:30:40 +08:00
|
|
|
if (root_dirent != RT_NULL)
|
|
|
|
{
|
2022-01-26 16:02:24 +08:00
|
|
|
/* lock scheduler */
|
|
|
|
rt_enter_critical();
|
|
|
|
|
2013-06-26 22:30:40 +08:00
|
|
|
root_dirent->devices = (rt_device_t *)(root_dirent + 1);
|
|
|
|
root_dirent->read_index = 0;
|
|
|
|
root_dirent->device_count = count;
|
|
|
|
count = 0;
|
|
|
|
/* get all device node */
|
|
|
|
for (node = information->object_list.next; node != &(information->object_list); node = node->next)
|
|
|
|
{
|
2022-01-26 16:02:24 +08:00
|
|
|
/* avoid memory write through */
|
|
|
|
if (count == root_dirent->device_count)
|
|
|
|
{
|
|
|
|
rt_kprintf("warning: There are newly added devices that are not displayed!");
|
|
|
|
break;
|
|
|
|
}
|
2013-06-26 22:30:40 +08:00
|
|
|
object = rt_list_entry(node, struct rt_object, list);
|
|
|
|
root_dirent->devices[count] = (rt_device_t)object;
|
|
|
|
count ++;
|
|
|
|
}
|
2022-01-26 16:02:24 +08:00
|
|
|
rt_exit_critical();
|
2013-06-26 22:30:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* set data */
|
2022-12-03 12:07:44 +08:00
|
|
|
file->vnode->data = root_dirent;
|
2019-04-03 18:09:52 +08:00
|
|
|
|
2017-10-15 22:44:53 +08:00
|
|
|
return RT_EOK;
|
2013-06-26 22:30:40 +08:00
|
|
|
}
|
2022-12-03 12:07:44 +08:00
|
|
|
#ifdef RT_USING_DEV_BUS
|
|
|
|
else if (file->flags & O_CREAT)
|
|
|
|
{
|
|
|
|
if (!(file->flags & O_DIRECTORY))
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
/* regester bus device */
|
|
|
|
if (rt_device_bus_create(&file->vnode->path[1], 0) == RT_NULL)
|
|
|
|
{
|
|
|
|
return -EEXIST;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2013-06-26 22:30:40 +08:00
|
|
|
|
2022-12-03 12:07:44 +08:00
|
|
|
device = rt_device_find(&file->vnode->path[1]);
|
2013-06-26 22:30:40 +08:00
|
|
|
if (device == RT_NULL)
|
2022-12-03 12:07:44 +08:00
|
|
|
{
|
2017-10-15 22:44:53 +08:00
|
|
|
return -ENODEV;
|
2022-12-03 12:07:44 +08:00
|
|
|
}
|
2013-06-26 22:30:40 +08:00
|
|
|
|
2021-11-24 22:14:46 +08:00
|
|
|
#ifdef RT_USING_POSIX_DEVIO
|
2017-10-15 22:44:53 +08:00
|
|
|
if (device->fops)
|
2015-01-28 14:13:44 +08:00
|
|
|
{
|
2017-10-15 22:44:53 +08:00
|
|
|
/* use device fops */
|
2022-12-03 12:07:44 +08:00
|
|
|
file->vnode->fops = device->fops;
|
|
|
|
file->vnode->data = (void *)device;
|
2017-10-15 22:44:53 +08:00
|
|
|
|
|
|
|
/* use fops */
|
2022-12-03 12:07:44 +08:00
|
|
|
if (file->vnode->fops->open)
|
2017-10-15 22:44:53 +08:00
|
|
|
{
|
2022-12-03 12:07:44 +08:00
|
|
|
result = file->vnode->fops->open(file);
|
2017-10-15 22:44:53 +08:00
|
|
|
if (result == RT_EOK || result == -RT_ENOSYS)
|
|
|
|
{
|
2022-12-03 12:07:44 +08:00
|
|
|
file->vnode->type = FT_DEVICE;
|
2017-10-15 22:44:53 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2021-11-24 22:14:46 +08:00
|
|
|
#endif /* RT_USING_POSIX_DEVIO */
|
2017-10-15 22:44:53 +08:00
|
|
|
{
|
|
|
|
result = rt_device_open(device, RT_DEVICE_OFLAG_RDWR);
|
|
|
|
if (result == RT_EOK || result == -RT_ENOSYS)
|
|
|
|
{
|
2022-12-03 12:07:44 +08:00
|
|
|
file->vnode->data = device;
|
|
|
|
file->vnode->type = FT_DEVICE;
|
2017-10-15 22:44:53 +08:00
|
|
|
return RT_EOK;
|
|
|
|
}
|
2015-01-28 14:13:44 +08:00
|
|
|
}
|
|
|
|
|
2022-12-03 12:07:44 +08:00
|
|
|
file->vnode->data = RT_NULL;
|
2015-01-28 14:13:44 +08:00
|
|
|
/* open device failed. */
|
2017-10-15 22:44:53 +08:00
|
|
|
return -EIO;
|
2011-10-08 22:50:08 +08:00
|
|
|
}
|
|
|
|
|
2022-12-03 12:07:44 +08:00
|
|
|
int dfs_device_fs_unlink(struct dfs_filesystem *fs, const char *path)
|
|
|
|
{
|
|
|
|
#ifdef RT_USING_DEV_BUS
|
|
|
|
rt_device_t dev_id;
|
|
|
|
|
|
|
|
dev_id = rt_device_find(&path[1]);
|
|
|
|
if (dev_id == RT_NULL)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (dev_id->type != RT_Device_Class_Bus)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
rt_device_bus_destroy(dev_id);
|
|
|
|
#endif
|
|
|
|
return RT_EOK;
|
|
|
|
}
|
|
|
|
|
2012-07-10 08:42:39 +08:00
|
|
|
int dfs_device_fs_stat(struct dfs_filesystem *fs, const char *path, struct stat *st)
|
2011-10-08 22:50:08 +08:00
|
|
|
{
|
2013-06-26 22:30:40 +08:00
|
|
|
/* stat root directory */
|
|
|
|
if ((path[0] == '/') && (path[1] == '\0'))
|
|
|
|
{
|
|
|
|
st->st_dev = 0;
|
|
|
|
|
2017-10-15 22:44:53 +08:00
|
|
|
st->st_mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH |
|
2019-04-03 18:09:52 +08:00
|
|
|
S_IWUSR | S_IWGRP | S_IWOTH;
|
2017-10-15 22:44:53 +08:00
|
|
|
st->st_mode &= ~S_IFREG;
|
|
|
|
st->st_mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH;
|
2013-06-26 22:30:40 +08:00
|
|
|
|
|
|
|
st->st_size = 0;
|
|
|
|
st->st_mtime = 0;
|
2015-10-01 14:46:52 +08:00
|
|
|
|
2017-10-15 22:44:53 +08:00
|
|
|
return RT_EOK;
|
2013-06-26 22:30:40 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rt_device_t dev_id;
|
|
|
|
|
|
|
|
dev_id = rt_device_find(&path[1]);
|
|
|
|
if (dev_id != RT_NULL)
|
|
|
|
{
|
|
|
|
st->st_dev = 0;
|
|
|
|
|
2017-10-15 22:44:53 +08:00
|
|
|
st->st_mode = S_IRUSR | S_IRGRP | S_IROTH |
|
2019-04-03 18:09:52 +08:00
|
|
|
S_IWUSR | S_IWGRP | S_IWOTH;
|
2013-06-26 22:30:40 +08:00
|
|
|
|
|
|
|
if (dev_id->type == RT_Device_Class_Char)
|
2017-10-15 22:44:53 +08:00
|
|
|
st->st_mode |= S_IFCHR;
|
2013-06-26 22:30:40 +08:00
|
|
|
else if (dev_id->type == RT_Device_Class_Block)
|
2017-10-15 22:44:53 +08:00
|
|
|
st->st_mode |= S_IFBLK;
|
|
|
|
else if (dev_id->type == RT_Device_Class_Pipe)
|
|
|
|
st->st_mode |= S_IFIFO;
|
2022-12-03 12:07:44 +08:00
|
|
|
else if (dev_id->type == RT_Device_Class_Bus)
|
|
|
|
st->st_mode |= S_IFDIR;
|
2013-06-26 22:30:40 +08:00
|
|
|
else
|
2017-10-15 22:44:53 +08:00
|
|
|
st->st_mode |= S_IFREG;
|
2013-06-26 22:30:40 +08:00
|
|
|
|
|
|
|
st->st_size = 0;
|
|
|
|
st->st_mtime = 0;
|
2015-10-01 14:46:52 +08:00
|
|
|
|
2017-10-15 22:44:53 +08:00
|
|
|
return RT_EOK;
|
2013-06-26 22:30:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-15 22:44:53 +08:00
|
|
|
return -ENOENT;
|
2011-10-08 22:50:08 +08:00
|
|
|
}
|
|
|
|
|
2023-04-08 22:25:51 +08:00
|
|
|
int dfs_device_fs_getdents(struct dfs_file *file, struct dirent *dirp, uint32_t count)
|
2011-10-08 22:50:08 +08:00
|
|
|
{
|
2013-06-26 22:30:40 +08:00
|
|
|
rt_uint32_t index;
|
|
|
|
rt_object_t object;
|
|
|
|
struct dirent *d;
|
|
|
|
struct device_dirent *root_dirent;
|
|
|
|
|
2022-12-03 12:07:44 +08:00
|
|
|
root_dirent = (struct device_dirent *)file->vnode->data;
|
2013-06-26 22:30:40 +08:00
|
|
|
RT_ASSERT(root_dirent != RT_NULL);
|
|
|
|
|
|
|
|
/* make integer count */
|
|
|
|
count = (count / sizeof(struct dirent));
|
|
|
|
if (count == 0)
|
2017-10-15 22:44:53 +08:00
|
|
|
return -EINVAL;
|
2013-06-26 22:30:40 +08:00
|
|
|
|
2021-03-08 18:19:04 +08:00
|
|
|
for (index = 0; index < count && index + root_dirent->read_index < root_dirent->device_count;
|
2013-06-26 22:30:40 +08:00
|
|
|
index ++)
|
|
|
|
{
|
|
|
|
object = (rt_object_t)root_dirent->devices[root_dirent->read_index + index];
|
|
|
|
|
|
|
|
d = dirp + index;
|
2022-12-03 12:07:44 +08:00
|
|
|
if ((((rt_device_t)object)->type) == RT_Device_Class_Bus)
|
|
|
|
{
|
|
|
|
d->d_type = DT_DIR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
d->d_type = DT_REG;
|
|
|
|
}
|
2013-06-26 22:30:40 +08:00
|
|
|
d->d_namlen = RT_NAME_MAX;
|
|
|
|
d->d_reclen = (rt_uint16_t)sizeof(struct dirent);
|
|
|
|
rt_strncpy(d->d_name, object->name, RT_NAME_MAX);
|
|
|
|
}
|
|
|
|
|
|
|
|
root_dirent->read_index += index;
|
|
|
|
|
|
|
|
return index * sizeof(struct dirent);
|
2011-10-08 22:50:08 +08:00
|
|
|
}
|
|
|
|
|
2023-04-08 22:25:51 +08:00
|
|
|
static int dfs_device_fs_poll(struct dfs_file *fd, struct rt_pollreq *req)
|
2011-10-08 22:50:08 +08:00
|
|
|
{
|
2017-10-15 22:44:53 +08:00
|
|
|
int mask = 0;
|
|
|
|
|
|
|
|
return mask;
|
|
|
|
}
|
2013-06-26 22:30:40 +08:00
|
|
|
|
2019-04-03 18:09:52 +08:00
|
|
|
static const struct dfs_file_ops _device_fops =
|
2017-10-15 22:44:53 +08:00
|
|
|
{
|
2013-06-26 22:30:40 +08:00
|
|
|
dfs_device_fs_open,
|
|
|
|
dfs_device_fs_close,
|
|
|
|
dfs_device_fs_ioctl,
|
|
|
|
dfs_device_fs_read,
|
|
|
|
dfs_device_fs_write,
|
2017-10-15 22:44:53 +08:00
|
|
|
RT_NULL, /* flush */
|
|
|
|
RT_NULL, /* lseek */
|
|
|
|
dfs_device_fs_getdents,
|
|
|
|
dfs_device_fs_poll,
|
|
|
|
};
|
|
|
|
|
2019-04-03 18:09:52 +08:00
|
|
|
static const struct dfs_filesystem_ops _device_fs =
|
2017-10-15 22:44:53 +08:00
|
|
|
{
|
|
|
|
"devfs",
|
|
|
|
DFS_FS_FLAG_DEFAULT,
|
|
|
|
&_device_fops,
|
|
|
|
dfs_device_fs_mount,
|
2021-05-21 17:50:57 +08:00
|
|
|
RT_NULL, /*unmount*/
|
|
|
|
RT_NULL, /*mkfs*/
|
2023-03-29 14:36:36 +08:00
|
|
|
dfs_device_fs_statfs,
|
2022-12-03 12:07:44 +08:00
|
|
|
dfs_device_fs_unlink,
|
2013-06-26 22:30:40 +08:00
|
|
|
dfs_device_fs_stat,
|
2021-05-21 17:50:57 +08:00
|
|
|
RT_NULL, /*rename*/
|
2011-10-08 22:50:08 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
int devfs_init(void)
|
|
|
|
{
|
2020-11-28 22:47:06 +08:00
|
|
|
/* register device file system */
|
2013-06-26 22:30:40 +08:00
|
|
|
dfs_register(&_device_fs);
|
2011-10-08 22:50:08 +08:00
|
|
|
|
2013-06-26 22:30:40 +08:00
|
|
|
return 0;
|
2011-10-08 22:50:08 +08:00
|
|
|
}
|