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

📄 xnsrestore.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
	Filing4_AttributeSequence attrseq;	Filing4_OpenResults openresult;	if ( name != 0 )		username = CH_StringToName(name,&hostobjname);	if ( name == 0 && pwd == 0 ) {		GetSimpleCredsAndVerifier(&username, 0, 					&credentials, &verifier);	} else {		MakeSimpleCredsAndVerifier(&username,pwd,					&credentials, &verifier);	}	logonresult= Filing4_Logon(connected, NULL, hostobjname,					credentials, verifier);	session = logonresult.session;	attrseq.length= 0;	attrseq.sequence= 0;	openresult= Filing4_Open(connected, NULL, attrseq,				 Filing4_nullHandle, nullControls,				 session);	copyhandle(rootHandle, openresult.file);	strcpy(cur_dir, ROOT_DIRECTORY);}logout(){	Filing4_Logoff(connected, NULL, session);	clear_Filing4_Session(&session);}deserializefile(local, remote)	char *local;	char *remote;{	FILE *fopen();	Filing4_Handle remotehandle; /* note: an array */	Filing4_Handle dirhandle; /* note: an array */	Filing4_Handle listhandle; /* note: an array */	Filing4_DeserializeResults results;	Filing4_AttributeSequence attrseq;	Filing4_Attribute attrvals[50];	Filing4_AttributeTypeSequence typeseq;	Filing4_AttributeType tsvals[10];	Filing4_ScopeSequence scopeseq;	Filing4_Scope scope;	Filing4_ScopeSequence lscopeseq;	Filing4_Scope lscope;	int i;	char *name, *rindex();	long date;	Boolean piping= FALSE;	name= '\0';	scopeseq.sequence= &scope; lscopeseq.sequence= &lscope;	attrseq.sequence= attrvals;	if ( strcmp(local, "-") == 0 ) {		fin= stdin;		piping= TRUE;	} else {		if ( (fin= fopen(local, "r")) == NULL ) {			perror("Cannot open local file ");			return(1);		}		if ( (name= rindex(local, '/')) == 0 ) {			name= local;		} else {			name++;		}	}	getdirhandle(remote, dirhandle);	scopeseq.length= 1;	scope.designator= Filing4_filter;	scope.Filing4_filter_case.designator= Filing4_matches;	scope.Filing4_filter_case.Filing4_matches_case.attribute.type= Filing4_name;	StringToAttr(cur_name,&scope.Filing4_filter_case.Filing4_matches_case.attribute);	typeseq.length = 2;  typeseq.sequence = tsvals;	typeseq.sequence[0] = Filing4_name;	typeseq.sequence[1] = Filing4_isDirectory;	is_a_directory= FALSE;	ProcEachSeq = isdirproc;	Filing4_List(connected, GetAttributeSequences, dirhandle,				     typeseq, scopeseq,				     BulkData1_immediateSink, session);	if ( files_found ) {		if ( is_a_directory ) {			if ( piping ) {				fprintf(stderr, "Must specify file name when pinput is from stdin\n");				return(1);			}			freefilehandle(dirhandle);			getfilehandle(remote, dirhandle);			strcat(cur_pathname, "/");			strcat(cur_pathname, name);		} else {			name= cur_name;		}	} else {		name= cur_name;	}	attrseq.length= 1;	attrvals[0].type= Filing4_name;	StringToAttr(name, &attrvals[0]);	if ( AddExtendedDeserializeAttributes(fin, &attrseq) != -1 ) {		fprintf(stderr, "Cannot determine extended attributes\n");		fclose(fin);		return(1);	}	if ( verbose ) {		fprintf(stdout, "   Restoring %s\n", cur_pathname);	}	results= Filing4_Deserialize(connected, storeproc, dirhandle,				 attrseq, nullControls,				 BulkData1_immediateSink, session);	if ( logfile ) {		if ( (lfile= fopen(logfile, "w")) != NULL ) {			scopeseq.length= 1;			scope.designator= Filing4_filter;			scope.Filing4_filter_case.designator= Filing4_matches;			scope.Filing4_filter_case.Filing4_matches_case.attribute.type= Filing4_name;			StringToAttr(name,&scope.Filing4_filter_case.Filing4_matches_case.attribute);				typeseq.length = 2;  typeseq.sequence = tsvals;			typeseq.sequence[0] = Filing4_pathname;			typeseq.sequence[1] = Filing4_isDirectory;				is_a_directory= FALSE;				ProcEachSeq = isdirproc;			Filing4_List(connected, GetAttributeSequences, dirhandle,					     typeseq, scopeseq,					     BulkData1_immediateSink, session);			/*			 * for a directory, we list all files...			 * for non-directory, just list it...			 */			if ( is_a_directory ) {				copyhandle(listhandle, results.file);				lscopeseq.length= 1;				lscope.designator= Filing4_depth;				lscope.Filing4_depth_case= Filing4_allDescendants;			} else {				copyhandle(listhandle, dirhandle);				lscopeseq.length= 1;				lscope.designator= Filing4_filter;				lscope.Filing4_filter_case.designator= Filing4_matches;				lscope.Filing4_filter_case.Filing4_matches_case.attribute.type= Filing4_name;				StringToAttr(name,&lscope.Filing4_filter_case.Filing4_matches_case.attribute);				}			typeseq.length = 4;			typeseq.sequence[0] = Filing4_pathname;			typeseq.sequence[1] = Filing4_type;			typeseq.sequence[2] = Filing4_createdOn;			typeseq.sequence[3] = Filing4_modifiedOn;			date= time(0);			fprintf(lfile, "\n\n\tRestore of %s\n\tPerformed on %s\n\n\n", cur_pathname, ctime(&date));			fprintf(lfile, "\tFiles restored as follows:\n\n");			fprintf(lfile, "    Create Date\t\t Modification Date\t    Type\t\t\t\t\t\tName\n\n");				ProcEachSeq = listproc;			Filing4_List(connected, GetAttributeSequences, listhandle,					     typeseq, lscopeseq,					     BulkData1_immediateSink, session);			fclose(lfile);		}	}	freefilehandle(results.file);	freefilehandle(dirhandle);}listproc(attr)	Filing4_AttributeSequence attr;{	int i;	char *thisname, *typetostring();	char createstr[30], modstr[30];	LongCardinal thistype, createdate, moddate;	Filing4_AttributeType t;	files_found= TRUE;	createdate= moddate= time(0);	for (i = 0; i < attr.length; i++) {		t = attr.sequence[i].type;		if (t == Filing4_pathname) {			thisname = AttrToString(&attr.sequence[i]);		} else if (t == Filing4_type) {			thistype = AttrToLongCardinal(&attr.sequence[i]);		} else if (t == Filing4_createdOn) {			createdate= AttrToLongCardinal(&attr.sequence[i]);			createdate= createdate - XNS_TIME_DIFFERENCE;			strcpy(createstr, ctime(&createdate));			createstr[24]= '\0';		} else if (t == Filing4_modifiedOn) {			moddate= AttrToLongCardinal(&attr.sequence[i]);			moddate= moddate - XNS_TIME_DIFFERENCE;			strcpy(modstr, ctime(&moddate));			modstr[24]= '\0';		}	}	fprintf(lfile, "%s\t%s\t%-16s\t%s\n", createstr+4, modstr+4, typetostring(thistype), thisname);	clear_String(&thisname);}isdirproc(attr)	Filing4_AttributeSequence attr;{	int i;	Filing4_AttributeType t;	char *thisname;	files_found= TRUE;	for (i = 0; i < attr.length; i++) {		t = attr.sequence[i].type;		if (t == Filing4_isDirectory) {			is_a_directory = AttrToBoolean(&attr.sequence[i]);		} else if (t == Filing4_name) {			thisname= AttrToString(&attr.sequence[i]);			strcpy(cur_name, thisname);			clear_String(&thisname);		}	}}#define MAXPACKS 20staticGetAttributeSequences(conn)	CourierConnection *conn;{	int count, i;	Unspecified buffer[MAXWORDS*MAXPACKS], *bp, *bufend;	Filing4_StreamOfAttributeSequence attrs;		files_found= FALSE;	bufend = buffer;	bp = buffer+((MAXWORDS-1)*MAXPACKS);    /* end of available space */	while ((count = BDTread(conn, (char*)bufend, 				MAXWORDS*sizeof(Unspecified))) > 0) {		bufend += count/sizeof(Unspecified);		if (bufend > bp) {			fprintf(stderr,"BDT read too big to fit\n");			BDTabort(conn);			/* should clear out stuff here if we knew how much */		}	}	bp = buffer;	while (bp < bufend) {		bp += internalize_Filing4_StreamOfAttributeSequence(&attrs,bp);		if (0 == (int) attrs.designator) {		   for (i=0; i < attrs.nextSegment_case.segment.length; i++) {			(*ProcEachSeq)(				attrs.nextSegment_case.segment.sequence[i]);		   }		   free(attrs.nextSegment_case.segment.sequence);		} else {		   for (i = 0; i < attrs.lastSegment_case.length; i++) {			(*ProcEachSeq)(				attrs.lastSegment_case.sequence[i]);		   }		   free(attrs.lastSegment_case.sequence);		   return;		}	}}storeproc(conn)	CourierConnection *conn;{	int count, ocount, ch;	char buffer[SPPMAXDATA];	char *bp;	errno = ocount = 0;	clearerr(fin);	while ( ((count= fread(buffer, sizeof(char), SPPMAXDATA, fin)) != 0)		 && (ocount= BDTwrite (conn, buffer, count)) > 0) {			;	}	if ( count < 0 ) {		BDTabort(conn);		perror("netout");		exit(1);	} else if ( ferror(fin) ) {		BDTabort(conn);		perror("fread");		exit(1);	} else {		BDTclosewrite(conn);	}}

⌨️ 快捷键说明

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