繁体   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