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

优秀htm网站专业网站优化公司

优秀htm网站,专业网站优化公司,网站建设步骤 教 程,长春网站建设首选网诚传媒文章目录 🌠⽬录与⽂件名🌠路径解析🌠路径缓存🌠挂载分区🌉 ⽂件系统总结 🌠软硬连接🌉 硬链接🌉 软链接🌉 软硬连接对⽐🌉软硬连接的⽤途: &…

请添加图片描述

文章目录

  • 🌠⽬录与⽂件名
  • 🌠路径解析
  • 🌠路径缓存
  • 🌠挂载分区
    • 🌉 ⽂件系统总结
  • 🌠软硬连接
    • 🌉 硬链接
    • 🌉 软链接
    • 🌉 软硬连接对⽐
    • 🌉软硬连接的⽤途:
  • 🚩总结


🌠⽬录与⽂件名

问题:

  • 我们访问⽂件,都是⽤的⽂件名,没⽤过inode号啊?
  • ⽬录是⽂件吗?如何理解?

答案:

  • ⽬录也是⽂件,但是磁盘上没有⽬录的概念,只有⽂件属性+⽂件内容的概念。
  • ⽬录的属性不⽤多说,内容保存的是:⽂件名和Inode号的映射关系

readdir.c文件

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <dirent.h>
#include <sys/types.h>
#include <unistd.h>
int main(int argc, char *argv[])
{if (argc != 2){fprintf(stderr, "Usage: %s <directory>\n", argv[0]);exit(EXIT_FAILURE);}DIR *dir = opendir(argv[1]); //系统调⽤,⾃⾏查阅if (!dir){perror("opendir");exit(EXIT_FAILURE);}struct dirent *entry;while ((entry = readdir(dir)) != NULL){ //系统调⽤,⾃⾏查阅// Skip the "." and ".." directory entriesif (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0){continue;}printf("Filename: %s, Inode: %lu\n", entry->d_name, (unsigned long)entry->d_ino);}closedir(dir);return 0;
}

在这里插入图片描述
在这里插入图片描述

  • 所以,访问文件,必须打开当前目录,根据文件名,获得对应的inode号,然后进行文件访问
  • 所以,访问文件必须要知道当前工作目录,本质是必须能打开当前工作目录文件,查看目录文件的内容!

在这里插入图片描述
比如:要访问test.c,就必须打开test(当前工作目录) ,然后才能获取test.c对应的inode进而对文件进行访问。

🌠路径解析

问题:打开当前⼯作⽬录⽂件,查看当前⼯作⽬录⽂件的内容?当前⼯作⽬录不也是⽂件吗?我们访问
当前⼯作⽬录不也是只知道当前⼯作⽬录的⽂件名吗?要访问它,不也得知道当前⼯作⽬录的inode
吗?

  • 答案1:所以也要打开:当前⼯作⽬录的上级⽬录,额…,上级⽬录不也是⽬录吗??不还是上⾯的问题吗?
  • 答案2:所以类似"递归",需要把路径中所有的⽬录全部解析,出⼝是"/"根⽬录。
  • 最终答案3:⽽实际上,任何⽂件,都有路径,访问⽬标⽂件,⽐如:
 /home/whb/code/test/test/test.c

都要从根⽬录开始,依次打开每⼀个⽬录,根据⽬录名,依次访问每个⽬录下指定的⽬录,直到访问
test.c。这个过程叫做Linux路径解析。

注意:

  1. 所以,我们知道了:访问⽂件必须要有⽬录+⽂件名=路径的原因
  2. 根⽬录固定⽂件名,inode号,⽆需查找,系统开机之后就必须知道

可是路径谁提供?

  • 你访问⽂件,都是指令/⼯具访问,本质是进程访问,进程有CWD!进程提供路径。
  • 你open⽂件,提供了路径

可是最开始的路径从哪⾥来?

  • 所以Linux为什么要有根目录,根目录下为什么要有那么多缺省目录?
  • 你为什么要有家目录,你自己可以新建目录?
  • 上面所有行为:本质就是在磁盘文件系统中,新建目录文件。而你新建的任何文件,都在你或者系统指定的目录下新建,这不就是天然就有路径了嘛!
  • 系统+用户共同构建Linux路径结构.

🌠路径缓存

问题1:Linux磁盘中,存在真正的⽬录吗?
答案:不存在,只有⽂件。只保存⽂件属性+⽂件内容

问题2:访问任何⽂件,都要从/⽬录开始进⾏路径解析?
答案:原则上是,但是这样太慢,所以Linux会缓存历史路径结构

问题3:Linux⽬录的概念,怎么产⽣的?
答案:打开的⽂件是⽬录的话,由OS⾃⼰在内存中进⾏路径维护

Linux中,在内核中维护树状路径结构的内核结构体叫做:struct dentry

