简体   繁体   中英

Initializing disk in a file system simulator

I have currently two files that i am working with. I have the following code and the question is from this site: https://www.it2051229.com/filesystemsimulation.html

/* fs.h
* Various definitions for OSP Practical Case Study E
*/
#ifndef FS_H
#define FS_H
/* Prevent multiple inclusion */
#include<stdint.h>
/* The bitmap */
extern uint8_t bitmap[142];
/* 568Kb disk with 512b blocks-> 1136 bits for bitmap -> 142 bytes
*/
/* The directory entry */
struct entry
{
int8_t user;
int8_t name[9];
int8_t extension[4];
int16_t blockcount;
int16_t block[24];
};
/* The Directory */
extern struct entry directory[64];
/* extern means its defined in another
file, prevents multiple definition
errors
*/
int toggle_bit(int block);
/* Toggles the value of the bit ’block’, in
the external array ’bitmap’.
returns the current value of the bit
Does NOT validate ’block’!!!
*/
int block_status(int block);
/* Returns the status of ’block’,
in the external array bitmap
returns 0 if bitmap bit is 0,
not 0 if bitmap bit is 1
Does NOT validate block!!!
*/
#endif

Another file:

/* fs.c
Some useful functions for OSP Practical Case Study E
*/
#include"fs.h"
uint8_t bitmap[142];
struct entry directory[64];
int toggle_bit(int block)
{
int elem=block/8;
int pos=block%8;
int mask=1<<pos;
bitmap[elem]ˆ=mask;
return bitmap[elem]&mask;
}
int block_status(int block)
{
int elem=block/8;
int pos=block%8;
int mask=1<<pos;
return bitmap[elem]&mask;
}

In the main.c:

#include<stdio.h>
/* stdio.h will be found in the system path */
#include"fs.h"
/* fs.h will be found in the local path */
int main(int ac, char**av)
{
    //here i am going to intialize the disk
    return 0;
}

I have total of 7 tasks to do

  1. Initialize Disk
  2. List Files in the Directory
  3. Display the Free Bitmap
  4. Open/Create File
  5. Read File
  6. Write File
  7. Delete File

I understand rest of tasks and I believe I can do them. I don't have an idea about which disk and how to Initialize the disk . You can look into the link for a better understanding.

Just create a real file onto your real filesystem with size of 320kbyte (probably 320kibibytes). This is your disk. Open the file with regular fopen .

Initializing your "imaginary" disk means to "format" it. It's stated that the blocksize of your imaginary disk shall be 4kibibytes and that your directory file (some kind of a custom MBR) shall be only 1 block big and it shall be the first block. 1 entry is 32bytes big, allowing to store 128 entries in your directory block.

Initializing means (formatting), just make sure the first 4096 bytes, aka the first block of your disk image is all zero, after that copy 128 times the struct entry to it in a row, while variable char user in each entry has value of '1' to indicate a free directory entry.

Any other value than '1' for variable char user indicates a used directory entry.

Some kind of quickformat would only set each entry variable char user to '1'.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM