***
10->16 ๋ณํ : https://ko.calcuworld.com/%EC%88%98%ED%95%99/16%EC%A7%84%EB%B2%95-%EA%B3%84%EC%82%B0%EA%B8%B0/
16๊ณฑ์ : https://kor.foxcalculators.com/converter/4824.html
16๋ง์ : https://purecalculators.com/ko/hex-calculator
***
1-3. DBM, IBM์ ๋ถ์ํ์ฌ inode ์ฐพ๊ธฐ
3. Directory file, Regular file
1) Make a virtual floppy disk
dd bs=1024 count=1440 if=/dev/zero of=myfd
๊ฐ์ ๋์คํฌ ์์ฑ
bs : ํ ๋ฒ์ ์ฒ๋ฆฌํ ๋ฐ์ดํฐ ํฌ๊ธฐ
count : ๋ธ๋ก์ ๊ฐ์
2) format
### ํฌ๋งท ๋ช
๋ น์ด
mkfs -t ext2 myfd
3) mount
mkdir temp # ๋น ๋๋ ํ ๋ฆฌ ์์ฑ
mouunt -o loop myfd temp
'myfd'๋ฅผ 'temp'dp dusruf
4) make some files
cd temp
echo korea > f1
5) read
cd ..
umount temp #์ฐ๊ฒฐ ๋๊ธฐ
xxd -g1 myfd > x
vi x
๋ฐ์ดํธ ๋จ์๋ก ์ฝ์ด์ x์ ์ ์ฅ
include/linux/ext2_fs.h
struct ext2_super_block {
__le32 s_inodes_count; /* Inodes count */
__le32 s_blocks_count; /* Blocks count */
__le32 s_r_blocks_count; /* Reserved blocks count */
__le32 s_free_blocks_count; /* Free blocks count */
__le32 s_free_inodes_count; /* Free inodes count */
__le32 s_first_data_block; /* First Data Block */
__le32 s_log_block_size; /* Block size */
__le32 s_log_frag_size; /* Fragment size */
__le32 s_blocks_per_group; /* # Blocks per group */
__le32 s_frags_per_group; /* # Fragments per group */
__le32 s_inodes_per_group; /* # Inodes per group */
__le32 s_mtime; /* Mount time */
__le32 s_wtime; /* Write time */
__le16 s_mnt_count; /* Mount count */
__le16 s_max_mnt_count; /* Maximal mount count */
__le16 s_magic; /* Magic signature */
...
Superblock starts at offset 1024(400h)
m_inode_count : inode total ๊ฐ์
m_block_count : count
m_magic : magic numver๋ก ๋ฆฌ๋ ์ค์ ํ์ผ ์์คํ
m_log_block_size : ๋ธ๋ก ์ฌ์ด์ฆ
m_first_data_block : ๋ช ๋ฒ์งธ ๋ธ๋ก์ธ์ง
super block ๋ถ์
-์ฃผ์ : ๊ฑฐ๊พธ๋ก ์ฝ์ด์ฃผ๊ธฐ
m_inode_count : b8 00 00 00 : (=184) ์ด 184๊ฐ์ inode๊ฐ ์๋ค
m_block_count : a0 05 00 00 : (=05a0 = 1440) count=1440์ผ๋ก ์ค์ ํด์ค ๊ฒ์ ํ์ธํ ์ ์๋ค.
m_magic : ef 53
m_first_data_block : 00 00 00 01์ด๋ฏ๋ก ๊ฑฐ๊พธ๋ก ์ฝ์ด์ฃผ๋ฉด 1. ์ฆ, ์ฒซ ๋ฒ์งธ ๋ธ๋ก
m_log_block_size : 00 00 00 00์ด๋ฏ๋ก block size = 1024 * 2^0 = 1024 byte
include/linux/ext2_fs.h:
superblock ๋ค์์ด Group Descriptor์ด๋ฏ๋ก 800h์ ์์นํ ๊ฒ์ด๋ค. <block๋ 1024(400h)์ด๋ฏ๋ก ํ ๋ธ๋ก์ 400h์ฉ>
- block location of DBM : 08 00 00 00 => 00 00 00 08 = 8 ์ด๋ค.
- block location of IBM : 09 00 00 00 => 00 00 00 09 = 9 ์ด๋ค.
- block location of inode table : 0a 00 00 00 => 00 00 00 0a = a(10)์ด๋ค.
<<<DBM, IBM์ ์ฝ๊ณ ์ฌ์ฉ์ค์ธ inode, block ๋ฒํธ ์ฐพ๊ธฐ>>>
DBM์ด 8์ด๋ฏ๋ก 8*400h -> 2000h
ff ff ff ff ff 7f (16) -> 11111111 11111111 11111111 11111111 11111111 01111111 : 48๊ฐ ์ค 1๊ฐ๊ฐ ๋น ์ํ
IBM์ด 9์ด๋ฏ๋ก 9*400h -> 2400h
ff 0f 00 00 (16) -> 111111111 00001111 : 12๊ฐ์ ๋ธ๋ก ์ฌ์ฉ์ค -> ์ด 12๊ฐ์ inode๊ฐ ์ฌ์ฉ์ค์ด๋ค.
** inode ๊ฐ์ ํ์ธํ๊ธฐ**
์์์ m_inode_count๋ 184์์ผ๋ฏ๋ก ์ด 184๊ฐ์ inode์์ 12๊ฐ๋ฅผ ์ฌ์ฉํ๋ฉด 172๊ฐ๊ฐ ๋จ๋๋ค
m_free_inode_count์ ์ ์ฅ๋ ๊ฐ์ ํ์ธํด๋ณด๋ฉด 00 00 00 ac์ด๋ฏ๋ก 172๊ฐ๊ฐ ๋ง๋ ๊ฒ์ ํ์ธํ ์ ์๋ค.
<<<inode table>>>
inode table์๋ ํ์ผ์ ์์น๊ฐ ์ ์ฅ๋์ด ์๋ค. ํ์ผ์ ์์น๋ฅผ ํ์ธํ์ฌ ์ด๋ํ๋ฉด ๋ฐ์ดํฐ๊ฐ ๋ณด์ผ ๊ฒ!
include/linux/ext2_fs.h:
struct ext2_inode {
__le16 i_mode; /* File mode */
__le16 i_uid; /* Low 16 bits of Owner Uid */
__le32 i_size; /* Size in bytes */
__le32 i_atime; /* Access time */
__le32 i_ctime; /* Creation time */
__le32 i_mtime; /* Modification time */
__le32 i_dtime; /* Deletion Time */
__le16 i_gid; /* Low 16 bits of Group Id */
__le16 i_links_count; /* Links count */
__le32 i_blocks; /* Blocks count */
__le32 i_flags; /* File flags */
union {
struct {
__le32 l_i_reserved1;
} linux1;
struct {
__le32 h_i_translator;
} hurd1;
struct {
__le32 m_i_reserved1;
} masix1;
} osd1; /* OS dependent 1 */
__le32 i_block[EXT2_N_BLOCKS]; /* Pointers to blocks */
...
};
inode table์ด a(10)์ด์์ผ๋ฏ๋ก a*400 = 2800h
ํ๋์ inode๋ 128byte๋ฅผ ์ฐจ์งํ๋ฏ๋ก 16์ง์๋ก ๋ฐ๊พธ๋ฉด 80h์ด๋ค. root directory๋ 2๋ฒ์ด๋ฏ๋ก,
2800 + 80 = 2880h์ด inode 2๋ฒ์ ํด๋นํ๋ table์ด๋ค.
block size : 02 00 00 00 -> 00 00 00 02์ด๋ฏ๋ก 2๋ธ๋ฝ์ ์ฐจ์งํจ.
block location : 21์ 10์ง์๋ก ๋ฐ๊พธ๋ฉด 33์ผ๋ก, 33๋ฒ์งธ ๋ธ๋ฝ์ ์์นํ๋ ๊ฒ์ ์ ์ ์๋ค.
i_size : 00 04 00 00 -> 400->1024๋ฐ์ดํธ
<<Directory file, Regular file>>
Regular file์ data๊ฐ ์๋ ํ์ผ์ด๊ณ , Directory file์ ํ์ผ ์ด๋ฆ, ํ์ผ ํ์ ๊ณผ ๊ฐ์ ์ ๋ณด๊ฐ ์๋ค.
struct ext2_dir_entry_2 { //directory file
__le32 inode; /* Inode number */
__le16 rec_len; /* Directory entry length */
__u8 name_len; /* Name length */
__u8 file_type;
char name[EXT2_NAME_LEN]; /* File name */
};
์์์ ๋ฃจํธ ๋๋ ํ ๋ฆฌ ํ์ผ์ 21h ๋ธ๋ฝ์ ์กด์ฌํ ๊ฒ์ ์ ์ ์์๋ค.
21 * 400(1024๋ฐ์ดํธ๋ก ์ค์ ํด์ฃผ์์ผ๋๊น) = 8400h
inode ๋ฒํธ : 4 byte
rec_len : 2byte //๋ฐ์ดํธ ์
name_len : 1byte //ํ์ผ ์ด๋ฆ ๊ธ์ ์
file type : 1(๋ด์ฉ ์๋ data type) , 2(๋ด์ฉ ์๋ ํ์ )
์๋ฅผ ํ ๋๋ก f1 ํ๋๋ง ๋ถ์ํด๋ณด์๋ฉด,
Inode ๋ฒํธ : 0c => 12๋ฒ
๋ฐ์ดํธ ์ : c => 12byte
Name length : 2๊ธ์
File type : 1 => ๋ด์ฉ์ด ์๋ data type
์์คํค์ฝ๋๋ก ํ์ผ ์ด๋ฆ ๋ถ์ -> f1
<<<data content ํ์ธ>>>
๊ณต์ : inode table ์์น + (inode - 1) * 0x80(=inode ํฌ๊ธฐ)
f1์ ๋ด์ฉ์ด ์ ์ฅ๋ block location์ ์ฐพ์๋ณด์.
0x2800 + (12-1) *0x80 = 2d80h
blcok location : 2f
ํ ๋ธ๋ญ์ด 400h(=1024byte๋ก ์ค์ ํด์ฃผ์๊ธฐ ๋๋ฌธ)์ด๋ฏ๋ก
2f * 400h = bc00
korea data ํ์ธ ์๋ฃ !
์ ์ฒด ํ์ธ ์ฝ๋
<disk.c>
inode count : 184
blocks count = 1440
dbm, ibm, inode table
block location <๋ธ๋ญ ์์นh * 400h(๋ฐ์ดํธ)>
'์์ > os' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[os] memory management (0) | 2022.11.26 |
---|---|
os file sys2 (0) | 2022.11.24 |
[os]memory file system (0) | 2022.11.18 |