8
26
2014
66

linux中ext4文件系统目录项管理

Ext4文件系统目录项有两种实现方式:

方式一:线性方式

        该方式的目录项以ext4_dir_entry_2的结构一个接连一个直接存储在目录结点所指向的block块中。(缺省配置使用ext4_dir_entry_2这个结构)

 

方式二:Hash树的方式

        若目录下的文件数量很多,则若按照线性方式查找对应文件名的信息则会很低效。Hash树的方式,则可以用文件名来做hash计算,从而定位到对应文件的目录项结构所在的block,从而缩小查找范围、加快查找效率。

 

1.查看文件系统是否开启了方式二的目录管理方式

      root@f303server:~# tune2fs -l /dev/sde3 | grep dir_index

Filesystem features:      has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super large_file huge_file uninit_bg 

  输入如上指令,则可以发现文件系统的目录已经开启了hash树的管理方式。

 

2.hash树管理方式的打开和关闭

      在上述开启状态下,我们可以关闭hash树目录管理方式。关闭之后再打开。

root@f303server:~# tune2fs -O ^dir_index /dev/sde3

tune2fs 1.42.11 (09-Jul-2014)

root@f303server:~# tune2fs -l /dev/sde3 | grep dir_index  # 查找不到了

root@f303server:~# tune2fs -O dir_index /dev/sde3

tune2fs 1.42.11 (09-Jul-2014)

root@f303server:~# tune2fs -l /dev/sde3 | grep dir_index

Filesystem features:      has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize

root@f303server:~# 

 

 

3.怎么判断某目录是否以hash树的方式管理

 

    文件系统开启了hash树管理目录结点的方式并不意味着所有的目录都按树形结构组织管理。在文件系统中,系统会根据某个目录底下文件的多少来自动进行目录管理方式的选择,只有当文件数量大于某个数时,才会采用hash树管理方式。

 

    怎么判断某目录的管理方式是那种?

   

    若不是hash树的管理方式,则htree中debugfs中则会有如下提示

 

debugfs:  htree linux-2.6.34.14

 

htree: Not a hash-indexed directory

 

 

     若是hash树的管理方式,则

debugfs:  htree linux-2.6.34.14/kernel 显示如下

 

 


Root node dump:
         Reserved zero: 0
         Hash Version: 1
         Info length: 8
         Indirect levels: 0
         Flags: 0
Number of entries (count): 2
Number of entries (limit): 508
Entry #0: Hash 0x00000000, block 1
Entry #1: Hash 0x775173ee, block 2

Entry #0: Hash 0x00000000, block 1
Reading directory block 1, phys 3154297
791969 0x33788c78-7df72ede (20) rtmutex.c   
791971 0x12e2688e-f00920c3 (28) .latencytop.o.cmd   
791973 0x6d76fd8a-f7dad208 (16) futex.o   
791974 0x1f1d389c-0beb6325 (20) ns_cgroup.c   
791975 0x21f726a2-367f43fb (24) .built-in.o.cmd   
791977 0x2a43c4ba-ae0695eb (16) itimer.o   
791978 0x6139ce78-4032f3c2 (16) user.c   
791979 0x615af808-2478500b (24) test_kprobes.c   
791981 0x30feba52-ba8da1e9 (20) audit_tree.c   
791982 0x24bb2b3c-8100eb0d (20) kallsyms.o   
791987 0x71a57d4c-81410e0a (20) .uid16.o.cmd   
791989 0x3e1650ba-3d29a28e (20) freezer.c   
791991 0x0ba6a23a-978af98d (20) spinlock.o   
791992 0x1c6819e6-010b1d97 (24) sched_clock.o   
791997 0x6dc7a2ac-6b0769cb (12) gcov   792005 0x1db5303a-76fff9c7 (16) cpu.o   
792009 0x74def468-a27557c6 (20) .timer.o.cmd   
792010 0x540fdfac-e9e8121b (20) slow-work.o   
792014 0x4c0dc1c8-05179835 (24) Kconfig.preempt   
792018 0x620198da-2fb834e3 (16) cred.c   
792019 0x5973e25e-39b86f3d (32) .cgroup_freezer.o.cmd   
792021 0x1077ffa8-16896967 (16) sys.o   
792025 0x4011172e-63cbf0ec (28) .audit_tree.o.cmd   
792026 0x4c92aabc-1f86d6e5 (20) seccomp.o   
792027 0x5d7f2368-8aaa1cf9 (20) latencytop.c   
792028 0x2ff6ae9c-7b348c25 (24) pid_namespace.o   
792030 0x5f780482-e9fe78e9 (16) groups.o   
792031 0x6079e2b2-acbbff3a (24) rcutree_plugin.h   
792034 0x624e25c0-64cbfd07 (20) stacktrace.o   
792035 0x6e2d0608-09d837e7 (24) .sys_ni.o.cmd   
792036 0x7035c67c-3620d4f6 (16) uid16.o   
792038 0x5b9c06d0-57b802ad (24) .rcutree.o.cmd   
792039 0x356bc37c-95dc4cfb (16) fork.o   
792042 0x46df975e-cef87f2d (16) async.c 

