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

📄 system_interface.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
{	int status;#ifdef DEBUG	fprintf(msgs," deleting '%s'",file_context_block->pathname);#endif DEBUG	if ( file_context_block->isdirectory ) {		if ( fork() == 0 ) {			/* use rm -rf for directories */			execl("/bin/rm", "rm", "-rf", file_context_block->pathname, 0);			ReturnAccessError(FILING_accessRightsInsufficient);			/* NOT REACHED */		}		wait(&status);		if ( status ) {			ReturnAccessError(FILING_accessRightsInsufficient);			/* NOT REACHED */		}	} else {					/* use unlink for non-directories */		if ( unlink(file_context_block->pathname) == -1 ) {			switch (errno) {				case EACCES :			/* user has no access */					ReturnAccessError(FILING_accessRightsInsufficient);					/* NOT REACHED */				case ENOENT :			/* no such file */				case ENOTDIR :			/* no such directory */					ReturnAccessError(FILING_fileNotFound);					/* NOT REACHED */				default :			/* all other errors */					ReturnAccessError(FILING_accessRightsIndeterminate);					/* NOT REACHED */			}		}	}}/* * routine: *	delete_partial_file * input: *	pointer to file handle * returns: *	-1 - success */delete_partial_file(file_context_block)file_handle *file_context_block;{	unlink(file_context_block->pathname);	return(-1);}/* * routine: *	access_file * input: *	pointer to file handle * returns: *	-1 - success */access_file(file_context_block)file_handle *file_context_block;{#ifdef DEBUG	fprintf(msgs, "access_file\n");#endif DEBUG	if ( access(file_context_block->pathname,R_OK | F_OK) == -1 ) {		switch (errno) {			case EACCES :				/* user has no access */				ReturnAccessError(FILING_fileChanged);				/* NOT REACHED */			case ENOENT :				/* no such file */			case ENOTDIR :				/* no such directory */				ReturnHandleError(FILING_invalid);				/* NOT REACHED */			default :				/* all other errors */				ReturnAccessError(FILING_accessRightsIndeterminate);				/* NOT REACHED */		}	}	return(-1);}/* * routine: *	set_create_time * input: *	pointer to file context block *		where *		if no createdOn value was specified on Store, createdon = 0 *		if createdOn value was specified on Store, createdOn != 0, *			value is in XNS time format * returns: *	none */set_create_time(file_context_block)file_handle *file_context_block;{	time_t time_buffer[2];	time_t time();	if ( file_context_block->createdon )		/* save createdOn if specified */		time_buffer[1]= file_context_block->createdon - XNS_TIME_DIFFERENCE;	else						/* else, set to current date/time */		time_buffer[1]= time(0);	time_buffer[0]= time(0);			/* set modifiedOn to current date/time */	utime(file_context_block->pathname,time_buffer);}/* * routine: *	make_attribute_sequence * inputs: *	pointer to file name *	pointer to sequence of attributes to fill in * returns: *	-1 - success */make_attribute_sequence(pathname, attrseq)char *pathname;FILING_AttributeSequence *attrseq;{	int i;	struct stat file_stat;	FILING_AttributeType t;	LongCardinal createdon, modifiedon;	LongCardinal type, get_type();	LongCardinal datasize;	Boolean isdirectory;	Boolean all_attributes= FALSE;	Cardinal unix_version= 1;	Boolean istemporary= FALSE;#ifdef FILETOOLCOMPATIBILITY	Cardinal fileid[6];	AUTHENTICATION_Clearinghouse_Name user;	AUTHENTICATION_Clearinghouse_Name CH_StringToName();	char *name, *pwname;	char *rindex();	struct passwd *getpwuid(), *pwd;#endif FILETOOLCOMPATIBILITY#ifdef EXTENSIONS	Boolean inroot= FALSE;	FILE *fd;#endif EXTENSIONS#ifdef DEBUG	fprintf(msgs, "make_attrseq '%s'\n", pathname);#endif DEBUG#ifndef FILINGSUBSET1	if ( (name= rindex(pathname, '/')) == 0 )		name= pathname;	else {#ifdef EXTENSIONS		if ( name == pathname ) inroot= TRUE;#endif EXTENSIONS		name++;	}#endif FILINGSUBSET1	if ( stat(pathname, &file_stat) == -1 ) {		ReturnAccessError(FILING_accessRightsInsufficient);		/* NOT REACHED */	}		createdon= file_stat.st_mtime + XNS_TIME_DIFFERENCE;	/* createdOn */	modifiedon= file_stat.st_atime + XNS_TIME_DIFFERENCE;	/* modifiedOn */	datasize= file_stat.st_size;				/* dataSize */								/* type and isDirectory */	if ( (file_stat.st_mode & S_IFDIR) != 0 ) {		isdirectory= TRUE;#ifdef EXTENSIONS		if ( inroot )				/* if root & directory, assume file drawer */			type= TYPE_VPDrawer;		else			type= FILING_tDirectory;#else EXTENSIONS		type= FILING_tDirectory;#endif EXTENSIONS	} else {		type= get_type(pathname);#ifdef EXTENSIONS		if ( (type > LAST_FILING_TYPE) && (type != TYPE_Interpress) &&					(type != TYPE_VPCanvas) ) {			if ( (fd= fopen(pathname, "r")) == NULL ) {				ReturnAccessError(FILING_fileChanged);				/* NOT REACHED */			}			isdirectory= GetDirectoryAttribute(fd);			fclose(fd);		} else {			isdirectory= FALSE;		}#else EXTENSIONS		isdirectory= FALSE;#endif EXTENSIONS	}#ifdef EXTENSIONS	if ( attrseq->length == -1 ) {		all_attributes= TRUE;		if ( (type > LAST_FILING_TYPE) && (type != TYPE_Interpress) &&					(type != TYPE_VPCanvas) )			make_required_attributes(attrseq);		else			make_supported_attributes(attrseq);	}#endif EXTENSIONS	for ( i= 0 ; i < attrseq->length ; i++ ) {		t= attrseq->sequence[i].type;#ifdef DEBUG		fprintf(msgs,"#%d  type= %d \n", i, t);#endif DEBUG		if ( t == FILING_pathname ) {			StringToAttr(pathname, &attrseq->sequence[i]);		} else if ( t == FILING_type ) {			LongCardinalToAttr(type, &attrseq->sequence[i]);		} else if ( t == FILING_dataSize ) {			LongCardinalToAttr(datasize, &attrseq->sequence[i]);		} else if ( t == FILING_isDirectory ) {			BooleanToAttr(isdirectory, &attrseq->sequence[i]);		} else if ( t == FILING_createdOn ) {			LongCardinalToAttr(createdon, &attrseq->sequence[i]);		} else if ( t == FILING_modifiedOn ) {			LongCardinalToAttr(modifiedon, &attrseq->sequence[i]);		} else if ( t == FILING_version ) {			CardinalToAttr(unix_version, &attrseq->sequence[i]);		} else if ( t == FILING_isTemporary ) {			BooleanToAttr(istemporary, &attrseq->sequence[i]);#ifdef FILETOOLCOMPATIBILITY		} else if ( t == FILING_name ) {			StringToAttr(name, &attrseq->sequence[i]);		} else if ( t == FILING_fileID ) {			fileid[0]= (file_stat.st_ino >> 16) & 0xffff;			fileid[1]= file_stat.st_ino & 0xffff;			fileid[2]= fileid[3]= fileid[4]= 0;			FileIDToAttr(fileid, &attrseq->sequence[i]);		} else if ( t == FILING_readOn ) {			LongCardinalToAttr(modifiedon, &attrseq->sequence[i]);		} else if ( t == FILING_createdBy ) {			if ( (pwd= getpwuid(file_stat.st_uid)) == 0 )				pwname= "Unkown";			else				pwname= pwd->pw_name;			user= CH_StringToName(pwname,NULL);			UserToAttr(user,&attrseq->sequence[i]);#endif FILETOOLCOMPATIBILITY		} else {			attrseq->sequence[i].value.length= 0;			attrseq->sequence[i].value.sequence= (Unspecified *)0;		}	}#ifdef EXTENSIONS	if ( all_attributes ) {		if ( (type > LAST_FILING_TYPE) && (type != TYPE_Interpress) &&					(type != TYPE_VPCanvas) ) {			if ( (fd= fopen(pathname, "r")) == NULL ) {				ReturnAccessError(FILING_fileChanged);				/* NOT REACHED */			}			if ( AddAllExtendedAttributes(fd, attrseq) != -1 ) {				fclose(fd);				ReturnAccessError(FILING_fileChanged);				/* NOT REACHED */			}			fclose(fd);		}	}#endif EXTENSIONS}intgetBDTch(conn,bpp)	CourierConnection *conn;	u_char **bpp;{	static u_char buffer[SPPMAXDATA];	static int count;	if (*bpp == NULL) {*bpp = buffer; count = 0;}	if (*bpp >= buffer+count) {		count=BDTread(conn,buffer,sizeof(buffer));		*bpp = buffer;	}	if (count <= 0) return(EOF);	else return(*((*bpp)++));		}storeproc(conn,handle)CourierConnection *conn;file_handle *handle;{	int count, ocount, ch, hashbytes;	char buffer[SPPMAXDATA];	int charset, charset16;	char *bp;	register FILE *fout;	register int fd;	fout= handle->file_desc;	fd= fileno(fout);#ifdef FILETOOLCOMPATIBILITY	if ( handle->type == FILING_tText ) {		charset = 0; charset16 = 0; bp = NULL;		while ((ch = getBDTch(conn,&bp)) != EOF) {			if (ch == '\377') {				ch = getBDTch(conn,&bp);				if (ch == '\377') charset16 = 1;				else charset = ch;				continue;			}			if (charset16) {				charset = ch;				ch = getBDTch(conn,&bp);			}			switch (charset) {			case 0:	/* normal character set -- minimal xlation */				if (ch == '\r') {				    	int nextch;				    	putc('\n',fout);				    	if ( (nextch = getBDTch(conn,&bp)) != '\n'){					    if (nextch == '\r')						putc('\n',fout);					    else if (nextch == ','+0200) 					        putc('_',fout);					    else if (nextch != EOF)				    		putc(nextch,fout);					    else						continue;					}					break;				}				else if (ch == ','+0200) ch = '_';				/* more mapping here */				putc(ch,fout);				break;			default:				break; /* ignore */			}		}		/* if (count < 0) perror("netin"); */	} else {#else FILETOOLCOMPATIBILITY	{#endif FILETOOLCOMPATIBILITY		errno = ocount = 0;		fflush(fout);		while ((count = BDTread(conn, buffer, sizeof(buffer))) > 0) {			if ((ocount = write(fd,buffer,count)) < 0) {				perror("write");				BDTabort(conn);				return(0);			}		}		if (count < 0) {			perror("netin");			return(0);		}	}	return(-1);}retrieveproc(conn, handle)CourierConnection *conn;file_handle *handle;{	int count, ocount;	u_char buffer[SPPMAXDATA];	u_char *bp;	errno = ocount = 0;	clearerr(handle->file_desc);	if ( handle->type == -1 )		handle->type= handle->truetype;#ifdef DEBUG	fprintf(msgs, "transferring data type= %d\n", handle->type);#endif DEBUG#ifdef FILETOOLCOMPATIBILITY	if (handle->type == FILING_tText) {		while ((count = fread(buffer, sizeof(char), SPPMAXDATA, handle->file_desc)) > 0) {			ocount = count;			for (bp = buffer; count > 0; count--, bp++) {				if (*bp == '\n') *bp = '\r';				else if (*bp == '_') *bp = ','+0200;				/* more translations here */			}			if ((ocount = BDTwrite(conn, buffer, ocount)) <= 0)				break;		}	} else {#else FILETOOLCOMPATIBILITY	{#endif FILETOOLCOMPATIBILITY		while ((count = fread(buffer, sizeof(char), SPPMAXDATA, handle->file_desc)) > 0		       && (ocount = BDTwrite(conn, buffer, count)) > 0) {		}	}	if (ocount < 0) {		BDTabort(conn);		perror("netout");		return(0);	}	else if (ferror(handle->file_desc)) {		BDTabort(conn);		perror("read");		return(0);	}	else		BDTclosewrite(conn);	return(-1);}#ifdef FILETOOLCOMPATIBILITYget_name_from_fileID(handle, fileid)file_handle *handle;Unspecified *fileid;{	char cmd[256];	char pathname[256];	char buffer[256];	int inode;	FILE *fd, *popen();	Boolean first= TRUE;	if ( *(handle->pathname) == '\0' ) {		ReturnAttributeTypeError(FILING_unreasonable, FILING_fileID);		/* NOT REACHED */	}#ifdef DEBUG	fprintf(msgs, "looking for fileid %x %x\n", fileid[0], fileid[1]);#endif DEBUG	strcpy(cmd, "/bin/ls -1ai ");	strcat(cmd, handle->pathname);	if ( (fd= popen(cmd, "r")) == NULL ) {		ReturnAccessError(FILING_accessRightsInsufficient);		/* NOT REACHED */	}	while ( fgets(buffer, sizeof(buffer), fd) != NULL ) {		buffer[strlen(buffer)-1]= '\0';		sscanf(buffer, "%d %s", &inode, pathname);#ifdef DEBUG		fprintf(msgs, "inode= %d '%s'\n",inode, pathname);#endif DEBUG		if ( (fileid[0] == ((inode>>16)&0xffff)) && 				(fileid[1] == (inode&0xffff)) ) {			if ( strcmp(handle->pathname, "/") != 0 )				strcat(handle->pathname, "/");			strcat(handle->pathname, pathname);			pclose(fd);			return(-1);		}	}	pclose(fd);	ReturnAccessError(FILING_fileNotFound);	/* NOT REACHED */}#endif FILETOOLCOMPATIBILITYcheck_pathname(pathname)char *pathname;{	char *ptr;	for ( ptr= pathname; *ptr != '\0' ;  ptr++ ) {		if ( isspace(*ptr) || iscntrl(*ptr) ) {			ReturnAttributeValueError(FILING_illegal, FILING_pathname);			/* NOT REACHED */		}	}	return(-1);}#ifdef EXTENSIONS/* * make_backup * */make_backup(handle)file_handle *handle;{	char buffer[2048];	char backup_name[MAX_FILE_NAME_LENGTH];	int fin, fout, count;	strcpy(backup_name, handle->pathname);	strcat(backup_name, ".REP");	if ( (fin= open(handle->pathname, O_RDONLY, 0)) < 0 ) {		return(0);		/* NOT REACHED */	}	if ( (fout= open(backup_name, O_WRONLY|O_CREAT, 0600)) < 0 ) {		return(0);		/* NOT REACHED */	}	while ( (count= read(fin, buffer, sizeof(buffer))) > 0 ) {		if ( write(fout, buffer, count) < 0 ) {			close(fin);			close(fout);			unlink(backup_name);			return(0);			/* NOT REACHED */		}	}	close(fin);	close(fout);	return(-1);}/* * recall_backup * */recall_backup(handle)file_handle *handle;{	char backup_name[MAX_FILE_NAME_LENGTH];	strcpy(backup_name, handle->pathname);	strcat(backup_name, ".REP");	/*	 * we better not see an error here, since we have already	 * munged the original file	 */	if ( rename(backup_name, handle->pathname) == -1 ) {		return(0);	}	return(-1);}unlink_backup(handle)file_handle *handle;{	char backup_name[MAX_FILE_NAME_LENGTH];	strcpy(backup_name, handle->pathname);	strcat(backup_name, ".REP");	if ( unlink(backup_name) == -1 ) {		return(0);	}	return(-1);}#endif EXTENSIONS

⌨️ 快捷键说明

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