Minix File System Learning. _ File System

Source: Internet
Author: User
Tags readable
Minix File System learning.

----------------------------------------
1. Create a Minix disk.
----------------------------------------
A. Create a 360K, blank image
DD If=/dev/zero of=image_360 count=720
B. Associated with the loop device
sudo losetup/dev/loop0 image_360
C. format disk as Minix format
sudo mkfs-t minix/dev/loop0
128 Inodes
360 blocks
Firstdatazone=8 (8)
zonesize=1024
maxsize=268966912
D. mount a device to an installation point
sudo mount/dev/loop0/mnt
E. Copying files to devices, for example:
sudo cp crash.cpp makefile/mnt
F. Uninstall installation point
sudo umount/mnt
G. Uninstalling equipment
sudo losetup-d/dev/loop0

----------------------------------------
2. The above command is organized with an SH file.
----------------------------------------
$ cat test.sh
#!/bin/bash-x
DD If=/dev/zero of=image_360 count=720
sudo losetup/dev/loop0 image_360
sudo mkfs-t minix/dev/loop0
sudo mount/dev/loop0/mnt
sudo cp crash.cpp makefile/mnt
sudo umount/mnt
sudo losetup-d/dev/loop0

----------------------------------------
3. Study of IMAGE_360 data composition
----------------------------------------
$hexdump image_360 > Minix_360.txt
0000000 0000 0000 0000 0000 0000 0000 0000 0000//Boot block is NO. 0 plate block
*
0000400 0080 0168 0001 0001 0008 0000 1c00 1008//1th disk block is super block
0000410 138f 0001 0000 0000 0000 0000 0000 0000 struct D_super_block {
0000420 0000 0000 0000 0000 0000 0000 0000 0000 unsigned short s_ninodes;
unsigned short s_nzones;
unsigned short s_imap_blocks;
unsigned short s_zmap_blocks;
unsigned short s_firstdatazone;
unsigned short s_log_zone_size;
unsigned long s_max_size;
unsigned short s_magic;
};

This is known:
Inodes = 0x80 =128
Zones = 0x168 = 360
Inode map takes up a piece of
Zone map takes up a piece of
The zone in the 8th block.
Log zone size is 0, logical block is the same as disk block
MAX_SIZE:0X10081C00 This pair of 360KB wrong.
Magic = 0x138f

*
0000800 000f 0000 0000 0000 0000 0000 0000 0000//2nd plate block. Inode bitmap
0000810 Fffe ffff ffff ffff ffff ffff ffff ffff//bit0 No, 128 bits capacity
0000820 ffff ffff ffff ffff ffff ffff FFFF FFFF//Where 3 inode is used
Bit1 represents the root directory, Bit2 represents the first file,
BIT3 represents a second file
*
0000c00 000f 0000 0000 0000 0000 0000 0000 0000//3rd plate block. Zone bitmap
0000c10 0000 0000 0000 0000 0000, 0000 0000//0000 No, 360 bits capacity
0000c20 0000 0000 0000 0000 0000 0000//Of which 3 Fffe were used.
0000C30 ffff ffff ffff ffff ffff ffff FFFF FFFF
*

0001000 41ed 0000 0080 0000 BC17 57be 0200 0008//4th plate block. (4,5,6,7 disk block)
0001010 0000 0000 0000 0000 0000 0000 0000 0000//Inodes (3 active Inode)
0001020 81a4 0000 011c 0000 BC17 57be 0100 0009 struct D_inode {
0001030 0000 0000 0000 0000 0000 0000 0000 0000 unsigned short i_mode;
0001040 81a4 0000 002b 0000 BC17 57be 0100 000a unsigned short i_uid;
0001050 0000 0000 0000 0000 0000 0000 0000 0000 unsigned long i_size;
* unsigned long i_time;
1. Each inode occupies 0x20 a bytes. unsigned char i_gid;
2. UID 0 is represented as root unsigned char i_nlinks;
3. Mode meaning: unsigned short i_zone[9];
};
15 14 13 12 11 10 9 8 7 6 5 4 3 2-1 0
R d c F g u r W x R W x r W x

Bit8-bit0: Host (RWX)-Crew (RWX)-Others (RWX)
Bit9: Setting uid at execution time
Bit10: Set GID at execution time
BIT11: I don't know.
Bit12:fifo file
BIT13: Character device files
BIT14: Catalog File
BIT15: Regular files
When bit13, Bit14 is set, represents the block device file
0x41ed says: Creator, readable, writable, executable.
Same group and others, readable, executable, not writable
is a directory file
0X81A4 says: Creator, readable, writable. The same group and other people can read
is a regular file
4. Time can be converted with the date command, for example:
date-d @ ' printf '%d\n ' 0X57BEBC17 '
Thursday, August 25, 2016 17:36:23 CST

5. Nlinks: Find this inode node from the number of filenames
6. I_zone 7 direct block, an indirect block, a two-level indirect block

struct Dir_entry {
unsigned short inode;
Char Name[name_len];
};

