In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "how to understand xattr in the ext2 file system". In the operation of actual cases, many people will encounter such a dilemma, so 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!
§0x01 background
One feature that the file system supports is extensibility, adding various attributes to an inode. For ext2 file systems, xattr (extend attribution) is one of the few modern file system features it supports.
So why do you need this feature? This starts with the difference between metadata and data in the file system. Xattr belongs to metadata, metadata is generally fixed, but in some scenarios it also has to provide a certain degree of scalability, and xattr exists for the scalability of metadata. Let's pull down my understanding of metadata and data and analyze why metadata is needed.
1.1 metadata and data of files
We know that the data in a file is divided into two categories: meta data and data. Metadata is used to control the user's operation on the data. This is also in line with the program paradigm of controlling objects through objects in k8s.
Data: record information that is really meaningful to the user. Such as: the contents of the file; the file name.
Metadata: assist in data access. Such as: the creation and modification time of the file, the permission of the file.
Generally speaking, metadata does not need to be actively perceived by users, for example, when a file is created, the corresponding time information is automatically written by the file system. But its access must be provided in different ways. If you put it with the regular data, it is as follows:
Filename: hello.txtmodify_time: 2021-3-7 20:00:00regular_data:hello world
Is this method feasible? Of course it works. It's just that you can't control whether the user will misoperate and change the corresponding metadata; one of the principles of modular programming, the minimum interface principle, is also applicable here, separate interface modification, compared with direct modification, the ability of the interface (degree of freedom) has decreased, and the constraints of the system to users have been enhanced, which can prevent users from modifying data indiscriminately.
Another problem is that metadata changes are stable, and even if you read and write a file frequently, the file's metadata needs to be modified only by the corresponding access timestamp and modification timestamp. Without separation, the metadata as a whole is read out and written frequently, which is a meaningless consumption for the system, let alone in the context of the lack of computing power.
Through the following analysis, we know that metadata needs to be stored separately. Separate storage requires a separate interface because the read and write interface permissions of ordinary files are too large. But on the one hand, for a file, the read-write interface can not meet the needs of metadata modification, so it is necessary to provide other system interfaces. Under Linux, ioctl system call is used to modify metadata.
§xattr experiment of 0x02 ext2
Main setfattr and getfattr. By looking at the ext2 code, you know that it supports three types of attr. Distinguished by different naming prefixes.
Security.xxx: currently selinux is in use
User.xxx: can also be used by ordinary users
Trusted.xxx: only superusers can use it to implement some features in user space.
Example:
Add an attribute to the test file.
Setfattr-n user.word-v "hello world" testgetfattr-n user.word hello# file: hellouser.word= "hello world" §purpose of 0x03 xattr
What we know now is that during the evolution of ceph, xattr was used to save some underlying information.
Applications related to security audit will use security attr
Attr also supports adding attributes to directories, which may be used in some scenarios, but I haven't thought of it yet.
This is the end of "how to understand xattr in the ext2 file system". 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.