该文如下部分探讨按照方式1组织的目录结构:

1.为了理解后文,首先了解ext4_dir_entry_2的每一个元素

Offset

Size

Name

Description

0x0

__le32

inode

Number of the inode that this directory entry points to.

0x4

__le16

rec_len

Length of this directory entry.

0x6

__u8

name_len

Length of the file name.

0x7

__u8

file_type

File type code, one of:

0x0

Unknown.

0x1

Regular file.

0x2

Directory.

0x3

Character device file.

0x4

Block device file.

0x5

FIFO.

0x6

Socket.

0x7

Symbolic link.

0x8

char

name[EXT4_NAME_LEN]

File name.

 

上表我们可以看到该结构中共5个数据项,前四项占8byte,

通过根目录为例,通过hexdump查看其二进制代码,则“目录项的长度(ren_len)= 文件名长度(name_len) + 8 ”。但是在很多情况下rec_len > = name_len + 8。原因是因为目录项每一项的起始位置必须按照后两位 00 对齐。故有时候会浪费几个字节。

 

 2.通过hexdump指令直接查看二进制内容

先通过

debugfs /dev/sde3

stat .

查找到根目录文件数据所在的块为9249,块大小为4K,故根目录数据所在的起始地址36996k。

 

root@f303server:~# hexdump -C /dev/sde3 -s 36996k -n 4096

02421000  02 00 00 00 0c 00 01 02  2e 00 00 00 02 00 00 00  |................|

02421010  0c 00 02 02 2e 2e 00 00  0b 00 00 00 14 00 0a 02  |................|

02421020  6c 6f 73 74 2b 66 6f 75  6e 64 00 00 01 00 0c 00  |lost+found......|

02421030  0c 00 04 02 64 69 72 31  01 00 0e 00 0c 00 04 02  |....dir1........|

02421040  64 69 72 32 0d 00 00 00  10 00 08 01 73 64 65 33  |dir2........sde3|

02421050  2e 74 78 74 0e 00 00 00  10 00 05 01 32 2e 74 78  |.txt........2.tx|

02421060  74 74 2e 73 11 00 00 00  10 00 05 01 33 2e 74 78  |tt.s........3.tx|

02421070  74 74 2e 73 01 00 10 00  0c 00 04 02 64 69 72 33  |tt.s........dir3|

02421080  01 00 12 00 0c 00 04 02  6d 6b 66 73 0c 00 00 00  |........mkfs....|

02421090  18 00 0e 01 62 6c 6b 74  72 61 63 65 5f 73 74 75  |....blktrace_stu|

024210a0  64 79 65 33 15 00 00 00  18 00 10 01 62 6c 6b 74  |dye3........blkt|

024210b0  72 61 63 65 5f 73 74 75  64 79 2e 63 10 00 00 00  |race_study.c....|

024210c0  14 00 0b 01 67 63 63 5f  62 6c 6b 74 2e 73 68 00  |....gcc_blkt.sh.|

