1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-04 09:09:56 +00:00

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>
This commit is contained in:
Jordan K. Hubbard 1996-12-11 09:35:06 +00:00
parent 92808b3c8a
commit 0fd6d431cf
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=20315
44 changed files with 1567 additions and 1562 deletions

View File

@ -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

View File

@ -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: attr.c,v 1.8 1996/09/08 01:39:23 jkh Exp $
* $Id: attr.c,v 1.9 1996/12/09 08:22:10 jkh Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@ -38,25 +38,25 @@
#include "sysinstall.h"
#include <ctype.h>
#include <fcntl.h>
#include <sys/errno.h>
int
attr_parse_file(Attribs *attr, char *file)
{
int fd, status;
int status;
FILE *fp;
if ((fd = open(file, O_RDONLY)) == -1) {
if ((fp = fopen(file, "r")) == NULL) {
msgConfirm("Cannot open the information file `%s': %s (%d)", file, strerror(errno), errno);
return DITEM_FAILURE;
}
status = attr_parse(attr, fd);
close(fd);
status = attr_parse(attr, fp);
fclose(fp);
return status;
}
int
attr_parse(Attribs *attr, int fd)
attr_parse(Attribs *attr, FILE *fp)
{
char hold_n[MAX_NAME+1];
char hold_v[MAX_VALUE+1];
@ -67,7 +67,7 @@ attr_parse(Attribs *attr, int fd)
n = v = lno = num_attribs = 0;
state = LOOK;
while (state == COMMIT || (read(fd, &ch, 1) == 1)) {
while (state == COMMIT || (fread(&ch, 1, 1, fp) == 1)) {
/* Count lines */
if (ch == '\n')
++lno;
@ -116,7 +116,7 @@ attr_parse(Attribs *attr, int fd)
continue;
else if (ch == '{') {
/* multiline value */
while (read(fd, &ch, 1) == 1 && ch != '}') {
while (fread(&ch, 1, 1, fp) == 1 && ch != '}') {
if (v == MAX_VALUE)
msgFatal("Value length overflow at line %d", lno);
hold_v[v++] = ch;

View File

@ -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

View File

@ -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;
}

View File

@ -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 @@ deviceGetAll(void)
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 @@ deviceGetAll(void)
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 @@ deviceGetAll(void)
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 @@ deviceGetAll(void)
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;

View File

@ -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;
}

View File

@ -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;
}

674
release/sysinstall/dosio.c Normal file
View File

@ -0,0 +1,674 @@
/*
* Copyright (c) 1996 Robert Nordier
* 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.
* 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 THE AUTHOR(S) ``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 THE AUTHOR(S) 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, 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.
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <ctype.h>
#include <string.h>
#include "dosio.h"
#define SECSIZ 512 /* sector size */
#define SSHIFT 9 /* SECSIZ shift */
#define DEPSEC 16 /* directory entries per sector */
#define DSHIFT 4 /* DEPSEC shift */
#define NFATS 2 /* number of FATs */
#define DENMSZ 8 /* DE name size */
#define DEXTSZ 3 /* DE extension size */
#define DENXSZ 11 /* DE name + extension size */
#define LOCLUS 2 /* lowest cluster number */
/* DOS "BIOS Parameter Block" */
typedef struct {
u_char secsiz[2]; /* sector size */
u_char spc; /* sectors per cluster */
u_char ressec[2]; /* reserved sectors */
u_char fats; /* FATs */
u_char dirents[2]; /* root directory entries */
u_char secs[2]; /* total sectors */
u_char media; /* media descriptor */
u_char spf[2]; /* sectors per FAT */
u_char spt[2]; /* sectors per track */
u_char heads[2]; /* drive heads */
u_char hidsec[4]; /* hidden sectors */
u_char lsecs[4]; /* huge sectors */
} DOS_BPB;
/* Fixed portion of DOS boot sector */
typedef struct {
u_char jmp[3]; /* usually 80x86 'jmp' opcode */
u_char oem[8]; /* OEM name and version */
DOS_BPB bpb; /* BPB */
u_char drive; /* drive number */
u_char reserved; /* reserved */
u_char extsig; /* extended boot signature */
u_char volid[4]; /* volume ID */
u_char label[11]; /* volume label */
u_char fstype[8]; /* file system type */
} DOS_BS;
/* Supply missing "." and ".." root directory entries */
static DOS_DE dot[2] = {
{". ", " ", FA_DIR, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0}, {0x21, 0}, {0, 0}, {0, 0, 0, 0} },
{".. ", " ", FA_DIR, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0}, {0x21, 0}, {0, 0}, {0, 0, 0, 0} }
};
/* I/O error handler address */
int (*dos_ioerr)(int op) = NULL;
/* The usual conversion macros to avoid multiplication and division */
#define bytsec(n) ((n) >> (SSHIFT))
#define secbyt(s) ((u_long)(s) << (SSHIFT))
#define entsec(e) ((e) >> (DSHIFT))
#define bytblk(fs, n) ((n) >> (fs)->bshift)
#define blkbyt(fs, b) ((u_long)(b) << (fs)->bshift)
#define blksec(fs, b) ((u_long)(b) << ((fs)->bshift - (SSHIFT)))
/* Convert cluster number to offset within filesystem */
#define blkoff(fs, b) secbyt((fs)->lsndta) + blkbyt(fs, (b) - (LOCLUS))
/* Convert cluster number to logical sector number */
#define blklsn(fs, b) ((fs)->lsndta + blksec(fs, (b) - (LOCLUS)))
/* Convert cluster number to offset within FAT */
#define fatoff(fat12, c) ((u_long)(c) + ((fat12) ? (c) >> 1 : (c)))
/* Does cluster number reference a valid data cluster? */
#define okclus(fs, c) ((c) >= (LOCLUS) && (c) <= (fs)->xclus)
/* Return on error */
#define RETERR(err) { \
errno = err; \
return -1; \
}
static int dosunmount(DOS_FS *fs);
static int dosstat(DOS_FS *fs, DOS_DE *de, struct stat *sb);
static int parsebs(DOS_FS *fs, DOS_BS *bs);
static int namede(DOS_FS *fs, const char *path, DOS_DE **dep);
static DOS_DE *lookup(DOS_FS *fs, unsigned c, const u_char *nx, int *err);
static off_t fsize(DOS_FS *fs, DOS_DE *de);
static u_short fatget(DOS_FS *fs, u_short c);
static int fatend(int fat12, u_short c);
static int fatcnt(DOS_FS *fs, u_short c);
static int ioread(int fd, off_t offset, void *buf, size_t nbytes);
static int ioget(int fd, u_long lsec, void *buf, u_int nsec);
static u_char *nxname(const char *name, char **endptr);
static int sepchar(int c);
static int wildchar(int c);
static int doschar(int c);
/*
* Mount DOS filesystem
*/
int
dos_mount(DOS_FS *fs, const char *devname)
{
char buf[SECSIZ];
int err;
memset(fs, 0, sizeof(DOS_FS));
if ((fs->fd = open(devname, O_RDONLY)) == -1)
RETERR(errno);
if (!(err = ioget(fs->fd, 0, buf, 1)) &&
!(err = parsebs(fs, (DOS_BS *)buf)))
if (!(fs->fat = malloc(secbyt(fs->spf))))
err = errno;
else
err = ioget(fs->fd, fs->lsnfat, fs->fat, fs->spf);
if (err) {
dosunmount(fs);
RETERR(err);
}
fs->bsize = secbyt(fs->spc);
fs->bshift = ffs(fs->bsize) - 1;
return 0;
}
/*
* Unmount mounted filesystem
*/
int
dos_unmount(DOS_FS *fs)
{
int err;
if (fs->links)
RETERR(EBUSY);
if ((err = dosunmount(fs)))
RETERR(err);
return 0;
}
/*
* Common code shared by dos_mount() and dos_unmount()
*/
static
int dosunmount(DOS_FS *fs)
{
if (fs->fat)
free(fs->fat);
return close(fs->fd) ? errno : 0;
}
/*
* Determine free data space in filesystem (in bytes)
*/
u_long
dos_free(DOS_FS *fs)
{
unsigned n, c;
n = 0;
for (c = LOCLUS; c <= fs->xclus; c++)
if (!fatget(fs, c))
n++;
return blkbyt(fs, n);
}
/*
* Close open file
*/
int
dos_close(void *v)
{
DOS_FILE *f = v;
f->fs->links--;
free(f);
return 0;
}
/*
* Reposition with file
*/
fpos_t
dos_seek(void *v, fpos_t offset, int whence)
{
off_t off;
u_long size;
DOS_FILE *f = v;
size = cv4(f->de.size);
switch (whence) {
case SEEK_SET:
off = 0;
break;
case SEEK_CUR:
off = f->offset;
break;
case SEEK_END:
off = size;
break;
default:
RETERR(EINVAL);
}
off += offset;
if (off < 0 || off > size)
RETERR(EINVAL);
f->offset = off;
f->c = 0;
return 0;
}
/*
* Read from file
*/
int
dos_read(void *v, char *buf, int nbytes)
{
off_t size;
u_long off, cnt, n;
unsigned clus, c;
int err;
DOS_FILE *f = v;
if ((size = fsize(f->fs, &f->de)) == -1)
RETERR(EBADFS);
if (nbytes > (n = size - f->offset))
nbytes = n;
off = f->offset;
if ((clus = cv2(f->de.clus)))
off &= f->fs->bsize - 1;
c = f->c;
cnt = nbytes;
while (cnt) {
n = 0;
if (!c) {
if ((c = clus))
n = bytblk(f->fs, f->offset);
} else if (!off)
n++;
while (n--) {
c = fatget(f->fs, c);
if (!okclus(f->fs, c))
RETERR(EBADFS);
}
if (!clus || (n = f->fs->bsize - off) > cnt)
n = cnt;
if ((err = ioread(f->fs->fd, (c ? blkoff(f->fs, c) :
secbyt(f->fs->lsndir)) + off,
buf, n)))
RETERR(err);
f->offset += n;
f->c = c;
off = 0;
buf += n;
cnt -= n;
}
return nbytes;
}
/*
* Get file status
*/
int
dos_stat(DOS_FS *fs, const char *path, struct stat *sb)
{
DOS_DE *de;
int err;
if ((err = namede(fs, path, &de)) || (err = dosstat(fs, de, sb)))
RETERR(err);
return 0;
}
/*
* Get file status of open file
*/
int
dos_fstat(DOS_FILE *f, struct stat *sb)
{
int err;
if ((err = dosstat(f->fs, &f->de, sb)))
RETERR(err);
return 0;
}
/*
* File status primitive
*/
static int
dosstat(DOS_FS *fs, DOS_DE *de, struct stat *sb)
{
memset(sb, 0, sizeof(struct stat));
sb->st_mode = (de->attr & FA_DIR) ? S_IFDIR | 0777 : S_IFREG | 0666;
if (de->attr & FA_RDONLY)
sb->st_mode &= ~0222;
if (de->attr & FA_HIDDEN)
sb->st_mode &= ~0007;
if (de->attr & FA_SYSTEM)
sb->st_mode &= ~0077;
sb->st_nlink = 1;
dos_cvtime(&sb->st_atime, cv2(de->date), cv2(de->time));
sb->st_mtime = sb->st_atime;
sb->st_ctime = sb->st_atime;
if ((sb->st_size = fsize(fs, de)) == -1)
return EBADFS;
if (!(de->attr & FA_DIR) || cv2(de->clus))
sb->st_blocks = bytblk(fs, sb->st_size + fs->bsize - 1);
sb->st_blksize = fs->bsize;
return 0;
}
/*
* Convert from DOS date and time
*/
void
dos_cvtime(time_t *timer, u_short ddate, u_short dtime)
{
struct tm tm;
memset(&tm, 0, sizeof(tm));
tm.tm_sec = (dtime & 0x1f) << 1;
tm.tm_min = dtime >> 5 & 0x3f;
tm.tm_hour = dtime >> 11;
tm.tm_mday = ddate & 0x1f;
tm.tm_mon = (ddate >> 5 & 0xf) - 1;
tm.tm_year = 80 + (ddate >> 9);
*timer = mktime(&tm);
}
/*
* Open DOS file
*/
FILE *
dos_open(DOS_FS *fs, const char *path)
{
DOS_DE *de;
DOS_FILE *f;
u_long size;
u_int clus;
int err;
FILE *fp;
if ((err = namede(fs, path, &de)))
return NULL;
clus = cv2(de->clus);
size = cv4(de->size);
if ((clus && (!okclus(fs, clus) || (!(de->attr & FA_DIR) && !size))) ||
(!clus && !(de->attr & FA_DIR) && size))
return NULL;
f = (DOS_FILE *)malloc(sizeof(DOS_FILE));
memset(f, 0, sizeof(DOS_FILE));
f->fs = fs;
fs->links++;
f->de = *de;
fp = funopen(f, dos_read, NULL, dos_seek, dos_close);
return fp;
}
/*
* Parse DOS boot sector
*/
static int
parsebs(DOS_FS *fs, DOS_BS *bs)
{
u_long sc;
if ((bs->jmp[0] != 0xe9 && (bs->jmp[0] != 0xeb || bs->jmp[2] != 0x90)) ||
bs->bpb.media < 0xf0 ||
cv2(bs->bpb.secsiz) != SECSIZ ||
!bs->bpb.spc || (bs->bpb.spc ^ (bs->bpb.spc - 1)) < bs->bpb.spc)
return EINVAL;
fs->spf = cv2(bs->bpb.spf);
fs->dirents = cv2(bs->bpb.dirents);
fs->spc = bs->bpb.spc;
sc = cv2(bs->bpb.secs);
if (!sc && bs->extsig == 0x29)
sc = cv4(bs->bpb.lsecs);
if (!sc || bs->bpb.fats != NFATS || bs->bpb.spc > 64)
return EINVAL;
if (!fs->dirents || fs->dirents & (DEPSEC - 1))
return EINVAL;
fs->lsnfat = cv2(bs->bpb.ressec);
fs->lsndir = fs->lsnfat + (u_long)fs->spf * NFATS;
fs->lsndta = fs->lsndir + entsec(fs->dirents);
if (fs->lsndta > sc || !(sc = (sc - fs->lsndta) / fs->spc) || sc >= 0xfff6)
return EINVAL;
fs->fat12 = sc < 0xff6;
fs->xclus = sc + 1;
if (fs->spf < bytsec(fatoff(fs->fat12, fs->xclus) + SECSIZ))
return EINVAL;
if (bs->extsig == 0x29)
fs->volid = cv4(bs->volid);
return 0;
}
/*
* Return directory entry from path
*/
static int
namede(DOS_FS *fs, const char *path, DOS_DE **dep)
{
DOS_DE *de;
u_char *nx;
int err;
err = 0;
de = dot;
if (*path == '/')
path++;
while (*path) {
if (!(nx = nxname(path, (char **)&path)))
return EINVAL;
if (!(de->attr & FA_DIR))
return ENOTDIR;
if (!(de = lookup(fs, cv2(de->clus), nx, &err)))
return err ? err : ENOENT;
if (*path == '/')
path++;
}
*dep = de;
return 0;
}
/*
* Lookup path segment
*/
static DOS_DE *
lookup(DOS_FS *fs, unsigned c, const u_char *nx, int *err)
{
static DOS_DE dir[DEPSEC];
u_long lsec;
u_int nsec;
int s, e;
if (!c)
for (e = 0; e < 2; e++)
if (!memcmp(dot + e, nx, DENXSZ))
return dot + e;
nsec = !c ? entsec(fs->dirents) : fs->spc;
lsec = 0;
do {
if (!c && !lsec)
lsec = fs->lsndir;
else if okclus(fs, c)
lsec = blklsn(fs, c);
else {
*err = EBADFS;
return NULL;
}
for (s = 0; s < nsec; s++) {
if ((e = ioget(fs->fd, lsec + s, dir, 1))) {
*err = e;
return NULL;
}
for (e = 0; e < DEPSEC; e++) {
if (!*dir[e].name)
return NULL;
if (*dir[e].name == 0xe5 || dir[e].attr & FA_LABEL)
continue;
if (!memcmp(dir + e, nx, DENXSZ))
return dir + e;
}
}
} while (c && !fatend(fs->fat12, c = fatget(fs, c)));
return NULL;
}
/*
* Return size of file in bytes
*/
static off_t
fsize(DOS_FS *fs, DOS_DE *de)
{
u_long size;
u_int c;
int n;
if (!(size = cv4(de->size)) && de->attr & FA_DIR)
if (!(c = cv2(de->clus)))
size = fs->dirents * sizeof(DOS_DE);
else {
if ((n = fatcnt(fs, c)) == -1)
return n;
size = blkbyt(fs, n);
}
return size;
}
/*
* Return next cluster in cluster chain
*/
static u_short
fatget(DOS_FS *fs, u_short c)
{
u_short x;
x = cv2(fs->fat + fatoff(fs->fat12, c));
return fs->fat12 ? c & 1 ? x >> 4 : x & 0xfff : x;
}
/*
* Count number of clusters in chain
*/
static int
fatcnt(DOS_FS *fs, u_short c)
{
int n;
for (n = 0; okclus(fs, c); n++)
c = fatget(fs, c);
return fatend(fs->fat12, c) ? n : -1;
}
/*
* Is cluster an end-of-chain marker?
*/
static int
fatend(int fat12, u_short c)
{
return c > (fat12 ? 0xff7 : 0xfff7) || c == 0xfff0;
}
/*
* Offset-based I/O primitive
*/
static int
ioread(int fd, off_t offset, void *buf, size_t nbytes)
{
char tmp[SECSIZ];
u_int off, n;
int err;
if ((off = offset & (SECSIZ - 1))) {
offset -= off;
if ((err = ioget(fd, bytsec(offset), tmp, 1)))
return err;
offset += SECSIZ;
if ((n = SECSIZ - off) > nbytes)
n = nbytes;
memcpy(buf, tmp + off, n);
buf += n;
nbytes -= n;
}
n = nbytes & (SECSIZ - 1);
if (nbytes -= n) {
if ((err = ioget(fd, bytsec(offset), buf, bytsec(nbytes))))
return err;
offset += nbytes;
buf += nbytes;
}
if (n) {
if ((err = ioget(fd, bytsec(offset), tmp, 1)))
return err;
memcpy(buf, tmp, n);
}
return 0;
}
/*
* Sector-based I/O primitive
*/
static int
ioget(int fd, u_long lsec, void *buf, u_int nsec)
{
size_t nbytes;
ssize_t n;
nbytes = secbyt(nsec);
do {
if (lseek(fd, secbyt(lsec), SEEK_SET) == -1)
return errno;
n = read(fd, buf, nbytes);
} while (n == -1 && errno == EIO && dos_ioerr && dos_ioerr(0));
if (n != nbytes)
return n == -1 ? errno : EIO;
return 0;
}
/*
* Convert name to DOS directory (name + extension) format
*/
static u_char *
nxname(const char *name, char **endptr)
{
static u_char nx[DENXSZ];
int i;
memset(nx, ' ', sizeof(nx));
for (i = 0; i < DENMSZ && doschar(*name); i++)
nx[i] = toupper(*name++);
if (i) {
if (i == DENMSZ)
while (!sepchar(*name))
name++;
if (*name == '.') {
name++;
for (i = 0; i < DEXTSZ && doschar(*name); i++)
nx[DENMSZ + i] = toupper(*name++);
if (i == DEXTSZ)
while(!sepchar(*name))
name++;
}
} else if (*name == '.') {
nx[0] = *name++;
if (*name == '.')
nx[1] = *name++;
}
if ((*name && *name != '/') || *nx == ' ')
return NULL;
if (*nx == 0xe5)
*nx = 5;
*endptr = (char *)name;
return nx;
}
/*
* Is character a path-separator?
*/
static int
sepchar(int c)
{
return !wildchar(c) && !doschar(c);
}
/*
* Is character a wildcard?
*/
static int
wildchar(int c)
{
return c == '*' || c == '?';
}
/*
* Is character valid in a DOS name?
*/
static int
doschar(int c)
{
return c & 0x80 || (c >= ' ' && !strchr("\"*+,./:;<=>?[\\]|", c));
}

118
release/sysinstall/dosio.h Normal file
View File

@ -0,0 +1,118 @@
/*
* Copyright (c) 1996 Robert Nordier
* 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.
* 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 THE AUTHOR(S) ``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 THE AUTHOR(S) 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, 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.
*/
#ifndef DOSIO_H
#define DOSIO_H
/*
* DOS file attributes
*/
#define FA_RDONLY 0x01 /* read-only */
#define FA_HIDDEN 0x02 /* hidden file */
#define FA_SYSTEM 0x04 /* system file */
#define FA_LABEL 0x08 /* volume label */
#define FA_DIR 0x10 /* directory */
#define FA_ARCH 0x20 /* archive (file modified) */
/*
* Error number to overload if filesystem errors are detected during
* routine processing
*/
#define EBADFS EINVAL
/*
* Macros to convert DOS-format 16-bit and 32-bit quantities
*/
#define cv2(p) ((u_short)(p)[0] | \
((u_short)(p)[1] << 010))
#define cv4(p) ((u_long)(p)[0] | \
((u_long)(p)[1] << 010) | \
((u_long)(p)[2] << 020) | \
((u_long)(p)[3] << 030))
/*
* DOS directory structure
*/
typedef struct {
u_char name[8]; /* name */
u_char ext[3]; /* extension */
u_char attr; /* attributes */
u_char reserved[10]; /* reserved */
u_char time[2]; /* time */
u_char date[2]; /* date */
u_char clus[2]; /* starting cluster */
u_char size[4]; /* file size */
} DOS_DE;
typedef struct {
u_char *fat; /* FAT */
u_long volid; /* volume id */
u_long lsnfat; /* logical sector number: fat */
u_long lsndir; /* logical sector number: dir */
u_long lsndta; /* logical sector number: data area */
short fd; /* file descriptor */
short fat12; /* 12-bit FAT entries */
u_short spf; /* sectors per fat */
u_short dirents; /* root directory entries */
u_short spc; /* sectors per cluster */
u_short xclus; /* maximum cluster number */
u_short bsize; /* cluster size in bytes */
u_short bshift; /* cluster conversion shift */
u_short links; /* active links to structure */
} DOS_FS;
typedef struct {
DOS_FS *fs; /* associated filesystem */
DOS_DE de; /* directory entry */
u_long offset; /* current offset */
u_short c; /* last cluster read */
} DOS_FILE;
/*
* The following variable can be set to the address of an error-handling
* routine which will be invoked when a read() returns EIO. The handler
* should return 1 to retry the read, otherwise 0.
*/
extern int (*dos_ioerr)(int op);
int dos_mount(DOS_FS *fs, const char *devname);
int dos_unmount(DOS_FS *fs);
u_long dos_free(DOS_FS *fs);
FILE *dos_open(DOS_FS *fs, const char *path);
int dos_close(void *v);
fpos_t dos_seek(void *v, fpos_t offset, int whence);
int dos_read(void *v, char *buf, int nbytes);
int dos_stat(DOS_FS *fs, const char *path, struct stat *sb);
int dos_fstat(DOS_FILE *f, struct stat *sb);
void dos_cvtime(time_t *timer, u_short ddate, u_short dtime);
#endif /* !DOSIO_H */

