diff options
author | jkh <jkh@FreeBSD.org> | 1996-12-11 09:35:06 +0000 |
---|---|---|
committer | jkh <jkh@FreeBSD.org> | 1996-12-11 09:35:06 +0000 |
commit | 3727883bddbc2a8ead72a97011cf4763fe5c7ede (patch) | |
tree | 3e96d1a8c70e76ad8e35ec46e4c61b3f0ab3295c /usr.sbin | |
parent | 90d182874d165b16fcb0758a86668941f1ddda01 (diff) | |
download | FreeBSD-src-3727883bddbc2a8ead72a97011cf4763fe5c7ede.zip FreeBSD-src-3727883bddbc2a8ead72a97011cf4763fe5c7ede.tar.gz |
Do a few things I've been threatening to do for a long time:
1. Don't use the MSDOSFS code for accessing FreeBSD distribution data.
Use Robert Nordier's stand-alone DOS I/O library for the purpose.
It this works as well as Robert says it does, it should drastically reduce
(or even eliminate) our "I can't install from my DOS partition!" calls.
2. As a result of the above, go to stdio file descriptors for all
media types.
3. Taking advantage of #2, start using libftpio for FTP transfers instead
of maintaining our own parallel version of the FTP transfer code.
Yay! I ripped something out for a change!
#1 Submitted-By: Robert Nordier <rnordier@iafrica.com>
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/sade/Makefile | 10 | ||||
-rw-r--r-- | usr.sbin/sade/config.c | 14 | ||||
-rw-r--r-- | usr.sbin/sade/devices.c | 35 | ||||
-rw-r--r-- | usr.sbin/sade/main.c | 20 | ||||
-rw-r--r-- | usr.sbin/sade/sade.h | 37 | ||||
-rw-r--r-- | usr.sbin/sysinstall/Makefile | 10 | ||||
-rw-r--r-- | usr.sbin/sysinstall/cdrom.c | 12 | ||||
-rw-r--r-- | usr.sbin/sysinstall/config.c | 14 | ||||
-rw-r--r-- | usr.sbin/sysinstall/devices.c | 35 | ||||
-rw-r--r-- | usr.sbin/sysinstall/dist.c | 36 | ||||
-rw-r--r-- | usr.sbin/sysinstall/dos.c | 69 | ||||
-rw-r--r-- | usr.sbin/sysinstall/floppy.c | 20 | ||||
-rw-r--r-- | usr.sbin/sysinstall/ftp.c | 604 | ||||
-rw-r--r-- | usr.sbin/sysinstall/index.c | 25 | ||||
-rw-r--r-- | usr.sbin/sysinstall/main.c | 20 | ||||
-rw-r--r-- | usr.sbin/sysinstall/media.c | 12 | ||||
-rw-r--r-- | usr.sbin/sysinstall/network.c | 4 | ||||
-rw-r--r-- | usr.sbin/sysinstall/nfs.c | 12 | ||||
-rw-r--r-- | usr.sbin/sysinstall/package.c | 15 | ||||
-rw-r--r-- | usr.sbin/sysinstall/sysinstall.h | 37 | ||||
-rw-r--r-- | usr.sbin/sysinstall/tape.c | 14 | ||||
-rw-r--r-- | usr.sbin/sysinstall/ufs.c | 12 |
22 files changed, 400 insertions, 667 deletions
diff --git a/usr.sbin/sade/Makefile b/usr.sbin/sade/Makefile index 10abd4c..d4b3e13 100644 --- a/usr.sbin/sade/Makefile +++ b/usr.sbin/sade/Makefile @@ -7,21 +7,21 @@ CLEANFILES+= keymap.tmp keymap.h .PATH: ${.CURDIR}/../disklabel ${.CURDIR}/../../usr.bin/cksum SRCS= anonFTP.c apache.c attr.c cdrom.c command.c config.c devices.c \ - disks.c dispatch.c dist.c dmenu.c doc.c dos.c floppy.c ftp.c \ - ftp_strat.c globals.c index.c install.c installUpgrade.c \ + disks.c dispatch.c dist.c dmenu.c doc.c dos.c dosio.c floppy.c ftp.c \ + globals.c index.c install.c installUpgrade.c \ keymap.c label.c lndir.c main.c makedevs.c media.c menus.c misc.c \ msg.c network.c nfs.c options.c package.c samba.c system.c \ tape.c tcpip.c termcap.c ufs.c user.c variable.c wizard.c \ uc_eisa.c uc_isa.c uc_kmem.c uc_list.c uc_main.c uc_pci.c \ - uc_scsi.c + uc_scsi.c keymap.h CFLAGS+= -Wall -I${.CURDIR}/../../gnu/lib/libdialog -I${.OBJDIR} -I/sys CFLAGS+= -DUC_PRIVATE -DKERN_NO_SYMBOLS -DSAVE_USERCONFIG #CFLAGS+= -DLOAD_CONFIG_FILE=\"install.cfg\" -DPADD= ${LIBDIALOG} ${LIBNCURSES} ${LIBMYTINFO} ${LIBUTIL} ${LIBDISK} -LDADD= -ldialog -lncurses -lmytinfo -lutil -ldisk +DPADD= ${LIBDIALOG} ${LIBNCURSES} ${LIBMYTINFO} ${LIBUTIL} ${LIBDISK} ${LIBFTPIO} +LDADD= -ldialog -lncurses -lmytinfo -lutil -ldisk -lftpio makedevs.c: Makefile rtermcap keymap.h rm -f makedevs.tmp diff --git a/usr.sbin/sade/config.c b/usr.sbin/sade/config.c index ab4f062..aa15e2a 100644 --- a/usr.sbin/sade/config.c +++ b/usr.sbin/sade/config.c @@ -4,7 +4,7 @@ * This is probably the last program in the `sysinstall' line - the next * generation being essentially a complete rewrite. * - * $Id: config.c,v 1.61 1996/12/02 05:01:00 jkh Exp $ + * $Id: config.c,v 1.62 1996/12/09 08:22:11 jkh Exp $ * * Copyright (c) 1995 * Jordan Hubbard. All rights reserved. @@ -467,7 +467,7 @@ configPackages(dialogMenuItem *self) static PkgNode top, plist; static Boolean index_initted = FALSE; PkgNodePtr tmp; - int fd; + FILE *fp; if (!mediaVerify()) return DITEM_FAILURE; @@ -477,8 +477,8 @@ configPackages(dialogMenuItem *self) if (!index_initted) { msgNotify("Attempting to fetch packages/INDEX file from selected media."); - fd = mediaDevice->get(mediaDevice, "packages/INDEX", TRUE); - if (fd < 0) { + fp = mediaDevice->get(mediaDevice, "packages/INDEX", TRUE); + if (!fp) { dialog_clear_norefresh(); msgConfirm("Unable to get packages/INDEX file from selected media.\n" "This may be because the packages collection is not available at\n" @@ -491,13 +491,13 @@ configPackages(dialogMenuItem *self) } msgNotify("Got INDEX successfully, now building packages menu.."); index_init(&top, &plist); - if (index_read(fd, &top)) { + if (index_read(fp, &top)) { msgConfirm("I/O or format error on packages/INDEX file.\n" "Please verify media (or path to media) and try again."); - mediaDevice->close(mediaDevice, fd); + fclose(fp); return DITEM_FAILURE | DITEM_RESTORE; } - mediaDevice->close(mediaDevice, fd); + fclose(fp); index_sort(&top); index_initted = TRUE; } diff --git a/usr.sbin/sade/devices.c b/usr.sbin/sade/devices.c index 8965f6c..35ae6e8 100644 --- a/usr.sbin/sade/devices.c +++ b/usr.sbin/sade/devices.c @@ -4,7 +4,7 @@ * This is probably the last program in the `sysinstall' line - the next * generation being essentially a complete rewrite. * - * $Id: devices.c,v 1.52 1996/12/08 12:27:53 jkh Exp $ + * $Id: devices.c,v 1.53 1996/12/09 08:22:11 jkh Exp $ * * Copyright (c) 1995 * Jordan Hubbard. All rights reserved. @@ -113,18 +113,10 @@ dummyInit(Device *dev) return TRUE; } -int +FILE * dummyGet(Device *dev, char *dist, Boolean probe) { - return -1; -} - -Boolean -dummyClose(Device *dev, int fd) -{ - if (!close(fd)) - return TRUE; - return FALSE; + return NULL; } void @@ -152,8 +144,8 @@ deviceTry(char *name, char *try) /* Register a new device in the devices array */ Device * deviceRegister(char *name, char *desc, char *devname, DeviceType type, Boolean enabled, - Boolean (*init)(Device *), int (*get)(Device *, char *, Boolean), - Boolean (*close)(Device *, int), void (*shutdown)(Device *), void *private) + Boolean (*init)(Device *), FILE * (*get)(Device *, char *, Boolean), + void (*shutdown)(Device *), void *private) { Device *newdev = NULL; @@ -167,7 +159,6 @@ deviceRegister(char *name, char *desc, char *devname, DeviceType type, Boolean e newdev->enabled = enabled; newdev->init = init ? init : dummyInit; newdev->get = get ? get : dummyGet; - newdev->close = close ? close : dummyClose; newdev->shutdown = shutdown ? shutdown : dummyShutdown; newdev->private = private; Devices[numDevs] = newdev; @@ -199,7 +190,7 @@ deviceGetAll(void) if (!d) msgFatal("Unable to open disk %s", names[i]); - (void)deviceRegister(names[i], names[i], d->name, DEVICE_TYPE_DISK, FALSE, NULL, NULL, NULL, NULL, d); + (void)deviceRegister(names[i], names[i], d->name, DEVICE_TYPE_DISK, FALSE, NULL, NULL, NULL, d); msgDebug("Found a disk device named %s\n", names[i]); /* Look for existing DOS partitions to register */ @@ -211,7 +202,7 @@ deviceGetAll(void) /* Got one! */ sprintf(devname, "/dev/%s", c1->name); dev = deviceRegister(c1->name, c1->name, strdup(devname), DEVICE_TYPE_DOS, TRUE, - mediaInitDOS, mediaGetDOS, NULL, mediaShutdownDOS, NULL); + mediaInitDOS, mediaGetDOS, mediaShutdownDOS, NULL); dev->private = c1; msgDebug("Found a DOS partition %s on drive %s\n", c1->name, d->name); } @@ -259,7 +250,7 @@ deviceGetAll(void) descr = "<unknown network interface type>"; deviceRegister(ifptr->ifr_name, descr, strdup(ifptr->ifr_name), DEVICE_TYPE_NETWORK, TRUE, - mediaInitNetwork, NULL, NULL, mediaShutdownNetwork, NULL); + mediaInitNetwork, NULL, mediaShutdownNetwork, NULL); msgDebug("Found a network device named %s\n", ifptr->ifr_name); close(s); if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { @@ -284,7 +275,7 @@ skipif: if (fd >= 0 || errno == EBUSY) { /* EBUSY if already mounted */ if (fd >= 0) close(fd); (void)deviceRegister(device_names[i].name, device_names[i].description, strdup(try), - DEVICE_TYPE_CDROM, TRUE, mediaInitCDROM, mediaGetCDROM, NULL, + DEVICE_TYPE_CDROM, TRUE, mediaInitCDROM, mediaGetCDROM, mediaShutdownCDROM, NULL); msgDebug("Found a CDROM device named %s\n", device_names[i].name); } @@ -295,7 +286,7 @@ skipif: if (fd >= 0) { if (fd) close(fd); deviceRegister(device_names[i].name, device_names[i].description, strdup(try), - DEVICE_TYPE_TAPE, TRUE, mediaInitTape, mediaGetTape, NULL, mediaShutdownTape, NULL); + DEVICE_TYPE_TAPE, TRUE, mediaInitTape, mediaGetTape, mediaShutdownTape, NULL); msgDebug("Found a TAPE device named %s\n", device_names[i].name); } break; @@ -305,7 +296,7 @@ skipif: if (fd >= 0) { if (fd) close(fd); deviceRegister(device_names[i].name, device_names[i].description, strdup(try), - DEVICE_TYPE_FLOPPY, TRUE, mediaInitFloppy, mediaGetFloppy, NULL, + DEVICE_TYPE_FLOPPY, TRUE, mediaInitFloppy, mediaGetFloppy, mediaShutdownFloppy, NULL); msgDebug("Found a floppy device named %s\n", device_names[i].name); } @@ -325,11 +316,11 @@ skipif: newdesc = safe_malloc(strlen(cp) + 40); sprintf(newdesc, cp, "SLIP interface"); deviceRegister("sl0", newdesc, strdup(try), DEVICE_TYPE_NETWORK, TRUE, mediaInitNetwork, - NULL, NULL, mediaShutdownNetwork, NULL); + NULL, mediaShutdownNetwork, NULL); newdesc = safe_malloc(strlen(cp) + 50); sprintf(newdesc, cp, "PPP interface"); deviceRegister("ppp0", newdesc, strdup(try), DEVICE_TYPE_NETWORK, TRUE, mediaInitNetwork, - NULL, NULL, mediaShutdownNetwork, NULL); + NULL, mediaShutdownNetwork, NULL); msgDebug("Found a serial network device named %s on %s\n", device_names[i].name, try); } break; diff --git a/usr.sbin/sade/main.c b/usr.sbin/sade/main.c index 2328c70..d61d0c1 100644 --- a/usr.sbin/sade/main.c +++ b/usr.sbin/sade/main.c @@ -4,7 +4,7 @@ * This is probably the last attempt in the `sysinstall' line, the next * generation being slated for what's essentially a complete rewrite. * - * $Id: main.c,v 1.27 1996/09/15 23:55:23 jkh Exp $ + * $Id: main.c,v 1.28 1996/09/26 21:03:35 pst Exp $ * * Copyright (c) 1995 * Jordan Hubbard. All rights reserved. @@ -112,21 +112,21 @@ main(int argc, char **argv) } { - int fd; + FILE *fp; Attribs attrs[512]; bzero(attrs, sizeof(attrs)); - fd = open("install.cfg", O_RDONLY); - if (fd >= 0) { + fp = fopen("install.cfg", "r"); + if (fp) { msgNotify("Loading pre-configuration file"); - if (DITEM_STATUS(attr_parse(attrs, fd)) == DITEM_SUCCESS) { + if (DITEM_STATUS(attr_parse(attrs, fp)) == DITEM_SUCCESS) { int i; for (i = 0; *attrs[i].name; i++) variable_set2(attrs[i].name, attrs[i].value); } - close(fd); + fclose(fp); } #if defined(LOAD_CONFIG_FILE) @@ -143,17 +143,17 @@ main(int argc, char **argv) mediaDevice->init(mediaDevice)) { int fd; - fd = mediaDevice->get(mediaDevice, LOAD_CONFIG_FILE, TRUE); - if (fd > 0) { + fp = mediaDevice->get(mediaDevice, LOAD_CONFIG_FILE, TRUE); + if (fp) { msgNotify("Loading %s pre-configuration file", LOAD_CONFIG_FILE); - if (DITEM_STATUS(attr_parse(attrs, fd)) == DITEM_SUCCESS) { + if (DITEM_STATUS(attr_parse(attrs, fp)) == DITEM_SUCCESS) { int i; for (i = 0; *attrs[i].name; i++) variable_set2(attrs[i].name, attrs[i].value); } - mediaDevice->close(mediaDevice, fd); + fclose(fp); } mediaDevice->shutdown(mediaDevice); } diff --git a/usr.sbin/sade/sade.h b/usr.sbin/sade/sade.h index dab2d63..3ebcecf 100644 --- a/usr.sbin/sade/sade.h +++ b/usr.sbin/sade/sade.h @@ -4,7 +4,7 @@ * This is probably the last attempt in the `sysinstall' line, the next * generation being slated to essentially a complete rewrite. * - * $Id: sysinstall.h,v 1.89 1996/12/09 06:37:45 jkh Exp $ + * $Id: sysinstall.h,v 1.90 1996/12/09 08:22:17 jkh Exp $ * * Copyright (c) 1995 * Jordan Hubbard. All rights reserved. @@ -214,8 +214,8 @@ typedef struct _device { DeviceType type; Boolean enabled; Boolean (*init)(struct _device *dev); - int (*get)(struct _device *dev, char *file, Boolean probe); - Boolean (*close)(struct _device *dev, int fd); + FILE * (*get)(struct _device *dev, char *file, Boolean probe); + Boolean (*close)(struct _device *dev, FILE *fp); void (*shutdown)(struct _device *dev); void *private; unsigned int flags; @@ -358,11 +358,11 @@ extern int configAnonFTP(dialogMenuItem *self); /* attrs.c */ extern char *attr_match(Attribs *attr, char *name); extern int attr_parse_file(Attribs *attr, char *file); -extern int attr_parse(Attribs *attr, int fd); +extern int attr_parse(Attribs *attr, FILE *fp); /* cdrom.c */ extern Boolean mediaInitCDROM(Device *dev); -extern int mediaGetCDROM(Device *dev, char *file, Boolean probe); +extern FILE *mediaGetCDROM(Device *dev, char *file, Boolean probe); extern void mediaShutdownCDROM(Device *dev); /* command.c */ @@ -401,12 +401,12 @@ extern Device **deviceFind(char *name, DeviceType type); extern int deviceCount(Device **devs); extern Device *new_device(char *name); extern Device *deviceRegister(char *name, char *desc, char *devname, DeviceType type, Boolean enabled, - Boolean (*init)(Device *mediadev), int (*get)(Device *dev, char *file, Boolean probe), - Boolean (*close)(Device *mediadev, int fd), void (*shutDown)(Device *mediadev), + Boolean (*init)(Device *mediadev), + FILE * (*get)(Device *dev, char *file, Boolean probe), + void (*shutDown)(Device *mediadev), void *private); extern Boolean dummyInit(Device *dev); -extern int dummyGet(Device *dev, char *dist, Boolean probe); -extern Boolean dummyClose(Device *dev, int fd); +extern FILE *dummyGet(Device *dev, char *dist, Boolean probe); extern void dummyShutdown(Device *dev); /* disks.c */ @@ -455,20 +455,21 @@ extern int docBrowser(dialogMenuItem *self); extern int docShowDocument(dialogMenuItem *self); /* dos.c */ +extern Boolean mediaCloseDOS(Device *dev, FILE *fp); extern Boolean mediaInitDOS(Device *dev); -extern int mediaGetDOS(Device *dev, char *file, Boolean probe); +extern FILE *mediaGetDOS(Device *dev, char *file, Boolean probe); extern void mediaShutdownDOS(Device *dev); /* floppy.c */ extern int getRootFloppy(void); extern Boolean mediaInitFloppy(Device *dev); -extern int mediaGetFloppy(Device *dev, char *file, Boolean probe); +extern FILE *mediaGetFloppy(Device *dev, char *file, Boolean probe); extern void mediaShutdownFloppy(Device *dev); /* ftp_strat.c */ -extern Boolean mediaCloseFTP(Device *dev, int fd); +extern Boolean mediaCloseFTP(Device *dev, FILE *fp); extern Boolean mediaInitFTP(Device *dev); -extern int mediaGetFTP(Device *dev, char *file, Boolean probe); +extern FILE *mediaGetFTP(Device *dev, char *file, Boolean probe); extern void mediaShutdownFTP(Device *dev); /* globals.c */ @@ -476,7 +477,7 @@ extern void globalsInit(void); /* index.c */ int index_get(char *fname, PkgNodePtr papa); -int index_read(int fd, PkgNodePtr papa); +int index_read(FILE *fp, PkgNodePtr papa); int index_menu(PkgNodePtr top, PkgNodePtr plist, int *pos, int *scroll); void index_init(PkgNodePtr top, PkgNodePtr plist); void index_node_free(PkgNodePtr top, PkgNodePtr plist); @@ -536,7 +537,7 @@ extern int mediaSetNFS(dialogMenuItem *self); extern int mediaSetFTPUserPass(dialogMenuItem *self); extern int mediaSetCPIOVerbosity(dialogMenuItem *self); extern int mediaGetType(dialogMenuItem *self); -extern Boolean mediaExtractDist(char *dir, int fd); +extern Boolean mediaExtractDist(char *dir, FILE *fp); extern Boolean mediaExtractDistBegin(char *dir, int *fd, int *zpid, int *cpic); extern Boolean mediaExtractDistEnd(int zpid, int cpid); extern Boolean mediaVerify(void); @@ -590,7 +591,7 @@ extern void mediaShutdownNetwork(Device *dev); /* nfs.c */ extern Boolean mediaInitNFS(Device *dev); -extern int mediaGetNFS(Device *dev, char *file, Boolean probe); +extern FILE *mediaGetNFS(Device *dev, char *file, Boolean probe); extern void mediaShutdownNFS(Device *dev); /* options.c */ @@ -618,7 +619,7 @@ extern int vsystem(char *fmt, ...); /* tape.c */ extern char *mediaTapeBlocksize(void); extern Boolean mediaInitTape(Device *dev); -extern int mediaGetTape(Device *dev, char *file, Boolean probe); +extern FILE *mediaGetTape(Device *dev, char *file, Boolean probe); extern void mediaShutdownTape(Device *dev); /* tcpip.c */ @@ -632,7 +633,7 @@ extern int set_termcap(void); /* ufs.c */ extern void mediaShutdownUFS(Device *dev); extern Boolean mediaInitUFS(Device *dev); -extern int mediaGetUFS(Device *dev, char *file, Boolean probe); +extern FILE *mediaGetUFS(Device *dev, char *file, Boolean probe); /* user.c */ extern int userAddGroup(dialogMenuItem *self); diff --git a/usr.sbin/sysinstall/Makefile b/usr.sbin/sysinstall/Makefile index 10abd4c..d4b3e13 100644 --- a/usr.sbin/sysinstall/Makefile +++ b/usr.sbin/sysinstall/Makefile @@ -7,21 +7,21 @@ CLEANFILES+= keymap.tmp keymap.h .PATH: ${.CURDIR}/../disklabel ${.CURDIR}/../../usr.bin/cksum SRCS= anonFTP.c apache.c attr.c cdrom.c command.c config.c devices.c \ - disks.c dispatch.c dist.c dmenu.c doc.c dos.c floppy.c ftp.c \ - ftp_strat.c globals.c index.c install.c installUpgrade.c \ + disks.c dispatch.c dist.c dmenu.c doc.c dos.c dosio.c floppy.c ftp.c \ + globals.c index.c install.c installUpgrade.c \ keymap.c label.c lndir.c main.c makedevs.c media.c menus.c misc.c \ msg.c network.c nfs.c options.c package.c samba.c system.c \ tape.c tcpip.c termcap.c ufs.c user.c variable.c wizard.c \ uc_eisa.c uc_isa.c uc_kmem.c uc_list.c uc_main.c uc_pci.c \ - uc_scsi.c + uc_scsi.c keymap.h CFLAGS+= -Wall -I${.CURDIR}/../../gnu/lib/libdialog -I${.OBJDIR} -I/sys CFLAGS+= -DUC_PRIVATE -DKERN_NO_SYMBOLS -DSAVE_USERCONFIG #CFLAGS+= -DLOAD_CONFIG_FILE=\"install.cfg\" -DPADD= ${LIBDIALOG} ${LIBNCURSES} ${LIBMYTINFO} ${LIBUTIL} ${LIBDISK} -LDADD= -ldialog -lncurses -lmytinfo -lutil -ldisk +DPADD= ${LIBDIALOG} ${LIBNCURSES} ${LIBMYTINFO} ${LIBUTIL} ${LIBDISK} ${LIBFTPIO} +LDADD= -ldialog -lncurses -lmytinfo -lutil -ldisk -lftpio makedevs.c: Makefile rtermcap keymap.h rm -f makedevs.tmp diff --git a/usr.sbin/sysinstall/cdrom.c b/usr.sbin/sysinstall/cdrom.c index 517fa90..beb22db 100644 --- a/usr.sbin/sysinstall/cdrom.c +++ b/usr.sbin/sysinstall/cdrom.c @@ -4,7 +4,7 @@ * This is probably the last attempt in the `sysinstall' line, the next * generation being slated to essentially a complete rewrite. * - * $Id: cdrom.c,v 1.25 1996/10/10 09:22:24 jkh Exp $ + * $Id: cdrom.c,v 1.26 1996/10/14 21:32:22 jkh Exp $ * * Copyright (c) 1995 * Jordan Hubbard. All rights reserved. @@ -120,7 +120,7 @@ mediaInitCDROM(Device *dev) return TRUE; } -int +FILE * mediaGetCDROM(Device *dev, char *file, Boolean probe) { char buf[PATH_MAX]; @@ -129,15 +129,15 @@ mediaGetCDROM(Device *dev, char *file, Boolean probe) msgDebug("Request for %s from CDROM\n", file); snprintf(buf, PATH_MAX, "/cdrom/%s", file); if (file_readable(buf)) - return open(buf, O_RDONLY); + return fopen(buf, "r"); snprintf(buf, PATH_MAX, "/cdrom/dists/%s", file); if (file_readable(buf)) - return open(buf, O_RDONLY); + return fopen(buf, "r"); snprintf(buf, PATH_MAX, "/cdrom/%s/%s", variable_get(VAR_RELNAME), file); if (file_readable(buf)) - return open(buf, O_RDONLY); + return fopen(buf, "r"); snprintf(buf, PATH_MAX, "/cdrom/%s/dists/%s", variable_get(VAR_RELNAME), file); - return open(buf, O_RDONLY); + return fopen(buf, "r"); } void diff --git a/usr.sbin/sysinstall/config.c b/usr.sbin/sysinstall/config.c index ab4f062..aa15e2a 100644 --- a/usr.sbin/sysinstall/config.c +++ b/usr.sbin/sysinstall/config.c @@ -4,7 +4,7 @@ * This is probably the last program in the `sysinstall' line - the next * generation being essentially a complete rewrite. * - * $Id: config.c,v 1.61 1996/12/02 05:01:00 jkh Exp $ + * $Id: config.c,v 1.62 1996/12/09 08:22:11 jkh Exp $ * * Copyright (c) 1995 * Jordan Hubbard. All rights reserved. @@ -467,7 +467,7 @@ configPackages(dialogMenuItem *self) static PkgNode top, plist; static Boolean index_initted = FALSE; PkgNodePtr tmp; - int fd; + FILE *fp; if (!mediaVerify()) return DITEM_FAILURE; @@ -477,8 +477,8 @@ configPackages(dialogMenuItem *self) if (!index_initted) { msgNotify("Attempting to fetch packages/INDEX file from selected media."); - fd = mediaDevice->get(mediaDevice, "packages/INDEX", TRUE); - if (fd < 0) { + fp = mediaDevice->get(mediaDevice, "packages/INDEX", TRUE); + if (!fp) { dialog_clear_norefresh(); msgConfirm("Unable to get packages/INDEX file from selected media.\n" "This may be because the packages collection is not available at\n" @@ -491,13 +491,13 @@ configPackages(dialogMenuItem *self) } msgNotify("Got INDEX successfully, now building packages menu.."); index_init(&top, &plist); - if (index_read(fd, &top)) { + if (index_read(fp, &top)) { msgConfirm("I/O or format error on packages/INDEX file.\n" "Please verify media (or path to media) and try again."); - mediaDevice->close(mediaDevice, fd); + fclose(fp); return DITEM_FAILURE | DITEM_RESTORE; } - mediaDevice->close(mediaDevice, fd); + fclose(fp); index_sort(&top); index_initted = TRUE; } diff --git a/usr.sbin/sysinstall/devices.c b/usr.sbin/sysinstall/devices.c index 8965f6c..35ae6e8 100644 --- a/usr.sbin/sysinstall/devices.c +++ b/usr.sbin/sysinstall/devices.c @@ -4,7 +4,7 @@ * This is probably the last program in the `sysinstall' line - the next * generation being essentially a complete rewrite. * - * $Id: devices.c,v 1.52 1996/12/08 12:27:53 jkh Exp $ + * $Id: devices.c,v 1.53 1996/12/09 08:22:11 jkh Exp $ * * Copyright (c) 1995 * Jordan Hubbard. All rights reserved. @@ -113,18 +113,10 @@ dummyInit(Device *dev) return TRUE; } -int +FILE * dummyGet(Device *dev, char *dist, Boolean probe) { - return -1; -} - -Boolean -dummyClose(Device *dev, int fd) -{ - if (!close(fd)) - return TRUE; - return FALSE; + return NULL; } void @@ -152,8 +144,8 @@ deviceTry(char *name, char *try) /* Register a new device in the devices array */ Device * deviceRegister(char *name, char *desc, char *devname, DeviceType type, Boolean enabled, - Boolean (*init)(Device *), int (*get)(Device *, char *, Boolean), - Boolean (*close)(Device *, int), void (*shutdown)(Device *), void *private) + Boolean (*init)(Device *), FILE * (*get)(Device *, char *, Boolean), + void (*shutdown)(Device *), void *private) { Device *newdev = NULL; @@ -167,7 +159,6 @@ deviceRegister(char *name, char *desc, char *devname, DeviceType type, Boolean e newdev->enabled = enabled; newdev->init = init ? init : dummyInit; newdev->get = get ? get : dummyGet; - newdev->close = close ? close : dummyClose; newdev->shutdown = shutdown ? shutdown : dummyShutdown; newdev->private = private; Devices[numDevs] = newdev; @@ -199,7 +190,7 @@ deviceGetAll(void) if (!d) msgFatal("Unable to open disk %s", names[i]); - (void)deviceRegister(names[i], names[i], d->name, DEVICE_TYPE_DISK, FALSE, NULL, NULL, NULL, NULL, d); + (void)deviceRegister(names[i], names[i], d->name, DEVICE_TYPE_DISK, FALSE, NULL, NULL, NULL, d); msgDebug("Found a disk device named %s\n", names[i]); /* Look for existing DOS partitions to register */ @@ -211,7 +202,7 @@ deviceGetAll(void) /* Got one! */ sprintf(devname, "/dev/%s", c1->name); dev = deviceRegister(c1->name, c1->name, strdup(devname), DEVICE_TYPE_DOS, TRUE, - mediaInitDOS, mediaGetDOS, NULL, mediaShutdownDOS, NULL); + mediaInitDOS, mediaGetDOS, mediaShutdownDOS, NULL); dev->private = c1; msgDebug("Found a DOS partition %s on drive %s\n", c1->name, d->name); } @@ -259,7 +250,7 @@ deviceGetAll(void) descr = "<unknown network interface type>"; deviceRegister(ifptr->ifr_name, descr, strdup(ifptr->ifr_name), DEVICE_TYPE_NETWORK, TRUE, - mediaInitNetwork, NULL, NULL, mediaShutdownNetwork, NULL); + mediaInitNetwork, NULL, mediaShutdownNetwork, NULL); msgDebug("Found a network device named %s\n", ifptr->ifr_name); close(s); if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { @@ -284,7 +275,7 @@ skipif: if (fd >= 0 || errno == EBUSY) { /* EBUSY if already mounted */ if (fd >= 0) close(fd); (void)deviceRegister(device_names[i].name, device_names[i].description, strdup(try), - DEVICE_TYPE_CDROM, TRUE, mediaInitCDROM, mediaGetCDROM, NULL, + DEVICE_TYPE_CDROM, TRUE, mediaInitCDROM, mediaGetCDROM, mediaShutdownCDROM, NULL); msgDebug("Found a CDROM device named %s\n", device_names[i].name); } @@ -295,7 +286,7 @@ skipif: if (fd >= 0) { if (fd) close(fd); deviceRegister(device_names[i].name, device_names[i].description, strdup(try), - DEVICE_TYPE_TAPE, TRUE, mediaInitTape, mediaGetTape, NULL, mediaShutdownTape, NULL); + DEVICE_TYPE_TAPE, TRUE, mediaInitTape, mediaGetTape, mediaShutdownTape, NULL); msgDebug("Found a TAPE device named %s\n", device_names[i].name); } break; @@ -305,7 +296,7 @@ skipif: if (fd >= 0) { if (fd) close(fd); deviceRegister(device_names[i].name, device_names[i].description, strdup(try), - DEVICE_TYPE_FLOPPY, TRUE, mediaInitFloppy, mediaGetFloppy, NULL, + DEVICE_TYPE_FLOPPY, TRUE, mediaInitFloppy, mediaGetFloppy, mediaShutdownFloppy, NULL); msgDebug("Found a floppy device named %s\n", device_names[i].name); } @@ -325,11 +316,11 @@ skipif: newdesc = safe_malloc(strlen(cp) + 40); sprintf(newdesc, cp, "SLIP interface"); deviceRegister("sl0", newdesc, strdup(try), DEVICE_TYPE_NETWORK, TRUE, mediaInitNetwork, - NULL, NULL, mediaShutdownNetwork, NULL); + NULL, mediaShutdownNetwork, NULL); newdesc = safe_malloc(strlen(cp) + 50); sprintf(newdesc, cp, "PPP interface"); deviceRegister("ppp0", newdesc, strdup(try), DEVICE_TYPE_NETWORK, TRUE, mediaInitNetwork, - NULL, NULL, mediaShutdownNetwork, NULL); + NULL, mediaShutdownNetwork, NULL); msgDebug("Found a serial network device named %s on %s\n", device_names[i].name, try); } break; diff --git a/usr.sbin/sysinstall/dist.c b/usr.sbin/sysinstall/dist.c index 7ecd8dd..40a0c860 100644 --- a/usr.sbin/sysinstall/dist.c +++ b/usr.sbin/sysinstall/dist.c @@ -4,7 +4,7 @@ * This is probably the last program in the `sysinstall' line - the next * generation being essentially a complete rewrite. * - * $Id: dist.c,v 1.79 1996/11/09 19:47:24 jkh Exp $ + * $Id: dist.c,v 1.80 1996/12/08 12:27:54 jkh Exp $ * * Copyright (c) 1995 * Jordan Hubbard. All rights reserved. @@ -342,9 +342,10 @@ static Boolean distExtract(char *parent, Distribution *me) { int i, status, total; - int cpid, zpid, fd, fd2, chunk, numchunks; + int cpid, zpid, fd2, chunk, numchunks; char *path, *dist, buf[BUFSIZ]; const char *tmp; + FILE *fp; Attribs *dist_attr; WINDOW *w = savescr(); struct timeval start, stop; @@ -384,12 +385,12 @@ distExtract(char *parent, Distribution *me) numchunks = 0; snprintf(buf, sizeof buf, "%s/%s.inf", path, dist); - fd = mediaDevice->get(mediaDevice, buf, TRUE); - if (fd >= 0) { + fp = mediaDevice->get(mediaDevice, buf, TRUE); + if (fp > 0) { if (isDebug()) msgDebug("Parsing attributes file for distribution %s\n", dist); dist_attr = safe_malloc(sizeof(Attribs) * MAX_ATTRIBS); - if (DITEM_STATUS(attr_parse(dist_attr, fd)) == DITEM_FAILURE) + if (DITEM_STATUS(attr_parse(dist_attr, fp)) == DITEM_FAILURE) msgConfirm("Cannot parse information file for the %s distribution!\n" "Please verify that your media is valid and try again.", dist); else { @@ -400,11 +401,11 @@ distExtract(char *parent, Distribution *me) numchunks = strtol(tmp, 0, 0); } safe_free(dist_attr); - mediaDevice->close(mediaDevice, fd); + fclose(fp); if (!numchunks) continue; } - else if (fd == IO_ERROR) { /* Hard error, can't continue */ + else if (fp == (FILE *)IO_ERROR) { /* Hard error, can't continue */ mediaDevice->shutdown(mediaDevice); status = FALSE; goto done; @@ -416,16 +417,16 @@ distExtract(char *parent, Distribution *me) * Passing TRUE as 3rd parm to get routine makes this a "probing" get, for which errors * are not considered too significant. */ - fd = mediaDevice->get(mediaDevice, buf, TRUE); - if (fd >= 0) { + fp = mediaDevice->get(mediaDevice, buf, TRUE); + if (fp > 0) { char *dir = root_bias(me[i].my_dir); msgNotify("Extracting %s into %s directory...", dist, dir); - status = mediaExtractDist(dir, fd); - mediaDevice->close(mediaDevice, fd); + status = mediaExtractDist(dir, fp); + fclose(fp); goto done; } - else if (fd == IO_ERROR) { /* Hard error, can't continue */ + else if (fp == (FILE *)IO_ERROR) { /* Hard error, can't continue */ mediaDevice->shutdown(mediaDevice); status = FALSE; goto done; @@ -455,8 +456,8 @@ distExtract(char *parent, Distribution *me) snprintf(buf, 512, "%s/%s.%c%c", path, dist, (chunk / 26) + 'a', (chunk % 26) + 'a'); if (isDebug()) msgDebug("trying for piece %d of %d: %s\n", chunk + 1, numchunks, buf); - fd = mediaDevice->get(mediaDevice, buf, FALSE); - if (fd < 0) { + fp = mediaDevice->get(mediaDevice, buf, FALSE); + if (fp <= (FILE *)0) { msgConfirm("failed to retreive piece file %s!\n" "Aborting the transfer", buf); goto punt; @@ -466,7 +467,7 @@ distExtract(char *parent, Distribution *me) while (1) { int seconds; - n = read(fd, buf, BUFSIZ); + n = fread(buf, 1, BUFSIZ, fp); if (n <= 0) break; total += n; @@ -488,13 +489,13 @@ distExtract(char *parent, Distribution *me) } retval = write(fd2, buf, n); if (retval != n) { - mediaDevice->close(mediaDevice, fd); + fclose(fp); dialog_clear_norefresh(); msgConfirm("Write failure on transfer! (wrote %d bytes of %d bytes)", retval, n); goto punt; } } - mediaDevice->close(mediaDevice, fd); + fclose(fp); } close(fd2); status = mediaExtractDistEnd(zpid, cpid); @@ -595,4 +596,3 @@ distExtractAll(dialogMenuItem *self) } return DITEM_SUCCESS; } - diff --git a/usr.sbin/sysinstall/dos.c b/usr.sbin/sysinstall/dos.c index d1aa615..a127c2c 100644 --- a/usr.sbin/sysinstall/dos.c +++ b/usr.sbin/sysinstall/dos.c @@ -4,7 +4,7 @@ * This is probably the last attempt in the `sysinstall' line, the next * generation being slated to essentially a complete rewrite. * - * $Id: dos.c,v 1.13 1996/07/08 08:54:25 jkh Exp $ + * $Id: dos.c,v 1.14 1996/08/23 07:55:58 jkh Exp $ * * Copyright (c) 1995 * Jordan Hubbard. All rights reserved. @@ -44,57 +44,53 @@ #include <unistd.h> #include <fcntl.h> #include <grp.h> +#include "dosio.h" -#define MSDOSFS -#include <sys/mount.h> -#undef MSDOSFS - +static DOS_FS DOSFS; static Boolean DOSMounted; Boolean mediaInitDOS(Device *dev) { - struct msdosfs_args args; - if (!RunningAsInit || DOSMounted) return TRUE; - if (DITEM_STATUS(Mkdir("/dos")) != DITEM_SUCCESS) - return FALSE; - - memset(&args, 0, sizeof(args)); - args.fspec = dev->devname; - args.uid = args.gid = 0; - args.mask = 0777; - - if (mount(MOUNT_MSDOS, "/dos", MNT_RDONLY, (caddr_t)&args) == -1) { - msgConfirm("Error mounting %s on /dos: %s (%u)", args.fspec, strerror(errno), errno); + if (dos_mount(&DOSFS, dev->devname)) { + msgConfirm("Error mounting DOS partition %s : %s (%u)", dev->devname, strerror(errno), errno); return FALSE; } - else - msgDebug("Mounted DOS device (%s) on /dos.\n", args.fspec); DOSMounted = TRUE; + if (isDebug()) + msgDebug("DOS partition %s mounted\n", dev->devname); return TRUE; } -int +FILE * mediaGetDOS(Device *dev, char *file, Boolean probe) { - char buf[PATH_MAX]; + char buf[PATH_MAX]; + FILE *fp; + + if (!DOSMounted) { + msgDebug("Can't get DOS file %s - DOSFS currently unmounted!\n", file); + return NULL; + } if (isDebug()) msgDebug("Request for %s from DOS\n", file); - snprintf(buf, PATH_MAX, "/dos/freebsd/%s", file); - if (file_readable(buf)) - return open(buf, O_RDONLY); - snprintf(buf, PATH_MAX, "/dos/freebsd/dists/%s", file); - if (file_readable(buf)) - return open(buf, O_RDONLY); - snprintf(buf, PATH_MAX, "/dos/%s", file); - if (file_readable(buf)) - return open(buf, O_RDONLY); - snprintf(buf, PATH_MAX, "/dos/dists/%s", file); - return open(buf, O_RDONLY); + snprintf(buf, PATH_MAX, "/freebsd/%s", file); + if ((fp = dos_open(&DOSFS, buf))) + return fp; + snprintf(buf, PATH_MAX, "/freebsd/dists/%s", file); + if ((fp = dos_open(&DOSFS, buf))) + return fp; + snprintf(buf, PATH_MAX, "/%s", file); + if ((fp = dos_open(&DOSFS, buf))) + return fp; + snprintf(buf, PATH_MAX, "/dists/%s", file); + if ((fp = dos_open(&DOSFS, buf))) + return fp; + return NULL; } void @@ -102,11 +98,10 @@ mediaShutdownDOS(Device *dev) { if (!RunningAsInit || !DOSMounted) return; - msgDebug("Unmounting %s from /dos\n", dev->name); - if (unmount("/dos", MNT_FORCE) != 0) - msgConfirm("Could not unmount the DOS partition: %s", strerror(errno)); - if (isDebug()) - msgDebug("Unmount successful\n"); + if (dos_unmount(&DOSFS)) + msgConfirm("Could not unmount DOS partition %s : %s", dev->devname, strerror(errno)); + else if (isDebug()) + msgDebug("Unmount of DOS partition on %s successful\n", dev->devname); DOSMounted = FALSE; return; } diff --git a/usr.sbin/sysinstall/floppy.c b/usr.sbin/sysinstall/floppy.c index 8d4b519..71e5be7 100644 --- a/usr.sbin/sysinstall/floppy.c +++ b/usr.sbin/sysinstall/floppy.c @@ -4,7 +4,7 @@ * This is probably the last attempt in the `sysinstall' line, the next * generation being slated to essentially a complete rewrite. * - * $Id: floppy.c,v 1.15 1996/09/15 23:55:22 jkh Exp $ + * $Id: floppy.c,v 1.16 1996/10/09 09:53:30 jkh Exp $ * * Copyright (c) 1995 * Jordan Hubbard. All rights reserved. @@ -152,34 +152,34 @@ mediaInitFloppy(Device *dev) return TRUE; } -int +FILE * mediaGetFloppy(Device *dev, char *file, Boolean probe) { - char buf[PATH_MAX]; - int fd; - int nretries = 5; + char buf[PATH_MAX]; + FILE *fp; + int nretries = 5; snprintf(buf, PATH_MAX, "/dist/%s", file); msgDebug("Request for %s from floppy on /dist, probe is %d.\n", buf, probe); if (!file_readable(buf)) { if (probe) - return -1; + return NULL; else { while (!file_readable(buf)) { if (!--nretries) { msgConfirm("GetFloppy: Failed to get %s after retries;\ngiving up.", buf); - return -1; + return NULL; } distWanted = buf; mediaShutdownFloppy(dev); if (!mediaInitFloppy(dev)) - return -1; + return NULL; } } } - fd = open(buf, O_RDONLY); - return fd; + fp = fopen(buf, "r"); + return fp; } void diff --git a/usr.sbin/sysinstall/ftp.c b/usr.sbin/sysinstall/ftp.c index 372206b..a9e9060 100644 --- a/usr.sbin/sysinstall/ftp.c +++ b/usr.sbin/sysinstall/ftp.c @@ -1,467 +1,221 @@ /* - * ---------------------------------------------------------------------------- - * "THE BEER-WARE LICENSE" (Revision 42): - * <phk@login.dknet.dk> wrote this file. As long as you retain this notice you - * can do whatever you want with this stuff. If we meet some day, and you think - * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp - * ---------------------------------------------------------------------------- + * The new sysinstall program. * - * $Id: ftp.c,v 1.17 1996/07/08 10:08:00 jkh Exp $ + * This is probably the last attempt in the `sysinstall' line, the next + * generation being slated to essentially a complete rewrite. + * + * $Id: ftp_strat.c,v 1.30 1996/12/09 08:22:13 jkh Exp $ + * + * Copyright (c) 1995 + * Jordan Hubbard. All rights reserved. + * Copyright (c) 1995 + * Gary J Palmer. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer, + * verbatim and that no modifications are made prior to this + * point in the file. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. * - * Return values have been sanitized: - * -1 error, but you (still) have a session. - * -2 error, your session is dead. - * */ -#include <stdlib.h> -#include <stdio.h> -#include <unistd.h> -#include <netdb.h> -#include <errno.h> -#include <sys/types.h> -#include <stdarg.h> -#include <string.h> -#include <signal.h> -#include <errno.h> -#include <ctype.h> -#include "ftp.h" +#include "sysinstall.h" #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> +#include <sys/param.h> +#include <sys/wait.h> +#include <netdb.h> +#include <ftpio.h> -/* Handy global for us to stick the port # */ +Boolean ftpInitted = FALSE; +static FILE *OpenConn; int FtpPort; -/* How to see by a given code whether or not the connection has timed out */ -#define FTP_TIMEOUT(code) (code == 421) - -#ifndef STANDALONE_FTP -#include "sysinstall.h" -#endif /*STANDALONE_FTP*/ - -static int sigpipe_caught = 0; - -static void -catch_pipe(int sig) +Boolean +mediaInitFTP(Device *dev) { - sigpipe_caught = TRUE; -} + int i, code; + char *cp, *rel, *hostname, *dir; + char *user, *login_name, password[80]; -static void -debug(FTP_t ftp, const char *fmt, ...) -{ - char p[BUFSIZ]; - va_list ap; - va_start(ap, fmt); -#ifdef STANDALONE_FTP - strcpy(p,"LIBFTP: "); - (void) vsnprintf(p + strlen(p), sizeof p - strlen(p), fmt, ap); - va_end(ap); - write(ftp->fd_debug, p, strlen(p)); -#else - if (isDebug()) { - (void) vsnprintf(p, sizeof p - strlen(p), fmt, ap); - msgDebug(p); - } -#endif -} + if (ftpInitted) + return TRUE; -static int -writes(int fd, char *s) -{ - int i = strlen(s); + if (isDebug()) + msgDebug("Init routine for FTP called.\n"); - signal(SIGPIPE, catch_pipe); - if (i != write(fd, s, i) || sigpipe_caught) { - if (sigpipe_caught) - msgDebug("sigpipe caught during write - connection invalid\n"); - sigpipe_caught = FALSE; - return IO_ERROR; + if (OpenConn) { + fclose(OpenConn); + OpenConn = NULL; } - return 0; -} - -static __inline char* -get_a_line(FTP_t ftp) -{ - static char buf[BUFSIZ]; - int i,j; - signal(SIGPIPE, catch_pipe); - for(i = 0; i < BUFSIZ;) { - j = read(ftp->fd_ctrl, buf+i, 1); - if (j != 1 || sigpipe_caught) { - if (sigpipe_caught) - msgDebug("sigpipe caught during read - connection invalid\n"); - sigpipe_caught = FALSE; - return 0; - } - if (buf[i] == '\r' || buf[i] == '\n') { - if (!i) - continue; - buf[i] = '\0'; - debug(ftp, "received <%s>\n", buf); - return buf; - } - i++; +try: + cp = variable_get(VAR_FTP_PATH); + if (!cp) { + if (DITEM_STATUS(mediaSetFTP(NULL)) == DITEM_FAILURE || (cp = variable_get(VAR_FTP_PATH)) == NULL) + return FALSE; } - return buf; -} -static int -get_a_number(FTP_t ftp, char **q) -{ - char *p; - int i = -1,j; + hostname = variable_get(VAR_FTP_HOST); + dir = variable_get(VAR_FTP_DIR); + if (!hostname || !dir) + msgFatal("Missing FTP host or directory specification - something's wrong!"); - while(1) { - p = get_a_line(ftp); - if (!p) - return IO_ERROR; - if (!(isdigit(p[0]) && isdigit(p[1]) && isdigit(p[2]))) - continue; - if (i == -1 && p[3] == '-') { - i = strtol(p, 0, 0); - continue; - } - if (p[3] != ' ' && p[3] != '\t') - continue; - j = strtol(p, 0, 0); - if (i == -1) { - if (q) *q = p+4; - return j; - } else if (j == i) { - if (q) *q = p+4; - return j; - } + user = variable_get(VAR_FTP_USER); + if (!user || !*user) + login_name = "anonymous"; + else + login_name = user; + if (variable_get(VAR_FTP_PASS)) + SAFE_STRCPY(password, variable_get(VAR_FTP_PASS)); + else + sprintf(password, "installer@%s", variable_get(VAR_HOSTNAME)); + msgNotify("Logging in as %s..", login_name); + if ((OpenConn = ftpLogin(hostname, login_name, password, FtpPort, isDebug(), &code)) != 0) { + if (variable_get(VAR_NO_CONFIRM)) + msgNotify("Couldn't open FTP connection to %s, errcode = %d", hostname, code); + else + msgConfirm("Couldn't open FTP connection to %s, errcode = %d", hostname, code); + goto punt; } -} - -static int -zap(FTP_t ftp) -{ - int i; - - i = writes(ftp->fd_ctrl,"QUIT\r\n"); - if (isDebug()) - msgDebug("Zapping ftp connection on %d returns %d\n", ftp->fd_ctrl, i); - close(ftp->fd_ctrl); ftp->fd_ctrl = -1; - close(ftp->fd_xfer); ftp->fd_xfer = -1; - ftp->state = init; - return IO_ERROR; -} - -static int -botch(FTP_t ftp, char *func, char *state) -{ - debug(ftp, "Botch: %s called outside state %s\n",func,state); - return IO_ERROR; -} - -static int -cmd(FTP_t ftp, const char *fmt, ...) -{ - char p[BUFSIZ]; - int i; - - va_list ap; - va_start(ap, fmt); - (void) vsnprintf(p, sizeof p, fmt, ap); - va_end(ap); - - debug(ftp, "send <%s>\n", p); - strcat(p,"\r\n"); - if (writes(ftp->fd_ctrl, p)) - return IO_ERROR; - i = get_a_number(ftp, 0); - return i; -} - -FTP_t -FtpInit() -{ - FTP_t ftp; - - ftp = malloc(sizeof *ftp); - if (!ftp) - return ftp; - memset(ftp, 0, sizeof *ftp); - ftp->fd_ctrl = -1; - ftp->fd_xfer = -1; - ftp->fd_debug = -1; - ftp->state = init; - return ftp; -} - -#ifdef STANDALONE_FTP -void -FtpDebug(FTP_t ftp, int i) -{ - ftp->fd_debug = i; -} -#endif - -int -FtpOpen(FTP_t ftp, char *host, char *user, char *passwd) -{ - struct hostent *he = NULL; - struct sockaddr_in sin; - int s; - unsigned long temp; - int i; - - if (ftp->state != init) - return botch(ftp,"FtpOpen","init"); - - if (!user) - user = "ftp"; - - if (!passwd) - passwd = "??@??(FreeBSD:libftp)"; /* XXX */ - debug(ftp, "FtpOpen(ftp, %s, %s, %s)\n", host, user, passwd); - - temp = inet_addr(host); - if (temp != INADDR_NONE) { - debug(ftp, "Using dotted IP address `%s'\n", host); - ftp->addrtype = sin.sin_family = AF_INET; - sin.sin_addr.s_addr = temp; - } - else { - debug(ftp, "Trying to resolve `%s'\n", host); - he = gethostbyname(host); - if (!he) { - debug(ftp, "Lookup of `%s' failed!\n", host); - return zap(ftp); + ftpPassive(OpenConn, !strcmp(variable_get(VAR_FTP_STATE), "passive")); + ftpBinary(OpenConn); + if (dir && *dir != '\0') { + if ((i = ftpChdir(OpenConn, dir)) != 0) { + msgDebug("Attempt to chdir to distribution in %s returns error code %d\n", dir, i); + goto punt; } - ftp->addrtype = sin.sin_family = he->h_addrtype; - bcopy(he->h_addr, (char *)&sin.sin_addr, he->h_length); } - sin.sin_port = htons(FtpPort ? FtpPort : 21); - - if ((s = socket(ftp->addrtype, SOCK_STREAM, 0)) < 0) - { - debug(ftp, "Socket open failed: %s (%i)\n", strerror(errno), errno); - return zap(ftp); - } - - if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) { - debug(ftp,"Connection failed: %s (%i)\n", strerror(errno), errno); - (void)close(s); - return zap(ftp); + /* Give it a shot - can't hurt to try and zoom in if we can, unless the release is set to + __RELEASE or "none" which signifies that it's not set */ + rel = variable_get(VAR_RELNAME); + if (strcmp(rel, "__RELEASE") && strcmp(rel, "none")) + i = ftpChdir(OpenConn, rel); + else + i = 0; + if (i) { + if (!msgYesNo("Warning: Can't CD to `%s' distribution on this\n" + "FTP server. You may need to visit a different server for\n" + "the release you're trying to fetch or go to the Options\n" + "menu and to set the release name to explicitly match what's\n" + "available on %s (or set to \"none\").\n\n" + "Would you like to select another FTP server?", + rel, hostname)) { + variable_unset(VAR_FTP_PATH); + if (DITEM_STATUS(mediaSetFTP(NULL)) == DITEM_FAILURE) + goto punt; + else + goto try; + } + else + goto punt; } - - ftp->fd_ctrl = s; - - debug(ftp, "open (%d)\n",get_a_number(ftp,0)); - - i = cmd(ftp, "USER %s", user); - if (i >= 300 && i < 400) - i = cmd(ftp,"PASS %s",passwd); - if (i >= 299 || i < 0) { - close(ftp->fd_ctrl); - ftp->fd_ctrl = -1; - return zap(ftp); + if (isDebug()) + msgDebug("mediaInitFTP was successful (logged in and chdir'd)\n"); + ftpInitted = TRUE; + return TRUE; + +punt: + if (OpenConn != NULL) { + fclose(OpenConn); + OpenConn = NULL; } - ftp->state = isopen; - return 0; -} - -void -FtpClose(FTP_t ftp) -{ - if (ftp->state != init) - return; - - if (ftp->state != isopen) - botch(ftp,"FtpClose","open or init"); - - debug(ftp, "FtpClose(ftp)\n"); - zap(ftp); -} - -int -FtpChdir(FTP_t ftp, char *dir) -{ - int i; - - if (ftp->state != isopen) - return botch(ftp,"FtpChdir","open"); - i = cmd(ftp, "CWD %s", dir); - if (i < 0) - return i; - else if (i != 250) - return -1; - return 0; + variable_unset(VAR_FTP_PATH); + return FALSE; } -int -FtpGet(FTP_t ftp, char *file) +FILE * +mediaGetFTP(Device *dev, char *file, Boolean probe) { - int i,s; - char *q; - unsigned char addr[64]; - struct sockaddr_in sin; - u_long a; + int nretries = 1; + FILE *fp; + char *try, buf[PATH_MAX]; - debug(ftp, "FtpGet(ftp,%s)\n", file); - if (ftp->state != isopen) - return botch(ftp, "FtpGet", "open"); - if (ftp->binary) { - i = cmd(ftp, "TYPE I"); - if (i < 0 || FTP_TIMEOUT(i)) - return zap(ftp); - if (i > 299) - return -1; + if (!OpenConn) { + msgDebug("No FTP connection open, can't get file %s\n", file); + return NULL; } - else - return -1; - - if ((s = socket(ftp->addrtype, SOCK_STREAM, 0)) < 0) - return zap(ftp); - - if (ftp->passive) { - debug(ftp, "send <%s>\n", "PASV"); - if (writes(ftp->fd_ctrl, "PASV\r\n")) - return zap(ftp); - i = get_a_number(ftp, &q); - if (i < 0) - return zap(ftp); - if (i != 227) - return zap(ftp); - while (*q && !isdigit(*q)) - q++; - if (!*q) - return zap(ftp); - q--; - for(i = 0; i < 6; i++) { - q++; - addr[i] = strtol(q, &q, 10); - } - - sin.sin_family = ftp->addrtype; - bcopy(addr, (char *)&sin.sin_addr, 4); - bcopy(addr + 4, (char *)&sin.sin_port, 2); - debug(ftp, "Opening active socket to %s : %u\n", inet_ntoa(sin.sin_addr), htons(sin.sin_port)); - debug(ftp, "Connecting to %s:%u\n", inet_ntoa(sin.sin_addr), htons(sin.sin_port)); - if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) { - (void)close(s); - debug(ftp, "connect: %s (%d)\n", strerror(errno), errno); - return -1; - } - ftp->fd_xfer = s; - i = cmd(ftp,"RETR %s", file); - if (i < 0 || FTP_TIMEOUT(i)) { - close(s); - return zap(ftp); - } - else if (i > 299) { - if (isDebug()) - msgDebug("FTP: No such file %s, moving on.\n", file); - close(s); - return -1; - } - ftp->state = xfer; - return s; - } else { - i = sizeof sin; - getsockname(ftp->fd_ctrl, (struct sockaddr *)&sin, &i); - sin.sin_port = 0; - i = sizeof sin; - if (bind(s,(struct sockaddr *)&sin, i) < 0) { - close (s); - debug(ftp, "bind failed %d\n", errno); - return zap(ftp); - } - getsockname(s, (struct sockaddr *)&sin, &i); - if (listen(s, 1) < 0) { - close (s); - debug(ftp, "listen failed %d\n", errno); - return zap(ftp); - } - a = ntohl(sin.sin_addr.s_addr); - i = cmd(ftp, "PORT %d,%d,%d,%d,%d,%d", - (a >> 24) & 0xff, - (a >> 16) & 0xff, - (a >> 8) & 0xff, - a & 0xff, - (ntohs(sin.sin_port) >> 8) & 0xff, - ntohs(sin.sin_port) & 0xff); - if (i != 200) - return -1; - i = cmd(ftp,"RETR %s", file); - if (i < 0) { - close(s); - return zap(ftp); - } - else if (i > 299 || FTP_TIMEOUT(i)) { - if (isDebug()) - msgDebug("FTP: No such file %s, moving on.\n", file); - close(s); - if (FTP_TIMEOUT(i)) - return zap(ftp); + try = file; + while ((fp = ftpGet(OpenConn, try, 0)) == NULL) { + /* If a hard fail, try to "bounce" the ftp server to clear it */ + if (ftpErrno(OpenConn) != 550) { + char *cp = variable_get(VAR_FTP_PATH); + + dev->shutdown(dev); + variable_unset(VAR_FTP_PATH); + /* If we can't re-initialize, just forget it */ + if (!dev->init(dev)) { + fclose(OpenConn); + OpenConn = NULL; + return NULL; + } else - return -1; - } - ftp->fd_xfer = accept(s, 0, 0); - if (ftp->fd_xfer < 0) { - close(s); - return zap(ftp); + variable_set2(VAR_FTP_PATH, cp); + } + else if (probe) + return NULL; + else { + /* Try some alternatives */ + switch (nretries++) { + case 1: + sprintf(buf, "dists/%s", file); + try = buf; + break; + + case 2: + sprintf(buf, "%s/%s", variable_get(VAR_RELNAME), file); + try = buf; + break; + + case 3: + sprintf(buf, "%s/dists/%s", variable_get(VAR_RELNAME), file); + try = buf; + break; + + case 4: + try = file; + break; + } } - ftp->state = xfer; - close(s); - return(ftp->fd_xfer); } + return fp; } -int -FtpEOF(FTP_t ftp) -{ - int i; - - if (ftp->state != xfer) - return botch(ftp, "FtpEOF", "xfer"); - debug(ftp, "FtpEOF(ftp)\n"); - close(ftp->fd_xfer); - ftp->fd_xfer = -1; - ftp->state = isopen; - i = get_a_number(ftp,0); - if (i < 0) - return zap(ftp); - else if (i != 250 && i != 226) - return -1; - else - return 0; -} - -#ifdef STANDALONE_FTP - -/* main.c */ -int -main(int argc, char **argv) +void +mediaShutdownFTP(Device *dev) { - FTP_t ftp; - int i; - char c; + /* Device *netdev = (Device *)dev->private; */ - ftp = FtpInit(); - if (!ftp) - err(1, "FtpInit()"); + if (!ftpInitted) + return; - FtpDebug(ftp, 1); - i = FtpOpen(ftp, "freefall.cdrom.com", "ftp", "phk-libftp@"); - FtpBinary(ftp, 1); - FtpPassive(ftp, 0); - FtpChdir(ftp, "/pub"); - FtpChdir(ftp, "FreeBSD"); - i = FtpGet(ftp, "README"); - while (1 == read(i, &c, 1)) - putchar(c); - FtpEOF(ftp); - return 0; + if (isDebug()) + msgDebug("FTP shutdown called. OpenConn = %x\n", OpenConn); + if (OpenConn != NULL) { + fclose(OpenConn); + OpenConn = NULL; + } + /* (*netdev->shutdown)(netdev); */ + ftpInitted = FALSE; } - -#endif /*STANDALONE_FTP*/ diff --git a/usr.sbin/sysinstall/index.c b/usr.sbin/sysinstall/index.c index 62bcc0e..de3caeb 100644 --- a/usr.sbin/sysinstall/index.c +++ b/usr.sbin/sysinstall/index.c @@ -4,7 +4,7 @@ * This is probably the last program in the `sysinstall' line - the next * generation being essentially a complete rewrite. * - * $Id: index.c,v 1.38 1996/08/03 10:10:54 jkh Exp $ + * $Id: index.c,v 1.39 1996/12/09 08:22:13 jkh Exp $ * * Copyright (c) 1995 * Jordan Hubbard. All rights reserved. @@ -199,12 +199,12 @@ copy_to_sep(char *to, char *from, int sep) } static int -readline(int fd, char *buf, int max) +readline(FILE *fp, char *buf, int max) { int rv, i = 0; char ch; - while ((rv = read(fd, &ch, 1)) == 1 && ch != '\n' && i < max) + while ((rv = fread(&ch, 1, 1, fp)) == 1 && ch != '\n' && i < max) buf[i++] = ch; if (i < max) buf[i] = '\0'; @@ -212,13 +212,13 @@ readline(int fd, char *buf, int max) } int -index_parse(int fd, char *name, char *pathto, char *prefix, char *comment, char *descr, char *maint, char *cats, char *deps) +index_parse(FILE *fp, char *name, char *pathto, char *prefix, char *comment, char *descr, char *maint, char *cats, char *deps) { char line[1024]; char *cp; int i; - i = readline(fd, line, 1024); + i = readline(fp, line, 1024); if (i <= 0) return EOF; cp = line; @@ -237,25 +237,26 @@ index_parse(int fd, char *name, char *pathto, char *prefix, char *comment, char int index_get(char *fname, PkgNodePtr papa) { - int i, fd; + int i; + FILE *fp; - fd = open(fname, O_RDONLY); - if (fd < 0) { + fp = fopen(fname, "r"); + if (!fp) { fprintf(stderr, "Unable to open index file `%s' for reading.\n", fname); i = -1; } else - i = index_read(fd, papa); - close(fd); + i = index_read(fp, papa); + fclose(fp); return i; } int -index_read(int fd, PkgNodePtr papa) +index_read(FILE *fp, PkgNodePtr papa) { char name[127], pathto[255], prefix[255], comment[255], descr[127], maint[127], cats[511], deps[511]; - while (index_parse(fd, name, pathto, prefix, comment, descr, maint, cats, deps) != EOF) { + while (index_parse(fp, name, pathto, prefix, comment, descr, maint, cats, deps) != EOF) { char *cp, *cp2, tmp[511]; IndexEntryPtr idx; diff --git a/usr.sbin/sysinstall/main.c b/usr.sbin/sysinstall/main.c index 2328c70..d61d0c1 100644 --- a/usr.sbin/sysinstall/main.c +++ b/usr.sbin/sysinstall/main.c @@ -4,7 +4,7 @@ * This is probably the last attempt in the `sysinstall' line, the next * generation being slated for what's essentially a complete rewrite. * - * $Id: main.c,v 1.27 1996/09/15 23:55:23 jkh Exp $ + * $Id: main.c,v 1.28 1996/09/26 21:03:35 pst Exp $ * * Copyright (c) 1995 * Jordan Hubbard. All rights reserved. @@ -112,21 +112,21 @@ main(int argc, char **argv) } { - int fd; + FILE *fp; Attribs attrs[512]; bzero(attrs, sizeof(attrs)); - fd = open("install.cfg", O_RDONLY); - if (fd >= 0) { + fp = fopen("install.cfg", "r"); + if (fp) { msgNotify("Loading pre-configuration file"); - if (DITEM_STATUS(attr_parse(attrs, fd)) == DITEM_SUCCESS) { + if (DITEM_STATUS(attr_parse(attrs, fp)) == DITEM_SUCCESS) { int i; for (i = 0; *attrs[i].name; i++) variable_set2(attrs[i].name, attrs[i].value); } - close(fd); + fclose(fp); } #if defined(LOAD_CONFIG_FILE) @@ -143,17 +143,17 @@ main(int argc, char **argv) mediaDevice->init(mediaDevice)) { int fd; - fd = mediaDevice->get(mediaDevice, LOAD_CONFIG_FILE, TRUE); - if (fd > 0) { + fp = mediaDevice->get(mediaDevice, LOAD_CONFIG_FILE, TRUE); + if (fp) { msgNotify("Loading %s pre-configuration file", LOAD_CONFIG_FILE); - if (DITEM_STATUS(attr_parse(attrs, fd)) == DITEM_SUCCESS) { + if (DITEM_STATUS(attr_parse(attrs, fp)) == DITEM_SUCCESS) { int i; for (i = 0; *attrs[i].name; i++) variable_set2(attrs[i].name, attrs[i].value); } - mediaDevice->close(mediaDevice, fd); + fclose(fp); } mediaDevice->shutdown(mediaDevice); } diff --git a/usr.sbin/sysinstall/media.c b/usr.sbin/sysinstall/media.c index 673baba..bf6cc51 100644 --- a/usr.sbin/sysinstall/media.c +++ b/usr.sbin/sysinstall/media.c @@ -4,7 +4,7 @@ * This is probably the last attempt in the `sysinstall' line, the next * generation being slated to essentially a complete rewrite. * - * $Id: media.c,v 1.65 1996/11/07 14:17:09 jkh Exp $ + * $Id: media.c,v 1.66 1996/12/09 08:22:15 jkh Exp $ * * Copyright (c) 1995 * Jordan Hubbard. All rights reserved. @@ -349,7 +349,7 @@ mediaSetFTP(dialogMenuItem *self) ftpDevice.type = DEVICE_TYPE_FTP; ftpDevice.init = mediaInitFTP; ftpDevice.get = mediaGetFTP; - ftpDevice.close = mediaCloseFTP; + ftpDevice.close = NULL; ftpDevice.shutdown = mediaShutdownFTP; ftpDevice.private = mediaDevice; /* Set to network device by tcpDeviceSelect() */ mediaDevice = &ftpDevice; @@ -385,7 +385,6 @@ mediaSetUFS(dialogMenuItem *self) ufsDevice.type = DEVICE_TYPE_UFS; ufsDevice.init = dummyInit; ufsDevice.get = mediaGetUFS; - ufsDevice.close = dummyClose; ufsDevice.shutdown = dummyShutdown; ufsDevice.private = strdup(cp); mediaDevice = &ufsDevice; @@ -433,7 +432,6 @@ mediaSetNFS(dialogMenuItem *self) nfsDevice.type = DEVICE_TYPE_NFS; nfsDevice.init = mediaInitNFS; nfsDevice.get = mediaGetNFS; - nfsDevice.close = dummyClose; nfsDevice.shutdown = mediaShutdownNFS; nfsDevice.private = mediaDevice; mediaDevice = &nfsDevice; @@ -523,7 +521,7 @@ mediaExtractDistEnd(int zpid, int cpid) Boolean -mediaExtractDist(char *dir, int fd) +mediaExtractDist(char *dir, FILE *fp) { int i, j, zpid, cpid, pfd[2]; @@ -537,7 +535,7 @@ mediaExtractDist(char *dir, int fd) if (!zpid) { char *gunzip = RunningAsInit ? "/stand/gunzip" : "/usr/bin/gunzip"; - dup2(fd, 0); close(fd); + dup2(fileno(fp), 0); fclose(fp); dup2(pfd[1], 1); close(pfd[1]); if (DebugFD != -1) dup2(DebugFD, 2); @@ -556,7 +554,7 @@ mediaExtractDist(char *dir, int fd) char *cpio = RunningAsInit ? "/stand/cpio" : "/usr/bin/cpio"; dup2(pfd[0], 0); close(pfd[0]); - close(fd); + fclose(fp); close(pfd[1]); if (DebugFD != -1) { dup2(DebugFD, 1); diff --git a/usr.sbin/sysinstall/network.c b/usr.sbin/sysinstall/network.c index f2136f4..2fc90df 100644 --- a/usr.sbin/sysinstall/network.c +++ b/usr.sbin/sysinstall/network.c @@ -4,7 +4,7 @@ * This is probably the last attempt in the `sysinstall' line, the next * generation being slated to essentially a complete rewrite. * - * $Id: network.c,v 1.21 1996/12/09 08:22:16 jkh Exp $ + * $Id: network.c,v 1.22 1996/12/09 15:16:36 jkh Exp $ * * Copyright (c) 1995 * Jordan Hubbard. All rights reserved. @@ -256,7 +256,7 @@ startPPP(Device *devp) struct termios foo; extern int login_tty(int); - for (i = 0; i < 64; i++) + for (i = getdtablesize(); i; i--) close(i); /* We're going over to VTY2 */ diff --git a/usr.sbin/sysinstall/nfs.c b/usr.sbin/sysinstall/nfs.c index ce16cec..8c270f8 100644 --- a/usr.sbin/sysinstall/nfs.c +++ b/usr.sbin/sysinstall/nfs.c @@ -4,7 +4,7 @@ * This is probably the last attempt in the `sysinstall' line, the next * generation being slated to essentially a complete rewrite. * - * $Id: nfs.c,v 1.10 1996/07/08 08:54:31 jkh Exp $ + * $Id: nfs.c,v 1.11 1996/08/23 07:55:59 jkh Exp $ * * Copyright (c) 1995 * Jordan Hubbard. All rights reserved. @@ -70,7 +70,7 @@ mediaInitNFS(Device *dev) return TRUE; } -int +FILE * mediaGetNFS(Device *dev, char *file, Boolean probe) { char buf[PATH_MAX]; @@ -79,15 +79,15 @@ mediaGetNFS(Device *dev, char *file, Boolean probe) msgDebug("Request for %s from NFS\n", file); snprintf(buf, PATH_MAX, "/dist/%s", file); if (file_readable(buf)) - return open(buf, O_RDONLY); + return fopen(buf, "r"); snprintf(buf, PATH_MAX, "/dist/dists/%s", file); if (file_readable(buf)) - return open(buf, O_RDONLY); + return fopen(buf, "r"); snprintf(buf, PATH_MAX, "/dist/%s/%s", variable_get(VAR_RELNAME), file); if (file_readable(buf)) - return open(buf, O_RDONLY); + return fopen(buf, "r"); snprintf(buf, PATH_MAX, "/dist/%s/dists/%s", variable_get(VAR_RELNAME), file); - return open(buf, O_RDONLY); + return fopen(buf, "r"); } void diff --git a/usr.sbin/sysinstall/package.c b/usr.sbin/sysinstall/package.c index 5d2cfd2..a55ca29 100644 --- a/usr.sbin/sysinstall/package.c +++ b/usr.sbin/sysinstall/package.c @@ -4,7 +4,7 @@ * This is probably the last program in the `sysinstall' line - the next * generation being essentially a complete rewrite. * - * $Id: package.c,v 1.48 1996/10/12 19:30:26 jkh Exp $ + * $Id: package.c,v 1.49 1996/11/04 12:56:28 jkh Exp $ * * Copyright (c) 1995 * Jordan Hubbard. All rights reserved. @@ -85,7 +85,8 @@ int package_extract(Device *dev, char *name, Boolean depended) { char path[511]; - int fd, ret; + int ret; + FILE *fp; /* Check to make sure it's not already there */ if (package_exists(name)) @@ -113,8 +114,8 @@ package_extract(Device *dev, char *name, Boolean depended) sprintf(path, "packages/All/%s%s", name, strstr(name, ".tgz") ? "" : ".tgz"); else sprintf(path, "%s%s", name, strstr(name, ".tgz") ? "" : ".tgz"); - fd = dev->get(dev, path, TRUE); - if (fd >= 0) { + fp = dev->get(dev, path, TRUE); + if (fp) { int i, tot, pfd[2]; pid_t pid; @@ -141,7 +142,7 @@ package_extract(Device *dev, char *name, Boolean depended) tot = 0; (void)gettimeofday(&start, (struct timezone *)0); - while (!sigpipe_caught && (i = read(fd, buf, BUFSIZ)) > 0) { + while (!sigpipe_caught && (i = fread(buf, 1, BUFSIZ, fp)) > 0) { int seconds; tot += i; @@ -162,7 +163,7 @@ package_extract(Device *dev, char *name, Boolean depended) } } close(pfd[1]); - dev->close(dev, fd); + fclose(fp); if (sigpipe_caught) msgDebug("Caught SIGPIPE while trying to install the %s package.\n", name); else @@ -189,7 +190,7 @@ package_extract(Device *dev, char *name, Boolean depended) } } else { - msgDebug("pkg_extract: get operation returned %d\n", fd); + msgDebug("pkg_extract: get returned NULL\n"); dialog_clear_norefresh(); if (variable_get(VAR_NO_CONFIRM)) msgNotify("Unable to fetch package %s from selected media.\n" diff --git a/usr.sbin/sysinstall/sysinstall.h b/usr.sbin/sysinstall/sysinstall.h index dab2d63..3ebcecf 100644 --- a/usr.sbin/sysinstall/sysinstall.h +++ b/usr.sbin/sysinstall/sysinstall.h @@ -4,7 +4,7 @@ * This is probably the last attempt in the `sysinstall' line, the next * generation being slated to essentially a complete rewrite. * - * $Id: sysinstall.h,v 1.89 1996/12/09 06:37:45 jkh Exp $ + * $Id: sysinstall.h,v 1.90 1996/12/09 08:22:17 jkh Exp $ * * Copyright (c) 1995 * Jordan Hubbard. All rights reserved. @@ -214,8 +214,8 @@ typedef struct _device { DeviceType type; Boolean enabled; Boolean (*init)(struct _device *dev); - int (*get)(struct _device *dev, char *file, Boolean probe); - Boolean (*close)(struct _device *dev, int fd); + FILE * (*get)(struct _device *dev, char *file, Boolean probe); + Boolean (*close)(struct _device *dev, FILE *fp); void (*shutdown)(struct _device *dev); void *private; unsigned int flags; @@ -358,11 +358,11 @@ extern int configAnonFTP(dialogMenuItem *self); /* attrs.c */ extern char *attr_match(Attribs *attr, char *name); extern int attr_parse_file(Attribs *attr, char *file); -extern int attr_parse(Attribs *attr, int fd); +extern int attr_parse(Attribs *attr, FILE *fp); /* cdrom.c */ extern Boolean mediaInitCDROM(Device *dev); -extern int mediaGetCDROM(Device *dev, char *file, Boolean probe); +extern FILE *mediaGetCDROM(Device *dev, char *file, Boolean probe); extern void mediaShutdownCDROM(Device *dev); /* command.c */ @@ -401,12 +401,12 @@ extern Device **deviceFind(char *name, DeviceType type); extern int deviceCount(Device **devs); extern Device *new_device(char *name); extern Device *deviceRegister(char *name, char *desc, char *devname, DeviceType type, Boolean enabled, - Boolean (*init)(Device *mediadev), int (*get)(Device *dev, char *file, Boolean probe), - Boolean (*close)(Device *mediadev, int fd), void (*shutDown)(Device *mediadev), + Boolean (*init)(Device *mediadev), + FILE * (*get)(Device *dev, char *file, Boolean probe), + void (*shutDown)(Device *mediadev), void *private); extern Boolean dummyInit(Device *dev); -extern int dummyGet(Device *dev, char *dist, Boolean probe); -extern Boolean dummyClose(Device *dev, int fd); +extern FILE *dummyGet(Device *dev, char *dist, Boolean probe); extern void dummyShutdown(Device *dev); /* disks.c */ @@ -455,20 +455,21 @@ extern int docBrowser(dialogMenuItem *self); extern int docShowDocument(dialogMenuItem *self); /* dos.c */ +extern Boolean mediaCloseDOS(Device *dev, FILE *fp); extern Boolean mediaInitDOS(Device *dev); -extern int mediaGetDOS(Device *dev, char *file, Boolean probe); +extern FILE *mediaGetDOS(Device *dev, char *file, Boolean probe); extern void mediaShutdownDOS(Device *dev); /* floppy.c */ extern int getRootFloppy(void); extern Boolean mediaInitFloppy(Device *dev); -extern int mediaGetFloppy(Device *dev, char *file, Boolean probe); +extern FILE *mediaGetFloppy(Device *dev, char *file, Boolean probe); extern void mediaShutdownFloppy(Device *dev); /* ftp_strat.c */ -extern Boolean mediaCloseFTP(Device *dev, int fd); +extern Boolean mediaCloseFTP(Device *dev, FILE *fp); extern Boolean mediaInitFTP(Device *dev); -extern int mediaGetFTP(Device *dev, char *file, Boolean probe); +extern FILE *mediaGetFTP(Device *dev, char *file, Boolean probe); extern void mediaShutdownFTP(Device *dev); /* globals.c */ @@ -476,7 +477,7 @@ extern void globalsInit(void); /* index.c */ int index_get(char *fname, PkgNodePtr papa); -int index_read(int fd, PkgNodePtr papa); +int index_read(FILE *fp, PkgNodePtr papa); int index_menu(PkgNodePtr top, PkgNodePtr plist, int *pos, int *scroll); void index_init(PkgNodePtr top, PkgNodePtr plist); void index_node_free(PkgNodePtr top, PkgNodePtr plist); @@ -536,7 +537,7 @@ extern int mediaSetNFS(dialogMenuItem *self); extern int mediaSetFTPUserPass(dialogMenuItem *self); extern int mediaSetCPIOVerbosity(dialogMenuItem *self); extern int mediaGetType(dialogMenuItem *self); -extern Boolean mediaExtractDist(char *dir, int fd); +extern Boolean mediaExtractDist(char *dir, FILE *fp); extern Boolean mediaExtractDistBegin(char *dir, int *fd, int *zpid, int *cpic); extern Boolean mediaExtractDistEnd(int zpid, int cpid); extern Boolean mediaVerify(void); @@ -590,7 +591,7 @@ extern void mediaShutdownNetwork(Device *dev); /* nfs.c */ extern Boolean mediaInitNFS(Device *dev); -extern int mediaGetNFS(Device *dev, char *file, Boolean probe); +extern FILE *mediaGetNFS(Device *dev, char *file, Boolean probe); extern void mediaShutdownNFS(Device *dev); /* options.c */ @@ -618,7 +619,7 @@ extern int vsystem(char *fmt, ...); /* tape.c */ extern char *mediaTapeBlocksize(void); extern Boolean mediaInitTape(Device *dev); -extern int mediaGetTape(Device *dev, char *file, Boolean probe); +extern FILE *mediaGetTape(Device *dev, char *file, Boolean probe); extern void mediaShutdownTape(Device *dev); /* tcpip.c */ @@ -632,7 +633,7 @@ extern int set_termcap(void); /* ufs.c */ extern void mediaShutdownUFS(Device *dev); extern Boolean mediaInitUFS(Device *dev); -extern int mediaGetUFS(Device *dev, char *file, Boolean probe); +extern FILE *mediaGetUFS(Device *dev, char *file, Boolean probe); /* user.c */ extern int userAddGroup(dialogMenuItem *self); diff --git a/usr.sbin/sysinstall/tape.c b/usr.sbin/sysinstall/tape.c index 5c8f602..8e7ccb3 100644 --- a/usr.sbin/sysinstall/tape.c +++ b/usr.sbin/sysinstall/tape.c @@ -4,7 +4,7 @@ * This is probably the last attempt in the `sysinstall' line, the next * generation being slated to essentially a complete rewrite. * - * $Id: tape.c,v 1.12 1996/07/08 08:54:36 jkh Exp $ + * $Id: tape.c,v 1.13 1996/08/23 07:56:00 jkh Exp $ * * Copyright (c) 1995 * Jordan Hubbard. All rights reserved. @@ -77,25 +77,25 @@ mediaInitTape(Device *dev) return FALSE; } -int +FILE * mediaGetTape(Device *dev, char *file, Boolean probe) { char buf[PATH_MAX]; - int fd; + FILE *fp; sprintf(buf, "%s/%s", (char *)dev->private, file); if (isDebug()) msgDebug("Request for %s from tape (looking in %s)\n", file, buf); if (file_readable(buf)) - fd = open(buf, O_RDONLY); + fp = fopen(buf, "r"); else { sprintf(buf, "%s/dists/%s", (char *)dev->private, file); - fd = open(buf, O_RDONLY); + fp = fopen(buf, "r"); } /* Nuke the files behind us to save space */ - if (fd != -1) + if (fp) unlink(buf); - return fd; + return fp; } void diff --git a/usr.sbin/sysinstall/ufs.c b/usr.sbin/sysinstall/ufs.c index 9a70070..9bbea03 100644 --- a/usr.sbin/sysinstall/ufs.c +++ b/usr.sbin/sysinstall/ufs.c @@ -4,7 +4,7 @@ * This is probably the last attempt in the `sysinstall' line, the next * generation being slated to essentially a complete rewrite. * - * $Id: ufs.c,v 1.8 1996/04/13 13:32:14 jkh Exp $ + * $Id: ufs.c,v 1.9 1996/08/23 07:56:01 jkh Exp $ * * Copyright (c) 1995 * Jordan Hubbard. All rights reserved. @@ -42,7 +42,7 @@ /* No init or shutdown routines necessary - all done in mediaSetUFS() */ -int +FILE * mediaGetUFS(Device *dev, char *file, Boolean probe) { char buf[PATH_MAX]; @@ -51,13 +51,13 @@ mediaGetUFS(Device *dev, char *file, Boolean probe) msgDebug("Request for %s from UFS\n", file); snprintf(buf, PATH_MAX, "%s/%s", dev->private, file); if (file_readable(buf)) - return open(buf, O_RDONLY); + return fopen(buf, "r"); snprintf(buf, PATH_MAX, "%s/dists/%s", dev->private, file); if (file_readable(buf)) - return open(buf, O_RDONLY); + return fopen(buf, "r"); snprintf(buf, PATH_MAX, "%s/%s/%s", dev->private, variable_get(VAR_RELNAME), file); if (file_readable(buf)) - return open(buf, O_RDONLY); + return fopen(buf, "r"); snprintf(buf, PATH_MAX, "%s/%s/dists/%s", dev->private, variable_get(VAR_RELNAME), file); - return open(buf, O_RDONLY); + return fopen(buf, "r"); } |