linux 内核 虚拟文件系统VFS 路径查找 path_lookup

Linux结构体--path Linux内核结构体 path struct path { struct vfsmount *mnt; struct dentry *dentry; }; vfsmount struct vfsmount { struct list_head mnt_hash; struct vfsmount *mnt_parent; /* fs we are mounted on */ ... 阅读详情

路径查找是VFS的一个主要操作:给定一个文件名,获取该文件名的inode。路径查找是VFS中相当繁琐的一部分,主要是符号链接,文件系统装载点,以及. ..和//等奇怪路径 引入了复杂性。

 

nameidata数据结构

查找过程涉及到很多函数调用,在这些调用过程中,nameidata起到了很重要的作用:1. 向查找函数传递参数;2. 保存查找结果。

struct nameidata
{
    struct dentry *	 dentry;
    struct vfsmount *mnt;
    struct qstr		 last;
    unsigned int	 flags;
    int				 last_type;
    unsigneddepth;
    char *saved_names[MAX_NESTED_LINKS + 1];

    /* Intent data */
    union
    {
        struct open_intent open;
    } intent;
};

查找完成后@dentry 包含了找到文件的dentry目录项; @mnt 包含了文件目录项所在的vfsmount

@last 包含了需要查找的名称,这是一个快速字符串,除了路径字符串本身外,还包含字符串的长度和一个散列值

@depth 当前路径深度。

@saved_names: 由于在符号链接处理时,nd的名字一直发生变化,这里用来保存符号链接处理中的路径名

内核路径查找的函数很多,我们这里以 path_lookup为列,内核版本2.6.24

 

path_lookup

int fastcall path_lookup(const char *name, unsigned int flags, struct nameidata *nd)
{
    return do_path_lookup(AT_FDCWD, name, flags, nd);
}

给定三个参数@name是文件路径名(可以是全路径,也可以是相对路径名);@flags路径查找标记;@nd此时不包含任何有用信息,用来返回查找结果。

 

do_path_lookup

1119 static int fastcall do_path_lookup(int dfd, const char *name,
1120                                 unsigned int flags, struct nameidata *nd)
1121 {
1122         int retval = 0;
1123         int fput_needed;
1124         struct file *file;
1125         struct fs_struct *fs = current->fs;
1126 
1127         nd->last_type = LAST_ROOT; /* if there are only slashes... */
1128         nd->flags = flags;
1129         nd->depth = 0;
1130 
1131         if (*name=='/') {
1132                 read_lock(&fs->lock);
1133                 if (fs->altroot && !(nd->flags & LOOKUP_NOALT)) {
1134                         nd->mnt = mntget(fs->altrootmnt);
1135                         nd->dentry = dget(fs->altroot);
1136                         read_unlock(&fs->lock);
1137                         if (__emul_lookup_dentry(name,nd))
1138                                 goto out; /* found in altroot */
1139                         read_lock(&fs->lock);
1140                 }
1141                 nd->mnt = mntget(fs->rootmnt);
1142                 nd->dentry = dget(fs->root);
1143                 read_unlock(&fs->lock);
1144         } else if (dfd == AT_FDCWD) {
1145                 read_lock(&fs->lock);
1146                 nd->mnt = mntget(fs->pwdmnt);
1147                 nd->dentry = dget(fs->pwd);
1148                 read_unlock(&fs->lock);
1149         } else {
1150                 struct dentry *dentry;
1151 
1152                 file = fget_light(dfd, &fput_needed);
1153                 retval = -EBADF;
1154                 if (!file)
1155                         goto out_fail;
1157                 dentry = file->f_path.dentry;
1158 
1159                 retval = -ENOTDIR;
1160                 if (!S_ISDIR(dentry->d_inode->i_mode))
1161                         goto fput_fail;
1162 
1163                 retval = file_permission(file, MAY_EXEC);
1164                 if (retval)
1165                         goto fput_fail;
1166 
1167                 nd->mnt = mntget(file->f_path.mnt);
1168                 nd->dentry = dget(dentry);
1169 
1170                 fput_light(file, fput_needed);
1171         }
1172 
1173         retval = path_walk(name, nd);
1174 out:
1175         if (unlikely(!retval && !audit_dummy_context() && nd->dentry &&
1176                                 nd->dentry->d_inode))
1177                 audit_inode(name, nd->dentry);
1178 out_fail:
1179         return retval;
1180 
1181 fput_fail:
1182         fput_light(file, fput_needed);
1183         goto out_fail;
1184 }

这个函数有一点长,但是逻辑很清楚,即为调用path_walk做准备,在进入do_path_lookup函数时,参数@nd不包含任何有用信息,而调用path_walk时,@nd则包含了查找起始点信息

因此从1127~1171行就是准备查找起始点的过程,这里分为三种情况:

1. 1131~1143 文件名包含绝对路径,因此我们优先使用文件系统的根目录作为查找起始点

2. 1144 ~ 1148 路径不是绝对路径,我们指定从当前目录开始开始查找

3. 1149 ~ 1171 函数第一个参数@dfd是一个目录文件描述符,我们就从这个目录开始查找。

1173 一切就绪,调用path_walk开始查找。

 

path_walk

1042 static int fastcall path_walk(const char * name, struct nameidata *nd)
1043 {
1044         current->total_link_count = 0;
1045         return link_path_walk(name, nd);
1046 }

符号链接是需要特殊处理的,一般情况下我们都会跟踪链接,如果没有符号链接,那么文件系统的必定是一个完美的树结构,符号链接使得这棵树不那么完美,有时可能会导致树内存在循环,所以路径查询时,会对跟进符号链接的数目有一个最大限制,2.6.24硬编码为40

1044 在开始一次新查找之前,我们初始化为0

 

link_path_walk

1018 static int fastcall link_path_walk(const char *name, struct nameidata *nd)
1019 {
1020         struct nameidata save = *nd;
1021         int result;
1022 
1023         /* make sure the stuff we saved doesn't go away */
1024         dget(save.dentry);
1025         mntget(save.mnt);
1026 
1027         result = __link_path_walk(name, nd);
1028         if (result == -ESTALE) {
1029                 *nd = save;
1030                 dget(nd->dentry);
1031                 mntget(nd->mnt);
1032                 nd->flags |= LOOKUP_REVAL;
1033                 result = __link_path_walk(name, nd);
1034         }
1035 
1036         dput(save.dentry);
1037         mntput(save.mnt);
1038 
1039         return result;
1040 }

这个函数看起来也有点烦,主要是有的函数会返回ESTALE错误,此时需要重新执行路径查找,并且不要使用dcache。

我们这里不care这种特殊情况,因此只需要考虑__link_path_walk

 

__link_path_walk

这个函数接近200行,超出了我的大脑空间处理能力,因此分段阅读

 826 static fastcall int __link_path_walk(const char * name, struct nameidata *nd)
 827 {
 828         struct path next;
 829         struct inode *inode;
 830         int err;
 831         unsigned int lookup_flags = nd->flags;
 832 
 833         while (*name=='/')
 834                 name++;
 835         if (!*name)
 836                 goto return_reval;
 837 
 838         inode = nd->dentry->d_inode;
 839         if (nd->depth)
 840                 lookup_flags = LOOKUP_FOLLOW | (nd->flags & LOOKUP_CONTINUE);

833~836首先处理掉路径名前的/,

紧接着是一个大的循环,逐个路径分量进行处理。@name在循环内分解为各个路径分量。每个分量表示一个路径名。下图给出了代码流程图

权限检查

 848                 nd->flags |= LOOKUP_CONTINUE;
 849                 err = exec_permission_lite(inode, nd);
 850                 if (err == -EAGAIN)
 851                         err = vfs_permission(nd, MAY_EXEC);
 852                 if (err)
 853                         break;


计算路径分量hash

 855                 this.name = name;
 856                 c = *(const unsigned char *)name;
 857 
 858                 hash = init_name_hash();
 859                 do {
 860                         name++;
 861                         hash = partial_name_hash(c, hash);
 862                         c = *(const unsigned char *)name;
 863                 } while (c && (c != '/'));
 864                 this.len = name - (const char *) this.name;
 865                 this.hash = end_name_hash(hash);

 

处理.和..

 874                 /*
 875                  * "." and ".." are special - ".." especially so because it has
 876                  * to be able to know about the current root directory and
 877                  * parent relationships.
 878                  */
 879                 if (this.name[0] == '.') switch (this.len) {
 880                         default:
 881                                 break;
 882                         case 2:
 883                                 if (this.name[1] != '.')
 884                                         break;
 885                                 follow_dotdot(nd);
 886                                 inode = nd->dentry->d_inode;
 887                                 /* fallthrough */
 888                         case 1:
 889                                 continue;
 890                 }

“.”表示当前路径,那么我们只需略过这个路径分量,开始处理下一个路径分量即可。

".."表示回到父目录,调用follow_dotdot即可,follow_dotdot并不像看起来那么简单,因为还要考虑安装点的存在

 

重新计算hash

 891                 /*
 892                  * See if the low-level filesystem might want
 893                  * to use its own hash..
 894                  */
 895                 if (nd->dentry->d_op && nd->dentry->d_op->d_hash) {
 896                         err = nd->dentry->d_op->d_hash(nd->dentry, &this);
 897                         if (err < 0)
 898                                 break;
 899                 }

有些文件系统有他们自己的hash计算函数,比如fat文件系统并不区分大小写字母,因此hash函数需要做相应更改。
 

do_lookup

 900                 /* This does the actual lookups.. */
 901                 err = do_lookup(nd, &this, &next);
 902                 if (err)
 903                         break;

这个函数后面会重点介绍

 

处理符号链接

 913                 if (inode->i_op->follow_link) {
 914                         err = do_follow_link(&next, nd);
 915                         if (err)
 916                                 goto return_err;
 917                         err = -ENOENT;
 918                         inode = nd->dentry->d_inode;
 919                         if (!inode)
 920                                 break;
 921                         err = -ENOTDIR;
 922                         if (!inode->i_op)
 923                                 break;
 924                 } else
 925                         path_to_nameidata(&next, nd);

当inode->i_op->follow_link不为空时,说明这个inode对应的文件是一个符号链接文件,否则必定为空

do_follow_link用来处理符号链接的情况

924~925 不为符号链接,那么把next的结果赋给返回值@nd

 

do_lookup

 779 /*
 780  *  It's more convoluted than I'd like it to be, but... it's still fairly
 781  *  small and for now I'd prefer to have fast path as straight as possible.
 782  *  It _is_ time-critical.
 783  */
 784 static int do_lookup(struct nameidata *nd, struct qstr *name,
 785                      struct path *path)
 786 {
 787         struct vfsmount *mnt = nd->mnt;
 788         struct dentry *dentry = __d_lookup(nd->dentry, name);
 789 
 790         if (!dentry)
 791                 goto need_lookup;
 792         if (dentry->d_op && dentry->d_op->d_revalidate)
 793                 goto need_revalidate;
 794 done:
 795         path->mnt = mnt;
 796         path->dentry = dentry;
 797         __follow_mount(path);
 798         return 0;
 799 
 800 need_lookup:
 801         dentry = real_lookup(nd->dentry, name, nd);
 802         if (IS_ERR(dentry))
 803                 goto fail;
 804         goto done;
 805 
 806 need_revalidate:
 807         dentry = do_revalidate(dentry, nd);
 808         if (!dentry)
 809                 goto need_lookup;
 810         if (IS_ERR(dentry))
 811                 goto fail;
 812         goto done;
 813 
 814 fail:
 815         return PTR_ERR(dentry);
 816 }

@nd 是输入参数,这个结构指定了查找的父目录项以及它所在的vfsmount

@name 输入参数,指定了路径分量名称。

@path 输出参数,保存查找结果。

788 在dentry cache中根据父dentry和路径分量名称查找,如果找到则在标号done中对path赋值,__follow_mount处理装载点的情况

790 如果没有在dentry cache中找到,那么就要调用底层文件系统的lookup进行查找了,real_lookup会调用底层lookup函数

792 如果存在dentry->d_op->d_revalidate,那么dentry cache中的目录项不一定是最新的,VFS并没有实现这个函数,但是为底层文件系统提供了这个接口,比如NFS文件系统,可能会导致本地dentry cache和远程文件内容不同步,我们不care这种情况。

 

__follow_mount

follow mount有两个版本,__follow_mount和follow_mount,差别不大。分析一个,另外一个其义自现

 689 /* no need for dcache_lock, as serialization is taken care in
 690  * namespace.c
 691  */
 692 static int __follow_mount(struct path *path)
 693 {
 694         int res = 0;
 695         while (d_mountpoint(path->dentry)) {
 696                 struct vfsmount *mounted = lookup_mnt(path->mnt, path->dentry);
 697                 if (!mounted)
 698                         break;
 699                 dput(path->dentry);
 700                 if (res)
 701                         mntput(path->mnt);
 702                 path->mnt = mounted;
 703                 path->dentry = dget(mounted->mnt_root);
 704                 res = 1;
 705         }
 706         return res;
 707 }

这个函数代码非常的简单,复杂在于其中隐含的概念。不过很难讲清楚,有点 只可意会,不可言传的意思。

我们知道,lookup的查找路径上可能存在着安装点,举个例子:

/mnt/sdcard/sd1是一个路径,有一个sd卡内部有文件file1 file2等,我们把一个sd卡mount到/mnt/sdcard/sd1/上。

此时我们的lookup查找/mnt/sdcard/sd1/file1,当我们查找到/mnt/sdcard/sd1时,我们得到的是根文件系统的vfsmount以及/mnt/sdcard/sd1的dentry,但是如果我们想要继续找到file1,那么我们一定要转为

sd1的vfsmount以及sd1的根dentry,才能继续查找file1.

ok, __follow_mount就是干的这个事情。循环是因为在sd1 mount到/mnt/sdcard/sd1之前,已经有其他设备也mount到/mnt/sdcard/sd1上了。

从这里,我们看到了 vfsmount的中要性了,因为dentry并不能唯一确定一个目录项,必须要由vfsmount和dentry二者共同确定,缺一不可。

 

do_follow_link

symlink和hardlink这小哥俩给文件系统引入了许多复杂性,hardlink对文件路径查找没有影响,symlink引入了一些麻烦

 637 /*
 638  * This limits recursive symlink follows to 8, while
 639  * limiting consecutive symlinks to 40.
 640  *
 641  * Without that kind of total limit, nasty chains of consecutive
 642  * symlinks can cause almost arbitrarily long lookups. 
 643  */
 644 static inline int do_follow_link(struct path *path, struct nameidata *nd)
 645 {
 646         int err = -ELOOP;
 647         if (current->link_count >= MAX_NESTED_LINKS)
 648                 goto loop;
 649         if (current->total_link_count >= 40)
 650                 goto loop;
 651         BUG_ON(nd->depth >= MAX_NESTED_LINKS);
 652         cond_resched();
 653         err = security_inode_follow_link(path->dentry, nd);
 654         if (err)
 655                 goto loop;
 656         current->link_count++;
 657         current->total_link_count++;
 658         nd->depth++;
 659         err = __do_follow_link(path, nd);
 660         current->link_count--;
 661         nd->depth--;
 662         return err;
 663 loop:
 664         dput_path(path, nd);
 665         path_release(nd);
 666         return err;
 667 }

在路径查找中,symlink文件本身,并不是查找的目录,查找目标是它所表示的文件路径。

为了防止路径死循环,以及那些很nasty的情况(nasty这个词只可意会,不可言传啊),linux允许最大递归次数是8次,最大连接数是40个

发生递归是656行还有可能调用到do_follow_link,因此如果递归次数超过8次,647就会返回ELOOP

 

 

Linux内核源代码分析 -- 路径查找 本文详细介绍了Linux内核中路径查找的实现机制,从`vfs_path_lookup`函数开始,逐步解析了路径查找过程中的关键函数如`path_init`、`link_path_walk`、`walk_component`和`lookup_last`。`path_init`初始化路径查找上下文并确定起始点;`link_path_walk`递归遍历路径组件,处理符号链接和特殊目录;`walk_component`负责具体路径组件的解析与查找;`lookup_last`处理路径最后一个组件 阅读详情

相关推荐

Linux内核源码分析--打开块设备文件--open_bdev_excl函数

本文主要参考《深入理解Linux内核》,结合2.6.11.1版的内核代码,分析内核文件子系统中的打开设备文件函数,梳理了关于内核块设备文件打开的处理流程。 注意: 1、不描述内核同步、错误处理相关的内容 2、参考信息除具体说明外,包含在《深入理解Linux内核》第三版中 3、源码摘自Linux内核2.6.11.1版 1、open_bdev_excl 函数功能: 打开设备名为path的

魏峰海的专栏 5206

理解linux虚拟文件系统VFS - 路径查找 path_lookup

VFS的一个主要操作,是给定一个文件名,获取该文件名的inode。路径查找是VFS中相当繁琐的一部分,主要是符号链接,文件系统装载点,已经. ..和//等奇怪路径带来了一些额外处理。 nameidata数据结构 查找过程涉及到很多函数调用,在这些调用过程中,nameidata起到了很重要的作用:1. 向查找函数传递参数;2. 保存查找结果。 struct nameidata {

kickxxx的专栏 1万+

VFS与Ext2文件系统------《深入Linux内核架构》笔记

1. VFS简介(Virtual File System, 虚拟文件系统) 在Linux内核中支持40多种文件系统,其来源也多种多样:来自MS-DOS的FAT文件系统, UFS(Berkeley UNIX), Ext2/3/4, 用于CD-ROM的iso9660, 网络文件系统(如coda和NFS)和虚拟的文件系统(如proc)。 Linux为了向用户空间(如C标准库)提供标准的接口,

daniel_ice的专栏 5614

linux path_lookup,Linux虚拟文件系统(4)-- 路径名查找

前言几乎所有Linux的文件操作,例,read、write、mkdir等都会涉及到路径名查找操作。而文件查找对Linux内核来说,主要指的是找到文件路径对应的Dentry节点。其主要过程就是对路径字符串进行一级级解析(以路径名中的.. , . , /等字符作为解析依据),找到路径的最后一级目录。若传入的路径字符串是以/开始的,那么查找会从系统根目录开始。否则,从当前工作目录开始查找。 然而,查找过...

weixin_29231221的博客 1209

Linux虚拟文件系统--文件路径名的解析(1)--整体过程

文件路径名的解析是VFS中最基本也是最频繁用到的一个部分,它的代码实现还是十分繁杂的,主要是因为除了普通文件名的解析,内核还要考虑各种可能出现的情况,如一个目录下挂载了多个文件系统,路径中的符号链接等等……后面我会分几次将整个过程进行一个尽量仔细的分析,其中所涉及到的各种数据结构在ULK等相关内核书籍上都有比较详细的介绍,就不列出来了        文件路径名的解析路口函数为path_looku

vanbreaker的专栏 6493

图解Linux虚拟文件系统(VFS)之挂载机制解析

本文深入解析Linux虚拟文件系统(VFS)的挂载机制,详细讲解挂载点索引、挂载实例创建和挂载对接三大核心环节。通过代码示例和实际案例,揭示VFS如何统一管理ext4、NTFS等不同文件系统,并探讨绑定挂载、命名空间隔离等高级应用场景,为系统开发和故障排查提供实用指导。

weixin_30357231的博客 492

【Linux】路径查找-path lookup

路径查找是Linux文件系统中一个频繁且重要的操作。通过路径查找,Linux内核能够高效地将用户提供的路径名转换为内核中的dentry结构。路径查找过程中的起始点和挂载点是影响查找结果的两个关键因素,内核通过符号链接和挂载树等机制处理路径中的特殊情况,使得路径查找可以在复杂的文件系统环境中高效、准确地工作。

qq_46063517的博客 4610

Linux内核VFS的open

open系统调用定义在内核源码目录fs/open.c里面参数:dfd 文件描述符filename 文件具体路径名字flags打开文件标志位,方式mode 权限控制位。

新时代农民工 322

vfs 中查找路径名的函数,具体实现和分析

• 当整个路径名解析完成后,link_path_walk()返回一个有效的dentry和inode,它们可以被后续的系统调用用于进一步的操作,如打开文件、读写数据等。• VFS利用dentry缓存来加速查找过程,dentry是一个轻量级的数据结构,它代表路径中的一个分量并关联到inode(即文件在磁盘上的唯一标识符)。• 每当查找一个新的路径分量时,VFS会首先检查dentry缓存是否存在匹配项,如果存在则直接复用,否则会进行实际的文件系统操作(如读取inode)。

bai915290475的博客 401

SAP 超详细解析信用控制

当然,集团内中国区、日本或欧洲区的公司使用了不同本位货币会计核算虽然分开,但对于客户的信用也可以统一管 理的,只要将这些不同本位币的公司代码纳入同一信用控制范围,信用控制范围货币可以考虑使用总部集团的货币,各公司代码的信用发生额自动根据系统设定汇率 转换为统一的信用控制范围货币。此步有一个“覆盖CC范 围”的选项,表示在过账时此步缺省的分配给公司代码的信用控制范围可以在其它信用控制范围使用,有时当一个公司代码的客户需要将信用数据过账到其它信用控 制区域,这个选择就非常有必要。

matinal 當冬夜漸暖 。公众号:matinal 1万+

图解Linux虚拟文件系统(VFS)之挂载实战篇

本文深入剖析Linux虚拟文件系统(VFS)的挂载机制,通过“嫁接树枝”的生动比喻,详解从路径查找、创建超级块到挂载实例对接的完整流程。核心阐述了VFS如何统一管理不同文件系统,并利用`struct mount`、`struct path`等关键数据结构实现精密的挂载操作,是理解Linux文件子系统运作的关键。

perl8的博客 449

Vivado2022.2下载安装

链接:https://pan.baidu.com/s/1lyfE2d-VmaWC-_aR8ratCQ提取码:mt09。

weixin_61081689的博客 2万+

Linux VFS 路径名查找

本文摘要:Linux内核路径查找机制解析了用户态路径字符串到内核dentry+inode+vfsmount的转换过程。核心流程包括确定查找起点、路径分量拆分、逐层查找(缓存/磁盘)和最终处理。采用RCU-walk(无锁快速)和REF-walk(安全慢速)双模式,处理符号链接、挂载点等复杂场景。关键数据结构包括dentry(路径分量映射)、nameidata(查找上下文)和path(文件系统位置)。该机制通过dcache缓存、并发锁和权限检查,高效安全地支撑open/stat等文件操作,是VFS的核心功能。

tangzhangyin的专栏 233

描述符链表(Descriptor Chain)是什么?

描述符链表是硬件加速数据传输的核心数据结构,通过链式描述符(包含地址、长度、控制标志等)实现DMA自动批量处理,显著降低CPU负载。其工作原理为:CPU初始化链表后,硬件按序处理每个描述符,完成自动跳转与中断通知。在网卡收包、NVMe存储等场景中应用广泛,优势包括批处理、低延迟和灵活调度。需注意内存对齐、缓存一致性等实现细节,优化手段包括预分配描述符池、环形缓冲区等。该技术是网络/存储领域提升吞吐量的关键方案。

guigenyi的专栏 781

4位无符号比较器设计

4位无符号比较器设计

好好学习,天天向上 7891

Linux VFS子系统深度解析:虚拟文件系统架构与实现

用户空间↓系统调用接口(open/read/write/close...)↓|虚拟文件系统(VFS)|| 文件对象(file) | 目录项(dentry)|| inode| 超级块(super_block)||页缓存管理| 路径查找||文件系统通知| 权限验证|↓具体文件系统实现(ext4/XFS/NFS/procfs...)↓设备驱动/网络协议栈/内核子系统统一抽象层:为应用程序提供一致的文件操作接口多文件系统支持:无缝集成数十种文件系统实现高性能访问。

niuTyler的博客 504

基于Python的新闻聚合与推荐系统:抓取多新闻网站内容并根据用户兴趣进行个性化推荐

本文介绍了如何使用Python构建一个新闻聚合与推荐系统,涵盖了从新闻数据抓取、用户兴趣建模到推荐算法实现的全过程。通过爬虫技术抓取新闻网站内容,使用TF-IDF、Word2Vec等算法进行内容分析,并通过推荐算法向用户推送个性化的新闻,最终帮助用户快速获取自己感兴趣的信息。你可以根据具体需求,进一步扩展和优化系统。例如,加入更多的推荐算法、优化爬虫的抓取效率、增强前端展示的互动性等。通过本文的指导,您应该能够构建一个完整的新闻聚合与推荐系统,并为用户提供个性化的新闻推荐服务。

2201_76125261的博客 1516

linux内核 文件系统 相关api

本文介绍了Linux内核中文件系统相关的API,主要分为两类:VFS通用接口和文件系统底层接口。详细阐述了内核文件操作的核心API,包括文件打开(filp_open)、关闭(filp_close)、读写(kernel_read/write)和定位(vfs_llseek)等函数;路径/inode操作API如path_lookup和kern_path;文件系统注册/挂载API;以及文件属性操作API。文章还解释了关键的内核结构体如file、inode、dentry等,并总结了不同场景下的API使用建议,为内核开

tangzhangyin的专栏 677

【异常】Cursor导入Karpathy指南失败解决方案Failed to import GitHub/GitLab rules: Error executing git: Cloning into

摘要:本文解决了Git克隆单个文件报错的问题,指出git clone只能克隆整个仓库而非单个文件。提供了两种解决方案:1) 推荐手动创建规则文件,在Cursor项目中新建.mdc文件并粘贴Karpathy行为指南完整内容;2) 备选克隆整个仓库获取文件。指南包含编码行为规范,强调简单性、精准修改和明确目标。还说明了如何设置全局规则和即时生效的方法。

