資源簡介
給出一個磁盤塊序列:1、2、3、……、500,初始狀態所有塊為空的,每塊的大小為2k。選擇使用位表、鏈式空閑區、索引和空閑塊列表四種算法之一來管理空閑塊。對于基于塊的索引分配執行以下步驟:
? 隨機生成2k-10k的文件50個,文件名為1.txt、2.txt、……、50.txt,按照上述算法存儲到模擬磁盤中。
? 刪除奇數.txt(1.txt、3.txt、……、49.txt)文件
? 新創建5個文件(A.txt、B.txt、C.txt、D.txt、E.txt),大小為:7k、5k、2k、9k、3.5k,按照與(1)相同的算法存儲到模擬磁盤中。
給出文件A.txt、B.txt、C.txt、D.txt、E.txt的文件分配表和空閑區塊的狀態。
實驗報告(含程序流程圖)&源碼

代碼片段和文件信息
#include
#include
#include
#include
#define?memorysize?500 //內存大小500
#define?singleblocksize?2.0?????????????????????????????//塊大小2k
#define?finenamelength?10???????????????????????????????//文件名長度10
#define?suffix?“.txt“???????????????????????????????????//文件名后綴
#define?true?1??????????????????????????????????????????//真值
#define?false?0?????????????????????????????????????????//假值
int?bittable[memorysize];???????????????????????????????//位表?0代表空閑?1代表已占用
typedef?struct?Fat?{????????????????????????????????????//文件分配表結構
char?filename[finenamelength];??????????????????//文件名
int?IndexBlock;?????????????????????????????????//索引塊位置
struct?Fat?*next;???????????????????????????????//指針
}?*FileAllocationTable?FAT;
typedef?struct?{
int?*partition;?????????????????????????????????//文件分區
int?blocksize;??????????????????????????????????//文件分區大小
}?IndexBlock;
IndexBlock?indexblocktable[memorysize];?????????????????//索引塊表
FileAllocationTable?FAThead?=?NULL?FATcurrent?=?NULL;
void?putfile(char?filename[]?double?filesize)??????????//放置文件
{
int?i?j?k;
FAT?*temp?=?(FAT*)malloc(sizeof(FAT));
if?(FAThead?==?NULL)???????????????????????????//首次存儲文件
{
strcpy(temp->filename?filename);?????//存儲文件名
i?=?rand()?%?memorysize;??????????????//隨機選取索引塊的位置
while?(bittable[i])???????????????????//判斷索引塊是否已被占用
{
i?=?rand()?%?memorysize;
}
bittable[i]?=?true;???????????????????//位表設為已占用
temp->IndexBlock?=?i;?????????????????//記錄索引塊的位置
temp->next?=?NULL;
FAThead?=?FATcurrent?=?temp;
}
else
{
strcpy(temp->filename?filename);?????//存儲文件名
i?=?rand()?%?memorysize;??????????????//隨機選取索引塊位置
while?(bittable[i])???????????????????//判斷索引塊位置是否已被占用
{
i?=?rand()?%?memorysize;
}
bittable[i]?=?true;??????????????????//位表設為已占用
temp->IndexBlock?=?i;????????????????//記錄索引塊的位置
temp->next?=?NULL;
FATcurrent->next?=?temp;
FATcurrent?=?temp;
}
int?blocknum?=?(int)(filesize?/?singleblocksize);???//計算文件分區數目
if?(filesize?-?blocknum*singleblocksize>1e-7)???????//判斷文件大小與塊的大小是否整除
++blocknum;
indexblocktable[i].partition?=?(int?*)malloc(sizeof(int)*blocknum);//創建文件分區記錄表
for?(j?=?0;?j {
k?=?rand()?%?memorysize;????????????????????//隨機選取記錄文件分區位置
while?(bittable[k])?????????????????????????//判斷位表是否已被占用
{
k?=?rand()?%?memorysize;
}
bittable[k]?=?true;?????????????????????????//位表設為已占用
indexblocktable[i].partition[j]?=?k;????????//記錄文件分區
}
indexblocktable[i].blocksize?=?blocknum;????????????//記錄分區數目
}
void?deletefile(char?filename[])??????????????????????????????//按文件名刪除文件
{
FileAllocationTable?temp?=?FAThead?current;
if?(strcmp(temp->filename?filename)?==?0)????????????//匹配文件分配表第一個文件名
{
current?=?FAThead;????????????????????????????//記錄查找到的文件分配表
FAThead?=?FAThead->next;
}
else
{
while?(temp->next)????????????????????????????//匹配第一個文件名
{
if?(strcmp(temp->next->filename?filename)?==?0)
break;
temp?=?temp->next;
}
if?(temp->next?==?NULL)?????????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????408082??2017-12-08?16:12??實驗報告.docx
?????文件????????5988??2017-12-08?11:51??osLab.cpp
?????文件???????59392??2017-12-30?11:03??實驗5?文件管理.doc
評論
共有 條評論