当前位置: 首页 > news >正文

许昌做网站哪家好亚马逊网站建设的目的

许昌做网站哪家好,亚马逊网站建设的目的,中国建设工程造价管理系统网站,自己如何建设刷赞网站简介#xff1a; CSDN博客专家#xff0c;专注Android/Linux系统#xff0c;分享多mic语音方案、音视频、编解码等技术#xff0c;与大家一起成长#xff01; 优质专栏#xff1a;Audio工程师进阶系列【原创干货持续更新中……】#x1f680; 优质专栏#xff1a;多媒… 简介 CSDN博客专家专注Android/Linux系统分享多mic语音方案、音视频、编解码等技术与大家一起成长 优质专栏Audio工程师进阶系列【原创干货持续更新中……】 优质专栏多媒体系统工程师系列【原创干货持续更新中……】 人生格言 人生从来没有捷径只有行动才是治疗恐惧和懒惰的唯一良药. 更多原创,欢迎关注Android系统攻城狮 1.前言 本篇目的Linux内核之debugfs_create_dir与debugfs_create_file实例与调用栈流程 2.Linux内核之debugfs_create_dir与debugfs_create_file函数介绍 Linux内核提供了丰富的调试和监控功能其中debugfs是内核调试的一个非常有用的接口。debugfs是一个虚拟文件系统专门用于内核调试信息。开发者可以通过它来创建、读取、写入和删除文件以此来获取和设置内核的调试信息。debugfs_create_dir和debugfs_create_file是debugfs提供的两个关键函数用于在内核中创建目录和文件。 debugfs_create_dir debugfs_create_dir函数用于在debugfs文件系统中创建一个新目录。这个函数在内核中的定义大致如下 int debugfs_create_dir(const char *name, struct dentry *parent);const char *name: 要创建的目录的名称。struct dentry *parent: 父目录的 dentry 结构。 返回值是一个整数表示操作的结果。如果成功返回0如果有错误返回一个负值。 创建目录的流程大致是 调用debugfs_create_dir函数。函数内部会使用kmalloc分配内存创建一个dir_operations结构体并设置该结构体中的必要函数指针比如lookup、for_each_child等。调用debugfs_create_file函数来创建这个目录下的文件。将这个目录的dentry结构添加到父目录的dentry链表中。将这个目录的inode结构设置为可写并将其添加到debugfs的目录树中。 debugfs_create_file debugfs_create_file函数用于在debugfs文件系统中创建一个新文件。这个函数在内核中的定义大致如下 int debugfs_create_file(const char *name, umode_t mode, struct dentry *parent,void *data, const struct file_operations *fops);const char *name: 要创建的文件的名称。umode_t mode: 文件的权限模式。struct dentry *parent: 父目录的 dentry 结构。void *data: 传递给文件操作的私有数据。const struct file_operations *fops: 文件操作结构体包含了文件操作的函数指针。 返回值同debugfs_create_dir。 创建文件的流程大致是 调用debugfs_create_file函数。函数内部会使用kmalloc分配内存创建一个file_operations结构体并设置该结构体中的必要函数指针比如read、write、open、release等。调用者需要提供这个文件的file_operations结构体和私有数据。函数将这个文件的dentry结构添加到父目录的dentry链表中。函数创建这个文件的inode结构并将其添加到debugfs的目录树中。 通过这两个函数开发者可以在内核中方便地创建用于调试和监控的目录和文件。这些目录和文件可以用来存储内核的调试信息或者作为内核模块之间的通信媒介。这对于内核开发和故障排查都是非常有益的。 3.代码实例 1.debugfs_create_dir创建目录驱动例子 #include linux/module.h #include linux/fs.h #include linux/debugfs.h #include linux/uaccess.h#define MY_DEBUGFS_DIR my_debugfs static int my_debugfs_create_dir_handler(struct dentry *parent, const char *name) {int ret;struct dentry *debugfs_dir;debugfs_dir debugfs_create_dir(name, parent);if IS_ERR(debugfs_dir)) {ret PTR_ERR(debugfs_dir);printk(KERN_ERR Failed to create debugfs directory: %d\n, ret);return ret;}return 0; }int __init my_debugfs_init(void) {struct dentry *debugfs_root;debugfs_root debugfs_create_dir(my_module, NULL);if IS_ERR(debugfs_root)) {printk(KERN_ERR Failed to create debugfs root directory\n);return PTR_ERR(debugfs_root);}// 创建 debugfs 目录my_debugfs_create_dir_handler(debugfs_root, MY_DEBUGFS_DIR);return 0; }void __exit my_debugfs_exit(void) { } MODULE_LICENSE(GPL); 2.debugfs_create_file创建文件驱动例子 #include linux/module.h #include linux/fs.h #include linux/debugfs.h #include linux/uaccess.h#define MY_DEBUGFS_FILE my_file static int my_debugfs_read_handler(struct file *file, char __user *buffer, size_t length, loff_t *offset) {// 实现读取逻辑return length; }static int my_debugfs_write_handler(struct file *file, const char __user *buffer, size_t length, loff_t *offset) {// 实现写入逻辑return length; }static const struct file_operations my_debugfs_fops {.read my_debugfs_read_handler,.write my_debugfs_write_handler, };int __init my_debugfs_init(void) {struct dentry *debugfs_root;debugfs_root debugfs_create_dir(my_module, NULL);if IS_ERR(debugfs_root)) {printk(KERN_ERR Failed to create debugfs root directory\n);return PTR_ERR(debugfs_root);}// 创建 debugfs 文件debugfs_create_file(MY_DEBUGFS_FILE, 0644, debugfs_root, NULL, my_debugfs_fops);return 0; }void __exit my_debugfs_exit(void) { }MODULE_LICENSE(GPL); 4.debugfs_create_dir函数调用栈流程 1.debugfs_create_dir调用流程 private/msm-google/fs/debugfs/inode.c struct dentry *debugfs_create_dir(const char *name, struct dentry *parent) {struct dentry *dentry start_creating(name, parent);struct inode *inode;if (IS_ERR(dentry))return NULL;inode debugfs_get_inode(dentry-d_sb);if (unlikely(!inode))return failed_creating(dentry);inode-i_mode S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;inode-i_op simple_dir_inode_operations;inode-i_fop simple_dir_operations;/* directory inodes start off with i_nlink 2 (for . entry) */inc_nlink(inode);d_instantiate(dentry, inode);inc_nlink(d_inode(dentry-d_parent));fsnotify_mkdir(d_inode(dentry-d_parent), dentry);return end_creating(dentry); } simple_dir_inode_operations设置权限 simple_dir_operations回调函数设置目录 2.simple_dir_operations回调函数实现 const struct file_operations simple_dir_operations {.open dcache_dir_open,.release dcache_dir_close,.llseek dcache_dir_lseek,.read generic_read_dir,.iterate_shared dcache_readdir,.fsync noop_fsync, };3.dcache_dir_open实现 int dcache_dir_open(struct inode *inode, struct file *file) {file-private_data d_alloc_cursor(file-f_path.dentry);return file-private_data ? 0 : -ENOMEM; }4.dcache_readdir实现 int dcache_readdir(struct file *file, struct dir_context *ctx) {struct dentry *dentry file-f_path.dentry;struct dentry *cursor file-private_data;struct list_head *anchor dentry-d_subdirs;struct dentry *next NULL;struct list_head *p;if (!dir_emit_dots(file, ctx))return 0;if (ctx-pos 2)p anchor;elsep cursor-d_child;while ((p scan_positives(cursor, p, 1, next)) ! anchor) {if (!dir_emit(ctx, next-d_name.name, next-d_name.len,d_inode(next)-i_ino, dt_type(d_inode(next))))break;ctx-pos;}spin_lock(dentry-d_lock);list_move_tail(cursor-d_child, p);spin_unlock(dentry-d_lock);dput(next);return 0; } 5.debugfs_create_file函数调用栈流程 1.debugfs_create_file调用流程 private/msm-google/fs/debugfs/inode.c static struct dentry *__debugfs_create_file(const char *name, umode_t mode,struct dentry *parent, void *data,const struct file_operations *proxy_fops,const struct file_operations *real_fops) {struct dentry *dentry;struct inode *inode;if (!(mode S_IFMT))mode | S_IFREG;BUG_ON(!S_ISREG(mode));dentry start_creating(name, parent);if (IS_ERR(dentry))return NULL;inode debugfs_get_inode(dentry-d_sb);if (unlikely(!inode))return failed_creating(dentry);inode-i_mode mode;inode-i_private data;inode-i_fop proxy_fops;dentry-d_fsdata (void *)((unsigned long)real_fops |DEBUGFS_FSDATA_IS_REAL_FOPS_BIT);d_instantiate(dentry, inode);fsnotify_create(d_inode(dentry-d_parent), dentry);return end_creating(dentry); } simple_pin_fs挂载文件系统 2.simple_pin_fs挂载文件系统 int simple_pin_fs(struct file_system_type *type, struct vfsmount **mount, int *count) {struct vfsmount *mnt NULL;spin_lock(pin_fs_lock);if (unlikely(!*mount)) {spin_unlock(pin_fs_lock);mnt vfs_kern_mount(type, SB_KERNMOUNT, type-name, NULL);if (IS_ERR(mnt))return PTR_ERR(mnt);spin_lock(pin_fs_lock);if (!*mount)*mount mnt;}mntget(*mount);*count;spin_unlock(pin_fs_lock);mntput(mnt);return 0; } 调用vfs_kern_mount挂载文件系统 3.vfs_kern_mount struct vfsmount * vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data) {struct mount *mnt;struct dentry *root;if (!type)return ERR_PTR(-ENODEV);mnt alloc_vfsmnt(name);if (!mnt)return ERR_PTR(-ENOMEM);if (type-alloc_mnt_data) {mnt-mnt.data type-alloc_mnt_data();if (!mnt-mnt.data) {mnt_free_id(mnt);free_vfsmnt(mnt);return ERR_PTR(-ENOMEM);}}if (flags SB_KERNMOUNT)mnt-mnt.mnt_flags MNT_INTERNAL;root mount_fs(type, flags, name, mnt-mnt, data);if (IS_ERR(root)) {mnt_free_id(mnt);free_vfsmnt(mnt);return ERR_CAST(root);}mnt-mnt.mnt_root root;mnt-mnt.mnt_sb root-d_sb;mnt-mnt_mountpoint mnt-mnt.mnt_root;mnt-mnt_parent mnt;lock_mount_hash();list_add_tail(mnt-mnt_instance, root-d_sb-s_mounts);unlock_mount_hash();return mnt-mnt; } 调用mount_fs函数 4.mount_fs函数 struct dentry * mount_fs(struct file_system_type *type, int flags, const char *name, struct vfsmount *mnt, void *data) {struct dentry *root;struct super_block *sb;char *secdata NULL;int error -ENOMEM;if (data !(type-fs_flags FS_BINARY_MOUNTDATA)) {secdata alloc_secdata();if (!secdata)goto out;error security_sb_copy_data(data, secdata);if (error)goto out_free_secdata;}if (type-mount2)root type-mount2(mnt, type, flags, name, data);elseroot type-mount(type, flags, name, data);if (IS_ERR(root)) {error PTR_ERR(root);goto out_free_secdata;}sb root-d_sb;BUG_ON(!sb);WARN_ON(!sb-s_bdi);smp_wmb();sb-s_flags | SB_BORN;error security_sb_kern_mount(sb, flags, secdata);if (error)goto out_sb;WARN((sb-s_maxbytes 0), %s set sb-s_maxbytes to negative value (%lld)\n, type-name, sb-s_maxbytes);up_write(sb-s_umount);free_secdata(secdata);return root; out_sb:dput(root);deactivate_locked_super(sb); out_free_secdata:free_secdata(secdata); out:return ERR_PTR(error); } 5.debugfs_get_inode获取节点信息 static struct inode *debugfs_get_inode(struct super_block *sb) {struct inode *inode new_inode(sb);if (inode) {inode-i_ino get_next_ino();inode-i_atime inode-i_mtime inode-i_ctime current_time(inode);}return inode; } 6.new_inode创建一个节点 struct inode *new_inode(struct super_block *sb) {struct inode *inode;spin_lock_prefetch(sb-s_inode_list_lock);inode new_inode_pseudo(sb);if (inode)inode_sb_list_add(inode);return inode; }
http://www.pierceye.com/news/356528/

