操作系統(tǒng)課程設(shè)計(jì)-模擬文件系統(tǒng)_第1頁(yè)
操作系統(tǒng)課程設(shè)計(jì)-模擬文件系統(tǒng)_第2頁(yè)
操作系統(tǒng)課程設(shè)計(jì)-模擬文件系統(tǒng)_第3頁(yè)
操作系統(tǒng)課程設(shè)計(jì)-模擬文件系統(tǒng)_第4頁(yè)
操作系統(tǒng)課程設(shè)計(jì)-模擬文件系統(tǒng)_第5頁(yè)
已閱讀5頁(yè),還剩13頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

目錄

第1章需求分析........................................1

第2章概要設(shè)計(jì)........................................1

2.1系統(tǒng)的主要功能..................................1

2.2系統(tǒng)模塊功能結(jié)構(gòu)................................1

2.3運(yùn)行環(huán)境要求....................................2

2.4數(shù)據(jù)結(jié)構(gòu)設(shè)計(jì)....................................2

第3章詳細(xì)設(shè)計(jì).......................................3

3.1模塊設(shè)計(jì)........................................3

3.2算法流程圖......................................3

第4章系統(tǒng)源代碼.....................................4

第5章系統(tǒng)測(cè)試及調(diào)試.................................4

5.1運(yùn)行結(jié)果及分析..................................4

5.2系統(tǒng)測(cè)試結(jié)論....................................5

第6章總結(jié)與體會(huì)......................................6

第7章參考文獻(xiàn).......................................6

附錄...................................................7

第1章需求分析

通過模擬文件系統(tǒng)的實(shí)現(xiàn),深入理解操作系統(tǒng)中文件系統(tǒng)的理論知識(shí),加深

對(duì)教材中的重要算法的理解。同時(shí)通過編程實(shí)現(xiàn)這些算法,更好地掌握操作系統(tǒng)

的原理及實(shí)現(xiàn)方法,提高綜合運(yùn)用各專業(yè)課知識(shí)的能力;掌握操作系統(tǒng)結(jié)構(gòu)、實(shí)

現(xiàn)機(jī)理和各種典型算法,系統(tǒng)地了解操作系統(tǒng)的設(shè)計(jì)和實(shí)現(xiàn)思路,并了解操作系

統(tǒng)的發(fā)展動(dòng)向和趨勢(shì)。

模擬二級(jí)文件管理系統(tǒng)的課程設(shè)計(jì)目的是通過研究Linux的文件系統(tǒng)結(jié)構(gòu),

模擬設(shè)計(jì)一個(gè)簡(jiǎn)單的二級(jí)文件系統(tǒng),第一級(jí)為主目錄文件,第二級(jí)為用戶文件。

第2章概要設(shè)計(jì)

2.1系統(tǒng)的主要功能

1)系統(tǒng)運(yùn)行時(shí)根據(jù)輸入的用戶數(shù)目創(chuàng)建主目錄

2)能夠?qū)崿F(xiàn)下列命令:

Login用戶登錄

Create建立文件

Read讀取文件

Write寫入文件

Delete刪除文件

Mkdir建立目錄

Cd切換目錄

Logout退出登錄

2.2系統(tǒng)模塊功能結(jié)構(gòu)

2.3運(yùn)行環(huán)境要求

操作系統(tǒng)windowsxp,開發(fā)工具vc++6.0

2.4數(shù)據(jù)結(jié)構(gòu)設(shè)計(jì)

用戶結(jié)構(gòu):賬號(hào)與密碼結(jié)構(gòu)

typcdcfstructusers

(

charname[8];

charpwd[l()];

}users;

本系統(tǒng)有8個(gè)默認(rèn)的用戶名,前面是用戶名,后面為密碼用戶登陸時(shí)只要輸入

正確便可進(jìn)入系統(tǒng),否則提示失敗要求重新輸入。

usersusrarray[8J=

(

"usrr'/'usrl",

"usr2","usr2n,

"usr3"Jusr3”,

"usr4n,"usr4",

"usr5","usr5",

"usr6"/'usr6",

nusr7","usr7n,

"usr8"/'usr8",

};

(3)數(shù)據(jù)結(jié)構(gòu)說明

a)文件結(jié)構(gòu)鏈表