奶爸的编程之路,也就一周冷个三天 181

29.Labview界面设计 --- (下篇)自定义控件库、界面布局与外观设计

1.自定义控件外观(自定义控件)1.1 自定义外观库1.2 手动自定义控件外观2. 前面板控件布局方式(控件排布)2.1 模块化控制布局方式2.2 数据采集布局方式3. 前面板外观优化项(背景设计)3.1 前面板背景设计3.2 前面板窗口整理本节第一部分教大家安装一种可以直接用的自定义控件库,第二部分教大家如何自己设计控件并保存调用。

关注我,更多技术问题欢迎私聊~ 4787

路径查找之进入文件系统安装点

1. 关于路径名查找 1.1 处理过程 VFS路径名查找,也就是如何从文件路径名导出相应的索引节点。这个处理过程可以简述为:检查与第一个名字匹配的目录项,获得相应的索引节点。然后,从磁盘读出包含那个索引节点的目录文件,并检查与第二个名字匹配的目录项,以获得相应的索引节点。对于包含在路径中的每个名字,这个过程反复执行。 1.2 绝对路径与相对路径 如果路径名的第一个字符是“/”,那么这个路径是绝对路径,因此从 current->fs->root(进程根目录)所标识的目录开始搜索。否则路径是相对路径

指向NULL 388

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

