Linux file system homework

1. There are a total of 500 disk blocks in a disk file space. If a bitmap with a word length of 32 bits is used to manage the disk, please ask:

(1) How many bytes does the bitmap need?
(2) What is the block number corresponding to the jth bit of the i-th byte?

(1) 500/32=15.625, 16 bytes are required

(2) The corresponding disk block number is: 32 * i + j

2. If the disk block size is 4KB, the block address is represented by 4 bytes, the file system adopts an index organization method, index items 0 to 9 are direct indexes, index item 10 is a primary indirect index, and index item 11 is a secondary index Indirect index, index item 12 is a three-level indirect index. If the file index node is already in the memory, please calculate how many disk blocks do you need to read and write when reading 1500 bytes of data below the file?

(1)9000
(2)180000
(3)4200000

(1) 9000 / 4k = 2.197265625 position 9000 is in index item 2

​ (9000 + 1500) /4k = 2.5634765625 The position (9000 + 1500) is located in index item 2, and 1 disk block needs to be read and written

(2) 180000 / 4k = 43.9453125

​ (180000+ 1500)/4k = 44.3115234375 located in index item 10, 3 disk blocks need to be read and written

(3) 4200000 / 4k = 1,025.390625

​ (4200000+ 1500) / 4k = 1,025.7568359375 at index item 10, 2 disk blocks need to be read and written

3. A computer system uses the bitmap shown in Figure 4-24 (the row number and column number are numbered starting from 0) to manage free disk blocks. If disk blocks are numbered starting from 0, the size of each disk block is 1KB.

Insert picture description here

(1) Now to allocate two disk blocks for the file, try to specify the allocation process.
(2) What should I do if I want to release the 1000th block of the disk?
(3) Assuming that the bitmap represented by the global array variable short bm [N] has been read into the memory, write out the allocation function alloc () that returns a free disk block number, and the recovery function int release (intb) that returns a disk block b ) Description code.

(1) Find a free disk block, hang to the end of the disk block chain of the file, and modify the FCB of the file.

(2) Find FAT, find the location of the 1000th disk block, delete the information at that location, and delete other pointers linked to this location.

​ (3)

int alloc()
{
    
    
	for(int i = 0; i < N; i++)
        for(int j = 0; j < 16; j++)
        {
    
    
            if(!(bm[i] & 1 << j)
                return i*16 + j+1;
        }
    return -1;
}
               
int release (int b)
{
    
    
	int bx = b / 16;
    int by = b % 16;
    bm[bx] &= ~(1 << by);
    return 0;
}

4. Assuming that the size of the logical block and physical block of a certain system on the disk is 4KB, and the disk block number is stored in 4 bytes, it is assumed that the attribute information of each file is already in the memory. For the three allocation methods (continuous allocation, link allocation, and index allocation), assuming that you are currently in logical block 10 (the last accessed is logical block 10), and now you want to access logical block 4, how many physical blocks must be read from the disk ? Give reasons.

1 (Direct access) 4 (Access logical blocks in sequence) 2 (First read the index node, and then obtain direct index access)

5. The directory structure of a file system is shown in Figure 4-30, using an integrated directory, each directory entry occupies 256B, and the disk block size is 512B. Assume that the current directory is the root directory.

Insert picture description here

(1) What is the path of the file Wang?
(2) Which directory files does the system need to read before it can find the file Wang?
(3) The system finds the file Wang, at least how many disk blocks need to be read?
(4) Provide a directory structure that speeds up file search.

(1)/D/DC/DDC/Wang

(2) 4 directory files: /, /D, /D/DC, /D/DC/DDC

(3) 7

(4) Adopting decomposed catalog management

6. Consider a file containing 100 data blocks. If the file control block (and index block, when allocated with an index) is already in memory, the logical block is the same size as the physical block. When using continuous, linked, and single-level index allocation strategies, how many disk IO operations are required for each of the following operations? Assume that during continuous allocation, there is no expansion space at the beginning, but there is expansion space at the end, and it is assumed that the block is to be added. The information is already in memory.

(1) Add a block at the beginning.
(2) Add a piece in the middle
(3) Add a piece at the end.
(4) Delete a block at the beginning.
(5) Delete a block in the middle.
(6) Delete a piece at the end.

Continuous: 101, 51, 1, 99, 49, 0

Links: 1, 50, 100, 1, 50, 100

Single level: 1, 1, 1, 0, 0, 0

7. Consider a file system that uses inodes to represent files. The disk block size is 8kb, and the pointer to the disk block requires 4 bytes. This file system has 12 direct disk blocks, as well as single, double, and triple indirect disk blocks. What is the maximum size of files that can be stored in this file system?

8kb / 4b = 2048

8 * 12 + 8 * 2048 + 8 * 2048 * 2048 + 8 * 2048 * 2048 * 2048 = 68,753,047,648 kb

8. Why must the bitmap of the file allocation be stored in the mass storage instead of in the main storage?

In the event of a system crash or memory failure, the bitmap of the file allocation will not be lost as it is stored in the main memory.

9. Compare the performance of three technologies that allocate disk blocks (continuous, link, and index) for sequential and random file access

Sequential file access: Continuous>Link>Index

Sequential file access: Continuous>Index>Link

10.What are the advantages of the variant of link allocation that uses FAT to link file blocks together?

The advantage is that when accessing a block stored in the middle of the file, the location can be determined by tracking the pointer stored in the FAT, instead of sequentially accessing all individual blocks of the file to find the pointer to the target block. Most FAT can be stored in memory, so the pointer can be determined by memory access without having to access the disk block.

11. If an index node is 128B, the disk block pointer is 4B long, the status information occupies 68B, and the size of each block is 8KB, how much space is left in the index node for the disk pointer? How large files can be represented by direct, primary, secondary, and tertiary indirect pointers?

Space left for disk pointer: 128-68 = 60 B

Number of direct indexes: 60/4-3 = 12

Direct index: 12 * 8KB = 96 KB

The number of indexes that each disk block can hold: 8KB / 4B = 2,048

Primary index: 2048 * 8KB = 16,384KB

Secondary index: 2048 * 2048 * 8KB = 33,554,432KB

Three-level index: 2048 * 2048 * 2048 * 8KB = 68,719,476,736

12. Consider a file system on the disk. The file system has both logical and physical functions. The block size is 512 bytes. Assume that information about each file is already in memory. For these three allocation strategies (continuous, link and index), please answer the following questions:

a. How to complete the logical to physical address mapping in this system? (For index allocation, assume that a file is always less than 512 blocks.
b. If we are currently in logical block 10 (the last accessed block is block 10) and want to access logical block 4, how many physical blocks must be read from the disk?

a. Continuous allocation: the logical address is equal to the physical address/disk block size

Link allocation: Set up a table for the entire disk or disk partition. The sequence number of each table entry corresponds to the disk block number, and the disk number where the next data block (logical address) of the file is held.

​ Index allocation: The first ten logical addresses of the file are kept on the disk block number that is directly indexed in sequence, and the next primary index, secondary index, and tertiary index can hold 1024, 1024*1024, 1024*1024*1024 in sequence. Logical address.

b.1 4 2

Some of the answers are not sure, I hope you guys can help correct the mistakes

Guess you like

Origin blog.csdn.net/Qingyuyuehua/article/details/115146233