structfnode

(

charfilename[FILENAME_LENGTH];

intisdir;

intisopen;

charconlent[255J;

fnode*parent;

fnode*child;

fnode*prcv;

fnode*next;

);

b)函數(shù)介紹

fnode*inilfile(charfilename口,intisdir);//初始化文件或目錄

voidcreateroot。;//建立系統(tǒng)根目錄

intrun();系統(tǒng)運(yùn)行

intfindpara(char*topara);對(duì)參數(shù)進(jìn)行處理

boolchklogin(char*users,char*pwd);檢查賬號(hào)與口令

voidhelp();命令列表

intmkdir();建立目錄

intcreate。;建立文件

intread。;讀取文件

intwrite。;寫入文件

intdel();刪除文件

intcd();切換目錄

intdir();文件與目錄列表

第3章詳細(xì)設(shè)計(jì)

3.1模塊設(shè)計(jì)

此課程設(shè)計(jì)把文木作為研究對(duì)象來模擬操作系統(tǒng)的文件系統(tǒng)工作過程.所以

用一個(gè)字符串?dāng)?shù)組來模擬磁盤空間,顧名思義,模擬磁盤提供字符的存儲(chǔ)服務(wù)。

所有用戶構(gòu)成一個(gè)數(shù)組,每個(gè)數(shù)組元素是一個(gè)結(jié)構(gòu)體,每個(gè)結(jié)構(gòu)體包括三部

分,用戶的用戶名、用戶密碼和文件鏈表(由于模擬文件系統(tǒng)的文件數(shù)量不多,

故文件表采用線性鏈表來存儲(chǔ)。線性表每個(gè)結(jié)點(diǎn)放置一個(gè)文件的FCB,其中存

儲(chǔ)一個(gè)文件的信息,文件名、長(zhǎng)度、類型、創(chuàng)建時(shí)間等);

磁盤空間分配表,采用鏈表結(jié)構(gòu),每個(gè)節(jié)點(diǎn)保存模擬磁盤的一個(gè)邏輯塊的信

息,包括塊的最大長(zhǎng)度,文件占用長(zhǎng)度,占用標(biāo)志。如果占用標(biāo)志為0,即該空

間可分配給文件。初始化磁盤空間分配表鏈表,首先把整個(gè)模擬磁盤作來一塊,

并置占用位為0。當(dāng)有進(jìn)程申請(qǐng)磁盤空間時(shí),從頭開始遍歷,檢查占用位,如果

該塊為可分配,則檢查塊大小,若塊長(zhǎng)度大于或等于申請(qǐng)空間大小,則把塊的前

一部分(等于申請(qǐng)大小)分配給文件,并置標(biāo)志位為占用。剩下的大小作來一個(gè)

新塊,作來一個(gè)新節(jié)點(diǎn)插入到原節(jié)點(diǎn)的后邊,標(biāo)志位為可用。這樣就實(shí)現(xiàn)了模擬

磁盤的線性分配。

3.2算法流程圖

第4章系統(tǒng)源代碼

見附錄

第5章系統(tǒng)測(cè)試及調(diào)試

5.1運(yùn)行結(jié)果及分析

|回—

■'D:\Debug\Cppi.exe"

模擬Lin件系統(tǒng)

賬號(hào):usrl-usr8密碼:usrl-usr8

你只有三次機(jī)會(huì)來試驗(yàn)賬號(hào)

Login:

■'D:\Debug\Cppl.exe"

模擬LinuxR件系統(tǒng)

賬號(hào):usrl-usr8也碼:usrl-usr8

你只有三次機(jī)會(huì)來試驗(yàn)賬號(hào)

Login:usrl

Passusri令

-

文,

:取0

create,

件0

:人

read文

寫#

:-

write文

除#

:瞿0

del目

:立0

nkdir目

:畬。

cd登

logout:。

linux:/>

命令一覽

立文4

create:Uo

:戈UO

read持多

線程

M*

:除

write文L

:0

del目

:立0

mkdir目

錄0

:電

d登

錄0

logout:

linux:/>create

文件建立成功,

linux:/>reada

aa

linux:/>

linux:/>createaaa