文件系统挂载和文件查询的关系(《图解Linux内核》虚拟文件系统篇笔记一)

一句话总结,系统初始化时会创建出一个vfsmount结构体mnt,并把创建出来的这个mnt以及他的小兄弟mnt->mnt_root包装成一个path结构体root并赋值给current->fs->root,然后在后续文件查找时,会先初始化一个namedatai结构体nd,将nd->root初始化为current->fs->root。的前提,是所有查找的起点。所以我们知道了,初始化nd->root的最终目标是为了初始化nd->path以及nd->inode,,path_init之后,nd指代的就是应该是。

qq_34116044的博客 614

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

Linux 内核源代码情景分析(三)

首先,其中“文件”的含义就自狭义与广义之分。以在网络环境中用来收发报文的“插口”机制来说,它就并不代表存储着的信息,但是插口的发送端“消耗”信息,而接收端则“产出”信息,所以把插口看成文件是合乎逻辑的。这样,用户程序就可以把所有的文件都看作一致的、抽象的 “VFS文件” ,通过这些系统调用对文件进行操作,而无需关心具体的文件属于什么文件系统以及具体文件系统的设计和实现。这样,就可以对用户程序隐去各种不同文件系统的实现细节,为用户程序提供一个统一的、抽象的、虚拟的文件系统界面,这就是所谓“虚拟文件系统”

Liuqz2009的专栏 739

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

探秘Linux VFS:从磁盘到用户的文件之旅

从磁盘眼中的文件,到操作系统眼中的文件,再到用户眼中的文件,这篇文章都会给予较为完整自洽的解释。需要注意的是,OS以块为基本单位进行IO,所以一个DataBlock不是一个扇区,而一般是4KB,而若干个inode结构体因为单个体积太小所以挤在一起,不是一个inode一个块。不同文件系统的inode类型是不同的,所以需要每个文件系统提供inode的创建方法。,包括每个分组的大小,分组内的结构划分,分组的存储块以及属性块个数,等等,总之,一切都变成了固定的。虽然不是四大主对象之一,但它是普通文件页缓存的核心。

2302_80221042的博客 628
上一篇: web安全攻防演练网站 靶机 测试环境 收集
下一篇: linux 内核 目录项高速缓存 dentry cache 简介
whatday
博客等级 码龄20年 4567粉丝 96原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值