024210d0  0f 00 00 00 10 00 07 01  6e 65 77 2e 74 78 74 63  |........new.txtc|

024210e0  12 00 00 00 1c 00 13 01  62 6c 6b 74 72 61 63 65  |........blktrace|

024210f0  5f 73 74 75 64 79 2d 76  31 2e 63 01 01 00 02 00  |_study-v1.c.....|

02421100  10 00 06 02 4e 65 77 44  69 72 61 63 13 00 00 00  |....NewDirac....|

02421110  1c 00 13 01 62 6c 6b 74  72 61 63 65 5f 73 74 75  |....blktrace_stu|

02421120  64 79 2d 76 32 2e 63 77  14 00 00 00 18 00 0e 01  |dy-v2.cw........|

02421130  64 72 6f 70 5f 63 61 63  68 65 73 2e 73 68 79 2e  |drop_caches.shy.|

02421140  01 00 04 00 10 00 06 02  73 64 65 31 63 70 15 01  |........sde1cp..|

02421150  01 00 08 00 b0 0e 0f 02  6c 69 6e 75 78 2d 32 2e  |........linux-2.|

02421160  36 2e 33 34 2e 31 34 00  00 00 00 00 00 00 00 00  |6.34.14.........|

02421170  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

*

02422000

 

上图中每个颜色表示一个dentry的记录

 

1

观察lost+found目录:

Rec_len = 0x 00 14   name_len = 0a

 

rec_len = name_len +8 +2   则在对齐时浪费了第三行的第1112个字节。

 

2

我们看到2.txt的文件名变成了2.txtt.s

 

原因是最后三个字节是无效字节,在对齐时已经去掉,对齐时三个字节的内容是随便填充的。

 

 

 

 

 

Category: 文件系统 | Tags: linux 文件系统 目录项 | Read Count: 10565
Avatar_small
Liwovosa 说:
2021年5月06日 15:41

Thanks for every other informative site. The place else may just I get that kind of information written in such an ideal means? I have a venture that I’m just now operating on, and I have been on the look out for such information. 123movies

Avatar_small
لی ویوسوہ ہو یار 说:
2021年5月21日 13:22

The article looks magnificent, but it would be beneficial if you can share more about the suchlike subjects in the future. Keep posting. 먹튀검증업체

Avatar_small
لی ویوسوہ ہو یار 说:
2021年5月21日 17:29

There are a lot of blogs over the Internet. But I can surely say that your blog is amazing in all. It has all the qualities that a perfect blog should have. 844 area code

Avatar_small
슈어맨 说:
2021年5月21日 23:21

Truly, this article is really one of the very best in the history of articles. I am a antique ’Article’ collector and I sometimes read some new articles if I find them interesting. And I found this one pretty fascinating and it should go into my collection. Very good work!

Avatar_small
seo 说:
2021年5月24日 15:25

Hello, this weekend is good for me, since this time i am reading this enormous informative article here at my home. Setting Up Company in Indonesia

Avatar_small
sand blasting work i 说:
2021年5月25日 21:39

Here at this site really the fastidious material collection so that everybody can enjoy a lot.

Avatar_small
China PP woven bags 说:
2021年5月27日 18:43

China Non Woven Bags Co., Ltd Is a professional recycle bags manufacturer in China, our main products including non woven bags series, PP woven bags series, PET/RPET bags series, cotton & canvas bags series, nylon & polyester bags series, etc. Our products already well received in Europe, America, Japan, Malaysia, HK, Taiwan and China since 2003.
We have more than 300 employees with modern standard workshop, advanced imported equipment as well as high quality management and technical researchers. All of our products aim to be perfect from design, choice of material, production, packaging, and after-sales service. Based on our principle of "Quality defines existence and management is the key for development", we continually strive to exceed our customers' expectation.
We sincerely hope to cooperate with customers from all over the world to build long-term business relationships,If you have any question of our products, Just feel free to contact us. We will provide you professional advises and are looking forward to receiving your inquiry.
The tenet of our company: Same product, we compare with quality; Same quality we compare with price; Same price, we compare with service; Same service, we compare with speed.

