Thread View: cn.bbs.comp.program
1 messages
1 total messages
Started by ���ܵ�Сʨ
Thu, 07 May 1998 00:00
�ָ̻�UNIX����ɾ���ļ�
Author: ���ܵ�Сʨ
Date: Thu, 07 May 1998 00:00
Date: Thu, 07 May 1998 00:00
163 lines
8927 bytes
8927 bytes
Undelete��Recycled(����վ)���ѳ�ΪDos/Windows�û���Ϥ�Ļ�
��ɾ���ļ��Ĺ��?��,����UNIX��,��Ȼ��Щ�汾��UNIX����ϵͳ��
����������"������"�Ĺ���,ȴһֱû�и��û��ṩ�ָ�ɾ���ļ���
������UNIX��,һ��С����ɾ����Ҫ�ļ�����ô��?����,�в�����
���Լ����Ƴ�����������,�������ṹ�ϸ���,���ҿɿ���Ƿ��,
һ��UNIX�����û�Ҳ�������ա�������Դ������д��һ�μ�̵�C
���Գ���(UNIX��ANSIC��),��UNIX�Դ��C������cc���б���,��UN
IX������
���Ƚ���һ��UNIX�����ļ�ϵͳ�ṹ��UNIX�ļ�ϵͳ�ṹ��ȫ��
ͬ��DOS/Windowsϵͳ,�������ϵ�ÿ�������һ����Ӧ�������
����һ�㲻�漰�����ȡ�IJ�����ֻ�������,���漰�������ȡ
ʱ,�ٽ�����ת��Ϊ������ ��UNIX���Ѵ��̵��ļ������Ŵ�����
��,һ�����Ϊһ���ļ��?ÿ���ļ����ɴ��һ���������ļ�ϵͳ,
�����ܽ�һ���ļ����ɢ�ڶ���������ϡ��ļ�����������������
��ʾ:
0# 1# 2# �� m# m+1# m+2# �� n-1# n#
���ļ�����,0#��һ������ϵͳ������,���ļ�ϵͳ��ϵ����
��1#����������ļ������Դ��Ϣ,һ���Ϊ������(superblock)
��ר�ÿ顣��2#����ֱ��ijһ��(�������Ҷ�Ϊm+1#��)ֹ������ڵ�
,��Ϊi�ڵ��,���д�ŵ����ļ���������Ϣ,���û���ʶ�����ʶ��
�ļ�����ļ���ȡʱ�䡢�ļ����Ӹ����ļ���С�ȡ�ÿ�����̵�
i�ڵ��СΪ64�ֽ�,��ÿ�������Ϊ512�ֽ�(��1024�ֽ�),���һ��
�������Դ��8(��16)���ڵ㡣�ӵ�m+2#�鵽��n��,����ļ�����
��
�������ǶԱ�����Ĺ�˼�ͻ������ʵ��������û���ʹ��ij����
��ʱ,ͨ����ļ���·���ҵ����ļ���Ŀ¼��,����Ŀ¼�е�i�ڵ��
�ҵ����ļ���i�ڵ�,���i�ڵ��ṩ�ĵ�ַ��Ϣ�����ҵ����ļ��е�
��ݡ��ļ���ɾ���,Ŀ¼���е�i�ڵ�ű��ó�0,�ڲ�i�ڵ���뵽
����i�ڵ����,���ļ�ռ�õ������Ҳ��Ϊ���п����뵽���п����
������i�ڵ㼰�ļ���ռ��ݿ��е����ݲ�δ���ƻ�(δ���д���д��
��),���Ϊ�ļ��Ļָ������ṩ���ܡ�
����������,���ļ���ɾ���,��û�д��̿ռ�������ʱ,��
�������������ָ�ɾ���ļ�����ȡ��ɾ���ļ���i�ڵ��,���ļ�ϵͳ
�Ľṹ�ҵ���Ӧ��i�ڵ�,��ȡ����ָ������ݿ���Ϣ,����һ������
���� ,�ɴ˿ɴﵽ�ָ��ļ���Ŀ�ġ�����,��lk�ļ�ϵͳ��,m��i�ڵ�
���ļ�ϵͳ�е�ƫ��ֵΪ(2*1024)+64*(m-1),��Ҫ��ȡ��Ӧ��i�ڵ�
��Ϣ,��������lseek�����ļ��Ķ�дָ���Ƶ���λ��,��ȡ64����
��,����i�ڵ���Ϣ��,���������е�addr[40]���ҵ��ļ������
���ַ��
�ļ���ɾ��ʱ,���ļ���i�ڵ���Ѵӵ�ǰĿ¼��ɾ��,�������
���뱣��i�ڵ��,�Ա��ָ�ʱʹ�á�����,������ļ���ɾ��ʱ����i
�ڵ�žͳ�Ϊһ���ؼ����⡣������ÿ��ٻ�����ķ���:���ļ���
ɾ��֮ǰ�����ļ���Ŀ¼�����ݿ�����ijһ�����õ��ļ���,��ʱ��
��������������ļ�����Ϊ/usr/restore,���ļ�������ǹ̶�
��,��ָ�ɾ���ļ�ʱ�ʹ�/usr/restore�ļ��ж�ȡi�ڵ�š�������
�����嵥��
/*restore.c*/
#include<stdio.h>
#include<sys/types.h>
#include<sys/ino.h>
#include<dirent.h>
#include<sys/dir.h>
main(argc,argv)
int argc;
char*argv[];
{
int no,a,fd,fdt,*ip,i,m,k,n;
char s[4],buf[1024],buft[1024],sbu[300000],*point;
struct dinode inodet;
if(argc!=3){
printf("Usage:restore oldfile newfile!\n");
exit(1);
}
if((no=getino(argv[1]))==0 {
printf("No file has been delete!\n");
exit(1);
}
if((fd=open("/dev/dsk/0s3",0))==-1 ){
printf("Can not open /dev/dsk/0s3 \n");
/* /dev/dsk/0s3Ϊ��ɾ�ļ������ļ�ϵͳ���豸�ļ��� *
/
exit(1);
}
lseek(fd,(no-1)*64+2048,0);
if((n=read(fd,&inode,64))!=64) {
printf("Error in read i-node\n");
exit(1);
}
if((fdt��creat(argv[2],0666))==-1) {
printf("Can not creat %s\n",argv[2]);
exit(1);
}
point=sbu;
k=inodet.di��size/1024;
if(k<10) {
m=0;
k++;
m=3*k;
}
else{
m=k-9;
k=30;
}
for(i=0;i<k;i++) {
s[i%3]=inodet.de��addr[i];
if(i%3==2) {
s[3]=0;
ip=(int *)s;
lseek(fd,(*ip)*1024,0);
n=read(fd,buf,1024);
strcpy(point,buf,n);
point+=n;
}
}
if(1) { /* �ļ���С���� 10k*/
s[0]=inodet.di��adrr[30];
s[1]=inodet.di��adrr[31];
s[2]=inodet.di��adrr[32];
s[3]=0;
ip=(int *)s;
lseek(fd,(*ip)*1024,0);
read(fd,buft,1024);
1 *=4;
for(i=0;i<1;i++){
s[i%4]=buf1[i];
if(i%4==3)
ip=(int *)s;
lseek(fd,(*ip)*1024,0);
n=read(fd,buf,1024);
strcpy(point,buf,n);
point +=n;
} /* if */
} /* for */
}
write(fdt,sbu,inodet,di��size);
}
int getino(name)
/*����getino��/usr/restore�ļ��л�ȡ��ɾ�ļ���i�ڵ��
char *name;
{
int fd,n;
struct direct buf;
fd=open("/usr/restore",0);
while((n=read(fd,&buf,sizeof(buf)))!=0) {
if(n!=16){
printf("Error in read \n");
exit(1);
}
if(strcmp(buf.d��name,name)==0) {
close(fd);
return(buf.d��ino);
}
} /*while */
close(fd);
return(0);
}
�û�����ֱ��ʹ��UNIX��vi�༭�����г���༭,Ȼ��ʹ��UNIX
��cc����������,����# cc -o unrm restore.c,��ɿ�ִ���ļ�unrm
������ע��,���ϳ�����Իָ�lk�ļ�ϵͳ�е�С�ͺ������ļ�,����
�ڻָ��ļ�ʱ,���봦�ڳ����û���Ȩ���¡�
��������AT&T System V Release 4�����±�дͨ��,����Ȥ����
�����Ը���Լ���ʹ�õ�ϵͳ��Ӳ��������� ,�Գ�������Ӧ����
,ʵ���书��
--
________ _____ _____ ______________ _____
___ __ \___(_)________ ___(_) __ ___/___ /_ ___(_)
__ /_/ /__ / ___ __ \__ / _____ \ __ __ \__ /
_ ____/ _ / __ /_/ /_ / ____/ / _ / / /_ /
/_/ /_/ _ .___/ /_/ /____/ /_/ /_/ /_/
/_/
[m[1;36m�� ��Դ:���ϴ�С�ٺ���Ϣ����վ bbs.nju.edu.cn��[FROM: hsia.nju.edu.cn][m
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads