-
大小: 14.25MB文件類型: .rar金幣: 1下載: 0 次發(fā)布日期: 2023-08-05
- 語(yǔ)言: C/C++
- 標(biāo)簽:
資源簡(jiǎn)介
C語(yǔ)言實(shí)現(xiàn)建議的虛擬文件系統(tǒng),完成dir,mv,copy等命令,基于文件模擬一個(gè)電腦磁盤上的文件管理。C語(yǔ)言實(shí)現(xiàn)建議的虛擬文件系統(tǒng),完成dir,mv,copy等命令,基于文件模擬一個(gè)電腦磁盤上的文件管理。
代碼片段和文件信息
#include
#include
#include
#include
#include
#include
using?namespace?std;
#define?MAX_SIZE??1024*1024?//虛擬磁盤最大存儲(chǔ)容量?1M
#define?MAX_BLOCK??20????//物理塊的個(gè)數(shù)
#define?MAX_DIR??5???//最大目錄項(xiàng)的個(gè)數(shù)
struct?Inode{
SYSTEMTIME?create_t;?//創(chuàng)建時(shí)間
string?creator;//創(chuàng)建者
SYSTEMTIME?modify_t;??//文件或目錄修改時(shí)間
int?size;//文件大小
int?addr;//數(shù)據(jù)塊首地址
};
struct?Dentry{
int?inode_num;//i節(jié)點(diǎn)號(hào)
char?name[20];//目錄名稱
};
typedef?struct{
?Dentry?dentry[MAX_DIR];???//該目錄下的目錄項(xiàng)
int?number;?????//目錄項(xiàng)個(gè)數(shù)
char?name[20]; //目錄名稱
Inode?inode;
int?num;//inode索引號(hào)
int?parent;//父目錄首地址(假設(shè)以inode號(hào)為標(biāo)志)
char?stat[10];//文件屬性
//int?flag;//標(biāo)志該目錄是否已刪除;0沒(méi)有;1已刪除
}Direct;
Direct?root;?//根目錄
Direct?curr;??//當(dāng)前目錄
Direct?tab[1024];//目錄表
int?n=0;??//當(dāng)前已使用物理塊的個(gè)數(shù)
int?inodetab[MAX_BLOCK];//inode表,inode結(jié)點(diǎn)是否被用過(guò)0表示未被使用,1為已使用
string?command;//命令
char*?arg[10];//參數(shù)
char*?arg2[10];//參數(shù)2
int?a;//參數(shù)個(gè)數(shù)
int?a2;//參數(shù)2個(gè)數(shù)
char?route[50];//當(dāng)前路徑
SYSTEMTIME?sys_t;//系統(tǒng)時(shí)間
void?Initial()
{
root.number=0;
root.num=0;
strcpy(root.name“\\“);
strcpy(root.stat“DIR“);
root.parent=0;
root.inode.creator=“root“;
SYSTEMTIME?sys;
GetLocalTime(?&sys?);
root.inode.create_t=sys;
root.inode.modify_t=sys;
root.inode.size=0;
root.inode.addr=1024*root.num;
curr=root;
tab[n]=root;
inodetab[n]=1;
n++;
}
void?Refresh_tab()//完成tab的更新
{
}
void?Write_new(Direct?block)//將新的塊占用寫入虛擬磁盤
{
FILE?*fp;
fp=fopen(“Virtul““rb+“);
if(fp==NULL)?????????????/*判斷文件是否打開(kāi)成功*/
????????puts(“File?open?error“);/*提示打開(kāi)不成功*/
else{
if(-1?==?(fseek(fpblock.num*sizeof(Direct)SEEK_SET)))
????????????????????printf(“seek?error\n“);
????????????fwrite(&blocksizeof(Direct)1?fp); ??????
}
fclose(fp);
}
void??cat(char*str)//解析命令和參數(shù)
{
a=a2=0;
char?*tmp1*tmp2;
tmp1=strtok(str“?“);
tmp2=strtok(NULL“?“);
tmp1=strtok(tmp1“\\“);
while(tmp1!=NULL)
{
arg[a]=tmp1;
tmp1=strtok(NULL“\\“);
a++;
}
tmp2=strtok(NULL“\\“);
while(tmp2!=NULL)
{
arg2[a2]=tmp2;
tmp2=strtok(NULL“\\“);
a2++;
}
}
void?help()//幫助信息
{
char?parameter[100];
scanf(“%s“parameter);
cat(parameter);
if(strcmp(arg[0]“cd“)==0)
{
cout<<“cd“< cout<<“顯示目前工作目錄的名稱或是變更目錄。“< cout<<“cd?path“< cout<<“通過(guò)此命令,您可以修改當(dāng)前的目錄或路徑,前往您想去的目錄“< }
else?if(strcmp(arg[0]“copy“)==0)
{
cout<<“copy“< cout<<“將一個(gè)文件拷貝到另一個(gè)文件。“< cout<<“copy?source_file?destination_path_file“< cout<<“通過(guò)此命令您可以按自身需要拷貝文件“< }
else?if(strcmp(arg[0]“del“)==0)
{
cout<<“del“< cout<<“清空文件。“< cout<<“del?file“< cout<<“通過(guò)此命令您可以按自身需要清空文件“< }
else?if(strcmp(arg[0]“dir“)==0)
{
cout<<“dir“< cout<<“顯示目錄中的信息和子目錄清單。“< cout<<“dir?directory“< cout<<“通過(guò)此命令查看當(dāng)前的目錄信息“< }
else?if(strcmp(arg[0]“exit“)==0)
{
cout<<“exit“< cout<<“結(jié)束CMD
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件???????1888??2017-06-03?17:31??新建文件夾\實(shí)習(xí)\Debug\Virtul
?????文件??????98304??2017-06-03?18:10??新建文件夾\實(shí)習(xí)\Debug\實(shí)習(xí).exe
?????文件?????577544??2017-06-03?18:10??新建文件夾\實(shí)習(xí)\Debug\實(shí)習(xí).ilk
?????文件?????797696??2017-06-03?18:10??新建文件夾\實(shí)習(xí)\Debug\實(shí)習(xí).pdb
?????文件???44892160??2017-06-03?18:10??新建文件夾\實(shí)習(xí)\ipch\實(shí)習(xí)-7f57b56\實(shí)習(xí)-7e559c4a.ipch
?????文件????????484??2017-06-03?18:10??新建文件夾\實(shí)習(xí)\實(shí)習(xí)\Debug\cl.command.1.tlog
?????文件??????21938??2017-06-03?18:10??新建文件夾\實(shí)習(xí)\實(shí)習(xí)\Debug\CL.read.1.tlog
?????文件????????180??2017-06-03?18:10??新建文件夾\實(shí)習(xí)\實(shí)習(xí)\Debug\CL.write.1.tlog
?????文件????????960??2017-06-03?18:10??新建文件夾\實(shí)習(xí)\實(shí)習(xí)\Debug\li
?????文件???????2632??2017-06-03?18:10??新建文件夾\實(shí)習(xí)\實(shí)習(xí)\Debug\li
?????文件????????324??2017-06-03?18:10??新建文件夾\實(shí)習(xí)\實(shí)習(xí)\Debug\li
?????文件?????249557??2017-06-03?18:10??新建文件夾\實(shí)習(xí)\實(shí)習(xí)\Debug\main.obj
?????文件????????328??2017-06-03?18:10??新建文件夾\實(shí)習(xí)\實(shí)習(xí)\Debug\mt.command.1.tlog
?????文件????????616??2017-06-03?18:10??新建文件夾\實(shí)習(xí)\實(shí)習(xí)\Debug\mt.read.1.tlog
?????文件????????158??2017-06-03?18:10??新建文件夾\實(shí)習(xí)\實(shí)習(xí)\Debug\mt.write.1.tlog
?????文件?????560128??2017-06-03?18:10??新建文件夾\實(shí)習(xí)\實(shí)習(xí)\Debug\vc100.idb
?????文件?????299008??2017-06-03?18:10??新建文件夾\實(shí)習(xí)\實(shí)習(xí)\Debug\vc100.pdb
?????文件????????381??2017-06-03?18:10??新建文件夾\實(shí)習(xí)\實(shí)習(xí)\Debug\實(shí)習(xí).exe.intermediate.manifest
?????文件?????????47??2017-06-03?18:10??新建文件夾\實(shí)習(xí)\實(shí)習(xí)\Debug\實(shí)習(xí).lastbuildstate
?????文件??????19086??2017-06-03?18:10??新建文件夾\實(shí)習(xí)\實(shí)習(xí)\Debug\實(shí)習(xí).log
?????文件????????713??2017-05-31?09:44??新建文件夾\實(shí)習(xí)\實(shí)習(xí)\Debug\實(shí)習(xí).vcxprojResolveAssemblyReference.cache
?????文件??????????0??2017-05-31?09:44??新建文件夾\實(shí)習(xí)\實(shí)習(xí)\Debug\實(shí)習(xí).write.1.tlog
?????文件??????20188??2017-06-03?18:04??新建文件夾\實(shí)習(xí)\實(shí)習(xí)\main.cpp
?????文件???????1180??2017-06-03?18:31??新建文件夾\實(shí)習(xí)\實(shí)習(xí)\Virtul
?????文件???????3216??2017-05-31?09:44??新建文件夾\實(shí)習(xí)\實(shí)習(xí)\實(shí)習(xí).vcxproj
?????文件????????953??2017-05-31?09:44??新建文件夾\實(shí)習(xí)\實(shí)習(xí)\實(shí)習(xí).vcxproj.filters
?????文件????????143??2017-05-31?09:23??新建文件夾\實(shí)習(xí)\實(shí)習(xí)\實(shí)習(xí).vcxproj.user
?????文件???30363648??2017-06-03?18:33??新建文件夾\實(shí)習(xí)\實(shí)習(xí).sdf
?????文件????????885??2017-05-31?09:23??新建文件夾\實(shí)習(xí)\實(shí)習(xí).sln
????..A..H.?????17920??2017-06-03?18:33??新建文件夾\實(shí)習(xí)\實(shí)習(xí).suo
............此處省略11個(gè)文件信息
評(píng)論
共有 條評(píng)論