Avatar_small
เว็บพนันออนไลน์ ที่ด 说:
2021年6月07日 19:23

Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info.

Avatar_small
mylowesbenefits 说:
2021年6月11日 19:53

I recently came across your article and have been reading along. I want to express my admiration of your writing skill and ability to make readers read from the beginning to the end. I would like to read newer posts and to share my thoughts with you.

Avatar_small
asd 说:
2021年6月14日 01:29

Excellent article. Very interesting to read. I really love to read such a nice article. Thanks! keep rocking. judi slot online terpercaya

Avatar_small
asd 说:
2021年6月25日 18:55

I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article. dadu online

Avatar_small
لی ویوسوہ ہو یار 说:
2021年6月29日 21:17

Great article Lot's of information to Read...Great Man Keep Posting and update to People..Thanks lottery sambad

Avatar_small
لی ویوسوہ ہو یار 说:
2021年7月01日 01:22

I am definitely enjoying your website. You definitely have some great insight and great stories. starke Schlaftabletten ohne Rezept

Avatar_small
seoservvise 说:
2021年7月01日 21:26

This is very educational content and written well for a change. It's nice to see that some people still understand how to write a quality post! สล็อต

Avatar_small
لی ویوسوہ ہو یار 说:
2021年7月03日 16:14

That appears to be excellent however i am still not too sure that I like it. At any rate will look far more into it and decide personally! arby's specials

Avatar_small
asd 说:
2021年7月04日 18:33

I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article. www.gecafs.org

Avatar_small
asd 说:
2021年7月06日 18:28

I admire this article for the well-researched content and excellent wording. I got so involved in this material that I couldn’t stop reading. I am impressed with your work and skill. Thank you so much. winslot303

Avatar_small
seoservvise 说:
2021年7月07日 16:01

Thanks for the blog loaded with so many information. Stopping by your blog helped me to get what I was looking for. SBI Careers

Avatar_small
seoservvise 说:
2021年7月08日 19:18

You know your projects stand out of the herd. There is something special about them. It seems to me all of them are really brilliant! YouTube SEO

Avatar_small
لی ویوسوہ ہو یار 说:
2021年7月08日 20:58 Wonderful article. Fascinating to read. I love to read such an excellent article. Thanks! It has made my task more and extra easy. Keep rocking. https://multinutri.shop/
Avatar_small
لی ویوسوہ ہو یار 说:
2021年7月10日 19:25

I think this is one of the most significant information for me. And i’m glad reading your article. But should remark on some general things, The web site style is perfect, the articles is really great : D. Good job, cheers ครีมซองเซเว่น

Avatar_small
لی ویوسوہ ہو یار 说:
2021年7月10日 20:37

Wow, What a Excellent post. I really found this to much informatics. It is what i was searching for.I would like to suggest you that please keep sharing such type of info.Thanks ครีมสำหรับผิวแพ้ง่าย

Avatar_small
seoservvise 说:
2021年7月11日 17:43

New web site is looking good. Thanks for the great effort. GTA 6 release date

Avatar_small
لی ویوسوہ ہو یار 说:
2021年7月11日 18:12

Wonderful blog! Do you have any tips and hints for aspiring writers? Because I’m going to start my website soon, but I’m a little lost on everything. Many thanks! ดาวน์โหลดslotxo

Avatar_small
لی ویوسوہ ہو یار 说:
2021年7月11日 20:17

Great post, you have pointed out some fantastic points , I likewise think this s a very wonderful website. live22 login

Avatar_small
لی ویوسوہ ہو یار 说:
2021年7月11日 21:14

Thanks for taking the time to discuss this, I feel strongly that love and read more on this topic. If possible, such as gain knowledge, would you mind updating your blog with additional information? It is very useful for me. Allen Greene

Avatar_small
لی ویوسوہ ہو یار 说:
2021年7月11日 21:55