View File

@ -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

View File

@ -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);
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;
}
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++;
}
return buf;
}
static int
get_a_number(FTP_t ftp, char **q)
{
char *p;
int i = -1,j;
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;
}
}
}
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;
}
msgDebug("Init routine for FTP called.\n");
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;
if (OpenConn) {
fclose(OpenConn);
OpenConn = NULL;
}
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);
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;
}
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!");
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;
}
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);
/* 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;
}
if (isDebug())
msgDebug("mediaInitFTP was successful (logged in and chdir'd)\n");
ftpInitted = TRUE;
return TRUE;
if ((s = socket(ftp->addrtype, SOCK_STREAM, 0)) < 0)
{
debug(ftp, "Socket open failed: %s (%i)\n", strerror(errno), errno);
return zap(ftp);
punt:
if (OpenConn != NULL) {
fclose(OpenConn);
OpenConn = NULL;
}
variable_unset(VAR_FTP_PATH);
return FALSE;
}
FILE *
mediaGetFTP(Device *dev, char *file, Boolean probe)
{
int nretries = 1;
FILE *fp;
char *try, buf[PATH_MAX];
if (!OpenConn) {
msgDebug("No FTP connection open, can't get file %s\n", file);
return NULL;
}
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);
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
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->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);
}
ftp->state = isopen;
return 0;
return fp;
}
void
FtpClose(FTP_t ftp)
mediaShutdownFTP(Device *dev)
{
if (ftp->state != init)
/* Device *netdev = (Device *)dev->private; */
if (!ftpInitted)
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;
}
int
FtpGet(FTP_t ftp, char *file)
{
int i,s;
char *q;
unsigned char addr[64];
struct sockaddr_in sin;
u_long a;
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;
}
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);
else
return -1;
}
ftp->fd_xfer = accept(s, 0, 0);
if (ftp->fd_xfer < 0) {
close(s);
return zap(ftp);
}
ftp->state = xfer;
close(s);
return(ftp->fd_xfer);
if (isDebug())
msgDebug("FTP shutdown called. OpenConn = %x\n", OpenConn);
if (OpenConn != NULL) {
fclose(OpenConn);
OpenConn = NULL;
}
/* (*netdev->shutdown)(netdev); */
ftpInitted = FALSE;
}
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)
{
FTP_t ftp;
int i;
char c;
ftp = FtpInit();
if (!ftp)
err(1, "FtpInit()");
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;
}
#endif /*STANDALONE_FTP*/