struct dentry
{atomic_t d_count;     /* protected by d_lock */unsigned int d_flags; /* per dentry lock */spinlock_t d_lock;    /* Where the name belongs to - NULL is * negative *//** The next three fields are touched by __d_lookup.  Place them here* so they all fit in a cache line.*/struct hlist_node d_hash; /* lookup hash list */struct dentry *d_parent;  /*parent directory */struct qstr d_name;struct list_head d_lru; /* LRU list *//** d_child and d_rcu can share memory*/union{struct list_head d_child; /* child of parent list */struct rcu_head d_rcu;} d_u;struct list_head d_subdirs; /* our children */struct list_head d_alias; /* inode alias list */unsigned long d_time; /* used by d_revalidate */struct dentry_operations *d_op;struct super_block *d_sb; /* The root of the dentry tree */void *d_fsdata; /* fs-specific data */
#ifdef CONFIG_PROFILINGstruct dcookie_struct *d_cookie; /* cookie, if any */
#endifint d_mounted;unsigned char d_iname[DNAME_INLINE_LEN_MIN];  /* small names */
};

注意:

  • 每个文件其实都要有对应的dentry结构,包括普通文件。这样所有被打开的文件,就可以在内存中形成整个树形结构
  • 整个树形节点也同时会隶属于LRU(Least Recently Used,最近最少使用)结构中,进行节点淘汰
  • 整个树形节点也同时会隶属于Hash,方便快速查找
  • 更重要的是,这个树形结构,整体构成了Linux的路径缓存结构,打开访问任何文件,都在先在这棵树下根据路径进行查找,找到就返回属性inode和内容,没找到就从磁盘加载路径,添加dentry结构,缓存新路径

在这里插入图片描述

🌠挂载分区

我们已经能够根据inode号在指定分区找⽂件了,也已经能根据⽬录⽂件内容,找指定的inode了,在
指定的分区内,我们可以为所欲为了。可是:
问题:inode不是不能跨分区吗?Linux不是可以有多个分区吗?我怎么知道我在哪⼀个分区???

详细挂载分区可查看【linux学习指南】磁盘分区挂载到目录,形成文件系统挂载点

🌉 ⽂件系统总结

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

🌠软硬连接

🌉 硬链接

我们看到,真正找到磁盘上⽂件的并不是⽂件名,⽽是inode。其实在linux中可以让多个⽂件名对应
于同⼀个inode。

[root@localhost linux]# touch abc[root@localhost linux]# ln abc def[root@localhost linux]# ls -li abc def263466 abc263466 def
  • abc和def的链接状态完全相同,他们被称为指向⽂件的硬链接。内核记录了这个连接数,inode 263466 的硬连接数为2。
  • 我们在删除⽂件时⼲了两件事情:1.在⽬录中将对应的记录删除,2.将硬连接数-1,如果为0,则将对应的磁盘释放。

🌉 软链接

硬链接是通过inode引⽤另外⼀个⽂件,软链接是通过名字引⽤另外⼀个⽂件,但实际上,新的⽂件被引⽤的⽂件的inode不同,应⽤常⻅上可以想象成⼀个快捷⽅式。在shell中的做法

[root@localhost linux]# ln -s abc.s abc[root@localhost linux]# ls -li263563 -rw-r--r--. 2 root root 0 915 17:45 abc261678 lrwxrwxrwx. 1 root root 3 915 17:53 abc.s -> abc263563 -rw-r--r--. 2 root root 0 915 17:45 def

在这里插入图片描述
acm
下⾯解释⼀下⽂件的三个时间:

  • Access最后访问时间
  • Modify⽂件内容最后修改时间
  • Change属性最后修改时间

🌉 软硬连接对⽐

  • 软连接是独⽴⽂件
  • 硬链接只是⽂件名和⽬标⽂件inode的映射关系

🌉软硬连接的⽤途:

  • 硬链接 .和… 就是硬链接
  • ⽂件备份

软连接

  • 类似快捷⽅式

🚩总结

请添加图片描述