Hey what a brilliant post I have come across and believe me I have been searching out for this similar kind of post for past a week and hardly came across this. Thank you very much and will look for more postings from you. pg slot game

Avatar_small
seoservvise 说:
2021年7月15日 18:52

I can see that you are an expert at your field! I am launching a website soon, and your information will be very useful for me.. Thanks for all your help and wishing you all the success in your business. Top 10 Richest Person in the World

Avatar_small
لی ویوسوہ ہو یار 说:
2021年7月17日 18:58

Awesome and interesting article. Great things you've always shared with us. Thanks. Just continue composing this kind of post. voyance gratuite

Avatar_small
لی ویوسوہ ہو یار 说:
2021年7月17日 23:59

I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work... Love Paragraphs For Him

Avatar_small
seoservvise 说:
2021年7月18日 16:45

Most of the time I don’t make comments on websites, but I'd like to say that this article really forced me to do so. Really nice post! Print In London

Avatar_small
لی ویوسوہ ہو یار 说:
2021年7月19日 19:50

Nice post mate, keep up the great work, just shared this with my friendz Bramfort

Avatar_small
seoservvise 说:
2021年7月20日 18:26

I’ve been surfing online more than three hours today, yet I never found any interesting article like yours. It’s pretty worth enough for me. In my opinion, if all webmasters and bloggers made good content as you did, the web will be a lot more useful than ever before. meilleur montre connectée homme

Avatar_small
لی ویوسوہ ہو یار 说:
2021年7月26日 19:33

Hello I am so delighted I located your blog, I really located you by mistake, while I was watching on google for something else, Anyways I am here now and could just like to say thank for a tremendous post and a all round entertaining website. Please do keep up the great work. บาคาร่า

Avatar_small
لی ویوسوہ ہو یار 说:
2021年7月26日 22:17

I am very happy to discover your post as it will become on top in my collection of favorite blogs to visit. how to take advantage of probiotic

Avatar_small
Angela Stewart 说:
2021年7月29日 17:35

I recently found some useful posts in your website especially this blog page. Among the lots of comments on your articles. Thanks for sharing. Virtual Assistant For Online Store

Avatar_small
seoservvise 说:
2021年8月01日 20:51 Thank you very much for this useful article. I like it. sermon transcription
Avatar_small
seoservvise 说:
2021年8月03日 18:04

This is very educational content and written well for a change. It's nice to see that some people still understand how to write a quality post! Animeflix

Avatar_small
seoservvise 说:
2021年8月04日 22:01

Wonderful article. Fascinating to read. I love to read such an excellent article. Thanks! It has made my task more and extra easy. Keep rocking. article

Avatar_small
seoservvise 说:
2021年8月05日 22:03

Im no expert, but I believe you just made an excellent point. You certainly fully understand what youre speaking about, and I can truly get behind that. minecraft smite command

Avatar_small
seoservvise 说:
2021年8月07日 21:46

Thanks for the blog loaded with so many information. Stopping by your blog helped me to get what I was looking for. Dallas Criminal Defense Lawyer

Avatar_small
razzaqseo 说:
2021年8月15日 19:03

Great job for publishing such a beneficial web site. Your web log isn’t only useful but it is additionally really creative too. Biofit probiotic review

Avatar_small
asd 说:
2021年8月20日 19:02

I have read all the comments and suggestions posted by the visitors for this article are very fine,We will wait for your next article so only.Thanks! jackpot404

Avatar_small
asd 说:
2021年8月21日 17:03 I’m going to read this. I’ll be sure to come back. thanks for sharing. and also This article gives the light in which we can observe the reality. this is very nice one and gives indepth information. thanks for this nice article... agen slot online
Avatar_small
This is a great arti 说:
2021年8月22日 15:58

Thanks for this great post, i find it very interesting and very well thought out and put together. I look forward to reading your work in the future. Dallas Manslaughter Defense lawyer

Avatar_small
This is a great arti 说:
2021年8月22日 22:55

