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

📄 media_io.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
	char		blocks[MEDIUM_STR];	/* #blocks for dumping */	menu_flash_on("Reading media file");	bzero(cmd, sizeof(cmd));	switch (soft_p->media_type) {	case MEDIAT_CD_ROM:		if (setup_cd_rom(soft_p) != 1)			return(-1);		/*		 * 	Don't bother reading the media file, just put it		 * 	where you want it to be : "XDRTOC".		 */		(void) sprintf(soft_p->media_path, "%s%s",			       INSTALL_TAR_DIR,			       std_cd_path("impl",soft_p->arch_str, "XDRTOC"));		/* Note that this is  k bytes */		(void) sprintf(blocks, "%dk", media_block_size(soft_p));		goto use_dd;		/* NOTREACHED */	case MEDIAT_TAPE:		/* Note that this is blocks, not k */		(void) sprintf(blocks, "%db", media_block_size(soft_p));use_dd:		if (soft_p->media_loc == LOC_REMOTE)			(void) sprintf(cmd, "rsh -n %s ", soft_p->media_host);		(void) sprintf(&cmd[strlen(cmd)],			"exec dd bs=%s if=%s > %s 2>> %s", blocks,			soft_p->media_path, name, LOGFILE);		/*		 *	Do not use x_system() here since we need to call		 *	menu_flash_off() to clean up the display.  Also the		 *	media device may be off-line and we don't want to		 *	be unfriendly.		 */		if (system(cmd) != 0) {			menu_flash_off(REDISPLAY);			menu_mesg("%s: cannot read file %s from %s",				  progname,				  name,				  soft_p->media_path);			return(0);		}		break;	case MEDIAT_FLOPPY:		if (soft_p->media_loc == LOC_REMOTE) {			menu_mesg("%s: remote floppy install not supported",			    progname);			return (0);		}		/*		 * the usage of verify_diskette is:		 * verify_diskette arch volno file/off device name [server]		 *		 * to just read a toc, volno = -1 and toc is on stdout		 * verify_diskette does its own logging		 */		(void) sprintf(cmd,		    "exec verify_diskette %s -1 0 %s dummy > %s ",			       (cv_arch_to_str(&soft_p->arch) != NULL) ?			       cv_arch_to_str(&soft_p->arch) : "-",			       soft_p->media_path, name);		if (system(cmd) != 0) {			menu_flash_off(REDISPLAY);			menu_mesg("%s: cannot read file %s from %s",				  progname, name, soft_p->media_path);			return(0);		}		break;	default:		menu_flash_off(REDISPLAY);		menu_mesg("%s: unknown media type %d.",			  progname, soft_p->media_type);		return(0);	}		menu_flash_off(redisplay);	return(1);} /* end media_read_file() *//* *	Name:		media_rewind() * *	Description:	Rewind the media file.  Uses 'soft_p' to determine *		attributes about the media device. * *		Returns 1 if everything is okay, and 0 if there was a *		non-fatal error. */intmedia_rewind(soft_p, redisplay)	soft_info *	soft_p;	int		redisplay;{	char		cmd[MAXPATHLEN + BUFSIZ]; /* command buffer */	switch (soft_p->media_type) {	case MEDIAT_CD_ROM:		/* No rewinding necessary for CD_ROMS */		return(1);	case MEDIAT_FLOPPY:		/* floppy handles its own re-positioning at extract time */		return(1);	case MEDIAT_TAPE:		break;	default:		menu_mesg("%s: unknown media type %d.", progname,		    soft_p->media_type);		return(0);	}	bzero(cmd, sizeof(cmd));	if (soft_p->media_loc == LOC_REMOTE) {		(void) sprintf(cmd,			"rsh -n %s exec mt -f %s rew 2> /dev/null",			       soft_p->media_host,			       soft_p->media_path);	} else {		/* don't rewind local devices (mt's "asf" will do it) */		return(1);	}	menu_flash_off(redisplay);	menu_flash_on("Rewinding media");	/*	 *	Do not use x_system() here since we need to call	 *	menu_flash_off() to clean up the display.  Also the	 *	media device may be off-line and we don't want to	 *	be unfriendly.	 */	if (system(cmd) != 0) {		menu_flash_off(REDISPLAY);		menu_mesg("%s: cannot rewind media device %s.",			  progname, soft_p->media_path);		return(0);	}	menu_flash_off(redisplay);	menu_flash_on("Forwarding media");	return(1);} /* end media_rewind() *//* *	Name:		(static int) setup_cd_rom() * *	Description:	Do all that is necessary to read a CD_ROM.  * *	Return Value:	1 : if everything is okay, *			0 : if there was anon-fatal error. * */static intsetup_cd_rom(soft_p)	soft_info *	soft_p;{	sys_info	sys;	char		cmd[MAXPATHLEN * 3];	char *		argv[2];	/* for exectution of get_arch_info */	FILE *		fp;		/* FILE * to the LOAD_ARCH */		/*	 *	get system info	 */	if (read_sys_info(SYS_INFO, &sys) != 1 &&	    read_sys_info(DEFAULT_SYS_INFO, &sys) != 1) {		menu_log("%s: Error in %s.", progname, DEFAULT_SYS_INFO);		menu_abort(1);	}	/*	 *	We must now mount the cdrom, if necessary	 */	if (mount_cd_rom(soft_p) != 1)		return(0);		/*	 *	Here we only want to invoke "get_arch_info" if we	 *	don't know what arch to read the toc from. This will	 *	create the file LOAD_ARCH, so we know what arch to	 *	load, or at least which XDRTOC to read.	 */	if (*(soft_p->arch_str) != '\0')		return(1);		/*	 *	So, we have a good mount, let's party and copy the	 *	AVAIL_ARCHES over to this system as well, if remote.	 */	if (soft_p->media_loc == LOC_REMOTE) {		(void) sprintf(cmd,		       "exec rcp %s:%s %s >> %s 2>&1", soft_p->media_host, 			       AVAIL_ARCHES, AVAIL_ARCHES, LOGFILE);				if (system(cmd) != 0) {			menu_mesg("%s: could not copy %s:", progname,				  AVAIL_ARCHES);			return(0);		}	}	/*	 *	If a system release has not been selected, grab the release	 *	name from the file RELEASE, and don't even bother invoking	 *	get_arch_info to get the architecture information.	 */		if (!sys_has_release(&sys)) {		if (read_sys_release(soft_p->arch_str) != 0)			return(-1);		else			return(1);	}	/*	 *	Since a release has been chosen by here, let's just go a	 *	head and get the next release from the architecture screen	 */	end_menu();	/*	 *	No archicture specified, so invoke get_arch_info.	 */	argv[0] = "get_arch_info";	argv[1] = (char *)NULL;		if (execute(argv) != 1) {		init_menu();		return(-1);	}		init_menu();		if ((fp = fopen(LOAD_ARCH, "r")) == (FILE *)NULL) {		menu_mesg("%s: failed to open %s", progname,			  LOAD_ARCH);		return(-1);	}		/*	 *	Ah, LOAD_ARCH was there, so lets read it.	 */	if (fgets(soft_p->arch_str, (int) sizeof(soft_p->arch_str), fp)	    == (char *)NULL) {		menu_mesg("%s: no architecture specified in  %s",			  progname, LOAD_ARCH);		(void)fclose(fp);		return(-1);	}		(void)fclose(fp);	(void)unlink(LOAD_ARCH);	/* 'tis no longer needed */	return(1);	/* NOTREACHED */} /* end setup_cd_rom() *//* *	Name:		(static int) mount_cd_rom() * *	Description:	Do all that is necessary to mount CD_ROMs.  * *	Return Value:	1 : if everything is okay, *			0 : if there was anon-fatal error. * */static intmount_cd_rom(soft_p)	soft_info *	soft_p;{	char		cmd[MAXPATHLEN];	/* commands */	struct stat	buf;	int		ret_code;	extern char	CD_EXPORT_DIR[];	(void) bzero(cmd, sizeof(cmd));	/*	 *	Mount the cd rom if necessary (AVAIL_ARCHES exists)	 */		switch(soft_p->media_loc) {	case LOC_REMOTE :		if (ck_remote_path(soft_p, CD_EXPORT_DIR))			return(1);		/*		 *	AVAIL_ARCHES isn't there, so mount the CD, remotely		 */		if (soft_p->media_loc == LOC_REMOTE)			(void) sprintf(cmd, "rsh -n %s ", soft_p->media_host);		break;	default :		if (access(CD_EXPORT_DIR, F_OK) == 0) {			/*			 *	Ahhh..., its alread mounted			 */			return(1);		}	}	/*	 *	Mount it using the hsfs file system type	 */	(void) sprintf(&cmd[strlen(cmd)],		       "exec mount -rt hsfs /dev/%s %s  > %s 2>&1",		       cv_media_to_str(&(soft_p->media_dev)),		       INSTALL_TAR_DIR, "/tmp/rsh.out");	/*	 *	One problem here is that even if the mount fails,	 *	the "rsh" might work and return a 0 exit	 *	status, and system() will succeed.  This is why we	 *	will not /dev/null the output, but put it in a file	 *	/tmp/rsh.out	 */	ret_code = system(cmd);	if (stat("/tmp/rsh.out", &buf) != 0) {		menu_log("stat failed on /tmp/rsh.out");		return(0);	}	unlink("/tmp/rsh.out");	 /* clean up */		if ((ret_code == 0) && (buf.st_size == (off_t)0)) {		return(1);	} else {		menu_flash_off(REDISPLAY);		menu_mesg("%s: cannot mount /dev/%s on %s",			  progname,			  cv_media_to_str(&(soft_p->media_dev)),			  INSTALL_TAR_DIR);		return(0);	}	/* NOTREACHED */} /* end mount_cd_rom() */

⌨️ 快捷键说明

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