From bc7cdcabe0b43adcf09790c8a887abafe4cd5b32 Mon Sep 17 00:00:00 2001 From: "Dr. Powers" <86083075+p-w-rs@users.noreply.github.com> Date: Wed, 1 Feb 2023 15:41:16 -0600 Subject: [PATCH] Update README.md --- 07-FunWithFileSystems/README.md | 207 -------------------------------- 1 file changed, 207 deletions(-) diff --git a/07-FunWithFileSystems/README.md b/07-FunWithFileSystems/README.md index 04cc347..a74f497 100644 --- a/07-FunWithFileSystems/README.md +++ b/07-FunWithFileSystems/README.md @@ -128,210 +128,3 @@ Unmount the file system with umount when done. When you have completed the step 2. Look at the image file with hexdump (hexdump –C flash.img | more). NOTE: make sure the image is **unmounted** before you do this. Can you find your files? How about the ones you deleted? How did you find them or why couldn't you? 3. Show a capture of the hexdump (of the flash.img) containing the directory entries for the files you added to the image as well as the ones you added and then deleted. What is different? 4. Remount the image, change directory to the directory where the file system is mounted. Now try to unmount the file system with "umount /media/myimage". Did it work successfully? Why or why not? - -## Interpreting a File System - TTFS - -Linux supports many file system types. Each has their own intended use along with advantages and disadvantages. New file systems are being developed all the time to fit the needs of newer backing storage and application purposes. In this activity you will be given the format for a new file system (teeny tiny file system – TTFS). Study the file system format and use the information to interpret a binary file containing a TTFS file system image. - -TTFS stores files and directories of varying sizes. Each file is allocated one or more blocks of data. An index node (inode) stores information about a file or directory in the file system. A TTFS file system image is a binary file divided into the following regions: - -1. File system super block – contains information about the entire file system -2. inode bitmap – a bit map that indicates which inodes are free and which are used to store file information -3. block bitmap – a bit map that indicates which blocks are free and which hare used to store file data -4. inode table – an array of inodes for files and directories in the file system -5. block array – the array of data blocks for files and directories in the file system - -An image for TTFS is laid out like this: - - - -Regions of the file system follow immediately after each other. The super block contains offset values that can be used to find where regions begin. Data blocks are 512 bytes long and are accessed via their block index. The block index is zero based, so the first block is block 0, the second is block 1, etc. - -### TTFS Super Block - -Each field in the super block is 4 bytes. The offset numbers indicate where the region begins from the ***start of the file system image***. Here is a diagram of each of the fields contained in the super block. - -
| TTFS Super Block |
|---|
| TTFS Magic Value |
| inode count |
| block count |
| offset to inode bitmap |
| offset to block bitmap |
| offset to inode table |
| offset to data blocks |
| unused pads to 32 bytes |
-54 54 46 53 14 00 00 00 64 00 00 00 20 00 00 00 |TTFS....d... ...| -23 00 00 00 30 00 00 00 30 05 00 00 00 00 00 00 |#...0...0.......| -- -
54 54 46 53 is the TTFS magic value14 00 00 00 is the number of inodes – hex 00 00 00 14 -> 20 in decimal64 00 00 00 is the number of blocks – hex 00 00 00 64 -> 100 in decimal20 00 00 00 is the offset to the inode bitmap – hex 00 00 00 20 -> 32 in decimal23 00 00 00 is the offset to the block bitmap – hex 00 00 00 23 -> 35 in decimal30 00 00 00 is the offset to the inode table – hex 00 00 00 30 -> 48 in decimal30 05 00 00 is the offset to the block array – hex 00 00 05 30 -> 1328 in decimal
-
-### TTFS Index Node
-
-An index node contains metadata (data about the data) for a file or directory. The inode table contains an array of inodes, each inode is 64 bytes long and contains several fields.
-
-The structure of an inode is as follows:
-
-
-
-- U – used bit – a single bit that indicates if this inode is used for a file (or directory) or not
-- D – directory bit – a single bit that indicates if this inode is for a regular file or a directory
-- block count – (1 byte) the total number of data blocks this file is using
-- file name – (22 bytes) a string of characters representing the name of the file (null terminated). The file name in TTFS cannot be longer than 21 characters to make room for the null terminator
-- file size – (4 bytes – little endian) represents the total size of the file in bytes. Block are 512 bytes long and a file might not end exactly at the end of a block
-- allocated block table – (up to 9 entries 4 bytes each little endian) represents the block numbers that are allocated to this file. The block count indicates which entries in this table are valid. NOTE: Entries in the table indicate the block number for the allocated block number, not an offset in bytes.
-
-The inode for a file consisting of 1 data block, that is using 10 bytes might look like this in a hexadecimal dump:
-
--01 01 74 65 73 74 2e 74 78 74 00 00 00 00 00 00 |..test.txt......| -00 00 00 00 00 00 00 00 0a 00 00 00 01 00 00 00 |................| -00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| -..... rest of the inode is zeros ..... -- -
01 shows the used bit is on but the directory bit is not01 indicates the is 1 used block in the file74 65 73 74 2e 74 78 74 is the name of the file - ASCII text "test.txt"0a 00 00 00 is the size of the file in bytes – hex 00 00 00 0a -> 10 in decimal01 00 00 00 is the index of the first (and only) data block – hex 00 00 00 01 -> 1 in decimal
-
-### TTFS Directory
-
-Directories (folders) in TTFS are special files. The inode for a directory has the directory bit flipped to indicate that is a directory and not an ordinary file. The data blocks for a directory entry to not contain file data. Instead, they indicate the inodes for the files (or directories) that are contained in the directory. The structure for a directory entry data block is:
-
-
-
-The first 4 bytes indicates an integer number (little endian) of the number of entries contained in the block. The rest of the data block contains 4-byte integers (little endian) for the inodes for entries (files or directories).
-
-For example, consider a directory 'mydir' that contains two files 'file1.txt' and 'file2.txt'
-
-
-
-The inode for 'mydir' (inode 3) would contain a single data block. The directory data block would look like:
-
--02 00 00 00 05 00 00 00 06 00 00 00 00 00 00 00 |................| -00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| -..... rest of the block is zeros ..... -- -
02 00 00 00 is the number of files in the block05 00 00 00 is the inode number for file1.txt – hex 00 00 00 05 -> 5 in decimal06 00 00 00 is the inode number for file2.txt – hex 00 00 00 06 -> 6 in decimal