資源簡介
課程設計:開辟一個20M的磁盤空間(20M文件)作為一個磁盤,按照linux位視圖的方式管理,可以創建文件,寫數據,讀取數據等

代碼片段和文件信息
////////////////////////////////////////////////////
//??time:2012-03-17
//author:think
//??????implement?the?function?FILE*?searchEmptyBlockFromData(FILE*?fp)
//
//??time:2012-03-17
//author:think
//??????implement?the?function?int?releaseBlock(unsigned?char?bitPic[10][256]?int?position)
////////////////////////////////////////////////////
#include?
#include?“data.h“
//從數據塊中找到一個空閑塊,返回指針
short?int?searchEmptyBlock(unsigned?char?bitPic[10][256])
{
????????int?i?=?0;
????????int?j?=?0;
????????for?(i?=?0;?i?10;?i++)
????????{
????????????????for?(j?=?0;?j?256;?j++)
????????????????{
????????????????????????if?(bitPic[i][j]?255)?????????????????//如果?小于?255,說明?此char型代表的數據塊中有空閑的
????????????????????????{
????????????????????????????????int?k?=?0;
????????????????????????????????unsigned?char?temp?=?0X80;??????//0X80?換成二進制是?1000?0000,根據二進制的與??可以判斷第一位是否為?0
????????????????????????????????for?(k?=?0;?k?8;?k++)
????????????????????????????????{
????????????????????????????????????????if?((bitPic[i][j]?&?temp)?==?0)???????????//如果當前位為0?,返回位置,
????????????????????????????????????????{
????????????????????????????????????????????????bitPic[i][j]?=?bitPic[i][j]?|?temp;
????????????????????????????????????????????????return?i?*?256?+?j?*?8?+?k;
????????????????????????????????????????}
????????????????????????????????????????else????????????????????????????????????//否則,temp?右移一位?,判斷下一位
????????????????????????????????????????{
????????????????????????????????????????????????temp?=?temp?>>?1;
????????????????????????????????????????}
????????????????????????????????}
????????????????????????}
????????????????}
????????}
????????return?-1;
}
//從數據塊中釋放一個塊,
int?releaseBlock(unsigned?char?bitPic[10][256]?int?position)
{
????????int?x?=?0?y?=?0?z?=?0;
????????z?=?position?/?(256?*?8);???????????????//求?二維數組中的?第二維坐標
????????y?=?(position?%?(256?*?8));
????????x?=?y?%?8;??????????????????????????????//求在某個字符中的位置
????????y?=?y?/?8;??????????????????????????????//求在二維數組?第一維中的位置
????????int?i?=?0?temp?=?0X80;
????????for?(i?=?0;?i?????????{
????????????????temp?=?temp?>>?1;
????????}
????????if?((bitPic[z][y]?&?temp)?!=?0)
????????{
????????????????bitPic[z][y]?=?bitPic[z][y]?&?(~temp);??//將?temp?取反,再與?對應字符相與?,可以將對應位?賦值為?0
????????????????return?1;
????????}
????????else
????????{
????????????????return?0;
????????}
????????return?0;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???20971520??2012-04-02?22:40??fileSystem\123.dat
?????文件???????2698??2012-03-17?22:59??fileSystem\data.cpp
?????文件????????842??2012-03-17?22:59??fileSystem\data.h
?????文件???????1638??2012-03-17?23:12??fileSystem\d_node.cpp
?????文件???????1157??2012-03-17?22:59??fileSystem\d_node.h
?????文件???????5248??2012-03-17?23:37??fileSystem\fileSystem.dsp
?????文件????????545??2012-03-17?22:55??fileSystem\fileSystem.dsw
?????文件??????74752??2012-04-02?22:51??fileSystem\fileSystem.ncb
?????文件??????49664??2012-04-02?22:51??fileSystem\fileSystem.opt
?????文件????????254??2012-04-02?22:40??fileSystem\fileSystem.plg
?????文件??????25957??2012-03-17?23:32??fileSystem\fileSystemFunction.cpp
?????文件???????2748??2012-03-17?23:08??fileSystem\fileSystemFunction.h
?????文件???????8511??2012-04-02?22:51??fileSystem\fileSystemInit.cpp
?????文件????????401??2012-03-17?22:59??fileSystem\fileSystemInit.h
?????文件????????203??2012-03-17?23:03??fileSystem\fileSystemNode.cpp
?????文件????????891??2012-03-17?23:03??fileSystem\fileSystemNode.h
?????文件????????958??2012-03-17?23:11??fileSystem\i_node.cpp
?????文件????????651??2012-03-17?23:02??fileSystem\i_node.h
?????文件????????812??2012-03-17?23:26??fileSystem\main.cpp
?????文件???????5186??2012-03-17?23:27??fileSystem\public.cpp
?????文件????????762??2012-03-17?23:03??fileSystem\public.h
?????目錄??????????0??2013-04-09?21:14??fileSystem
-----------?---------??----------?-----??----
?????????????21155398????????????????????22
- 上一篇:linux ext2 文件系統模擬 c語言實現
- 下一篇:矩陣求逆c程序
評論
共有 條評論