⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fileimage.cpp

📁 模拟Linux文件系统 在任一OS下
💻 CPP
字号:
#include"disk.h"
extern disk DISK;
void fileimage::fileimage_open(fstream ff,inode itemp){
	iof=ff;
	fileimageinode=itemp;
}
int fileimage::fileimage_location_text(int sit)
{
	int k=sit/12;
	int j=sit%12;
	if(fileimageinode.address[k]!=-1){
		DISK.block_to_buffer(fileimageinode.address[k],j*80);
		return 1;
	}
	else return -1;
}
int fileimage::myeof(char*nowline)//判断是否到文件末
{
	/*
	char end[5];
	end[0]=fileimageend;
	end[1]=fileimageend;
	end[2]=fileimageend;
	end[3]=fileimageend;
	end[4]='\0';
	*/
	if(strcmp(nowline,fileimageend)==0)
		return 1;
	return 0;
}
void fileimage::fileimage_getimage_text(char*image)//打开文件映像
{
	iof=DISK.iof;
	fstream imageiof(image,ios::in|ios::out);
	int line=0;
	char s[80];
	freebitmap fb(DISK.iof);
	while(!imageiof.eof()){
		imageiof.getline(s,80);
		if(fileimage_location_text(line)==-1){
			int k=fb.freebitmap_applyfor();
			fb.freebitmap_set(k);
			fileimageinode.address[line/12]=k;
			fileimage_location_text(line);//申请完空间后重新定位
		}
        iof<<s<<endl;
		line++;
	}
	strcpy(s,fileimageend);
	if(fileimage_location_text(line)==-1){
		int k=fb.freebitmap_applyfor();
		fb.freebitmap_set(k);
		fileimageinode.address[line/12]=k;
		fileimage_location_text(line);//申请完空间后重新定位
	}
	iof<<s<<endl;
	fileimageinode.type=MYTEXT;
	fileimageinode.file_size=line;
	fileimage_inodewriteback();
	imageiof.close();
}
void fileimage::fileimage_inodewriteback(){
	inodelist_disk id(iof);
	id.inodelist_disk_write(fileimageinode.inode_num,fileimageinode);
}
void fileimage::fileimage_outimage_text(char*image)//向外复制文件映像
{
	iof=DISK.iof;
	fstream imageiof(image,ios::in|ios::out);
	int line=0;
	char s[80];
	if(1!=fileimage_location_text(line)){
		cout<<"file wrong"<<endl;
		exit(0);
	}
	iof.getline(s,80);
	do{ 
        imageiof<< s << endl; //
//		imageiof.write(s,80);
		line++;
		fileimage_location_text(line);
		iof.getline(s,80);
	}while(!myeof(s));
	if(line!=fileimageinode.file_size){
		cout<<"text file wrong"<<endl;
		exit(0);
	}
	imageiof.close();
}
void fileimage::fileimage_cat_text(){
	int line=0;
	char s[80];
	if(1!=fileimage_location_text(line)){
		cout<<"file wrong"<<endl;
		exit(0);
	}
	iof.getline(s,80);
	do{ 
        cout<<s<<endl;
//		imageiof.write(s,80);
		line++;
		fileimage_location_text(line);
		iof.getline(s,80);
	}while(!myeof(s));
	if(line!=fileimageinode.file_size){
		cout<<"text file wrong"<<endl;
		exit(0);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -