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

📄 function.h

📁 linux文件系统试验 一、实验目的 学习有关linux文件管理程序如何组织的知识
💻 H
字号:
/***************************************************************************                          function.h  -  description                             -------------------    begin                : Wed Jul 23 2003    copyright            : (C) 2003 by Jeremy    email                : zhiming_z@hotmail.com ***************************************************************************//* start of void*/void getdiskinfo(){// i don't know how to write this part//maybe you read the first sector and save in sb_fat12  with the corresponding position	 sb_fat12.sector_p_cluster=1;  			 sb_fat12.num_fat=2;								 sb_fat12.num_root_dir_entry=14;		 sb_fat12.num_log_sector=2880;				 sb_fat12.sector_p_fat=9;						 sb_fat12.num_hid_sector=0;	 sb_fat12.other_use_sector=1;	}int get_sector_num(int clu)		//give it a cluster number the int it return will be the number of the logic sector{	int a;	a=clu+sb_fat12.sector_p_fat*sb_fat12.num_fat+sb_fat12.num_root_dir_entry+sb_fat12.other_use_sector; //or a=clu+31	return(a);}void read_cluster(int clu_num)				//intention here uses a logic cluster number{	int dest,len;	fid=open("/dev/fd0",O_RDWR); //fd0,hdd1	dest=lseek(fid,clu_num*BPS,SEEK_SET);	if(dest!=clu_num*BPS)			{				cout<<"sth. wrong while reading file"<<endl;			}	else len=read(fid,buffer,BPS);	//close(fid);}void read_list(unsigned char bu[BPS],int sector_num)			//here is a logic cluster number log=clu+31{	int i=0,k=0,num_files=0;	struct file_node *p1,*p2;	p1=p2=( struct file_node * ) malloc(FLEN);	head_per_cluster=NULL;		for (i=0;i<16;i++)		{			if ((bu[i*32]!=FILE_EMPTY)&&(bu[i*32]!=FILE_DEL))			{				p1=( struct file_node * ) malloc(FLEN);				num_files++;				if(num_files==1) head_per_cluster=p1;					else p2->next=p1;									for (k=0;k<8;k++) 					//fill file name				{					if (bu[i*32+k]!=32)			p1->file_name[k]=bu[i*32+k];					else										p1->file_name[k]='\0';  //no blank in file_name;				}					for (k=0;k<3;k++)						//fill extend name				{					if (bu[i*32+8+k]!=32)		p1->ext_name[k]=bu[i*32+8+k];					else				    					p1->ext_name[k]='\0';				}								k=0;								perbyte attby(bu[i*32+11]);					/*fill p1 with the attribute byte*/				p1->readonly=(int)attby.binary[7];				p1->hidden=(int)attby.binary[6];				p1->system=(int)attby.binary[5];				p1->isdir=(int)attby.binary[3];				p1->isfile=(int)attby.binary[2];									//fill p1 with the time byte 23 22												p1->start_cluster=bu[i*32+26];				p1->num_cluster=sector_num;				p1->num_index=i;								p2=p1;			}		} //end loop for i		//p2->next=NULL;		p_end=p2;}void read_index(int logic_number){	int i=0,k=0;	struct file_node *p1;		read_cluster(logic_number);	read_list(buffer,logic_number);		head=head_per_cluster;		if (logic_number==19)		//if in root	{		for(i=1;i<14;i++)			{				p1=( struct file_node * ) malloc(FLEN);				p1=p_end;								read_cluster(logic_number+i);							//caution when use void read_cluster() use a logic cluster number 				read_list(buffer,logic_number+i);   				//and void read_list()  use a logic number  .log=clu+31`						   if (head_per_cluster!=NULL)			   	p1->next=head_per_cluster;			   else			   	{p1->next=NULL;break;}			}p_end->next=NULL;	}		else 		//if not in root		{		}	}/*to show the files you have put in a link*/void show_list(struct file_node *p1){	int i;	printf("\nfolders and files:\n");	printf("name\t\tR_Only\tHidden\tSystem\tIsdir\tIsfile\n\n");	while (p1!=NULL)	{		while (p1->system==1) p1=p1->next;		while ((p1->isfile==0)&&(p1->isdir==0)) p1=p1->next;		for(i=0;i<8;i++)		{			if (p1->file_name[i]!='\0')				{		printf("%c",p1->file_name[i]);			}			else printf(" ");	   }				if (p1->ext_name[0]!='\0')			printf(".");		else printf(" ");				for (i=0;i<3;i++)		{			if (p1->ext_name[i]!='\0')				printf("%c",p1->ext_name[i]);			else				printf(" ");		}						printf("\t%2d\t%2d\t%2d\t%2d\t%2d\t",p1->readonly,p1->hidden,p1->system,p1->isdir,p1->isfile);		/*put date time ...*/				printf("\n");			p1=p1->next;	}	//end while}void show_buf(unsigned char *in_char){	int i=0,k=0,n=0;	unsigned char temp[16];	printf("from here we start\n\n"); 	printf("00 01 02 03 04 05 06 07 ,08 09 10 11 12 13 14 15\n"); 	printf("00 01 02 03 04 05 06 07 ,08 09 0a 0b 0c 0d 0e 0f\n\n"); 	while (i<BPS)	{			perbyte s1(in_char[i]);		printf("%x%x ",s1.h_10,s1.l_10);//this puts the ASCII number .if use%x then put the x number		n=i%16;		temp[n]=in_char[i];				if (n==7) printf(",");		if ((n==15)&&(i!=0))			{				printf("   | ");				for (k=0;k<16;k++)				{					if (((temp[k]>64)&&(temp[k]<91))||((temp[k]>96)&&(temp[k]<123))||(temp[k]==32))						printf("%c",temp[k]);					else printf(".");				}					printf(" |\n");			}			i++;		}}		void toupper(char *f_name) 	//this function can change file name whichj has small word to big word ,in char_big[]{	int i=0;	for (i=0;i<INP_LEN;i++)	{		if ((f_name[i]>96)&&(f_name[i]<123))			f_name[i]=f_name[i]-32;		else f_name[i]=f_name[i];	}}/*        second    */int read_fat(int n){	int clu_1,clu_2,clu_3;	int clu_fat_at=(int)(n/341);		read_cluster(clu_fat_at);	if (n%2==0)	{		perbyte f1 (buffer[(3*n)/2]);		perbyte f2 (buffer[(3*n+2)/2]);				clu_1=f2.l_10; // hundred		clu_2=f1.h_10; // ten		clu_3=f1.l_10; //	}	else	{		perbyte f3 (buffer[(3*n-1)/2]);		perbyte f4 (buffer[(3*n+1)/2]);		clu_1=f4.h_10; //hundred		clu_2=f4.l_10; //ten		clu_3=f3.h_10; //	}	return(clu_1*100+clu_2*10+clu_3);}struct file_node * find_file (char *name,char *ext){	struct file_node *p1;	p1=head; //  put a cur_head in the top	if (name[0]!='\0') toupper(name);	if (ext[0]!='\0') toupper(ext);	while(p1!=NULL)	{		if (strcmp(p1->file_name,name)==0)	//&&(strcmp(p1->ext_name,ext)==0)) 			{	if (ext[0]!='\0')										//if isfile 					{if (strcmp(p1->ext_name,ext)==0)	return (p1);}	 				else return(p1);									//if is a folder 			} 					else p1=p1->next;	}	return (p1);}void write_cluster(int sec_n){	int dest,len;	fid=open("/dev/fd0",O_RDWR);	dest=lseek(fid,sec_n*BPS,SEEK_SET);	if (dest!=sec_n*BPS)		cout<<"wrong!can't write"<<endl;	else	{		len=write(fid,buffer,BPS);				if (len!=BPS)			cout<<"wrong while writting"<<endl;		else cout<<"write success"<<endl;	}}void del_fat(int n){	unsigned a=240,b=16; //a 1111 0000 b 0000 1111	if (n%2==0)	{		buffer[(3*n+2)/2]=0;		buffer[(3*n+4)/2]=buffer[(3*n+4)/2]&a;	}	else	{		buffer[(3*n+1)/2]=buffer[(3*n+1)/2]&b;		buffer[(3*n+3)/2]=0;	}}	void del_file(int clu_index_at,int num_index,int clu_start){	int a,b;	read_cluster(clu_index_at);	buffer[clu_index_at*32]=229;  //e5 145 1110 0101	write_cluster(clu_index_at);	a=clu_start;				//if ((a!=0)&&(a!=4095))	{b=a;a=read_fat(b);del_fat(b);}		//else 	del_fat(a);}		/*end of void*/

⌨️ 快捷键说明

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