mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-11 21:36:46 +00:00
调整:devfs注册设备后,返回指向inode私有信息的指针
This commit is contained in:
parent
0435eb00b1
commit
0e624b1fcf
@ -205,7 +205,7 @@ void ps2_keyboard_init()
|
|||||||
// 先读一下键盘的数据,防止由于在键盘初始化之前,由于按键被按下从而导致接收不到中断。
|
// 先读一下键盘的数据,防止由于在键盘初始化之前,由于按键被按下从而导致接收不到中断。
|
||||||
io_in8(PORT_PS2_KEYBOARD_DATA);
|
io_in8(PORT_PS2_KEYBOARD_DATA);
|
||||||
// 将设备挂载到devfs
|
// 将设备挂载到devfs
|
||||||
devfs_register_device(DEV_TYPE_CHAR, CHAR_DEV_STYPE_PS2_KEYBOARD, &ps2_keyboard_fops);
|
devfs_register_device(DEV_TYPE_CHAR, CHAR_DEV_STYPE_PS2_KEYBOARD, &ps2_keyboard_fops, NULL);
|
||||||
kinfo("ps/2 keyboard registered.");
|
kinfo("ps/2 keyboard registered.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include <filesystem/VFS/VFS.h>
|
#include <filesystem/VFS/VFS.h>
|
||||||
#include "tty.h"
|
#include "tty.h"
|
||||||
|
|
||||||
|
static struct devfs_private_inode_info_t * tty_inode_private_data_ptr; // 由devfs创建的inode私有信息指针
|
||||||
static int tty_private_data;
|
static int tty_private_data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -87,6 +88,6 @@ struct vfs_file_operations_t tty_fops={
|
|||||||
|
|
||||||
void tty_init(){
|
void tty_init(){
|
||||||
//注册devfs
|
//注册devfs
|
||||||
devfs_register_device(DEV_TYPE_CHAR, CHAR_DEV_STYPE_TTY, &tty_fops);
|
devfs_register_device(DEV_TYPE_CHAR, CHAR_DEV_STYPE_TTY, &tty_fops, &tty_inode_private_data_ptr);
|
||||||
kinfo("tty driver registered.");
|
kinfo("tty driver registered. uuid=%d", tty_inode_private_data_ptr->uuid);
|
||||||
}
|
}
|
@ -42,4 +42,5 @@ struct devfs_private_inode_info_t
|
|||||||
uint16_t type; // 设备主类型
|
uint16_t type; // 设备主类型
|
||||||
uint16_t sub_type; // 设备子类型
|
uint16_t sub_type; // 设备子类型
|
||||||
struct vfs_file_operations_t *f_ops;
|
struct vfs_file_operations_t *f_ops;
|
||||||
|
uint64_t uuid;
|
||||||
};
|
};
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <common/glib.h>
|
#include <common/glib.h>
|
||||||
#include <common/string.h>
|
#include <common/string.h>
|
||||||
#include <mm/slab.h>
|
#include <mm/slab.h>
|
||||||
|
#include <common/spinlock.h>
|
||||||
|
|
||||||
struct vfs_super_block_operations_t devfs_sb_ops;
|
struct vfs_super_block_operations_t devfs_sb_ops;
|
||||||
struct vfs_dir_entry_operations_t devfs_dentry_ops;
|
struct vfs_dir_entry_operations_t devfs_dentry_ops;
|
||||||
@ -14,6 +15,15 @@ struct vfs_dir_entry_t *devfs_root_dentry; // 根结点的dentry
|
|||||||
struct vfs_superblock_t devfs_sb = {0};
|
struct vfs_superblock_t devfs_sb = {0};
|
||||||
const char __devfs_mount_path[] = "/dev";
|
const char __devfs_mount_path[] = "/dev";
|
||||||
|
|
||||||
|
static spinlock_t devfs_global_lock; // devfs的全局锁
|
||||||
|
static uint64_t __tmp_uuid = 0; // devfs的临时uuid变量(todo:在引入uuid lib之后删除这里)
|
||||||
|
|
||||||
|
static inline uint64_t __devfs_get_uuid()
|
||||||
|
{
|
||||||
|
// todo : 更改为使用uuid库来生成uuid
|
||||||
|
return ++__tmp_uuid;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 创建devfs的super block
|
* @brief 创建devfs的super block
|
||||||
*
|
*
|
||||||
@ -208,16 +218,19 @@ static __always_inline void __devfs_init_root_dentry()
|
|||||||
* @param device_type 设备主类型
|
* @param device_type 设备主类型
|
||||||
* @param sub_type 设备子类型
|
* @param sub_type 设备子类型
|
||||||
* @param file_ops 设备的文件操作接口
|
* @param file_ops 设备的文件操作接口
|
||||||
|
* @param ret_private_inode_info_ptr 返回的指向inode私有信息结构体的指针
|
||||||
* @return int 错误码
|
* @return int 错误码
|
||||||
*/
|
*/
|
||||||
int devfs_register_device(uint16_t device_type, uint16_t sub_type, struct vfs_file_operations_t *file_ops)
|
int devfs_register_device(uint16_t device_type, uint16_t sub_type, struct vfs_file_operations_t *file_ops, struct devfs_private_inode_info_t **ret_private_inode_info_ptr)
|
||||||
{
|
{
|
||||||
|
spin_lock(&devfs_global_lock);
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
// 申请private info结构体
|
// 申请private info结构体
|
||||||
struct devfs_private_inode_info_t *private_info = (struct devfs_private_inode_info_t *)kzalloc(sizeof(struct devfs_private_inode_info_t), 0);
|
struct devfs_private_inode_info_t *private_info = (struct devfs_private_inode_info_t *)kzalloc(sizeof(struct devfs_private_inode_info_t), 0);
|
||||||
private_info->f_ops = file_ops;
|
private_info->f_ops = file_ops;
|
||||||
private_info->type = device_type;
|
private_info->type = device_type;
|
||||||
private_info->sub_type = sub_type;
|
private_info->sub_type = sub_type;
|
||||||
|
private_info->uuid = __devfs_get_uuid();
|
||||||
|
|
||||||
struct vfs_dir_entry_t *dentry = NULL; // 该指针由对应类型设备的注册函数设置
|
struct vfs_dir_entry_t *dentry = NULL; // 该指针由对应类型设备的注册函数设置
|
||||||
|
|
||||||
@ -233,10 +246,14 @@ int devfs_register_device(uint16_t device_type, uint16_t sub_type, struct vfs_fi
|
|||||||
goto failed;
|
goto failed;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (ret_private_inode_info_ptr != NULL)
|
||||||
|
*ret_private_inode_info_ptr = private_info;
|
||||||
|
|
||||||
|
spin_unlock(&devfs_global_lock);
|
||||||
return retval;
|
return retval;
|
||||||
failed:;
|
failed:;
|
||||||
kfree(private_info);
|
kfree(private_info);
|
||||||
|
spin_unlock(&devfs_global_lock);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,9 +265,8 @@ void devfs_init()
|
|||||||
{
|
{
|
||||||
__devfs_init_root_dentry();
|
__devfs_init_root_dentry();
|
||||||
vfs_register_filesystem(&devfs_fs_type);
|
vfs_register_filesystem(&devfs_fs_type);
|
||||||
|
spin_init(&devfs_global_lock);
|
||||||
vfs_mount_fs(__devfs_mount_path, "DEVFS", NULL);
|
vfs_mount_fs(__devfs_mount_path, "DEVFS", NULL);
|
||||||
|
|
||||||
__devfs_chardev_init();
|
__devfs_chardev_init();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -14,6 +14,7 @@ void devfs_init();
|
|||||||
* @param device_type 设备主类型
|
* @param device_type 设备主类型
|
||||||
* @param sub_type 设备子类型
|
* @param sub_type 设备子类型
|
||||||
* @param file_ops 设备的文件操作接口
|
* @param file_ops 设备的文件操作接口
|
||||||
|
* @param ret_private_inode_info_ptr 返回的指向inode私有信息结构体的指针
|
||||||
* @return int 错误码
|
* @return int 错误码
|
||||||
*/
|
*/
|
||||||
int devfs_register_device(uint16_t device_type, uint16_t sub_type, struct vfs_file_operations_t *file_ops);
|
int devfs_register_device(uint16_t device_type, uint16_t sub_type, struct vfs_file_operations_t *file_ops, struct devfs_private_inode_info_t **ret_private_inode_info_ptr);
|
@ -13,6 +13,7 @@
|
|||||||
#include <exception/gate.h>
|
#include <exception/gate.h>
|
||||||
#include <filesystem/fat32/fat32.h>
|
#include <filesystem/fat32/fat32.h>
|
||||||
#include <filesystem/devfs/devfs.h>
|
#include <filesystem/devfs/devfs.h>
|
||||||
|
#include <filesystem/rootfs/rootfs.h>
|
||||||
#include <mm/slab.h>
|
#include <mm/slab.h>
|
||||||
#include <common/spinlock.h>
|
#include <common/spinlock.h>
|
||||||
#include <syscall/syscall.h>
|
#include <syscall/syscall.h>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user