Fantastic blog! Do you have any tips and hints for aspiring writers? I’m planning to start my own website soon but I’m a little lost on everything. Would you propose starting with a free platform like WordPress or go for a paid option? There are so many options out there that I’m completely overwhelmed .. Any suggestions? Many thanks! Dentitox Pro Reviews

Avatar_small
seoservise 说:
2021年8月31日 01:24

Great job for publishing such a beneficial web site. Your web log isn’t only useful but it is additionally really creative too. https://www.reddit.com/r/CryptoMars/comments/pbrjj1/polyrollorg_roll_top_gambling_dapp_on_polygon/

Avatar_small
seoservise 说:
2021年9月01日 20:49

This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free. fb88

Avatar_small
asd 说:
2021年9月02日 20:01

I admire this article for the well-researched content and excellent wording. I got so involved in this material that I couldn’t stop reading. I am impressed with your work and skill. Thank you so much. judi slot online

Avatar_small
seoservise 说:
2021年9月02日 22:15 You have done a great job on this article. It’s very readable and highly intelligent. You have even managed to make it understandable and easy to read. You have some real writing talent. Thank you. W88
Avatar_small
seoservise 说:
2021年9月04日 15:51

Your website is really cool and this is a great inspiring article. 188bet

Avatar_small
seoservise 说:
2021年9月04日 19:06

Yes, I am entirely agreed with this article, and I just want say that this article is very helpful and enlightening. I also have some precious piece of concerned info !!!!!!Thanks. 먹튀검증

Avatar_small
seoservise 说:
2021年9月08日 17:01

Thanks, that was a really cool read! 250 dofollow blog comments

Avatar_small
seoservise 说:
2021年9月08日 18:46

I recently found many useful information in your website especially this blog page. Among the lots of comments on your articles. Thanks for sharing. 250 dofollow blog comments

Avatar_small
seoservise 说:
2021年9月09日 21:37

Acknowledges for paper such a beneficial composition, I stumbled beside your blog besides decipher a limited announce. I want your technique of inscription... Uniques Christmas gifts

Avatar_small
seoservise 说:
2021年9月13日 17:56 Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with extra information? It is extremely helpful for me. 현금바둑이
Avatar_small
seoservise 说:
2021年9月13日 23:26

I am very enjoyed for this blog. Its an informative topic. It help me very much to solve some problems. Its opportunity are so fantastic and working style so speedy. Website

Avatar_small
seoservise 说:
2021年9月14日 17:24

I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work... Best gift ideas for baby shower

Avatar_small
seoservise 说:
2021年9月16日 18:41

I definitely enjoying every little bit of it. It is a great website and nice share. I want to thank you. Good job! You guys do a great blog, and have some great contents. Keep up the good work. 1500 blog comment

Avatar_small
seoservise 说:
2021年10月07日 20:37

This is just the information I am finding everywhere. Thanks for your blog, I just subscribe your blog. This is a nice blog.. 먹튀

Avatar_small
Digital Ali 说:
2021年10月12日 01:14

A very awesome blog post. We are really grateful for your blog post. You will find a lot of approaches after visiting your post. jasa pembuatan website

Avatar_small
daundadap 说:
2021年10月31日 20:05

This is a great <a href="https://www.aus.co.id/cara-bermain-cpa/">cara bermain CPA</a>

Avatar_small
seoservise 说:
2021年12月09日 22:21

Thank you for some other informative blog. Where else could I get that type of information written in such an ideal means? I have a mission that I’m just now working on, and I have been at the look out for such information. lottery sambad

Avatar_small
Zopicloneinuk 说:
2022年11月21日 23:22

Thanks for the nice blog. It was very useful for me. I am happy I found this blog. Thank you for sharing with us. <a href="https://zopicloneinuk.com/product/zopiclone-7-5-mg-by-intas/">Order Zopiclone For Anxiety</a>

Avatar_small
Zopicloneinuk 说:
2022年11月21日 23:22

Thanks for the nice blog. It was very useful for me. I am happy I found this blog. Thank you for sharing with us. <a href="https://zopicloneinuk.com/product/zopiclone-7-5-mg-by-intas/">Order Zopiclone For Anxiety</a>


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com