文件建立成功?

linux:/>reada

aa

linux:/>writeabb

x件寫入成功,

linux:/>reada

bb

linux:/>

linux:/>dela

文件已刪除?

linux:/>reada

R?件不存在?

linux:/>_

令一覽

立文4

:b

createF文

i-cad:M

^rite:M:支持多線程

文L

de1:目

V錄

nkdir目

cd:

logout:

linux:/>mkdirh

linux:/>cdh

linux:/h>

linux:/>nkdirh

linux:/>cdh

linux:/h>logout

Pressanykeytocontinue

5.2系統(tǒng)測(cè)試結(jié)論

從運(yùn)行結(jié)果截圖中可以看到,程序分別執(zhí)行了它所包含的7個(gè)功能,并且每

個(gè)功能都能正確的執(zhí)行。若程序執(zhí)行開始,三次都未輸入正確的帳號(hào)和密碼,程

序會(huì)退出不再執(zhí)行。

第6章總結(jié)與體會(huì)

雖然我們做過很多次課程設(shè)計(jì)了,但是感覺自己還有好多需要學(xué)習(xí)的地方,

接到題目要求時(shí),設(shè)計(jì)大體的框架,考慮好所使月的數(shù)據(jù)結(jié)構(gòu),然后用高級(jí)編程

語(yǔ)言分模塊的把架子的思路編寫出來,調(diào)試,運(yùn)行,再看看是不是符合題目的要

求,上網(wǎng)找些資料,看看想想是不是要提高要求,才可以滿足實(shí)際的需要,最后

把收集的勞動(dòng)成果組合起來,一個(gè)小程序終于成型了,雖然每次的過程差不多都

一樣,但是每次都會(huì)有不同的體會(huì)。

通過本次的課程設(shè)計(jì),使我能夠正確運(yùn)用操作系統(tǒng)課程中所學(xué)的基本理論和

知識(shí),加深了對(duì)文件系統(tǒng)基本概念的理解,以及磁盤文件系統(tǒng)的文件操作。在設(shè)

計(jì)過程中,查詢了不少相關(guān)資料,不斷的發(fā)現(xiàn)問題、提出問題、解決問題。在對(duì)

自己所編寫的源程序段的糾錯(cuò)的過程中,使我更好的理解了操作系統(tǒng)中文件系統(tǒng)

的理論知識(shí),同時(shí)在編程時(shí)用到了模塊化的設(shè)計(jì)思想,這種編程方法可以使我們

的編程變的更簡(jiǎn)單,可以使我們的直錯(cuò)與糾錯(cuò)變的更方便。總的來說通過這次的

設(shè)計(jì)的學(xué)習(xí)使我學(xué)到了很多在平時(shí)的學(xué)習(xí)中學(xué)不到的很多東西,通過這次課程設(shè)

計(jì),使我對(duì)操作系統(tǒng)和編程產(chǎn)生興趣,我想我會(huì)在這條路上繼續(xù)前進(jìn)下去。我相

信,只要不斷的嚴(yán)格要求自己,注意培養(yǎng)自己的思維能力,就一定會(huì)有更大更輝

煌的發(fā)展和提高。

第7章參考文獻(xiàn)

《操作系統(tǒng)原理實(shí)驗(yàn)教程》,清華大學(xué)出版社胡峰松主編

《操作系統(tǒng)實(shí)驗(yàn)教程》,清華大學(xué)出版社張麗芬等編著

《計(jì)算機(jī)操作系統(tǒng)實(shí)驗(yàn)教程》,清華大學(xué)出版社顏彬等編著

附錄

系統(tǒng)的主要源代碼

#include"stdio.h"

#include"iostream.h"

#include"string.h"

#include"iomanip.h1'

#defineFILENAME_LENGTH10//文件名稱長(zhǎng)度

#defineCOMMAND_LENGTH10//命令行長(zhǎng)度

#definePARA_LENGTH30〃參數(shù)長(zhǎng)度

〃賬號(hào)結(jié)構(gòu)

lypedefstructusers