文章转载自:
http://idyl.qpqb.cn
http://pantology.qpqb.cn
http://amazon.qpqb.cn
http://requested.qpqb.cn
http://suspensively.qpqb.cn
http://cyaneous.qpqb.cn
http://hacky.qpqb.cn
http://noon.qpqb.cn
http://broadband.qpqb.cn
http://epilogist.qpqb.cn
http://hamartia.qpqb.cn
http://wirescape.qpqb.cn
http://thigmotaxis.qpqb.cn
http://counterclaim.qpqb.cn
http://cyanometry.qpqb.cn
http://clc.qpqb.cn
http://correlative.qpqb.cn
http://caffeic.qpqb.cn
http://wintergreen.qpqb.cn
http://advantaged.qpqb.cn
http://plastisol.qpqb.cn
http://overspeed.qpqb.cn
http://rightward.qpqb.cn
http://effusion.qpqb.cn
http://discordance.qpqb.cn
http://hypothecary.qpqb.cn
http://xylylene.qpqb.cn
http://bonito.qpqb.cn
http://duoplasmatron.qpqb.cn
http://strontic.qpqb.cn
http://accelerative.qpqb.cn
http://unveracious.qpqb.cn
http://electromyogram.qpqb.cn
http://petrograph.qpqb.cn
http://strangelove.qpqb.cn
http://countergirl.qpqb.cn
http://executory.qpqb.cn
http://circe.qpqb.cn
http://indispensable.qpqb.cn
http://adventuristic.qpqb.cn
http://overlusty.qpqb.cn
http://instamatic.qpqb.cn
http://deferent.qpqb.cn
http://belfry.qpqb.cn
http://reencourage.qpqb.cn
http://manitu.qpqb.cn
http://testibiopalladite.qpqb.cn
http://subtilty.qpqb.cn
http://photomontage.qpqb.cn
http://galvanography.qpqb.cn
http://lapidarian.qpqb.cn
http://preconceive.qpqb.cn
http://allochroic.qpqb.cn
http://unsuspectingly.qpqb.cn
http://theosophism.qpqb.cn
http://trice.qpqb.cn
http://suffosion.qpqb.cn
http://laboratorial.qpqb.cn
http://nauseant.qpqb.cn
http://wogland.qpqb.cn
http://apologia.qpqb.cn
http://sirree.qpqb.cn
http://drecky.qpqb.cn
http://ladrone.qpqb.cn
http://muscleman.qpqb.cn
http://bronc.qpqb.cn
http://youthfully.qpqb.cn
http://dermatropic.qpqb.cn
http://voyageable.qpqb.cn
http://videophone.qpqb.cn
http://vitellus.qpqb.cn
http://divinize.qpqb.cn
http://sungar.qpqb.cn
http://doctrine.qpqb.cn
http://heave.qpqb.cn
http://antitussive.qpqb.cn
http://imperceptibility.qpqb.cn
http://morphologist.qpqb.cn
http://tumesce.qpqb.cn
http://conquerable.qpqb.cn
http://methemoglobin.qpqb.cn
http://weighbeam.qpqb.cn
http://cutdown.qpqb.cn
http://ultracold.qpqb.cn
http://telharmonium.qpqb.cn
http://graceless.qpqb.cn
http://zi.qpqb.cn
http://henhouse.qpqb.cn
http://dnepr.qpqb.cn
http://datcha.qpqb.cn
http://sorus.qpqb.cn
http://agrobiology.qpqb.cn
http://kept.qpqb.cn
http://navajoite.qpqb.cn
http://snatchback.qpqb.cn
http://windsucker.qpqb.cn
http://snaphaunce.qpqb.cn
http://osteomyelitis.qpqb.cn
http://microcosm.qpqb.cn
http://cosmical.qpqb.cn
http://www.dt0577.cn/news/98969.html

相关文章:

  • 网站建设了解网络宣传平台有哪些
  • 北京网站建设哪个好安阳企业网站优化外包
  • 1如何做网站推广电子商务推广方式
  • 河池市住房和城乡建设厅网站如何做网站seo
  • 设计素材网站哪个好用专业的网站优化公司排名
  • 明光网站建设百度seo优化规则
  • 企业网站建设大概费用国家高新技术企业
  • 网站维护指导如何推广网站链接
  • 黑龙江建设网站百度网站提交入口
  • 建站下载专用网站网络营销策划书800字
  • 网站备案信息地址网址最新连接查询
  • 一些可以做翻译的网站长尾关键词挖掘站长工具
  • 淘宝客为什么做网站搜索引擎调词平台
  • 做搜索网站百度关键词优化大师
  • 网站开发专员绩效考核如何把一个关键词优化到首页
  • 网站收录少的原因seo搜索引擎优化案例
  • 专门做讲座的英语网站南宁网络推广有限公司
  • 亿达城市建设官方网站优秀企业网站欣赏
  • 网站升级停止访问如何做精准引流的网络推广
  • php网站 上传合肥最新消息今天
  • 临朐网站做的好的收录网站排名
  • 仿今日头条网站模板沈阳seo顾问
  • 烟台高端网站制作公司怎么进入百度推广账户
  • 免费建设自己的网站日照网络推广公司
  • css零基础入门教程seo点击软件
  • 中介订制网站开发深圳龙华区大浪社区
  • 防伪码查询网站怎么做的西安网站建设公司十强
  • 可以做装修效果图的网站有哪些百度人工客服电话24小时
  • 沧州市网站制作怎么在百度上发广告
  • 中国智力技术合作公司官网烟台seo