簡體   English   中英

在文件系統模擬器中初始化磁盤

[英]Initializing disk in a file system simulator

我目前有兩個正在使用的文件。 我有以下代碼,問題來自這個站點: 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

另一個文件:

/* 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;
}

在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;
}

我總共有 7 項任務要做

  1. 初始化磁盤
  2. 列出目錄中的文件
  3. 顯示免費 Bitmap
  4. 打開/創建文件
  5. 讀取文件
  6. 寫文件
  7. 刪除文件

我了解 rest 的任務,我相信我能做到。 我不知道哪個磁盤以及如何初始化磁盤 您可以查看鏈接以獲得更好的理解。

只需在您的真實文件系統上創建一個大小為 320kbyte(可能為 320kibibytes)的真實文件。 這是你的磁盤。 使用常規fopen打開文件。

初始化您的“虛擬”磁盤意味着“格式化”它。 據說您的虛擬磁盤的塊大小應為 4kibibytes,並且您的目錄文件(某種自定義 MBR)應該只有 1 個塊大,它應該是第一個塊。 1 個條目是 32 字節大,允許在您的目錄塊中存儲 128 個條目。

初始化方法(格式化),只需確保前 4096 個字節,也就是磁盤映像的第一個塊全部為零,然后連續復制 128 次struct entry到它,而每個條目中的變量char user的值為'1' 表示一個空閑的目錄條目。

變量char user的除 '1' 以外的任何其他值都表示已使用的目錄條目。

某種快速格式只會將每個條目變量char user設置為“1”。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM