第一篇:操作系統(tǒng)課程設(shè)計(jì) 為LINUX 設(shè)計(jì)一個(gè)簡單的二級(jí)文件系統(tǒng) java實(shí)現(xiàn)界面
仲愷農(nóng)業(yè)工程學(xué)院
課
程
設(shè)
計(jì)
為LINUX 設(shè)計(jì)一個(gè)簡單的二級(jí)文件系統(tǒng)
姓
名
菜鳥程序員
院(系)
計(jì)算機(jī)科學(xué)與工程學(xué)院 專業(yè)班級(jí) 學(xué)
號(hào)
指導(dǎo)教師
職
稱
課程設(shè)計(jì)日期 2011年 6月2 日至7月1日
目 錄
1題目分析..........................................................1 2算法設(shè)計(jì)..........................................................1 2.1 用戶登錄模塊..................................................1 2.2 新建目錄模塊..................................................2 2.3新建文件模塊..................................................3 2.4 刪除文件模塊..................................................4 2.5 讀取文件模塊..................................................5 3 設(shè)計(jì)實(shí)現(xiàn)..........................................................6 3.1登錄界面外觀布局..............................................6 3.2樹狀顯示目錄..................................................7 3.3新建目錄實(shí)現(xiàn)主要代碼:.......................................10 3.4新建文件實(shí)現(xiàn).................................................12 3.5刪除文件實(shí)現(xiàn).................................................14 3.6讀取文件實(shí)現(xiàn).................................................16 4設(shè)計(jì)總結(jié).........................................................17 5參考文獻(xiàn).........................................................18
1題目分析
為Linux設(shè)計(jì)一個(gè)簡單的二級(jí)文件系統(tǒng),可以實(shí)現(xiàn)用戶登錄、列出文件目錄、創(chuàng)建目錄、創(chuàng)建文件、刪除目錄、刪除文件、讀取文件的功能。本次設(shè)計(jì)采用的開發(fā)語言是Java,通過Java來實(shí)現(xiàn)整體布局和實(shí)現(xiàn)相關(guān)的功能。
2算法設(shè)計(jì)
本次二級(jí)文件系統(tǒng)主要分為五大模塊,分別是用戶登錄模塊、新建目錄模塊、新建文件模塊、刪除文件模塊和讀取文件模塊。用戶登錄成功后才可以進(jìn)行其他模塊的操作。
2.1 用戶登錄模塊
用戶登錄模塊要求用戶輸入賬號(hào)與密碼,當(dāng)輸入正確后進(jìn)入主視圖并能進(jìn)行其他模塊操作,否則提示賬號(hào)密碼錯(cuò)誤并要求用戶重新輸入(默認(rèn)的賬號(hào)和密碼都是“123”)。用戶登錄模塊流程圖如圖1所示。
開始輸入賬號(hào)和密碼賬號(hào)和密碼都正確?否是顯示默認(rèn)目錄的所有文件與目錄提示輸入錯(cuò)誤結(jié)束 圖1 用戶登錄模塊流程圖
2.2 新建目錄模塊
新建目錄模塊是根據(jù)用戶鼠標(biāo)右擊時(shí)選擇到的節(jié)點(diǎn)來確定節(jié)點(diǎn)的名字與路徑,然后判斷該節(jié)點(diǎn)是否可以擁有子節(jié)點(diǎn),若擁有則根據(jù)用戶輸入的目錄名稱新建一個(gè)目錄,否則提示不能新增目錄。新建目錄模塊流程圖如圖2所示。
開始獲得右擊時(shí)選擇到的節(jié)點(diǎn)的路徑與名字被選擇的節(jié)點(diǎn)是否可以擁有子節(jié)點(diǎn)?否是用戶輸入新建目錄的名字提示不能創(chuàng)建目錄在本地硬盤新建一文件夾,在樹型視圖新增一節(jié)點(diǎn)結(jié)束 圖2 新建目錄流程圖
2.3新建文件模塊
新建文件模塊是根據(jù)用戶鼠標(biāo)右擊時(shí)選擇到的節(jié)點(diǎn)來確定節(jié)點(diǎn)的名字與路徑,然后判斷該節(jié)點(diǎn)是否可以擁有子節(jié)點(diǎn),若擁有則根據(jù)用戶輸入的文件名稱新建一個(gè)文件,否則提示不能新增文件。新建文件模塊流程圖如圖3所示。
開始獲得右擊時(shí)選擇到的節(jié)點(diǎn)的路徑與名字被選擇的節(jié)點(diǎn)是否可以擁有子節(jié)點(diǎn)?否是用戶輸入新建文件的名字提示不能創(chuàng)建文件在本地硬盤新建改文件,在樹型視圖新增一節(jié)點(diǎn)結(jié)束 圖3 新建文件流程圖
2.4 刪除文件模塊
刪除文件模塊是根據(jù)用戶鼠標(biāo)右擊時(shí)選擇到的節(jié)點(diǎn)來確定要?jiǎng)h除節(jié)點(diǎn)的名字與路徑,然后判斷該節(jié)點(diǎn)是目錄還是文件。若是文件則直接刪除文件,若是目錄則進(jìn)入該目錄再刪除其全部文件。刪除文件模塊流程圖如圖4所示。
開始獲得右擊時(shí)選擇到的節(jié)點(diǎn)的路徑與名字在樹狀視圖上刪除該節(jié)點(diǎn)否該節(jié)點(diǎn)是一目錄?是進(jìn)入該目錄并遍歷所有文件刪除該文件刪除所有被遍歷的文件結(jié)束 圖4 刪除文件模塊流程圖
2.5 讀取文件模塊
讀取文件模塊是根據(jù)FileDialog類中事先設(shè)定的默認(rèn)路徑而打開一個(gè)選擇對話框,然后根據(jù)用戶選擇的文件而獲取文件的名字與路徑。最后通過輸入流而把讀取到的數(shù)據(jù)顯示在一個(gè)文本域中。讀取文件流程圖如圖5所示。
開始新建一個(gè)空的文本區(qū)域生成FileDialog選擇框根據(jù)用戶的選擇而獲得文件的路徑和名字運(yùn)用輸入輸出流讀取文件的數(shù)據(jù)把讀取到的數(shù)據(jù)顯示到文本域中結(jié)束 圖5 讀取文件模塊流程圖 設(shè)計(jì)實(shí)現(xiàn)
3.1登錄界面外觀布局
登錄界面主要代碼:
JLabel labelID=null,labelPassword=null,title=null;JTextField id,password;JButton conform=new JButton(“確認(rèn)”);JButton cancle=new JButton(“取消”);LoginWindow(){ init();this.setTitle(“登錄界面”);this.setBounds(400,200,550,400);this.setResizable(false);
this.setVisible(true);
}
void init(){
this.setLayout(null);
labelID=new JLabel(“請輸入賬號(hào):”);labelID.setBounds(50, 100, 100, 30);this.add(labelID);
labelPassword=new JLabel(“請輸入密碼:”);labelPassword.setBounds(50, 200, 100, 30);this.add(labelPassword);
id=new JTextField(20);id.setBounds(170, 100, 300,30);this.add(id);
password=new JTextField(20);password.setBounds(170, 200, 300, 30);this.add(password);title=new JLabel(“登錄界面”);conform.setBounds(100, 280, 80, 30);cancle.setBounds(250, 280, 80, 30);
conform.addActionListener(new LoginListener());cancle.addActionListener(new LoginListener());
this.add(conform);this.add(cancle);} 登錄界面如圖6所示
圖6 登錄界面
3.2樹狀顯示目錄
登錄成功后顯示默認(rèn)路徑的樹狀文件目錄的主要代碼:
void getRoot(DefaultMutableTreeNode superroot, File f){
File files[] = f.listFiles();
for(int i = 0;i < files.length;i++){
DefaultMutableTreeNode de = new DefaultMutableTreeNode(files[i].getName());
if(files[i].isDirectory()){
de.setAllowsChildren(true);
} else {
de.setAllowsChildren(false);
System.out.println(“不是目錄的有:” + de.toString());
}
superroot.add(de);
} }
private class TreeListener implements TreeExpansionListener { // 重寫兩個(gè)方法
public void treeCollapsed(TreeExpansionEvent event){
}
public void treeExpanded(TreeExpansionEvent event){
DefaultMutableTreeNode node =(DefaultMutableTreeNode)(event
.getPath()).getLastPathComponent();
if(node.getChildCount()== 0){
DefaultMutableTreeNode originalNode = node;
String fileName = node.toString();
while(node.getParent()!= null){
node =(DefaultMutableTreeNode)node.getParent();
fileName = node.toString()+ “" + fileName;System.out.println(”當(dāng)前展開路徑名“ + fileName);
} if(originalNode!= null){
File f = new File(fileName);
if(f.isDirectory()){
File files[] = f.listFiles();
if(files!= null)
for(int i = 0;i < files.length;i++){
DefaultMutableTreeNode dmtn = new DefaultMutableTreeNode(files[i].getName());
if(files[i].isDirectory())
dmtn.setAllowsChildren(true);
else
dmtn.setAllowsChildren(false);
dtm.insertNodeInto(dmtn, originalNode,originalNode.getChildCount());
}
}
}
} }
樹狀目錄顯示如圖7所示:
圖7 樹狀顯示目錄
3.3新建目錄實(shí)現(xiàn)主要代碼:
private class NewMenuAction implements ActionListener {
public void actionPerformed(ActionEvent e){
TreePath path = tree.getSelectionPath();
MutableTreeNode node =(MutableTreeNode)path
.getLastPathComponent();
DefaultTreeModel model =(DefaultTreeModel)tree.getModel();
if(node.getAllowsChildren()){
String Name = JOptionPane.showInputDialog(null, ”創(chuàng)建目錄名稱:“);
if(!Name.equals(”“)){ MutableTreeNode newNode = new
DefaultMutableTreeNode(Name);// 建立新節(jié)點(diǎn)
1);
+ Name);
tree.fireTreeExpanded(path);model.insertNodeInto(newNode, node, 0);String fullPath = ”“;
for(Object obj : path.getPath()){ String str = obj.toString();if(str.endsWith(”“))
str = str.substring(0, str.length()1);if(fullPath.equals(”“))
fullPath += str;else
fullPath += ”“ + str;} String FileName = JOptionPane.showInputDialog(null, ”創(chuàng)建文件名稱:“);
if(!FileName.equals(null)){ File f = new File(fullPath + ”“ + FileName);try {
f.createNewFile();} catch(IOException e1){
e1.printStackTrace();} } else { JOptionPane.showMessageDialog(null, ”不能添加文件!“);return;
}
}
} }
新建文件如圖9所示,圖9 新建文件
3.5刪除文件實(shí)現(xiàn)
刪除文件主要代碼:
private class DeleteAction implements ActionListener{
public void actionPerformed(ActionEvent e){
TreePath tp = tree.getSelectionPath();
DefaultMutableTreeNode node =(DefaultMutableTreeNode)tp.getLastPathComponent();
DefaultTreeModel dtm =(DefaultTreeModel)tree.getModel();
dtm.removeNodeFromParent(node);
String fullPath = ”“;
for(Object obj : tp.getPath()){
String str = obj.toString();
if(str.endsWith(”“))
str = str.substring(0, str.length()-1);
if(fullPath.equals(”“))
fullPath += str;
else
fullPath += ”“ + str;
}
File currentFile = new File(fullPath);
if(currentFile.isFile())
currentFile.delete();
else
deleteDir(currentFile);
} } public static boolean deleteDir(File dir){
if(dir.isDirectory()){
String[] subDir = dir.list();
for(String s : subDir){
deleteDir(new File(dir, s));
}
}
return dir.delete();}
刪除文件如圖10所示:
圖10 刪除文件
3.6讀取文件實(shí)現(xiàn)
讀取文件主要代碼: void readFile(){
fileDialog = new JFileChooser(”F:“);
int state = fileDialog.showOpenDialog(null);
if(state == JFileChooser.APPROVE_OPTION){
try {
File dir = fileDialog.getCurrentDirectory();
String name = fileDialog.getSelectedFile().getName();File file = new File(dir, name);// 創(chuàng)建一新文件
fw = new FileReader(file);
br = new BufferedReader(fw);
String s = null;
this.setTitle(name);
jta.setText(” “);// 清空文本區(qū)的內(nèi)容
while((s = br.readLine())!= null){
jta.append(s + ”n");
}
br.close();
} catch(Exception e1){
e1.printStackTrace();
}
} } 讀取文件如圖11所示:
圖11 讀取文件
4設(shè)計(jì)總結(jié)
對于本次操作系統(tǒng)課程設(shè),由于對樹狀顯示目錄這樣面的內(nèi)容比較陌生,剛起步階段花了很大時(shí)間去查閱各種資料。當(dāng)完成設(shè)計(jì)時(shí),感覺掌握了以前學(xué)到的知識(shí),并且還對操作系統(tǒng)應(yīng)用有了更深入的認(rèn)識(shí)。比如對樹的展示有了很好的學(xué)習(xí),對二級(jí)文件系統(tǒng)也有了很好的了解,熟練Java布局的使用,如何解決實(shí)現(xiàn)里面功能的各種問題。本次設(shè)計(jì)集樹、監(jiān)聽器、布局、輸入輸出流、文件系統(tǒng)這幾方面的知識(shí)而成,具有一定挑戰(zhàn)性。
5參考文獻(xiàn)
[1] 李剛.瘋狂Java講義.電子工業(yè)出版社出版社,2008.[2] 耿祥義,張躍平.Java面向?qū)ο蟪绦蛟O(shè)計(jì).清華大學(xué)出版社出版社,2009.
第二篇:為LINUX 設(shè)計(jì)一個(gè)簡單的二級(jí)文件系統(tǒng)
#include
#define MEM_D_SIZE 1024*1024
//總磁盤空間為1M #define DISKSIZE 1024
//磁盤塊的大小1K #define DISK_NUM 1024 //磁盤塊數(shù)目1K #define FATSIZE DISK_NUM*sizeof(struct fatitem)//FAT表大小 #define ROOT_DISK_NO FATSIZE/DISKSIZE+1
//根目錄起始盤塊號(hào)
#define ROOT_DISK_SIZE sizeof(struct direct)//根目錄大小 #define DIR_MAXSIZE 1024 //路徑最大長度為1KB #define MSD
//最大子目錄數(shù)5 #define MOFN 5
//最大文件深度為5 #define MAX_WRITE 1024*128 //最大寫入文字長度128KB
struct fatitem /* size 8*/ {
int item;/*存放文件下一個(gè)磁盤的指針*/
char em_disk;/*磁盤塊是否空閑標(biāo)志位 0 空閑*/ };
struct direct
{
/*-----文件控制快信息-----*/
struct FCB
{
char name[9];/*文件/目錄名 8位*/
char property;/*屬性 1位目錄 0位普通文件*/
int size;
/*文件/目錄字節(jié)數(shù)、盤塊數(shù))*/
int firstdisk;/*文件/目錄 起始盤塊號(hào)*/
int next;
/*子目錄起始盤塊號(hào)*/
int sign;
/*1是根目錄 0不是根目錄*/
}directitem[MSD+2];
};
struct opentable
{
struct openttableitem
{
char name[9];/*文件名*/
int firstdisk;/*起始盤塊號(hào)*/
int size;/*文件的大小*/
}openitem[MOFN];
int cur_size;/*當(dāng)前打文件的數(shù)目*/ };
struct fatitem *fat;
/*FAT表*/ struct direct *root;
/*根目錄*/
struct direct *cur_dir;
/*當(dāng)前目錄*/
struct opentable u_opentable;/*文件打開表*/ int fd=-1;
/*文件打開表的序號(hào)*/
char *bufferdir;
/*記錄當(dāng)前路徑的名稱*/ char *fdisk;
/*虛擬磁盤起始地址*/
void initfile();void
format();void enter();void
halt();
int create(char *name);int
open(char *name);int close(char *name);
int write(int fd,char *buf,int len);int read(int fd,char *buf);int
del(char *name);int mkdir(char *name);int rmdir(char *name);void dir();
int cd(char *name);void print();void show();
void initfile(){
fdisk =(char *)malloc(MEM_D_SIZE*sizeof(char));/*申請 1M空間*/
format();
}
void format(){
int i;
FILE *fp;
fat =(struct fatitem *)(fdisk+DISKSIZE);/*計(jì)算FAT表地址,引導(dǎo)區(qū)向后偏移 1k)*/
/*-----初始化FAT表------------*/
fat[0].item=-1;/*引導(dǎo)塊*/
fat[0].em_disk='1';
for(i=1;i { fat[i].item=i+1; fat[i].em_disk='1'; } fat[ROOT_DISK_NO].item=-1;/*存放根目錄的磁盤塊號(hào)*/ fat[ROOT_DISK_NO].em_disk='1'; for(i=ROOT_DISK_NO+1;i { fat[i].item =-1; fat[i].em_disk = '0'; } /*----------------*/ root =(struct direct *)(fdisk+DISKSIZE+FATSIZE);/*根目錄的地址*/ /*初始化目錄*/ /*---------指向當(dāng)前目錄的目錄項(xiàng)---------*/ root->directitem[0].sign = 1; root->directitem[0].firstdisk = ROOT_DISK_NO; strcpy(root->directitem[0].name,“.”); root->directitem[0].next = root->directitem[0].firstdisk; root->directitem[0].property = '1'; root->directitem[0].size = ROOT_DISK_SIZE; /*-------指向上一級(jí)目錄的目錄項(xiàng)---------*/ root->directitem[1].sign = 1; root->directitem[1].firstdisk = ROOT_DISK_NO; strcpy(root->directitem[1].name,“..”); root->directitem[1].next = root->directitem[0].firstdisk; root->directitem[1].property = '1'; root->directitem[1].size = ROOT_DISK_SIZE; if((fp = fopen(“disk.dat”,“wb”))==NULL) { printf(“Error:n Cannot open file n”); return; } for(i=2;i { root->directitem[i].sign = 0; root->directitem[i].firstdisk =-1; strcpy(root->directitem[i].name,“"); root->directitem[i].next =-1; root->directitem[i].property = '0'; root->directitem[i].size = 0; } if((fp = fopen(”disk.dat“,”wb“))==NULL) { printf(”Error:n Cannot open file n“); return; } if(fwrite(fdisk,MEM_D_SIZE,1,fp)!=1)/*把虛擬磁盤空間保存到磁盤文件中*/ { printf(”Error:n File write error!n“); } fclose(fp); } void enter(){ FILE *fp; int i; fdisk =(char *)malloc(MEM_D_SIZE*sizeof(char));/*申請 1M空間*/ if((fp=fopen(”disk.dat“,”rb“))==NULL) { printf(”Error:nCannot open filen“); return; } if(!fread(fdisk,MEM_D_SIZE,1,fp))/*把磁盤文件disk.dat 讀入虛擬磁盤空間(內(nèi)存)*/ { printf(”Error:nCannot read filen“); exit(0); } fat =(struct fatitem *)(fdisk+DISKSIZE);/*找到FAT表地址*/ root =(struct direct *)(fdisk+DISKSIZE+FATSIZE);/*找到根目錄地址*/ fclose(fp); /*--------------初始化用戶打開表------------------*/ for(i=0;i { strcpy(u_opentable.openitem[i].name,”“); u_opentable.openitem[i].firstdisk =-1; u_opentable.openitem[i].size = 0; } u_opentable.cur_size = 0; cur_dir = root;/*當(dāng)前目錄為根目錄*/ bufferdir =(char *)malloc(DIR_MAXSIZE*sizeof(char)); strcpy(bufferdir,”Root:“); } void halt(){ FILE *fp; int i; if((fp=fopen(”disk.dat“,”wb“))==NULL) { printf(”Error:nCannot open filen“); return; } if(!fwrite(fdisk,MEM_D_SIZE,1,fp))/*把虛擬磁盤空間(內(nèi)存)內(nèi)容讀入磁盤文件disk.dat */ { printf(”Error:nFile write error!n“); } fclose(fp); free(fdisk); free(bufferdir); return;} int create(char *name){ int i,j; if(strlen(name)>8)/*文件名大于 8位*/ return(-1); for(j=2;j { if(!strcmp(cur_dir->directitem[j].name,name)) break; } if(j /*文件已經(jīng)存在*/ return(-4); for(i=2;i { if(cur_dir->directitem[i].firstdisk==-1) break; } if(i>=MSD+2)/*無空目錄項(xiàng)*/ return(-2); if(u_opentable.cur_size>=MOFN)/*打開文件太多*/ return(-3); for(j=ROOT_DISK_NO+1;j { if(fat[j].em_disk=='0') break; } if(j>=DISK_NUM) return(-5); fat[j].em_disk = '1';/*將空閑塊置為已經(jīng)分配*/ /*-----------填寫目錄項(xiàng)-----------------*/ strcpy(cur_dir->directitem[i].name,name); cur_dir->directitem[i].firstdisk = j; cur_dir->directitem[i].size = 0; cur_dir->directitem[i].next = j; cur_dir->directitem[i].property = '0'; /*--*/ fd = open(name); return 0; } int open(char *name){ int i, j; for(i=2;i { if(!strcmp(cur_dir->directitem[i].name,name)) break; } if(i>=MSD+2) return(-1); /*--------是文件還是目錄-----------------------*/ if(cur_dir->directitem[i].property=='1') return(-4); /*--------文件是否打開-----------------------*/ for(j=0;j { if(!strcmp(u_opentable.openitem[j].name,name)) break; } if(j return(-2); if(u_opentable.cur_size>=MOFN)/*文件打開太多*/ return(-3); /*--------查找一個(gè)空閑用戶打開表項(xiàng)-----------------------*/ for(j=0;j { if(u_opentable.openitem[j].firstdisk==-1) break; } /*--------------填寫表項(xiàng)的相關(guān)信息------------------------*/ u_opentable.openitem[j].firstdisk = cur_dir->directitem[i].firstdisk; strcpy(u_opentable.openitem[j].name,name); u_opentable.openitem[j].size = cur_dir->directitem[i].size; u_opentable.cur_size++; /*----------返回用戶打開表表項(xiàng)的序號(hào)--------------------------*/ return(j);} int close(char *name){ int i; for(i=0;i { if(!strcmp(u_opentable.openitem[i].name,name)) break; } if(i>=MOFN) return(-1); /*-----------清空該文件的用戶打開表項(xiàng)的內(nèi)容---------------------*/ strcpy(u_opentable.openitem[i].name,”"); u_opentable.openitem[i].firstdisk =-1; u_opentable.openitem[i].size = 0; u_opentable.cur_size--; return 0;} int write(int fd, char *buf, int len){ char *first; int item, i, j, k; int ilen1, ilen2, modlen, temp; /*----------用 $ 字符作為空格 # 字符作為換行符-----------------------*/ char Space = 32; char Endter= 'n'; for(i=0;i { if(buf[i] == '$') buf[i] = Space; else if(buf[i] == '#') buf[i] = Endter; } /*----------讀取用戶打開表對應(yīng)表項(xiàng)第一個(gè)盤塊號(hào)-----------------------*/ item = u_opentable.openitem[fd].firstdisk; /*-------------找到當(dāng)前目錄所對應(yīng)表項(xiàng)的序號(hào)-------------------------*/ for(i=2;i { if(cur_dir->directitem[i].firstdisk==item) break; } temp = i;/*-存放當(dāng)前目錄項(xiàng)的下標(biāo)-*/ /*------找到的item 是該文件的最后一塊磁盤塊-------------------*/ while(fat[item].item!=-1){ item =fat[item].item;/*-查找該文件的下一盤塊--*/ } /*-----計(jì)算出該文件的最末地址-------*/ first = fdisk+item*DISKSIZE+u_opentable.openitem[fd].size%DISKSIZE; /*-----如果最后磁盤塊剩余的大小大于要寫入的文件的大小-------*/ if(DISKSIZE-u_opentable.openitem[fd].size%DISKSIZE>len) { strcpy(first,buf); u_opentable.openitem[fd].size = u_opentable.openitem[fd].size+len; cur_dir->directitem[temp].size = cur_dir->directitem[temp].size+len; } else { for(i=0;i<(DISKSIZE-u_opentable.openitem[fd].size%DISKSIZE);i++) {/*寫一部分內(nèi)容到最后一塊磁盤塊的剩余空間(字節(jié))*/ first[i] = buf [i]; } /*-----計(jì)算分配完最后一塊磁盤的剩余空間(字節(jié))還剩下多少字節(jié)未存儲(chǔ)-------*/ ilen1 = len-(DISKSIZE-u_opentable.openitem[fd].size%DISKSIZE); ilen2 = ilen1/DISKSIZE; modlen = ilen1%DISKSIZE; if(modlen>0) ilen2 = ilen2+1;/*--還需要多少塊磁盤塊-*/ for(j=0;j { for(i=ROOT_DISK_NO+1;i { if(fat[i].em_disk=='0') break; } if(i>=DISK_NUM)/*--如果磁盤塊已經(jīng)分配完了-*/ return(-1); first = fdisk+i*DISKSIZE;/*--找到的那塊空閑磁盤塊的起始地址-*/ if(j==ilen2-1)/*--如果是最后要分配的一塊-*/ { for(k=0;k first[k] = buf[k]; } else/*-如果不是要最后分配的一塊--*/ { for(k=0;k first[k] =buf[k]; } fat[item].item = i;/*--找到一塊后將它的序號(hào)存放在上一塊的指針中-*/ fat[i].em_disk = '1';/*--置找到的磁盤快的空閑標(biāo)志位為已分配-*/ fat[i].item =-1;/*--它的指針為-1(即沒有下一塊)-*/ } /*--修改長度-*/ u_opentable.openitem[fd].size = u_opentable.openitem[fd].size+len; cur_dir->directitem[temp].size = cur_dir->directitem[temp].size+len; } return 0;} int read(int fd, char *buf){ int len = u_opentable.openitem[fd].size; char *first; int i, j, item; int ilen1, modlen; item = u_opentable.openitem[fd].firstdisk; ilen1 = len/DISKSIZE; modlen = len%DISKSIZE; if(modlen!=0) ilen1 = ilen1+1;/*--計(jì)算文件所占磁盤的塊數(shù)-*/ first = fdisk+item*DISKSIZE;/*--計(jì)算文件的起始位置-*/ for(i=0;i { if(i==ilen1-1)/*--如果在最后一個(gè)磁盤塊-*/ { for(j=0;j buf[i*DISKSIZE+j] = first[j]; } else /*--不在最后一塊磁盤塊-*/ { for(j=0;j buf[i*DISKSIZE+j] = first[j]; item = fat[item].item;/*-查找下一盤塊-*/ first = fdisk+item*DISKSIZE; } } return 0;} int del(char *name){ int i,cur_item,item,temp; for(i=2;i { if(!strcmp(cur_dir->directitem[i].name,name)) break; } }