(

charnamef81;

charpwd[10j;

}users;

〃文件結(jié)構(gòu)

structfnode

(

charfilename[FILENAME_LENGTH];

intisdir;

intisopcn;

charcontent[255];

fnode'parent;

fnode*child;

fnode*prev;

fnode*next;

);

〃賬號(hào)

usersusrarray[8]=

(

'?usrl'V'usrr',

nusr2'V,usr2,',

"usr3";'usr3H,

"usr4',,"usr4M,

,,usr5',,"usr5,',

"usr6";'usr6",

,,usr7n,nusr7,',

“usr8",“usr8”,

};

fnode*initfile(charfilename[],intisdir);

voidcreateroot();

intrun();

intfindpara(char*topara);

boolchklogin(char*users,char*pwd);

voidhelp();

intmkdir();

intcreate();

intread();

intwrite();

intdel();

intcd();

intdir();

fnode*root,*recent,*temp,*ttemp;

char

para[PARA_LENGTH],command[COMMAND_LENGTH],lemppara[PARA_LENG

TH],recentpara[PARA_LENGTH];

〃創(chuàng)建文件與目條結(jié)點(diǎn)

fnode*initfilc(charfilename」,intisdir)

(

fnode*node=newfnode;

strcpy(node->filename,filename);

node->isdir=isdir;

node->isopen=();

node->parent=NULL;

nodc->child=NULL;

node->prev=NULL;

node->next=NULL;

returnnode;

)

〃創(chuàng)建文件存儲(chǔ)結(jié)點(diǎn)

voidcreateroot()

(

recent=root=initfile(V",1);

root->parent=NULL;

root->chi!d=NULL;

root->prev=root->next=NULL;

strcpy(para,,7");

)

intmkdir()

(

temp=initfileC,M);

cin?temp->filename;

if(recent->child==NULL)

(

tcmp->parent=recent;

temp->child=NULL;

rcccnt->child=tcmp;

temp->prev=temp->next=NULL;

)

else

(

ttemp=recent->child;

while(ttcmp->next)

(

ttemp=ttemp->next;

if(strcinp(ttemp->filename,temp->filename)==()&&ttemp->isdir==l)

{

printf("對(duì)不起,目錄已存在!)

return1;

)

)

ttemp->next=temp;

temp->parent=NLJLL;

lemp->child=NULL;

temp->prev=ttemp;

temp->next=NULL;

)

return1;

)

intcreate()

(

temp=initfileC,",0);

cin?tcmp->filcnamc;

cin?temp->content;

if(reccnt->child==NULL)

(

temp->parent=recent;

temp->child=NULL;

recent->child=temp;

temp->prev=temp->next=NULL;

coutvv”文件建立成功!Nvendl;

else

ttemp=recent->child;

while(ttemp->next)

(

ttemp=ttemp->next;

if(strcmp(ttcmp->filcnamc,tcmp->filcnamc)==O&&ttcmp->isdir==O)

(

prinlf("對(duì)不起,文件已存在!)

return1;

1

1

ttemp->next=temp;

tcmp->parent=NULL;

temp->child=NULL;

temp->prev=ttemp;

temp->next=NULL;

coui<<”文件建立成功!”《endl;

I

return1;

)

intdir()

(

inti=Oj=O;

temp二newfnode;

temp=recent;

if(temp!=root)

{cout?°\<DIR>,,?H..,,?endl;i++;)

if(temp->chiId==NULL)

(

cout?nTotal:"<<"directors"?i?"filesn?j?endl;

return1;

1

temp=temp->child;

whilc(tcmp)

(

if(temp->isdir)

{cout?"<DIR>\n?teinp->filename?endl;i+4-;}

else

{cout?"<FILE>"?temp->filename?endl;j+4-;j

temp=temp->next;

)

cout?MTotal:"?"directors*'<<i<<"files,'?j?endl;

intread()

charfilename[FILENAME_LENGTH];

cin?filenamc;

if(recent->child==NULL)

(

coutcv"文件不存在!H?endl;

return1;

)

if(strcmp(recent->child->filename,fiiename)==O)

(

cout?recent->child->content?endl;

return1;

)

else

(

lemp=recent->child;

while(temp->next)

(

if(strcmp(tcmp->ncxt->filcname,filcnamc)==O)

{cout?temp->next->content?endl;

return1;)

}

cout?n文件不存在!n?endl;

intwrite()

(

charfilename[FILENAME_LENGTH];

cin?filename;

if(recent->child==NULL)

(

cout<v"文件不存在!"《cndl;

return1;

)

if(strcinp(recent->child->filename,fiIename)==O)

(

recent->child->isopen=l;〃設(shè)置文件標(biāo)記為打開

cin?recent->child->content;

recent->child->isopen=0;〃設(shè)置文件標(biāo)記為關(guān)閉

coutvv”文件寫入成功!”vvendl;

return1;

else

temp=recent->child;

while(temp->next)

(

if(strcmp(tcmp->ncxt->filcnamc,filcnamc)==O)

(

recent->chikl->isopen=l;〃設(shè)置文件標(biāo)記為打開

cin?temp->next->content;

recenl->child->isopen=0;〃設(shè)置文件標(biāo)記為關(guān)閉

coutvv”文件寫入成功!”vvendl;

return1;}

)

cout<<"文件不存在!"<<endl;

)

}

intcd()

{chartopara[PARA_LENGTH];

cin?topara;

if(strcmp(topara,H")==0)

(

inti;

while(recent->prev)

recent=recent->prev;

if(recent->parent)

(

rcccnt=rcccnt->parcnt;

)

i=strlen(para);

while(para[i]]=7'&&i>0)i-;

if(i!=0)

para[i]='\0';

else

para[i+lJ='\O';

)

else

(

findpara(topara);

)

return1;

I

intfindpara(char*topara)

(

inti=0;

intsign=l;

if(strcmp(topara,'7")==0)

(

recent=root;

strcpy(para,'7n);

return1;

)

temp二recent;

strepy(temppara,para);

if(topara[0]=='/')

(

recent=root->child;

i++;

strcpy(para/7");

)

else

{

if(recent!=NULL&&recent!=root)

strcaUpara,"/1');

if(rcccnt&&rcccnt->child)

(

if(recent->isdir)

recent=recent->child;

else

(

prinlf("路徑錯(cuò)誤!\nn);

return1;

)

)

)

while(i<=strlen(topara)&&recent)

(

intj=O;

if(topara[i]==7'&&rcccnt->child)

(

i++;

if(recent->isdir)

recent=recent->child;

else

地足1出'路徑錯(cuò)誤5");

return0;

)

strcat(para,,7u);

while(topara[i]!=7,&&i<=strlen(topara))

recentpara|j]=topara[i];

i++;j++;

)

rcccntpara[j]=,\O';

while((strcmp(recent->filename,recentpara)!=O||(recent->isdir!=l))&&

recent->nexl!=NULL)

(

recent=recent->next;

)

if(strcmp(recent->filename,recentpara)==O)

(

if(recent->isdir==O)

{strcpy(para,temppara);

recent=temp;

primf("是文件不是目錄。\n");

return0;

)

strcat(para,rcccnt->filcnamc);

)

if(strcmp(recent->filename,recentpara)!=O||recent==NULL)

(

strcpy(para,temppara);

recent=temp;

primf("輸入路徑錯(cuò)誤\n");

return0;

)

)

return1;

)

intdel()

(

charfilcnamc[FlLENAME_LENGTHJ;

cin?filename;

temp=newfnode;

if(recent->child)

(

temp=recent->child;

while(temp->next&&(strcmp(temp->filename,filename)!=0||temp->isdir!=0))

temp=temp->next;

if(strcmp(temp->filename,filename)!=O)

(

coutvv”不存在該文件!"?endl;

return0;

else

cout<<"不存在該文件IM?endl;

return0;

)

if(temp->parent==NULL)

(

temp->prev->next=temp->next;

if(temp->next)

tcmp->next->prev=temp->prev;

temp->prev=temp->next=NULL;

)

else

{

if(temp->next)

temp->next->parent=temp->parent;

temp->parent->child=temp->next;

)

deletetemp;

coutvv"文件已刪除!"《endl;

)

boolchklogin(char*users,char*pwd)

(

inti;

for(i=0;i<8;i++)

(

if((strcmp(users,usrarray[i].name)==O)&&(strcmp(pwd,usrarray[i].pwd)==O))

returntrue;

1

returnfalse;

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論