操作系统实验文件管理C代码
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#include <>
#include <>
#include <>
#include <>
#include
using namespace std;
#define BLKSIZE 512.\n");
printf("WARNING:ALL DATA ON THIS FILESYSTEM WILL BE LOST!\n");
printf("Proceed with Format(Y/N)?");
scanf("%c", &choice);
getchar();
if((choice == 'y') || (choice == 'Y'))
{
if((fp=fopen(image_name, "w+b")) == NULL)
{
printf("Can't create file %s\n", image_name);
exit(-1);
}
for(i = 0; i < BLKSIZE; i++)
fputc('0', fp);
= 0;
strcpy, "/");
= 'd';
strcpy, "/");
= 0;
= 0;
[0] = -1;
[1] = -1;
fwrite(&inode, sizeof(Inode), 1, fp);
= -1;
for(i = 0; i < 31; i++)
fwrite(&inode, sizeof(Inode), 1, fp);
for(i = 0; i < BLKNUM*BLKSIZE; i++)
fputc('\0', fp);
fclose(fp);
n", file_name);
printf("This filesystem not exist, it will be create!\n");
format();
login();
}
while(!feof(fp))
{
fread(&user, sizeof(User), 1, fp);
n");
flag = 1;
fclose(fp);
break;
}
}
if(flag == 0) break;
}while(flag);
n", image_name);
exit(-1);
}
num = -1;
}
n");
exit(-1);
}
bitmap[i] = '1';
if((fp=fopen(image_name, "r+b")) == NULL)
{
printf("Can't open file %s\n", image_name);
exit(-1);
}
fseek(fp, i, SEEK_SET);
fputc('1', fp);
fclose(fp);
return i;
}
ength;
add0 = inode_array[num].address[0];
if(len > 512)
add1 = inode_array[num].address[1];
if((fp = fopen(image_name, "r+b")) == NULL)
{
printf("Can't open file %s.\n", image_name);
exit(-1);
}
fseek(fp, BLKSIZE+INODESIZE*INODENUM +add0*BLKSIZE, SEEK_SET);
ch = fgetc(fp);
for(i=0; (i < len) && (ch != '\0') && (i < 512); i++)
{
temp[i] = ch;
ch = fgetc(fp);
}
if(i >= 512)
{
fseek(fp,BLKSIZE+INODESIZE*INODENUM+add1*BLKSIZE, SEEK_SET);
ch = fgetc(fp);
for(; (i < len) && (ch != '\0'); i++)
{
temp[i] = ch;
ch = fgetc(fp);
}
}
temp[i] = '\0';
fclose(fp);
}
ddress[0];
len = inode_array[num].length;
if((fp = fopen(image_name, "r+b")) == NULL)
{
printf("Can't open file %s.\n", image_name);
exit(-1);
}
fseek(fp, BLKSIZE+INODESIZE*INODENUM+add0*BLKSIZE, SEEK_SET);
for(i=0; (i fputc(temp[i], fp); if(i == 512) { add1 = inode_array[num].address[1]; fseek(fp, BLKSIZE+INODESIZE*INODENUM+add1*BLKSIZE, SEEK_SET); for(; (i < len) && (temp[i] != '\0'); i++) fputc(temp[i], fp); } fputc('\0', fp); fclose(fp); } num == 0) strcpy(path,; else { strcpy(path,; m=0; n=inum_cur; while(m != inum_cur) { while(inode_array[n].iparent != m) { n = inode_array[n].iparent;