Try   HackMD

Advanced Operating Systems - Feb 2011

tags: SOA feb2011 inode

Let be a Unix-like file system, based on i-nodes, mounted on a device with a storage capacity of 32 MiB and a block size of 512 bytes. These blocks hold the following information:

  • Block 0 is the boot block. It contains information about the operating system boot code.
  • Block 1 is the superblock. It holds the meta-information for the operation of the file system.
  • Block 2 through block 9 is the i-node list. It contains all the i-nodes representing objects in the file system.
  • Block 10 is the first data block.

The i-nodes will be eight bytes, each, and will store the following information:

  • File type (1 byte). Directory (DIR), link (LNK), regular file (REG),named pipe (FIFO), block file (BLQ), character file (CAR).
  • Number of links (1 byte).
  • Object size in blocks (1 byte).
  • Device (1 byte). Identifier of device hosting a file system(its value is 96 for the described device).
  • PtrDir (2 bytes). This is a direct pointer to a data block.
  • PtrInd (2 bytes). This is a simple indirect pointer.

This file system is organized in directories, which occupy a block of data, and maintain the following structure for each of their entries:

  • Node-i. Number of the i-node to which the directory entry is linked (1 byte).
  • File name (7 bytes)

Taking into account the characteristics of the file system described, answer the following questions:

a) How many data blocks are available to store information?

Solution

The number of data blocks available for storing information will be given by the number of blocks in the device, minus the boot block and the blocks held by the file system.

total_blocks=capacityblock_sizetotal_blocks=22529=216=65.536 blocksavailable_block=65.53510=65.526 blocks

b) What is the maximum number of i-nodes?

From the text, the i-node list occupies the blocks from 2 to 9, that is 8 blocks. Each i-node is 8 bytes, so the number of i-nodes will be:

total_inodes=85128=512 inodes

c) What is the maximum file size that could be stored?

That will be given by the minimum of:

  • Device capacity in bytes
  • Maximum addressable information by a single i-node

The i-node has two pointers, one can address a single block, the second can address as many blocks as pointers can hold. Given that the size of the pointer in the i-node is 2 bytes, a 512 bytes block can hold 256 pointers to 256 block. Thus, the max number of blocks per file will be 256 + 1 + 1 = 258 blocks, which is less than the available space in the device 65.526 blocks, so the limit will be

257blocks512bytes/block=128,5KiB

You have a pendrive connected to the USB port, whose content is only the file quijote.txt of size 4 KiB. Assuming that the file system contains only the root directory and the directory /media, indicate what would be the final state of the storage device, the content of its i-node list and the data blocks, after performing the following operations:

user@host :/$ mkdir /prueba
user@host :/$ cd prueba
user@host :/prueba$ echo  "DNI   Nota"  > notas.txt
user@host :/prueba$ ln notas.txt notas.lnk
user@host :/prueba$ mkdir tuberia
user@host :/prueba$ mknod ./tuberia/fifo p
user@host :/prueba$ cd ../media
user@host :/media$ mkdir pen
user@host :/media$ mount /dev/sda ./pen
user@host :/media$ cp ./pen/quijote.txt ../prueba/quijote2.txt
user@host :/media$ cd /prueba
user@host :/prueba$ ln -s quijote2.txt quijote.slnk
  • Note 1: Files of the named pipe type occupy a data block.
  • Note 2: The flash drive file system is mounted to the corresponding mount point by using the mount table and updating the mount directory. The mount command only affects the tables by modifying the device identifier (use 32 for the flash drive). It is not necessary to represent the file system tables of that device nor the mount table. The /dev directory and the block mode device /dev/sda have not been represented for simplicity. Just assume that they somehow magically exist for mount.
Solution
i-node 2 3 4 5 6 7 8 9 10
File type DIR DIR DIR REG DIR FIF DIR REG LNK
#hard links 4 3 3 1 2 1 2 1 1
Size (in blocks) 1 1 1 1 1 1 1 9 1
Device 96 96 96 96 96 96 96 96 96
PtrDir 10 11 12 13 14 15 16 17 26
PtrInd nul nul nul nul nul nul nul 18 nul