Comments (2)
The kernel passes the file_type back up to userspace. See [1], [2] and [3]. To quote from [4], when describing the d_type field which is returned by readdir:
This field contains a value indicating the file type, making it possible to avoid the expense of calling lstat(2) if further actions depend on the type of the file.
Example of utilities that use the file_type field including the find(1) program from GNU, where if a find command such as "find . -name super.c -print", use of the file_type field reduces the number of system calls by a huge percentage, because it doesn't become necessary to call stat(2) or lstat(2) on every single file returned by readdir to see if it is a directory that needs to be recursively searched.
Now, this extension is not required by POSIX or the Single Unix Specification, so feel free to not bother to implement in your hobby OS if you don't care about performance for applications that need to recursively search files in a directory tree. The NetBSD. FreeBSD, et. al., also implement, so ti's not a Linux specific extension.
[1] https://elixir.bootlin.com/linux/v6.3/source/fs/readdir.c#L256
[2] https://elixir.bootlin.com/linux/v6.3/source/fs/ext4/dir.c#L536
[3] https://elixir.bootlin.com/linux/v6.3/source/include/linux/fs.h#L3136
[4] https://man7.org/linux/man-pages/man3/readdir.3.html
from e2fsprogs.
Oh, I see, the dirent structure in newer Linux kernels includes the d_type
field:
struct dirent {
ino_t d_ino; /* Inode number */
off_t d_off; /* Not an offset; see below */
unsigned short d_reclen; /* Length of this record */
unsigned char d_type; /* Type of file; not supported
by all filesystem types */
char d_name[256]; /* Null-terminated filename */
};
In my case, I'm still using the old dirent structure, so user space programs are unable to take advantage of this field.
That's clears it up.
@tytso, thank you very much for your explanation.
from e2fsprogs.
Related Issues (20)
- Can't repair ext4 partition after power outage, e2fsck keeps crashing HOT 2
- m_rootdir_acl test fails when run from a btrfs filesystem (since its' introduction in v1.46.1) HOT 7
- Question: why there are 256 blocks for backup of superblock and block group descriptor table? HOT 2
- Memory leak in function compile_fs_type
- e2fsdroid is not compiling
- Is there a way to pass selinux file_contexts file to the mkfs.ext4 while building image?
- Extraneous tab inside output of tune2fs HOT 1
- Allow setting root dir permissions directly in mke2fs HOT 2
- e2scrub finds corruption immediately after mounting
- Correct smallest size estimation for `resize2fs` shrink HOT 3
- badblocks fails on large drives due to 32 bit value HOT 1
- Building for Windows
- Is mke2fs GPLv3 compatible? HOT 2
- Building on cygwin
- Building on MINGW
- Whether it is possible to erase the signature of the old file system before executing mkfs.ext4 HOT 1
- e2mkdir 'No free space in the directory' failure HOT 1
- tune2fs asks unwanted questions HOT 6
- Division by zero in e2fsck HOT 1
- `E2FSPROGS_FAKE_TIME` not respected when setting time to 0 HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from e2fsprogs.