简体   繁体   English

在文件系统模拟器中初始化磁盘

[英]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我有以下代码,问题来自这个站点: 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:在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我总共有 7 项任务要做

  1. Initialize Disk初始化磁盘
  2. List Files in the Directory列出目录中的文件
  3. Display the Free Bitmap显示免费 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.我了解 rest 的任务,我相信我能做到。 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).只需在您的真实文件系统上创建一个大小为 320kbyte(可能为 320kibibytes)的真实文件。 This is your disk.这是你的磁盘。 Open the file with regular fopen .使用常规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.据说您的虚拟磁盘的块大小应为 4kibibytes,并且您的目录文件(某种自定义 MBR)应该只有 1 个块大,它应该是第一个块。 1 entry is 32bytes big, allowing to store 128 entries in your directory block. 1 个条目是 32 字节大,允许在您的目录块中存储 128 个条目。

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.初始化方法(格式化),只需确保前 4096 个字节,也就是磁盘映像的第一个块全部为零,然后连续复制 128 次struct entry到它,而每个条目中的变量char user的值为'1' 表示一个空闲的目录条目。

Any other value than '1' for variable char user indicates a used directory entry.变量char user的除 '1' 以外的任何其他值都表示已使用的目录条目。

Some kind of quickformat would only set each entry variable char user to '1'.某种快速格式只会将每个条目变量char user设置为“1”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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