相关文章:

  • 网站直播用php怎么做的书城网站开发的参考文献
  • 广州免费自助建站平台韩国出线了吗
  • asp.net网站开发实训爆款采集推广引流软件
  • 怎么把自己做的网站挂到外网上中文 网站模板
  • 篮球运动装备网站模板昆明网站seo多少钱
  • 建筑网站起名wordpress评论折叠
  • 东莞seo网站推广建设抖音开放平台注册
  • 怎么做淘宝客采集网站建设局考试通知文件网站
  • 百度云网站建设视频教程超市网站设计
  • 主机屋 建网站教程wordpress收费会员插件
  • 天津网站建设的公司哪家好shopify和wordpress
  • 网站设计风格评价天元建设集团有限公司 伊永成
  • 望都网站建设山东的互联网公司都有什么
  • 开发一个网站需要多少人邢台网站建设服务商
  • 钦州建设局网站seo网站关键词优化机构
  • 北京工程信息网站网站建设及管理使用情况汇报
  • 网页网站原型图占位符怎么做公司宣传策划方案
  • 企业网站颜色选择wordpress自然志下载
  • 介绍几个网站重庆网站建设微信开发
  • wordpress小工具跟随最新外贸seo
  • 网站域名的密码电子商务网站策划书3500字
  • 2008 iis 添加 网站 权限设置权限网站开发工程师题
  • 公司域名查询网站网页设计工具软件有哪些
  • 毕业设计网站建设选题依据设计公司网站应该包括的信息
  • wordpress 仪表板主题seo网站排名厂商定制
  • 网站建设成本报表wordpress缺点
  • 外贸建站选择哪个服务器好免费自动生成二维码
  • 建设部申请自己网站c 做网站设计
  • 软件制作网站网站维护合同模板
  • 那家财经网站做的好陕西网站建设公司哪有