Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to analyze the principle of root file system mount based on linux0.11 file system

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

How to analyze the linux0.11 file system based on the root file system mount principle, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can get something.

After looking at the basic data structure of the file system. We then parse the mount of the root file system, because this is the starting point from which the file system is used. The root file system is mounted at the time of operating system initialization. The corresponding function is mount_root.

/ / Mount the root file system void mount_root (void) {int iForce freeway; struct super_block * p; struct m_inode * mi during system initialization

If (32! = sizeof (struct d_inode)) panic ("bad i-node size"); / / initialize the list of file structures, struct file file_ table [NR _ FILE]; for (s_lock = 0; p-> s_wait = 0; p-> table = NULL) } / / read the super block in a device (hard disk partition), that is, the super block if (! (p=read_super (ROOT_DEV) panic ("Unable to mount root") of the root file system; / / get the first inode node of the root file system, which contains the root directory data if (! (mi=iget (ROOT_DEV,ROOT_INO) panic ("Unable to read root i-node") / / mi is assigned in the following four places. The get_empty_inode function in iget has been set to i_count=1, so add three here to mi- > i_count + = 3; / * NOTE! It is logically used 4 times, not 1 * / / super block is mounted to the inode node corresponding to mi, and p-> s_isup sets the root node of the root file system p-> s_isup = p-> s_imount = mi; / / sets the root file directory of the current process and the current working directory current- > pwd = mi; current- > root = logical data blocks and inode number of mi; free=0; / / file system While (--I > = 0) if (! set_bit (iSzmapp [I > > 13]-> b_data)) free++; printk ("% d free blocks% d free blocks\ n\ r", free,p- > s_nzones); free=0; ionomp1; while (--I > = 0) if (! set_bit (iSIMAP [I > 13]-> b_data)) free++ Printk ("% dshock% d free inodes\ n\ r", free,p- > s_ninodes);}

We can see from the code that the main job of this function is to read the contents of the super block of the hard disk and then apply for an inode node as the root node of the root file system. Finally, set inode to the root node of the current process. The current process at this time is the initialization process of the operating system. The subsequent process is fork from that process. So the root nodes are all the same.

Let's take a look at the implementation of reading super blocks. The main logic is to apply for a structure that represents the super block, and then read the super block from the hard disk for field initialization and processing.

/ / read the super block static struct super_block * read_super (int dev) {struct super_block * s; struct buffer_head * bh; int iMagin block corresponding to dev

If (! dev) return NULL; check_disk_change (dev); / / return if (s = get_super (dev)) return s directly in the super block table; / / find an empty item for (s = 0+super_block;; slots +) {if (s > = NR_SUPER+super_block) return NULL; if (! s-> s_dev) break;} s-> s_dev = dev S-> s_isup = NULL; s-> s_imount = NULL; s-> s_time = 0; s-> s_rd_only = 0; s-> s_dirt = 0; / / lock to prevent other processes from using the data in the super block. Lock_super (s) has not been read at this time. / / read in the first block of the device, that is, the contents of the super block if (! (bh = bread (dev,1) {/ / release s-> sprinter _ 0; free_super (s); return NULL;} * ((struct d_super_block *) s) = * ((struct d_super_block *) bh- > b_data); brelse (bh) / / if it is not a super block, then rollback if (s-> s_magic! = SUPER_MAGIC) {s-> s_dev = 0; free_super (s); return NULL;} for (itemisisimapi [I] = NULL; for (iDeposit iszmapi [I] = NULL; block=2; / / read inode and block bitmap information, s_imap_blocks block represents inode bitmap, read in for

< s->

S_imap_blocks; iTunes +) if (s-> simap [I] = bread (dev,block)) / / s_imap_blocks > 8 will overflow block++; else break; for (iTun0; I)

< s->

S_zmap_blocks; iFix +) if (s-> szmap [I] = bread (dev,block)) block++; else break; / / not all if has been released successfully (block! = 2cm / s > s_zmap_blocks) {for (itemis _ imap [I]); for (iDeplox _ zmap [I]); s-> swordmap 0; free_super (s); } / / the first one cannot be used, set the first one to used, because when looking for free blocks, a return of 0 indicates failure. So if block 0 is available, there will be ambiguity: s-> s_imap [0]-> b_data [0] | = 1; s-> s_zmap [0]-> b_data [0] | = 1; free_super (s); return s;}

At this point, the root file system is loaded. Subsequent use of the file system is based on the root node of the root file system.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report