资源简介
本人花费了全部积分在CSDN上下载的,觉得对考研的同学有用,欢迎考华工CS的小伙伴下载~
代码片段和文件信息
/*
* UFS: our own Filesystem in Userspace
* Copyright (c) 2009 LuQianhui
* All rights reserved.
*
* 文件名称:init.c
* 摘 要: this is a format program to init the image
* file to write its super block and bitmap
* and blocks data.
*
*
* 当前版本:1.0
* 作 者:飘零青丝
* 完成日期:2009年2月20日
*
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include “ufs.h“
int main(void){
FILE * fp=NULL;
fp=fopen(DISK “r+“);//r+ 以可读写方式打开文件,该文件必须存在.打开DISK,并且fp指向它
if(fp == NULL) {//如果文件打开失败则返回NULL,并把错误代码存在errno中。
fprintf(stderr“open diskimg unsuccessful!\n“);
return 0;
}
sb *super_block_record=malloc(sizeof(sb));
/* calculate the size of the filesystem in block */
//如果执行成功,fp将指向以SEEK_END为基准,偏移0(指针偏移量)个字节的位置,函数返回0。
//如果执行失败,则不改变fp指向的位置,函数返回一个非0值。
fseek(fp 0 SEEK_END); //fp指向DISK文件尾
super_block_record->fs_size = ftell(fp)/BLOCK_BYTES;//ftell指针当前位置相对于文件首的偏移字节数
super_block_record->first_blk = 1 + MAX_BITMAP_IN_BLOCK;
super_block_record->bitmap = MAX_BITMAP_IN_BLOCK;
/* initialize the super block super block is block 0. */
if(fseek(fp 0 SEEK_SET )!=0)//fp指向DISK文件头
fprintf(stderr“unsuccessful!\n“);
//向文件写入一个数据块
fwrite(super_block_record sizeof(sb) 1 fp);//要获取数据的地址、要写入内容的字节数、要进行写入size字节的数据项的个数、目标文件指针;
if(fseek(fp 512 SEEK_SET )!=0)
fprintf(stderr“unsuccessful!\n“);
/* initialize the bitmap block */
/* it is the first bitmap block */
char a[180];
memset(a-1180);
fwrite(a 180 1 fp);
int temp=0x80000000;
int* pt=&temp;
fwrite(pt sizeof(int) 1 fp);
char b[328];
memset(b0328);
fwrite(b3281fp);
/* the rest bitmap blocks*/
int total = (MAX_BITMAP_IN_BLOCK-1)*BLOCK_BYTES;
char rest[total];
memset(rest 0 total);
fwrite(rest total 1 fp);
/* initialize the root directory block */
fseek(fp BLOCK_BYTES * (MAX_BITMAP_IN_BLOCK+1) SEEK_SET);
u_fs_disk_block *root=malloc(sizeof(u_fs_disk_block));
root->size= 0;
root->nNextBlock=-1;
root->data[0]=‘\0‘;
fwrite(root sizeof(u_fs_disk_block) 1 fp);
fclose(fp);
printf(“initialize successful!\n“);
return 0;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2019-01-06 00:36 鍗庡伐\
目录 0 2019-01-06 00:29 鍗庡伐\鎿嶄綔绯荤粺\
目录 0 2019-01-06 00:28 鍗庡伐\鎿嶄綔绯荤粺\瀹為獙\
文件 0 2019-01-06 00:28 鍗庡伐\鎿嶄綔绯荤粺\瀹為獙\201330551129鏋楃憺鐜?
文件 0 2019-01-06 00:28 鍗庡伐\鎿嶄綔绯荤粺\瀹為獙\201330551129鏋楃憺鐜?瀹為獙鍥?
文件 3134 2015-12-19 13:21 鍗庡伐\鎿嶄綔绯荤粺\瀹為獙\201330551129鏋楃憺鐜?瀹為獙鍥?comand.cpp
文件 1325 2015-12-19 19:56 鍗庡伐\鎿嶄綔绯荤粺\瀹為獙\201330551129鏋楃憺鐜?瀹為獙鍥?doit.cpp
文件 236032 2015-12-19 19:55 鍗庡伐\鎿嶄綔绯荤粺\瀹為獙\201330551129鏋楃憺鐜?瀹為獙鍥?瀹為獙鍥?doc
文件 1847051 2015-11-25 12:53 鍗庡伐\鎿嶄綔绯荤粺\瀹為獙\201330551129鏋楃憺鐜?瀹為獙涓€鎶ュ憡鍒濈.docx
文件 242332 2015-11-25 19:32 鍗庡伐\鎿嶄綔绯荤粺\瀹為獙\201330551129鏋楃憺鐜?瀹為獙浜屾姤鍛婂垵绋?doc
文件 35328 2015-10-03 13:31 鍗庡伐\鎿嶄綔绯荤粺\瀹為獙\201330551129鏋楃憺鐜?鎿嶄綔绯荤粺瀹為獙鎸囧涔︼紙linux鐗堬級.doc
文件 284271 2015-11-26 15:17 鍗庡伐\鎿嶄綔绯荤粺\瀹為獙\201330551129鏋楃憺鐜?瀹為獙涓夋姤鍛婂垵绋?docx
文件 38956 2015-11-26 15:44 鍗庡伐\鎿嶄綔绯荤粺\瀹為獙\201330551129鏋楃憺鐜?瀹為獙鍥涙姤鍛婂垵绋?docx
文件 6451 2015-11-24 22:41 鍗庡伐\鎿嶄綔绯荤粺\瀹為獙\201330551129鏋楃憺鐜?鑷繁鍐欑殑.txt
文件 0 2019-01-06 00:28 鍗庡伐\鎿嶄綔绯荤粺\瀹為獙\201330551129鏋楃憺鐜?瀹為獙浜?
文件 1897 2015-11-25 16:34 鍗庡伐\鎿嶄綔绯荤粺\瀹為獙\201330551129鏋楃憺鐜?瀹為獙浜?produce_consume.cpp
文件 278528 2015-12-19 12:01 鍗庡伐\鎿嶄綔绯荤粺\瀹為獙\201330551129鏋楃憺鐜?瀹為獙浜?瀹為獙浜?doc
文件 1817 2015-12-18 21:04 鍗庡伐\鎿嶄綔绯荤粺\瀹為獙\201330551129鏋楃憺鐜?瀹為獙浜?hair_cut.cpp
文件 3975 2015-11-25 19:06 鍗庡伐\鎿嶄綔绯荤粺\瀹為獙\201330551129鏋楃憺鐜?瀹為獙浜?read_write.cpp
目录 0 2019-01-06 00:28 鍗庡伐\鎿嶄綔绯荤粺\瀹為獙\201330551129鏋楃憺鐜?瀹為獙涓€\
文件 743936 2015-12-19 17:02 鍗庡伐\鎿嶄綔绯荤粺\瀹為獙\201330551129鏋楃憺鐜?瀹為獙涓€\瀹為獙涓€.doc
文件 424 2015-11-25 13:10 鍗庡伐\鎿嶄綔绯荤粺\瀹為獙\201330551129鏋楃憺鐜?瀹為獙涓€\share_var.cpp
文件 323 2015-11-25 12:51 鍗庡伐\鎿嶄綔绯荤粺\瀹為獙\201330551129鏋楃憺鐜?瀹為獙涓€\an_ch2_1a.cpp
文件 280 2015-11-25 12:49 鍗庡伐\鎿嶄綔绯荤粺\瀹為獙\201330551129鏋楃憺鐜?瀹為獙涓€\an_ch2_1b.cpp
文件 0 2019-01-06 00:28 鍗庡伐\鎿嶄綔绯荤粺\瀹為獙\201330551129鏋楃憺鐜?瀹為獙涓?
文件 9229 2015-11-26 15:48 鍗庡伐\鎿嶄綔绯荤粺\瀹為獙\201330551129鏋楃憺鐜?瀹為獙涓?myfind.cpp
文件 416768 2015-12-19 17:03 鍗庡伐\鎿嶄綔绯荤粺\瀹為獙\201330551129鏋楃憺鐜?瀹為獙涓?瀹為獙涓?doc
文件 8196 2019-01-06 00:30 鍗庡伐\鎿嶄綔绯荤粺\.DS_Store
目录 0 2019-01-06 00:36 __MACOSX\
目录 0 2019-01-06 00:36 __MACOSX\鍗庡伐\
目录 0 2019-01-06 00:36 __MACOSX\鍗庡伐\鎿嶄綔绯荤粺\
............此处省略192个文件信息
评论
共有 条评论