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

What is the management of linux1.2.13 file structure

2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article introduces the relevant knowledge of "how linux1.2.13 file structure management is". In the operation of actual cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The operating system maintains a list of open files for processes, and each process maintains a file array field (struct file * FDD [NR _ OPEN]); each element points to a file structure. Each file structure has a field pointing to the inode structure, and inode manages the contents, permissions, and other information of the file. The management of the file structure is analyzed here.

Here is the definition of the file structure

Struct file {mode_t favored; loff_t favored; unsigned short favored; unsigned short favored; off_t favoreada; struct file * f_next, * favored; int fanciowner; / * pid or-pgrp where SIGIO should be sent * / struct inode * fanciinode; struct file_operations * favored; unsigned long favored version; void * private_data; / * needed for tty driver, and maybe others * /}

The following is the management of the file structure, and when the process opens a file, it may need to apply for a file structure.

/ * * linux/fs/file_table.c * * Copyright (C) 1991, 1992 Linus Torvalds * /

# include # include # include

Struct file * first_file;int nr_files = 0

/ / two-way circular linked list, with first_file pointing to the head pointer. Insert a node static void insert_file_free (struct file * file) {file- > f_next = first_file; file- > f_prev = first_file- > favored list; file- > favored NextT-> f_prev = file; file- > favored list-> f_next = file; first_file = file } / / delete a node static void remove_file_free (struct file * file) {/ / if the node to be deleted is the first node, update the header pointer to the next node if (first_file = = file) first_file = first_file- > f_next / / if there is a node after the deleted node, you need to update the prev pointer of the next node, pointing to the previous node of the current node if (file- > f_next) file- > fancinextt-> f_prev = file- > favored pointer; / / similarly, update the next pointer of the previous node to the next node of the deleted node if (file- > f_prev) file- > fenced pointer-> f_next = file- > f_next / / leave file- > f_next = file- > f_prev = NULL;}

/ / file is inserted into the linked list to become the last node static void put_last_free (struct file * file) {/ / ensure that file breaks away from the original linked list remove_file_free (file); / / insert the linked list without updating the header pointer first_file, so file becomes the last node file- > f_prev = first_file- > fenced lists; file- > faded lists-> f_next = file; file- > f_next = first_file File- > fenestration-> f_prev = file;}

Void grow_files (void) {struct file * file; int i; / / apply for one page of memory file = (struct file *) get_free_page (GFP_KERNEL)

If (! file) return; / / i=PAGE_SIZE/sizeof (struct file), that is, how many nodes can be saved on a page, and update the maximum number of nodes nr_files+=i= PAGE_SIZE/sizeof (struct file) / * it is time for initialization. Initialize a node first. The number of nodes that need to be initialized is reduced by one. Before executing insert_file_free, you need to make sure that first_file is not empty. See first_file * / if (! first_file) file- > f_next = file- > f_prev = first_file = file++, iMuk in insert_file_free; / / form a linked list for (; I; iMuk -) insert_file_free (file++) } / / file linked list initializes unsigned long file_table_init (unsigned long start, unsigned long end) {first_file = NULL; return start;}

/ / get a possible file structure struct file * get_empty_filp (void) {int i; struct file * f

If (! first_file) grow_files (); repeat: / / nr_files is the total number of nodes in the linked list for (f = first_file, iNode 0; I

< nr_files; i++, f = f->

F_next) / / find the free node if (! f-> f_count) {/ / detach the linked list remove_file_free (f); / / clear the memory memset (fjin0pm sizeof (* f)); / / insert the end of the linked list put_last_free (f); / / the tag has been marked with f-> f_count = 1 F-> f_version = + + event; return f;} / / No free node is found. Expand the capacity and find if (nr_files).

< NR_FILE) { grow_files(); goto repeat; } return NULL;}

We can see from the figure that the system maintains a two-way circular linked list and stores a series of used and unused file structures. The first_file pointer executes the first idle node, which is placed at the end of the linked list when the process requests the file structure. The first_file pointer points to the next idle node. If there are no free nodes, the capacity will be expanded automatically.

This is the end of the content of "how linux1.2.13 file structure Management is". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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