院 黃 岡 師 范 學(xué) 院 提高型實(shí)驗(yàn)報(bào)告 實(shí)驗(yàn)課題 文件系統(tǒng)的設(shè)計(jì)與實(shí)現(xiàn) (實(shí)驗(yàn)類型:□綜合性
?設(shè)計(jì)性
□應(yīng)用性) 實(shí)驗(yàn)課程 操作系統(tǒng)原理 實(shí)驗(yàn)時(shí)間 2015-2016 第二學(xué)期 學(xué)生姓名 何正發(fā) 專業(yè)班級(jí) 軟件工程 1401 學(xué)
號(hào) 27
一、實(shí)驗(yàn)?zāi)康呐c要求 1、熟悉操作系統(tǒng)設(shè)計(jì)的過程,鞏固操作系統(tǒng)的基本知識(shí),加深對(duì)操作原理、功能及各種不同的存儲(chǔ)管理方法理解與應(yīng)用; 2、學(xué)會(huì)運(yùn)用各種語(yǔ)言、軟件開發(fā)新軟件的基本方法; 3、增強(qiáng)實(shí)際應(yīng)用能力與動(dòng)手操作能力。
二、實(shí)驗(yàn)條件
Win7 /Windows 8、1/Linux 等操作系統(tǒng),裝有 java、C、C++、C#等語(yǔ)言工具的環(huán)境。
三、實(shí)驗(yàn)原理分析
可以選擇最佳適應(yīng)算法,按照從小到大的次序組成空閑區(qū)自由鏈,當(dāng)用戶作業(yè)或進(jìn)程申請(qǐng)一個(gè)空閑區(qū)時(shí),存儲(chǔ)管理 程序從表頭開始查找,當(dāng)找到第一個(gè)満足要求的空閑區(qū)時(shí),停止查找。如果該空閑區(qū)大于請(qǐng)求表中的請(qǐng)求長(zhǎng) 度,將減去請(qǐng)求長(zhǎng)度后的剩余空閑區(qū)部分留在可用表中。回收時(shí),從作鏈中刪去要回收的作業(yè)塊,同時(shí)在空 閑鏈中插入該作業(yè)大小的空閑區(qū),并按順序排列 四、實(shí)驗(yàn)方案或步驟 1、應(yīng)用環(huán)境、需求分析 本模擬系統(tǒng)主要針對(duì)文件的管理與操作名主要有:創(chuàng)建用戶、文件、文件夾,讀文件,寫文件,執(zhí)行文件,關(guān)閉文件,刪除用戶、文件夾、文件的功能。
創(chuàng)建用戶、文件、文件夾:在對(duì)系統(tǒng)發(fā)出操作命令之前必須先登錄用戶,然而登錄之前必須創(chuàng)建該用戶。在創(chuàng)建完后,可通過登錄用戶來創(chuàng)建文件與文件夾。在創(chuàng)建文件時(shí)可設(shè)置文件的屬性與輸入文件的內(nèi)容。
讀文件:讀取任何已創(chuàng)建的只讀或讀寫文件的內(nèi)容;如果所要讀的文件不就是可讀文件時(shí),系統(tǒng)會(huì)顯示該文件不可讀;如果所讀文件不存在,系統(tǒng)會(huì)顯示文件不存在。
寫文件用戶可寫或重寫讀寫文件中的內(nèi)容,并保存文件中的重寫內(nèi)容,以供下次讀取;當(dāng)所要寫的文件不就是可寫的文件時(shí),系統(tǒng)會(huì)顯示該文件不可寫;當(dāng)所要寫的文件并不存在時(shí),系統(tǒng)會(huì)顯示該文件不存在。
執(zhí)行文件:登錄用戶后,用戶可執(zhí)行系統(tǒng)中已創(chuàng)建的執(zhí)行文件;當(dāng)該文件不就是成績(jī):
可執(zhí)行文件時(shí),系統(tǒng)會(huì)顯示該文件不可執(zhí)行;當(dāng)該文件不存在時(shí),系統(tǒng)將會(huì)顯示該文件不存在。
關(guān)閉文件:可通過選擇關(guān)閉文件的功能選項(xiàng),來關(guān)閉系統(tǒng)中所有打開的文件,如果沒有文件被打開,則系統(tǒng)會(huì)顯示沒有文件打開。
刪除用戶、文件、文件夾:用戶可通過選擇刪除的功能選項(xiàng)來刪除不想再保存的文件與文件夾,刪除后,用戶會(huì)自動(dòng)注銷;當(dāng)選擇刪除用戶的功能選項(xiàng)時(shí),系統(tǒng)會(huì)刪除該用戶,以及該用戶所創(chuàng)建的所有文件與文件夾。
2、概要設(shè)計(jì) 打開文件流程圖: 開始輸入文件判斷是否存在判斷是否打開打開文件結(jié)束錯(cuò)誤提示是是否否
寫文件流程圖:
輸入文件名判斷是否存在判斷是否打開是開始寫入內(nèi)容結(jié)束是錯(cuò)誤提示否打開文件否 關(guān)閉文件流程圖: 開始輸入文件名判斷是否存在錯(cuò)誤提示 判斷是否打開關(guān)閉結(jié)束是否是否
3、詳細(xì)設(shè)計(jì) (1)用戶結(jié)構(gòu):賬號(hào)與密碼結(jié)構(gòu) typedef struct users
{
char
name[8];
char
pwd[10]; }users; 本系統(tǒng)有8個(gè)默認(rèn)的用戶名,前面就是用戶名,后面為密碼,用戶登陸時(shí)只要輸入正確便可進(jìn)入系統(tǒng),否則提示失敗要求重新輸入。
users usrarray[8] = {
"usr1","usr1",
"usr2","usr2",
"usr3","usr3",
"usr4","usr4",
"usr5","usr5",
"usr6","usr6",
"usr7","usr7",
"usr8","usr8", }; (2)數(shù)據(jù)結(jié)構(gòu)說明 a)文件結(jié)構(gòu)鏈表 struct fnode {
char [];
int
isdir;
int isopen;
char content[255];
fnode *parent;
fnode *child;
fnode *prev;
fnode *next; }; b)函數(shù)介紹 fnode *init [],int isdir);//初始化文件或目錄
void createroot();//建立系統(tǒng)根目錄
int run();系統(tǒng)運(yùn)行
int findpara(char *topara);對(duì)參數(shù)進(jìn)行處理
bool chklogin(char *users, char *pwd);檢查賬號(hào)與口令
void help();命令列表
int mkdir();建立目錄
int create();建立文件
int read();讀取文件
int write();寫入文件
int del();刪除文件
int cd();切換目錄
int dir();文件與目錄列表 4、代碼清單
#include "stdio、h" #include "iostream、h" #include "string、h" #include "iomanip、h" #define
10 //文件名稱長(zhǎng)度 #define COMMAND_LENGTH 10
//命令行長(zhǎng)度 #define PARA_LENGTH 30
//參數(shù)長(zhǎng)度
//賬號(hào)結(jié)構(gòu)
typedef struct users
{
char
name[8];
char
pwd[10]; }users;
//文件結(jié)構(gòu) struct fnode {
char [];
int
isdir;
int isopen;
char content[255];
fnode *parent;
fnode *child;
fnode *prev;
fnode *next; }; //賬號(hào) users usrarray[8] = {
"usr1","usr1",
"usr2","usr2",
"usr3","usr3",
"usr4","usr4",
"usr5","usr5",
"usr6","usr6",
"usr7","usr7",
"usr8","usr8", };
fnode *init [],int isdir);
void createroot();
int run();
int findpara(char *topara);
bool chklogin(char *users, char *pwd);
void help();
int mkdir();
int create();
int read();
int write();
int del();
int cd();
int dir(); fnode *root,*recent,*temp,*ttemp; char para[PARA_LENGTH],command[COMMAND_LENGTH],temppara[PARA_LENGTH],recentpara[PARA_LENGTH]; //創(chuàng)建文件與目錄結(jié)點(diǎn)
fnode* init [],int isdir) {
fnode *node=new fnode;
strcpy(node->);
node->isdir=isdir;
node->isopen=0;
node->parent=NULL;
node->child=NULL;
node->prev=NULL;
node->next=NULL;
return node;
} //創(chuàng)建文件存儲(chǔ)結(jié)點(diǎn) void createroot () {
recent=root=initfile("/",1);
root->parent=NULL;
root->child=NULL;
root->prev=root->next=NULL;
strcpy(para,"/");
} int mkdir() {
temp=initfile(" ",1);
cin>>temp->;
if(recent->child==NULL)
{
temp->parent=recent;
temp->child=NULL;
recent->child=temp;
temp->prev=temp->next=NULL;
}
else
{
ttemp=recent->child;
while(ttemp->next)
{
ttemp=ttemp->next;
if(strcmp(ttemp->>)==0&&ttemp->isdir==1)
{
printf("對(duì)不起,目錄已存在!");
return 1;
}
}
ttemp->next=temp;
temp->parent=NULL;
temp->child=NULL;
temp->prev=ttemp;
temp->next=NULL;
} return 1; } int create() {
temp=initfile(" ",0);
cin>>temp->;
gets(temp->content);
//cin>>temp->content;
if(recent->child==NULL)
{
temp->parent=recent;
temp->child=NULL;
recent->child=temp;
temp->prev=temp->next=NULL;
cout<<"文件建立成功!"<<endl;
}
else
{
ttemp=recent->child;
while(ttemp->next)
{
ttemp=ttemp->next;
if(strcmp(ttemp->>)==0&&ttemp->isdir==0)
{
printf("對(duì)不起,文件已存在!");
return 1;
}
}
ttemp->next=temp;
temp->parent=NULL;
temp->child=NULL;
temp->prev=ttemp;
temp->next=NULL;
cout<<"文件建立成功!"<<endl;
} return 1; }
int dir() { int i=0,j=0; temp=new fnode; temp=recent; if(temp!=root) {cout<<"
<DIR>
"<<"、、"<<endl;i++;} if(temp->child==NULL) {
cout<<"Total: "<<" directors
" <<i<<"
files
"<< j <<endl;
return 1; } temp=temp->child; while(temp) {
if(temp->isdir)
{cout<<"
<DIR>
"<<temp-><<endl;i++;}
else
{cout<<"
<FILE>
"<<temp-><<endl;j++;}
temp=temp->next;
} cout<<"Total: "<<" directors
" <<i<<"
files
"<< j <<endl; } int read() { char []; cin>>;
if(recent->child==NULL)
{
cout<<"文件不存在!"<<endl;
return 1;
}
if(strcmp(recent->child->)==0)
{
cout<<recent->child->content<<endl;
return 1;
}
else
{
temp=recent->child;
while(temp->next)
{
if(strcmp(temp->next->)==0)
{cout<<temp->next->content<<endl;
return 1;}
}
cout<<"文件不存在!"<<endl;
} } int write() { char []; cin>>;
if(recent->child==NULL)
{
cout<<"文件不存在!"<<endl;
return 1;
}
if(strcmp(recent->child->)==0)
{
recent->child->isopen=1;//設(shè)置文件標(biāo)記為打開
cin>>recent->child->content;
recent->child->isopen=0;//設(shè)置文件標(biāo)記為關(guān)閉
cout<<"文件寫入成功!"<<endl;
return 1;
}
else
{
temp=recent->child;
while(temp->next)
{
if(strcmp(temp->next->)==0)
{
recent->child->isopen=1;//設(shè)置文件標(biāo)記為打開
cin>>temp->next->content;
recent->child->isopen=0;//設(shè)置文件標(biāo)記為關(guān)閉
cout<<"文件寫入成功!"<<endl;
return 1;}
}
cout<<"文件不存在!"<<endl;
} } int cd() {
char topara[PARA_LENGTH];
cin>>topara;
if(strcmp(topara,"、、")==0)
{
int i;
while(recent->prev)
recent=recent->prev;
if(recent->parent)
{
recent=recent->parent;
}
i=strlen(para);
while(para[i]!="/" && i>0) i--;
if(i!=0)
para[i]="\0";
else
para[i+1]="\0"; } else {
findpara(topara);
} return 1; } int findpara(char *topara) {
int i=0;
int sign=1;
if(strcmp(topara,"/")==0)
{
recent=root;
strcpy(para,"/");
return 1;
}
temp=recent;
strcpy(temppara,para);
if(topara[0]=="/")
{
recent=root->child;
i++;
strcpy(para,"/");
}
else
{
if(recent!=NULL && recent!=root)
strcat(para,"/");
if(recent && recent->child)
{
if(recent->isdir)
recent=recent->child;
else
{
printf("路徑錯(cuò)誤!\n");
return 1;
}
} }
while(i<=strlen(topara) && recent)
{
int j=0;
if(topara[i]=="/" && recent->child)
{
i++;
if(recent->isdir)
recent=recent->child;
else
{printf("路徑錯(cuò)誤\n");
return 0;
}
strcat(para,"/");
}
while(topara[i]!="/" && i<=strlen(topara))
{
recentpara[j]=topara[i];
i++;j++;
}
recentpara[j]="\0";
while((strcmp(recent->)!=0 || (recent->isdir!=1)) && recent->next!=NULL)
{
recent=recent->next;
}
if(strcmp(recent->)==0)
{
if(recent->isdir==0)
{strcpy(para,temppara);
recent=temp;
printf("就是文件不就是目錄。\n");
return 0;
}
strcat(para,recent->);
}
if(strcmp(recent->)!=0 || recent==NULL)
{
strcpy(para,temppara);
recent=temp;
printf("輸入路徑錯(cuò)誤\n");
return 0;
}
} return 1; } int del() {
char [];
cin>>;
temp=new fnode;
if(recent->child)
{
temp=recent->child;
while(temp->next && (strcmp(temp->)!=0 || temp->isdir!=0))
temp=temp->next;
if(strcmp(temp->)!=0)
{
cout<<"不存在該文件!"<<endl;
return 0;
}
}
else
{
cout<<"不存在該文件!"<<endl;
return 0;
}
if(temp->parent==NULL)
{
temp->prev->next=temp->next;
if(temp->next)
temp->next->prev=temp->prev;
temp->prev=temp->next=NULL;
}
else
{
if(temp->next)
temp->next->parent=temp->parent;
temp->parent->child=temp->next;
}
delete temp;
cout<<"文件已刪除!"<<endl; } bool chklogin(char *users, char *pwd) {
int i;
for(i=0; i<8; i++)
{
if( (strcmp(users,usrarray[i]、name)==0) && (strcmp(pwd,usrarray[i]、pwd)==0))
return true;
}
return false; } void help(void) {
cout<<"
命
令
一
覽
"<<endl;
cout<<endl;
cout<<"create:
建立文件。
"<<endl;
cout<<"read:
讀取文件。
"<<endl;
cout<<"write:
寫入文件,支持多線程
"<<endl;
cout<<"del
:
刪除文件。
"<<endl;
cout<<"mkdir:
建立目錄。
"<<endl;
cout<<"cd:
切換目錄。
"<<endl;
cout<<"logout:
退出登錄。
"<<endl; } int run() {
cout<<"linux:"<<para<<">";
cin>>command;
if(strcmp(command,"mkdir")==0)
mkdir();
else if(strcmp(command,"dir")==0)
dir();
else if(strcmp(command,"cd")==0)
cd();
else if(strcmp(command,"create")==0)
create();
else if(strcmp(command,"read")==0)
read();
else if(strcmp(command,"write")==0)
write(); else if(strcmp(command,"del")==0)
del(); else if(strcmp(command,"help")==0)
help();
else if(strcmp(command,"logout")==0)
return 0;
else
cout<<"請(qǐng)參考 help 提供的命令列表!"<<endl;
} int main() { int i=0; bool in=false; char users[8],pwd[12];
cout<<"***************************************************************"<<endl;
cout<<"*
簡(jiǎn)單的二級(jí) Linux 文件系統(tǒng)
*"<<endl;
cout<<"*
賬號(hào):usr1-usr8
密碼:usr1-usr8
*"<<endl;
cout<<"*
您只有三次機(jī)會(huì)來試驗(yàn)賬號(hào)
*"<<endl;
cout<<"*
鍵入 help 可以獲取幫助
*"<<endl;
cout<<"***************************************************************"<<endl;
cout<<endl; while(i<3) { cout<<"Login:"; cin>>users; cout<<"Pass:"; cin>>pwd; if(chklogin(users,pwd)) {in=true;break;} i++; } createroot(); while(in) { if(!run()) break; } }
五、實(shí)驗(yàn)結(jié)果與分析
能夠很成功的對(duì)文件進(jìn)行讀寫操作, 意見保存與刪除 六、討論總結(jié) 通過這次提高型實(shí)驗(yàn),我明白了做一個(gè)系統(tǒng)的難度之大,首先要進(jìn)行需求分析,然后通過ER圖來清晰自己的思路,整個(gè)過程雖然很繁瑣,很復(fù)雜,但完成任務(wù)后,內(nèi)心的成就感爆棚,給自己的未來增加了滿滿的信心!這次的實(shí)驗(yàn),我學(xué)會(huì)了如何用代碼實(shí)現(xiàn)
操作系統(tǒng)的部分功能,如創(chuàng)建文件,讀文件,寫文件,創(chuàng)建文件夾,以及刪除文件等等,瞬間覺得特別高大上。希望今后能學(xué)習(xí)到更多到社會(huì)上有用的東西,加油!
推薦訪問: 文件系統(tǒng) 實(shí)驗(yàn) 報(bào)告
同志們:今天這個(gè)大會(huì),是市委全面落實(shí)黨要管黨、從嚴(yán)治黨要求的一項(xiàng)重大舉措,也是對(duì)縣市區(qū)委書記履行基層黨建工作第一責(zé)任人情況的一次集中檢閱,同時(shí)是對(duì)全市基層黨建工作的一次再部署、再落實(shí)的會(huì)議。前面,**
***年,我認(rèn)真履行領(lǐng)班子、帶隊(duì)伍、抓黨員、保穩(wěn)定的基層黨建工作思路,以學(xué)習(xí)貫徹習(xí)近平新時(shí)代中國(guó)特色社會(huì)主義思想和黨的十九大歷次全會(huì)精神為主線,以市局基層黨建工作考核細(xì)則為落腳點(diǎn),落實(shí)全面從嚴(yán)治黨主體
根據(jù)會(huì)議安排,現(xiàn)將2022年履行抓基層黨建工作職責(zé)情況報(bào)告如下:一、履職工作特色和亮點(diǎn)1 突出政治建設(shè),著力在思想認(rèn)識(shí)上提高。牢固樹立抓黨建就是抓政績(jī)的理念,以“黨建工作抓引領(lǐng)、社區(qū)治理求突破,為民服
2022年以來,在**黨委的正確領(lǐng)導(dǎo)下,堅(jiān)持以習(xí)近平新時(shí)代中國(guó)特色社會(huì)主義思想為指導(dǎo),深入學(xué)習(xí)宣傳貫徹黨的二十大精神,以黨建工作為統(tǒng)領(lǐng),扎實(shí)開展夯實(shí)“三個(gè)基本”活動(dòng),以“四化四力”行動(dòng)為抓手,聚力創(chuàng)建
各位領(lǐng)導(dǎo),同志們:根據(jù)會(huì)議安排,現(xiàn)就2022年度抓基層黨建工作情況匯報(bào)如下:一、主要做法及成效(一)強(qiáng)化政治引領(lǐng)。一是不斷強(qiáng)化理論武裝。堅(jiān)持通過黨組會(huì)、中心組學(xué)習(xí)會(huì)和“三會(huì)一課”,第一時(shí)間、第一議題學(xué)
2022年度抓基層黨建工作述職報(bào)告按照黨委工作部署,現(xiàn)將本人2022年度抓基層黨建工作情況報(bào)告如下:一、2022年度抓基層黨建工作情況(一)旗幟鮮明講政治將旗幟鮮明講政治放在全局發(fā)展首要位置,積極開展
2022年,是我在數(shù)計(jì)系黨總支書記這個(gè)新崗位上度過的第一個(gè)完整的工作年度?;厥滓荒陙碓谛|h委的正確領(lǐng)導(dǎo)下,與數(shù)計(jì)系領(lǐng)導(dǎo)班子和全體師生共同走過的日子,艱辛歷歷在目,收獲溫潤(rùn)心田。作為黨總支書記,我始終牢
按照考核要求,現(xiàn)將本人一年來,作為統(tǒng)戰(zhàn)部長(zhǎng)履行職責(zé)、廉潔自律等方面情況報(bào)告如下:一、著眼增強(qiáng)政治素質(zhì),不斷深化理論學(xué)習(xí)堅(jiān)持把旗幟鮮明講政治作為履職從政的第一位要求,帶領(lǐng)統(tǒng)戰(zhàn)系統(tǒng)干部堅(jiān)決擁護(hù)“兩個(gè)確立”
**年,緊緊圍繞黨工委、管委會(huì)的決策部署,全體人員團(tuán)結(jié)協(xié)作、凝心聚力,緊扣黨工委“**”基本工作思路,全力開拓進(jìn)取,認(rèn)真履職盡責(zé),圓滿完成各項(xiàng)工作任務(wù)。一、個(gè)人思想政治狀況檸檬文苑www bgzjy
按照縣委關(guān)于開展抓基層黨建述職評(píng)議會(huì)議的有關(guān)要求,經(jīng)請(qǐng)示縣委組織部同意,今天,我們?cè)诖苏匍_2022年度基層黨組織書記抓基層黨建述職評(píng)議會(huì)議。1 首先,請(qǐng)**黨委書記,**同志述職。**黨委能夠主動(dòng)研究