資源簡介
Requirements
1. Simulate a Unix file system on your Windows Platform
2. Understand the file system on Unix system, and the usage of i-nodes
3. Implement the function of sub-directory
4. The task needs to be completed using C++ or C
5.
Tasks/Functionalities
The following functions are required in your file system:
1. Allocate 16MB space in memory as the storage for your file system. The space is divided as
blocks with block size 1KB
Assume block address length is 32-bit;
Design the information contained in i-node
The i-node should support up to 10 direct block addresses
The i-node should support at least one indirect block address
2. The fist block is used for storing the i-node for the root directory(/). While your program is
lunched, two directories (/dir1 and / dir1/dir2) should be created, and also two files need to be
written as /dir1/file1 and /dir1/dir2/file2 (5 marks)
3. File 1 and 2 contain the message of “This is file 1.” and “This is file2”.
4. Following commands should be supported in your system:
a) Create a file:createFile fileName fileSize (10 marks)
i.e.:createFile /dir1/myFile 1024 (in bytes)
if fileSiz > max file size, print out an error message.
The file content is filled up with filename + repeated digits from 0 - 9
i.e.: “myFile012345678901234567890123….”
b) Delete a file:deleteFile filename (10 marks)
i.e.:deleteFile /dir1/myFile
c) Create a directory:createDir (5 marks)
i.e.:createDir /dir1/sub1
d) Delete a directory:deleteDir (5 marks)
i.e.: deleteDir /dir1/sub1 (The current working directory is not allowed to be
deleted)
e) Change current working direcotry:changeDir (5 marks)
i.e.: changeDir /dir2
f) List all the files and sub-directories under current working directory:dir (5 marks)
You also need to list at least two file attributes. (i.e. file size, time created, etc.)
g) Copy a file : cp (5 marks)
i.e.: file1 file2
h) Display the usage of storage space:sum (10 marks)
Display the usage of the 16MB

代碼片段和文件信息
#include?
#include
#include
#include
#include
using?namespace?std;
#define?MAX_BLOCK?16*1024;//block的總數目
int?systemUsed?=1642;
struct?USER_INF{
char?user_id[22];
char?pass_word[20];
};
struct?BOOT_BLOCK{
USER_INF?user_inf?[3];
int?user_sum;
int?current_user;
};
struct?SUPER_BLOCK{
int?free_inode;
int?free_data_block;
int?total_data_block;
int?first_data_block;
int?first_inode_block;
int?last_inode_block;
int?inode_bitmap_block;
int?data_bitmap_block;
int?sizeof_block;
char?cwdir[1024];
char?usrdir[1024];
};
struct?I_NODE{
????int?uid;
int?lock;//0?can?be?delete1can;‘t?delete
int?read_only_flag;//0?can?be?for?read?and?wirte?1?read?only.
int?type;//0?is?directory?1?is?data;
time_t?create_time;
time_t?modification_time;
time_t?access_time;
int?current_size;
int?max_size;
int?direct_addr[10];
int?indirect_addr[2];
int?shareDir;
int?shareOffset;
};//100bytes
struct?DATA_BIT_MAP{
bool?data_bit_map[16*1024-1642];
};
struct?INODE_BIT_MAP{
bool?inode_bit_map[16*1024-1642];
};
struct?INDIRECT_ADDR_BLOCK{
long?addr[256];
};//1KB
struct?DATA_BLOCK{
?char?content[1024];
};//1KB
//3是databit_map?2是inode_bitmap
struct?DIRECTORY{
long?inode_number;
char?name[16];
};
struct?DIRECTORY_BLOCK
{?
char?name[16];
DIRECTORY?directory[50];
};
struct?DISK{
BOOT_BLOCK?*boot_block;
SUPER_BLOCK?*super_block;
INODE_BIT_MAP?*i_node_bit_map;
DATA_BIT_MAP?*data_bit_map;
I_NODE?*i_node;
//three?types?of?the?data?blocks
INDIRECT_ADDR_BLOCK?*in_addr;
DATA_BLOCK?*data;
DIRECTORY_BLOCK?*Dire_Block;
}?*disk;//具體的block類型按需求賦值;
/*############################################*/
//help?function!
int?findFile_INode(long?p?char?name[])//return?file‘s?inode
{
int?pointer?=?-1;
time_t?ti;
for(int?i=0;i<50;i++)
{
if(strcmp(disk[p].Dire_Block->directory[i].namename)?==?0)
{
pointer?=?disk[p].Dire_Block->directory[i].inode_number;
time(&ti);
disk[pointer].i_node->access_time?=?ti;
return?pointer;
}
}
return?pointer;
}
int?findFreeINode()
{
for(int?i=?0;itotal_data_block;i++)
if(disk[2].i_node_bit_map->inode_bit_map[i]==false)
return?i+disk[1].super_block->first_inode_block;
}
int?findFreeDataBlock()
{
for(int?i=?0;itotal_data_block;i++)
if(disk[3].data_bit_map->data_bit_map[i]==false)
return?i+systemUsed;
}
DIRECTORY_BLOCK*??newDirectory()
{
DIRECTORY_BLOCK*?temp?=?new?DIRECTORY_BLOCK?;
for(int?i=0;i<50;i++)
memset(temp->directory[i].name016);
return?temp;
}
?INDIRECT_ADDR_BLOCK*?newINDIR_Addr()
?{
??INDIRECT_ADDR_BLOCK*temp?=?new?INDIRECT_ADDR_BLOCK;
??for(int?i=0;i<256;i++)
??temp->addr[i]=0;
??return?temp;
?}
void?assign_INode(int?I)
{
time_t?t;
time(&t);
disk[I].i_node->create_time?=disk[I].i_node->access_time=?disk[I].i_node->modification_time=t;
disk[I].i_node->uid?=disk[0].boot_block->current_user;
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????29357??2014-02-13?16:43??file_system.cpp
?????文件??????444910??2014-02-13?22:36??readme.doc
?????文件?????1316462??2014-02-13?22:33??操作系統課設報告.pdf
評論
共有 條評論