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

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