📄 media_io.c
字号:
#ifndef lint#ifdef SunB1static char sccsid[] = "@(#)media_io.c 1.1 92/07/30 SMI; SunOS MLS";#elsestatic char sccsid[] = "@(#)media_io.c 1.1 92/07/30 SMI";#endif /* SunB1 */#endif lint/* * Copyright (c) 1989 Sun Microsystems, Inc. *//* * Name: media_io.c * * Description: This file contains all the routines necessary for * manipulating the media device. This includes some hairy * manipulations for CD_ROM. */#include <stdio.h>#include "install.h"#include "menu.h"#include "media.h"#include <sys/stat.h>#include "mktp.h"#include <unistd.h>/* * External functions: */extern char * sprintf();/* * Local functions: */static int setup_cd_rom();static int mount_cd_rom();/* * Name: media_extract() * * Description: Extract the given media file. Uses 'soft_p' to * determine attributes about the media device, 'sys_p' to * determine if the soft arch is the same as the machine * arch, and 'mf_p' to get information about the media * file itself. * * Returns 1 if everything is okay, and 0 if there was a * non-fatal error. */intmedia_extract(soft_p, sys_p, mf_p) soft_info * soft_p; sys_info * sys_p; media_file * mf_p;{ char cmd[MAXPATHLEN * 3]; /* command buffer */ char blocks[MEDIUM_STR]; /* # blocks for the media */ Os_ident soft_os; /* software os */ #ifdef lint sys_p = sys_p;#endif lint /* * XXX put in media specific place! */ /* * skip to the correct file */ if (media_fsf(soft_p, mf_p->file_no, REDISPLAY) != 1) return(0); (void) fill_os_ident(&soft_os, soft_p->arch_str); menu_log("Extracting the %s '%s' media file.", os_name(soft_p->arch_str), mf_p->mf_name); bzero(cmd, sizeof(cmd)); /* * XXX probably ought to split the code out into separate * functions too */ switch (soft_p->media_type) { case MEDIAT_CD_ROM: /* * If this is a CD_ROM or any disk for that matter, * implement the file naming scheme * for the modules. */ (void) sprintf(soft_p->media_path, "%s%s", INSTALL_TAR_DIR, std_cd_path(mf_p->mf_loadpt, soft_p->arch_str, mf_p->mf_name)); /* * 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) { /* * The redirect from /dev/null is necessary to prevent * the child of rsh from hanging around. */ (void)sprintf(cmd, "rsh -n %s exec dd bs=%s if=%s 2>> %s | ", soft_p->media_host, blocks, soft_p->media_path, LOGFILE); /* * Compressed? */ if (mf_p->mf_type == TARZ) { (void)strcat(cmd, "uncompress -c | "); } /* * The software and system architectures are * the same so read it all in. */ (void) sprintf(&cmd[strlen(cmd)],#ifdef SunB1 "tar xpfBHZ - 2>> %s",#else "tar xpfB - 2>> %s",#endif /* SunB1 */ LOGFILE); } else { /* * The software and system architectures are * the same so read it all in. * * Compressed? */ if (mf_p->mf_type == TARZ) { (void) sprintf(&cmd[strlen(cmd)],#ifdef SunB1 "tar xpfbHZ %s %s 2>> %s",#else "dd if=%s ibs=20b | uncompress -c | tar xpfB - 2>> %s",#endif SunB1 soft_p->media_path, LOGFILE); } else { (void) sprintf(&cmd[strlen(cmd)],#ifdef SunB1 "tar xpfbHZ %s %s 2>> %s",#else "tar xpfb %s %s 2>> %s",#endif SunB1 soft_p->media_path, blocks, LOGFILE); } }#ifdef TEST_JIG menu_log("%s", cmd);#else /* * Do not use x_system() here since the media device * may be off-line and we don't want to be unfriendly. */ macex_on(); if (system(cmd) != 0) { macex_off(); menu_mesg("%s: cannot extract file.", soft_p->media_path); menu_log("%s: '%s' failed.", progname, cmd); return(0); } macex_off();#endif break; case MEDIAT_FLOPPY:/* XXX NOTE: remote floppy disallowed at selection time? ??? */ if (soft_p->media_loc == LOC_REMOTE) { menu_mesg("remote floppy install not allowed"); menu_log("remote floppy install not allowed"); return (0); } macex_on(); /* * the usage of extract_diskette is: * extract_diskette arch device volno bs name [server] * arch - machine architecture * device - full pathname of device * volno - which volume the file starts on * bs - blocksize is ignored * name - Suninstall catagory to be extracted * it handles its own logging to LOGFILE * */ (void) sprintf(cmd, "exec /usr/etc/install/extract_diskette %s %s %d 99 %s", soft_os.impl_arch, soft_p->media_path, mf_p->media_no, mf_p->mf_name); if (system(cmd) != 0) { macex_off(); menu_mesg("%s: cannot extract file.", soft_p->media_path); menu_log("%s: '%s' failed.", progname, "extract_diskette"); return(0); } macex_off(); break; default: menu_mesg("media_extract: unknown media type: %d.", soft_p->media_type); return (0); } return(1);} /* end media_extract() *//* * Name: media_fsf() * * Description: Skip forward 'count' files on the media. 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_fsf(soft_p, count, redisplay) soft_info * soft_p; int count; int redisplay;{ char cmd[MAXPATHLEN + BUFSIZ]; /* command buffer */ int ret_code; struct stat buf; switch (soft_p->media_type) { case MEDIAT_CD_ROM: /* No positioning 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)); menu_flash_on("Positioning media"); if (soft_p->media_loc == LOC_REMOTE) { /* * If this fails, try mt rew and then mt fsf and try * again by rewinding and then fsf'ing (in case the * remote OS does not understand the asf option. * * One problem here is that even if asf is not * understood, 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 */ (void) sprintf(cmd, "rsh -n %s exec mt -f %s asf %d 2> /tmp/rsh.out", soft_p->media_host, soft_p->media_path, count); 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)) { menu_flash_off(REDISPLAY); return(1); } else { /* ** The sucker failed, so try again down below. */ if ((ret_code = media_rewind(soft_p, NOREDISPLAY)) != 1) { menu_flash_off(REDISPLAY); return(ret_code); } (void) sprintf(cmd, "rsh -n %s exec mt -f %s fsf %d 2> /dev/null", soft_p->media_host, soft_p->media_path, count); } } else { /* * use asf for local tapes */ (void) sprintf(cmd, "exec mt -f %s asf %d 2> /dev/null", soft_p->media_path, count); } /* * 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 position media device %s to file number %d.", progname, soft_p->media_path, count); return(0); } menu_flash_off(redisplay); return(1);} /* end media_fsf() *//* * Name: media_read_file() * * Description: Read the current media file into 'name. Uses * 'soft_p' to determine attributes about the media device. * NOTE: this turns out the be used *ONLY* for the XDRTOC, and CD_ROM and * floppy depend on that. * * Return Value: 1 : if everything is okay, * -1 : if there was an error. * */intmedia_read_file(soft_p, name, redisplay) soft_info * soft_p; char * name; int redisplay;{ char cmd[MAXPATHLEN + BUFSIZ]; /* command buffer */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -