Description
CSCI3150/ESTR3102 Introduction to Operating Systems Tutorial 1: Superblock – Define File system metadata
1. Background
File System is used to access and organize the data stored on the hard disk.
Superblock is the first block in the metadata region, which contains the metadata of the file system, for example, where the inodes and data blocks begin, how many data blocks we have, etc.
Thus, when mounting a file system, an operating system will first read the superblock so as to obtain those metadata, based on these, then we can find the information of a specific file (from inode list) and get the data (from data blocks).
A superblock structure can be found below:
typedef struct _super_block_
{
int inode_offset; /* the starting position of inode */ int data_offset; /* the starting position of data block */ int max_inode; /* the maximum number of inodes */ int max_data_blk; /* the maximum number of data blocks */ int next_available_inode; /* the index of next free inode */ int next_available_blk; /* the index of next free data block */ int blk_size; /* the size of data block */
};
1.1 Superblock parameters
In SFS (the file system in the project), the inode region starts at 4 KB (inode_offset); the data region starts at 10 MB (data_offset), the maximum number of inodes is 100 (max_inode); the maximum number of data blocks is 25600; next_available_inode and next_available_blk are used to represent the indexes of the next free inode and the next free block, respectively; the block size is 4 KB.
Some related parameters can be found below:
#define SB_OFFSET 512 /* The offset of superblock region*/
#define INODE_OFFSET 4096 /* The offset of inode region */
#define DATA_OFFSET 10485760 /* The offset of data region */
#define MAX_INODE 100 /* The maximum number of inode */
#define MAX_DATA_BLK 25600 /* The maximum number of block */
#define BLOCK_SIZE 4096 /* The size per block */
1.2 Get the metadata of a file system
When a file system is mounted, the operating system will first read the superblock region of the hard disk, load the superblock data into memory and initiate a superblock object. This superblock object will be kept in memory during the whole period of accessing the file system.
For SFS, the mounting process can be simply done by reading the data from the superblock region and initiate a superblock entity in memory.
2. superblock.c – A Simple Program to Display the Superblock.
A simple program (superblock.c) has been provided to display the superblock. There are several files in the zip file:
• HD: It is used to simulate the hard disk. This “HD” file has been properly initialized based on the data structure defined by _super_block_ with the parameters above.
• Superblock.h: It contains the structure of superblock and the parameters of the SFS.
• Superblock.c: The C program with functions to read the superblock.
• Superblock-test.c: It contains two cases which show the superblock region on the hard disk and its information, respectively.
2.1 Compile and Run
Copy the HD, superblock.c, superblock-test.c and superblock.h to your current directory.
Compile the super block test program as below:
gcc –o superblock-test superblock-test.c superblock.c Then you can run the test program by:
./superblock-test ./HD
You can find two test cases shown on your terminal like the figure below. The first case is about how to show the super block region. The second case is about how to read the super block into memory and show its information.
In the figure, the superblock region is show with the hexadecimal format. For example, the offset of the inode region is 4096, so it shows as 1000 with the hexadecimal format.
2.2 Implementation
In superblock.c program, there is one major function:
• read_sb(): read the superblock region into memory (This should be useful for the project and can be used in it).
For more detailed implementation, please read superblock.c.
Reviews
There are no reviews yet.