資源簡介
1.開辟100M的硬盤空間,作為設定的硬盤空間。
2.模擬Linux文件系統,功能如下:
(1)info: 顯示整個系統信息
(2)cd …: 改變目錄:改變當前工作目錄,目錄不存在時給出出錯信息。
(3)dir …: 顯示目錄:顯示指定目錄下或當前目錄下的信息,包括文件名、物理地址、保護碼、文件長度、子目錄等(帶/s參數的dir命令,顯示所有子目錄)。
(4)md …: 創建目錄:在指定路徑或當前路徑下創建指定目錄。重名時給出錯信息。
(5)rd …: 刪除目錄:刪除指定目錄下所有文件和子目錄。要刪目錄不空時,要給出提示是否要刪除。
(6)newfile …: 建立文件。
(7)cat …: 打開文件。
(8)copy …: 拷貝文件,除支持模擬Linux文件系統內部的文件拷貝外,還支持host文件系統與模擬Linux文件系統間的文件拷貝。
(9)del …: 刪除文件:刪除指定文件,不存在時給出出錯信息。
(10)check:檢測并恢復文件系統。
模擬文件系統的前端操作shell:
前端的shell進程和后端的simdisk進程之間利用共享內存進行進程間通信(IPC)

代碼片段和文件信息
/***************************************************************************************
command.cpp
所有可執行的命令,每個命令一個函數
***************************************************************************************/
#include“fs.h“
#include
#include
#include
#include
#include
//using?namespace?std;
void?fs::info()
{
int?fileNum?=?0;?//總文件數
int?dirNum?=?0;?//總目錄數
int?i;
freeSpace?=?Super.freeBlock?*?blockSize;?//空閑磁盤空間
usedSpace?=?(blockNum?-?Super.freeBlock)?*?blockSize;?//已用空間
for?(i?=?0;?i? {
if?(Inode[i].isFile?==?0)?dirNum++;
if?(Inode[i].isFile?==?1)?fileNum++;
}
cout?<“磁盤空間:“?<“100?MB“?< cout?<“已使用空間:?“?< cout?<“空閑空間:?“?< cout?<“總目錄數:?“?< cout?<“總文件數:?“?<}
int?fs::md(char?*path)
{
int?parent;
parent?=?getParentIndex(path);
if?((parent?!=?-2)?&&?(parent?!=?-1))?????????????????????//父目錄存在
{
int?flag;
flag?=?find(getName(path)?parent);??????????//判斷路徑是否存在
????????if?(flag!=-1)?????????????????????????????????//重名目錄
{
cout?<“目錄已存在!?“?< return?-1;
}
else
{?
if?(dirInit(parent?getName(path))?!=?-1)?????//使用Dir_Init函數
{
return?parent;
????????????}
}
}
if?(parent?==?-1)
{
cout?<“不能創建與根目錄同名的目錄!?“?< ????return?-1;
}
cout?<“目錄創建失敗!?“?<????return?-1;
}
int?fs::rd(char?*?path)
{
// HANDLE?shell?=?OpenSemaphore(SEMAPHORE_ALL_ACCESS?TRUE?“shell“);
// HANDLE?disk?=?OpenSemaphore(SEMAPHORE_ALL_ACCESS?TRUE?“disk“);
int?parent?=?getParentIndex(path);
int?flag?=?-1;
int?tmpIndex;
char?choice;
if?(parent?==?-1)
{
cout?<“根目錄無法刪除!?“?< return?-1;
}
if?(parent?!=?-2)?//判斷要刪除的目錄是否存在
{
flag?=?find(getName(path)?parent);
if?((flag?!=?-1)?&&?(Inode[flag].isFile?==?0))
{
tmpIndex?=?flag;
if?(Inode[tmpIndex].childNum?>?0)?//刪除目錄非空
{
cout?<“刪除目錄非空是否繼續?(Y/N)“?<// map->flag?=?1;
// ReleaseSemaphore(shell?1?NULL);
// WaitForSingleobject(disk?INFINITE);?
cin?>>?choice;
// strcpy(choice?map->display);
}
if?(choice?==?‘Y‘?||?choice?==?‘y‘?||?Inode[tmpIndex].childNum?==?0)
{
delDir(tmpIndex?parent);
return?1;
}
}
}
cout?<“刪除失敗!“?< return?-1;
}
int?fs::dir(char?*?path)
{
int?i?=?0?j?=?0;
int?parent;
int?flag;
if?(!strcmp(path?“/s“))???????????????????????//dir?/s命令,顯示所有文件和目錄
{
for?(i?=?1;?i?15;?i++)
{
if?((Inode[i].isFile?==?0)?||?(Inode[i].isFile?==?1))
{
cout?< ????for?(j?=?strlen(getAbsolutePath(i));?j?30;?j++)?//輸出格式控制
{
cout?<“?“;
}
if?(Inode[i].isFile?==?0)???????????//顯示是文件類型還是目錄類型
cout?<“目錄??????????????????????“;
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????11339??2009-02-24?22:17??DISK\command.cpp
?????文件????????615??2009-02-24?22:07??DISK\conf.cpp
?????文件??????45155??2009-02-24?22:17??DISK\Debug\command.obj
?????文件??????10954??2009-02-24?22:07??DISK\Debug\conf.obj
?????文件?????274476??2009-02-24?22:19??DISK\Debug\DISK.exe
?????文件?????358360??2009-02-24?22:19??DISK\Debug\DISK.ilk
?????文件????3750140??2009-02-24?22:19??DISK\Debug\DISK.pch
?????文件?????746496??2009-02-24?22:19??DISK\Debug\DISK.pdb
?????文件??????40944??2009-02-24?22:19??DISK\Debug\fs.obj
?????文件??????16814??2009-02-24?22:19??DISK\Debug\main.obj
?????文件??????22020??2009-02-24?22:17??DISK\Debug\shell.obj
?????文件?????189440??2009-02-24?22:19??DISK\Debug\vc60.idb
?????文件??????94208??2009-02-24?22:19??DISK\Debug\vc60.pdb
?????文件???????4618??2009-02-22?22:26??DISK\DISK.dsp
?????文件????????531??2009-02-08?22:42??DISK\DISK.dsw
?????文件?????107520??2009-02-24?22:20??DISK\DISK.ncb
?????文件??????55808??2009-02-24?22:20??DISK\DISK.opt
?????文件???????1346??2009-02-24?22:19??DISK\DISK.plg
?????文件??????14537??2009-02-24?22:19??DISK\fs.cpp
?????文件???????2634??2009-02-24?22:06??DISK\fs.h
?????文件???????1113??2009-02-24?22:18??DISK\main.cpp
?????文件???????3722??2009-02-24?22:17??DISK\shell.cpp
?????文件????????353??2009-02-24?22:07??DISK\struct.h
?????文件?????249902??2009-02-24?15:35??shell\Debug\shell.exe
?????文件?????376240??2009-02-24?15:35??shell\Debug\shell.ilk
?????文件??????67239??2009-02-24?15:35??shell\Debug\shell.obj
?????文件????5513468??2009-02-23?15:54??shell\Debug\shell.pch
?????文件?????582656??2009-02-24?15:35??shell\Debug\shell.pdb
?????文件?????214016??2009-02-24?15:35??shell\Debug\vc60.idb
?????文件?????143360??2009-02-24?15:35??shell\Debug\vc60.pdb
............此處省略28個文件信息
- 上一篇:VLSI超大規模集成電路電子學
- 下一篇:systemverilog經典教程
評論
共有 條評論