View File

@ -1,29 +0,0 @@
#ifndef _FTP_H_INCLUDE
#define _FTP_H_INCLUDE
typedef struct {
enum {init, isopen, xfer} state;
int fd_ctrl;
int fd_xfer;
int fd_debug;
int binary;
int passive;
int addrtype;
char *host;
char *file;
} *FTP_t;
FTP_t FtpInit();
int FtpOpen(FTP_t, char *host, char *user, char *passwd);
#define FtpBinary(ftp,bool) { (ftp)->binary = (bool); }
#define FtpPassive(ftp,bool) { (ftp)->passive = (bool); }
#ifndef STANDALONE_FTP
#define FtpDebug(ftp, bool) { (ftp)->fd_debug = (bool); }
#endif
int FtpChdir(FTP_t, char *);
int FtpGet(FTP_t, char *);
int FtpEOF(FTP_t);
void FtpClose(FTP_t);
#endif
/* _FTP_H_INCLUDE */

View File

@ -1,232 +0,0 @@
/*
* The new sysinstall program.
*
* 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.29 1996/10/12 23:48:31 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.
*
*/
#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 "ftp.h"
Boolean ftpInitted = FALSE;
static FTP_t ftp;
extern int FtpPort;
static char *lastRequest;
Boolean
mediaInitFTP(Device *dev)
{
int i;
char *cp, *rel, *hostname, *dir;
char *user, *login_name, password[80];
if (ftpInitted)
return TRUE;
if (isDebug())
msgDebug("Init routine for FTP called.\n");
if (!ftp && (ftp = FtpInit()) == NULL) {
msgConfirm("FTP initialisation failed!");
return FALSE;
}
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;
}
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!");
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 (FtpOpen(ftp, hostname, login_name, password) != 0) {
if (variable_get(VAR_NO_CONFIRM))
msgNotify("Couldn't open FTP connection to %s", hostname);
else
msgConfirm("Couldn't open FTP connection to %s", hostname);
goto punt;
}
FtpPassive(ftp, !strcmp(variable_get(VAR_FTP_STATE), "passive"));
FtpBinary(ftp, 1);
if (dir && *dir != '\0') {
if (FtpChdir(ftp, dir) == IO_ERROR) {
msgDebug("Attempt to chdir to distribution in %s returns I/O error\n", dir);
goto punt;
}
}
/* 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(ftp, rel);
else
i = 0;
if (i == -1) {
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;
}
else if (i == IO_ERROR)
goto punt;
if (isDebug())
msgDebug("mediaInitFTP was successful (logged in and chdir'd)\n");
ftpInitted = TRUE;
return TRUE;
punt:
if (ftp != NULL) {
FtpClose(ftp);
ftp = NULL;
}
variable_unset(VAR_FTP_PATH);
return FALSE;
}
int
mediaGetFTP(Device *dev, char *file, Boolean probe)
{
int fd;
int nretries;
char *fp;
char buf[PATH_MAX];
fp = file;
nretries = 0;
lastRequest = file;
while ((fd = FtpGet(ftp, fp)) < 0) {
/* If a hard fail, try to "bounce" the ftp server to clear it */
if (fd == IO_ERROR) {
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))
return IO_ERROR;
else
variable_set2(VAR_FTP_PATH, cp);
}
else if (probe)
return EOF;
else {
/* Try some alternatives */
switch (nretries) {
case 1:
sprintf(buf, "dists/%s", file);
fp = buf;
break;
case 2:
sprintf(buf, "%s/%s", variable_get(VAR_RELNAME), file);
fp = buf;
break;
case 3:
sprintf(buf, "%s/dists/%s", variable_get(VAR_RELNAME), file);
fp = buf;
break;
case 4:
fp = file;
break;
}
}
}
return fd;
}
Boolean
mediaCloseFTP(Device *dev, int fd)
{
if (isDebug())
msgDebug("FTP Close called\n");
if (ftp)
FtpEOF(ftp);
return FALSE;
}
void
mediaShutdownFTP(Device *dev)
{
/* Device *netdev = (Device *)dev->private; */
if (!ftpInitted)
return;
if (isDebug())
msgDebug("FTP shutdown called. FTP = %x\n", ftp);
if (ftp != NULL) {
FtpClose(ftp);
ftp = NULL;
}
/* (*netdev->shutdown)(netdev); */
ftpInitted = FALSE;
}

