ext4 exploring - efanov/mephi GitHub Wiki

$ dd if=/dev/zero of=fs.img bs=1M count=100 100+0 records in 100+0 records out 104857600 bytes (105 MB, 100 MiB) copied, 0.0820412 s, 1.3 GB/s $ mkfs -t ext4 fs.img mke2fs 1.45.5 (07-Jan-2020) Discarding device blocks: done
Creating filesystem with 102400 1k blocks and 25688 inodes Filesystem UUID: 12c8c0a2-f03a-46b7-9a9d-16ecf217dd78 Superblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729

Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done Writing superblocks and filesystem accounting information: done

$ dumpe2fs -h fs.img dumpe2fs 1.45.5 (07-Jan-2020) Filesystem volume name: Last mounted on: Filesystem UUID: 12c8c0a2-f03a-46b7-9a9d-16ecf217dd78 Filesystem magic number: 0xEF53 Filesystem revision #: 1 (dynamic) Filesystem features: has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csum Filesystem flags: signed_directory_hash Default mount options: user_xattr acl Filesystem state: clean Errors behavior: Continue Filesystem OS type: Linux Inode count: 25688 Block count: 102400 Reserved block count: 5120 Free blocks: 93504 Free inodes: 25677 First block: 1 Block size: 1024 Fragment size: 1024 Group descriptor size: 64 Reserved GDT blocks: 256 Blocks per group: 8192 Fragments per group: 8192 Inodes per group: 1976 Inode blocks per group: 247 Flex block group size: 16 Filesystem created: Mon Feb 13 17:56:41 2023 Last mount time: n/a Last write time: Mon Feb 13 17:56:41 2023 Mount count: 0 Maximum mount count: -1 Last checked: Mon Feb 13 17:56:41 2023 Check interval: 0 () Lifetime writes: 278 kB Reserved blocks uid: 0 (user root) Reserved blocks gid: 0 (group root) First inode: 11 Inode size: 128 Journal inode: 8 Default directory hash: half_md4 Directory Hash Seed: f169908c-2a43-4c19-a13c-ab6d2d11ab8e Journal backup: inode blocks Checksum type: crc32c Checksum: 0x77d17492 Journal features: (none) Journal size: 4096k Journal length: 4096 Journal sequence: 0x00000001 Journal start: 0

losetup --find --show fs.img

/dev/loop0

losetup --list

NAME SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE DIO LOG-SEC /dev/loop0 0 0 0 0 /root/fs.img 0 512

mount fs.img /mnt

echo 'Extent'>/mnt/file_ext4

lsattr /mnt/file_ext4

--------------e----- /mnt/file_ext4

Создадим ext3, создадим на ней обычный файл - данные будут храниться в виде блоков. Потом добавим опцию extent и смонтируем как ext4. Создадим ещё один файл - данные будут храниться в виде экстента.

$ dd if=/dev/zero of=fs-ext3.img bs=1M count=100 100+0 records in 100+0 records out 104857600 bytes (105 MB, 100 MiB) copied, 0.085753 s, 1.2 GB/s

$ mkfs -t ext3 fs-ext3.img mke2fs 1.45.5 (07-Jan-2020) Discarding device blocks: done
Creating filesystem with 102400 1k blocks and 25688 inodes Filesystem UUID: 274eb5b1-e0e8-48f1-9051-7a8b768c536d Superblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729

Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done Writing superblocks and filesystem accounting information: done

losetup --find --show fs-ext3.img

/dev/loop0

mount -t ext3 fs-ext3.img /mnt

dd if=/dev/zero bs=1K count=2 > /mnt/file-blocks

2+0 records in 2+0 records out 2048 bytes (2.0 kB, 2.0 KiB) copied, 0.000168946 s, 12.1 MB/s

umount /mnt

dumpe2fs -h fs-ext3.img

dumpe2fs 1.45.5 (07-Jan-2020) Filesystem volume name: Last mounted on: /mnt Filesystem UUID: 274eb5b1-e0e8-48f1-9051-7a8b768c536d Filesystem magic number: 0xEF53 Filesystem revision #: 1 (dynamic) Filesystem features: has_journal ext_attr resize_inode dir_index filetype sparse_super large_file - нет поддержки экстентов

tune2fs -O extent fs-ext3.img

tune2fs 1.45.5 (07-Jan-2020)

dumpe2fs -h fs-ext3.img | grep 'Filesystem features'

dumpe2fs 1.45.5 (07-Jan-2020) Filesystem features: has_journal ext_attr resize_inode dir_index filetype extent sparse_super large_file - теперь есть

mount -t ext4 fs-ext3.img /mnt - теперь монтировать можно только как ext4

dd if=/dev/zero bs=1K count=2 > /mnt/file-extent

2+0 records in 2+0 records out 2048 bytes (2.0 kB, 2.0 KiB) copied, 3.1438e-05 s, 65.1 MB/s

ls -il /mnt/

total 18 12 -rw-r--r--. 1 root root 2048 Feb 14 04:05 file-blocks 13 -rw-r--r--. 1 root root 2048 Feb 14 04:13 file-extent 11 drwx------. 2 root root 12288 Feb 14 04:00 lost+found - видно, что первый инод - 11

lsattr /mnt/

--------------e----- /mnt/file-extent - видно о чём говорит этот флаг -------------------- /mnt/file-blocks

umount /mnt

$ debugfs fs-ext3.img

debugfs: stat <12> Inode: 12 Type: regular Mode: 0644 Flags: 0x0 Generation: 4134292589 Version: 0x00000001 User: 0 Group: 0 Size: 2048 File ACL: 4635 Links: 1 Blockcount: 6 Fragment: Address: 0 Number: 0 Size: 0 ctime: 0x63eade6e -- Tue Feb 14 04:05:50 2023 atime: 0x63eade6e -- Tue Feb 14 04:05:50 2023 mtime: 0x63eade6e -- Tue Feb 14 04:05:50 2023 Extended attributes: security.selinux (37) = "unconfined_u:object_r:unlabeled_t:s0\000" BLOCKS: (0-1):5121-5122 TOTAL: 2

debugfs: stat <13> Inode: 13 Type: regular Mode: 0644 Flags: 0x80000 Generation: 1956869116 Version: 0x00000001 User: 0 Group: 0 Size: 2048 File ACL: 4636 Links: 1 Blockcount: 6 Fragment: Address: 0 Number: 0 Size: 0 ctime: 0x63eae03d -- Tue Feb 14 04:13:33 2023 atime: 0x63eae03d -- Tue Feb 14 04:13:33 2023 mtime: 0x63eae03d -- Tue Feb 14 04:13:33 2023 Extended attributes: security.selinux (37) = "unconfined_u:object_r:unlabeled_t:s0\000" EXTENTS: (0-1):5123-5124

Как формируются экстенты - непонятно. В i_block записывается заголовок экстента 0xF30A. Нужны большие файлы.

debugfs: blocks <12> 5121 5122 debugfs: blocks <13> 5123 5124

⚠️ **GitHub.com Fallback** ⚠️