0002000 0001 002e 0000 0000 0000 0000 0000 0000//8th disk block, data disk block, this disk block is the root directory content
0002010 0000 0000 0000 0000 0000 0000 0000 0000//Corresponding to the first inode data, is a catalog item content
0002020 0001 2e2e 0000 0000 0000 0000 0000 0000 struct Dir_entry {
0002030 0000 0000 0000 0000 0000 0000 0000 0000 short Inode;
0002040 0002 7263 7361 2e68 7063 0070 0000 0000 char Name[name_len];
0002050 0000 0000 0000 0000 0000 0000 0000 0000};
0002060 0003 614d 656b 6966 656c 0000 0000 0000 The Name_len here is 30,
0002070 0000 0000 0000 0000 0000 0000 0000 0000 Specific data contents are supplemented.
*
0002400 6923 636e 756c 6564 3c20 7473 6964//Data disk block, 9th disk block, corresponding to the second inode data
0002410 3e68 0a0a 6e69 2074 6574 7473 635f 6172//Pure data, the specific data content is added after the meeting.
0002420 6873 6928 746e 6920 0a29 0a7b 2009 6572
0002430 7574 6e72 3120 692f 2a20 3120 3030 0a3b
0002440 0a7d 6e69 2074 616d 6e69 6928 746e 6120
0002450 6772 2c63 6320 6168 2072 612a 6772 5b76
0002460 295d 2020 7b0a 2020 200a 2020 2020 2020
0002470 7020 6972 746e 2866 6822 6c65 6f6c 6e5c
0002480 2922 203b 0a20 2020 2020 2020 2020 6e69
0002490 2074 206b 203d 6574 7473 635f 6172 6873
00024a0 3028 3b29 2020 2f2f e420 A0BC 85e5 e4a5
00024b0 80b8 b8e4 e9aa 9e9d b3e6 e595 b09c 9de5
00024C0 2080 0a20 0909 7270 6e69 6674 2228 6163
00024d0 276e 2074 6f67 2074 6568 6572 5c21 226e
00024e0 3b29 200a 2020 2020 2020 7020 6972 746e
00024f0 2866 6b22 6920 2073 6425 6e5c 2c22 296b
0002500 203b 0a20 2020 2020 2020 2020 6572 7574
0002510 6e72 3020 203b 0a20 207d 0a20 0000 0000
0002520 0000 0000 0000 0000 0000 0000 0000 0000
*
0002800 7263 7361 3a68 7263 7361 2e68 7063//Data disk block, 10th disk block, corresponding to the third inode data
0002810 6709 2b2b 2d20 2067 6f2d 6320 6172 6873//Pure data, supplemented with specific data content.
0002820 6320 6172 6873 632e 7070 000a 0000 0000
0002830 0000 0000 0000 0000 0000 0000 0000 0000
*
005a000//End of File

########################################
Pure data content supplements, for completeness.
########################################
$hexdump-C image_360
......
00002000 2e 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00002010 00 00 00 00 00 00 00 00 00 00 00 00 00 00-00 00 |................|
00002020 2e 2e 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00002030 00 00 00 00 00 00 00 00 00 00 00 00 00 00-00 00 |................|
00002040 2e 63 70 70 00 00 00 00 00 |. crash.cpp.....|
00002050 00 00 00 00 00 00 00 00 00 00 00 00 00 00-00 00 |................|
00002060 4d 6b (6c) 65 00 00 00 00 00 00 |. makefile......|
00002070 00 00 00 00 00 00 00 00 00 00 00 00 00 00-00 00 |................|
*
00002400 6e 6c <stdio.| 3c-the 6f 2e | #include
00002410 3e 0a 0a |h&gt 6e------ int test_cra|
00002420 6e (0a 7b 0a)-|sh (int i). {.. re|
00002430 6e 2f (2a) 3b 0a |turn 1/i * 100;.|
00002440 7d 0a (6e) 6d 6e 74 20 61 |}. int main (int a|
00002450, 2c, 2a, 5b |RGC, Char *argv[|.
00002460 5d 0a 7b 0a 20 20 20 20 20 20 20 |] .       {  . |
00002470 6e--6c 6c 6f 5c 6e | printf ("hello\n|
00002480 3b 0a 6e | ");..... in|
00002490 6b 3d |t (5f) (MB) (k = test_crash|)
000024A0 3b 2f 2f e4 BC A0 e5 a5 e4 |  (0); // .......|
000024b0 b8 e4 b8 aa E9 9d 9e e6 b3 e5 9c b0 e5 9d |................|
000024C0 0a 6e 74 66 28 22 63 61 |. ... printf ("ca|
000024d0 6e 6f |n, 5c 6e got here!\n ' t-m |
000024E0 3b 0a (74 |);.... Print|
000024F0 6b, 5c 6e 2c 6b |f ("K is%d\n", k) |
00002500 3b 0a 20 20 20 20 20 20 20 20 72 65 74 75 |;        . retu|
00002510 6e 3b 0a 7d 0a |rn 0;);  .} .....|
00002520 00 00 00 00 00 00 00 00 00 00 00 00 00 00-00 00 |................|
*
00002800, 3a, 2e, 0a, |crash:crash.cpp.|.
00002810 2b 2b 2d 2d 6f 20 63 72 61 73 68 |. g++-g-o crash|
00002820, 2e 0a 00 00 00 00 00 | crash.cpp......|
00002830 00 00 00 00 00 00 00 00 00 00 00 00 00 00-00 00 |................|
*
0005a000

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.