View File

@ -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;

View File

@ -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);
}

View File

@ -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);

View File

@ -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 */

View File

@ -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

View File

@ -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"

View File

@ -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);

View File

@ -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

View File

@ -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");
}

View File

@ -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

View File

@ -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;
}

View File

@ -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 @@ deviceGetAll(void)
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 @@ deviceGetAll(void)
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 @@ deviceGetAll(void)
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 @@ deviceGetAll(void)
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;

View File

@ -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);
}

View File

@ -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);

View File

@ -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

View File

@ -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

View File

@ -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;
}

View File

@ -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 @@ deviceGetAll(void)
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 @@ deviceGetAll(void)
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 @@ deviceGetAll(void)
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 @@ deviceGetAll(void)
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;

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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

View File

@ -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);
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;
}
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++;
}
return buf;
}
static int
get_a_number(FTP_t ftp, char **q)
{
char *p;
int i = -1,j;
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;
}
}
}
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;
}
msgDebug("Init routine for FTP called.\n");
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;
if (OpenConn) {
fclose(OpenConn);
OpenConn = NULL;
}
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);
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;
}
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!");
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;
}
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);
/* 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;
}
if (isDebug())
msgDebug("mediaInitFTP was successful (logged in and chdir'd)\n");
ftpInitted = TRUE;
return TRUE;
if ((s = socket(ftp->addrtype, SOCK_STREAM, 0)) < 0)
{
debug(ftp, "Socket open failed: %s (%i)\n", strerror(errno), errno);
return zap(ftp);
punt:
if (OpenConn != NULL) {
fclose(OpenConn);
OpenConn = NULL;
}
variable_unset(VAR_FTP_PATH);
return FALSE;
}
FILE *
mediaGetFTP(Device *dev, char *file, Boolean probe)
{
int nretries = 1;
FILE *fp;
char *try, buf[PATH_MAX];
if (!OpenConn) {
msgDebug("No FTP connection open, can't get file %s\n", file);
return NULL;
}
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);
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
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->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);
}
ftp->state = isopen;
return 0;
return fp;
}
void
FtpClose(FTP_t ftp)
mediaShutdownFTP(Device *dev)
{
if (ftp->state != init)
/* Device *netdev = (Device *)dev->private; */
if (!ftpInitted)
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;
}
int
FtpGet(FTP_t ftp, char *file)
{
int i,s;
char *q;
unsigned char addr[64];
struct sockaddr_in sin;
u_long a;
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;
}
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);
else
return -1;
}
ftp->fd_xfer = accept(s, 0, 0);
if (ftp->fd_xfer < 0) {
close(s);
return zap(ftp);
}
ftp->state = xfer;
close(s);
return(ftp->fd_xfer);
if (isDebug())
msgDebug("FTP shutdown called. OpenConn = %x\n", OpenConn);
if (OpenConn != NULL) {
fclose(OpenConn);
OpenConn = NULL;
}
/* (*netdev->shutdown)(netdev); */
ftpInitted = FALSE;
}
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)
{
FTP_t ftp;
int i;
char c;
ftp = FtpInit();
if (!ftp)
err(1, "FtpInit()");
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;
}
#endif /*STANDALONE_FTP*/

View File

@ -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;

View File

@ -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);
}

View File

@ -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);

View File

@ -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 */

View File

@ -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

View File

@ -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"

View File

@ -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);

View File

@ -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

View File

@ -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");
}