Use the new mkdtemp() instead of mktemp();mkdir().
Various cleanups (and typecasts) to get lint quiet. Add remaining prototypes, enable -Wmissing-prototypes -Wstrict-prototypes.
This commit is contained in:
parent
57ae5a9baa
commit
fa0aee147e
@ -1,4 +1,4 @@
|
||||
# $NetBSD: Makefile,v 1.5 1998/03/02 19:57:01 cgd Exp $
|
||||
# $NetBSD: Makefile,v 1.6 1998/07/28 20:10:53 drochner Exp $
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
||||
@ -10,7 +10,7 @@ SRCS= installboot.c bootblks.c getmount.c
|
||||
NOMAN= yes
|
||||
|
||||
CPPFLAGS= -I${.CURDIR}/../lib/crt/bootsect
|
||||
CFLAGS+= -Wall
|
||||
CFLAGS+= -Wall -Wmissing-prototypes -Wstrict-prototypes
|
||||
LDSTATIC?=-static
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: bootblks.c,v 1.2 1997/07/21 18:04:35 drochner Exp $ */
|
||||
/* $NetBSD: bootblks.c,v 1.3 1998/07/28 20:10:54 drochner Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996
|
||||
@ -51,7 +51,7 @@ ino_t
|
||||
createfileondev(diskdev, bootblkname, bp, size)
|
||||
char *diskdev, *bootblkname;
|
||||
char *bp;
|
||||
int size;
|
||||
unsigned int size;
|
||||
{
|
||||
char *mntpoint;
|
||||
int fd = -1;
|
||||
@ -66,17 +66,17 @@ createfileondev(diskdev, bootblkname, bp, size)
|
||||
* try to rename existing file before
|
||||
*/
|
||||
havebackup = 0;
|
||||
sprintf(bootblkpath, "%s/%s", mntpoint, bootblkname);
|
||||
sprintf(backuppath, "%s%s", bootblkpath, backupext);
|
||||
if(rename(bootblkpath, backuppath) == -1) {
|
||||
if(errno != ENOENT) {
|
||||
(void) sprintf(bootblkpath, "%s/%s", mntpoint, bootblkname);
|
||||
(void) sprintf(backuppath, "%s%s", bootblkpath, backupext);
|
||||
if (rename(bootblkpath, backuppath) == -1) {
|
||||
if (errno != ENOENT) {
|
||||
warn("rename old %s", bootblkpath);
|
||||
goto out;
|
||||
}
|
||||
} else {
|
||||
if(verbose)
|
||||
fprintf(stderr, "renamed %s -> %s\n",
|
||||
bootblkpath, backuppath);
|
||||
if (verbose)
|
||||
(void) fprintf(stderr, "renamed %s -> %s\n",
|
||||
bootblkpath, backuppath);
|
||||
havebackup = 1;
|
||||
}
|
||||
fd = open(bootblkpath, O_RDWR | O_CREAT | O_EXCL, 0444);
|
||||
@ -103,12 +103,12 @@ createfileondev(diskdev, bootblkname, bp, size)
|
||||
|
||||
out:
|
||||
if (fd != -1) {
|
||||
close(fd);
|
||||
(void) close(fd);
|
||||
if (!allok)
|
||||
unlink(bootblkpath);
|
||||
(void) unlink(bootblkpath);
|
||||
}
|
||||
if(!allok && havebackup)
|
||||
rename(backuppath, bootblkpath);
|
||||
if (!allok && havebackup)
|
||||
(void) rename(backuppath, bootblkpath);
|
||||
cleanupmount(mntpoint);
|
||||
return (allok ? statbuf.st_ino : (ino_t) - 1);
|
||||
}
|
||||
@ -116,30 +116,31 @@ out:
|
||||
void
|
||||
cleanupfileondev(diskdev, bootblkname, recover)
|
||||
char *diskdev, *bootblkname;
|
||||
int recover;
|
||||
{
|
||||
char *mntpoint;
|
||||
|
||||
/* save some work if nothing to do */
|
||||
if(!(recover || havebackup))
|
||||
if (!(recover || havebackup))
|
||||
return;
|
||||
|
||||
if ((mntpoint = getmountpoint(diskdev)) == NULL)
|
||||
return;
|
||||
|
||||
sprintf(bootblkpath, "%s/%s", mntpoint, bootblkname);
|
||||
sprintf(backuppath, "%s%s", bootblkpath, backupext);
|
||||
(void) sprintf(bootblkpath, "%s/%s", mntpoint, bootblkname);
|
||||
(void) sprintf(backuppath, "%s%s", bootblkpath, backupext);
|
||||
|
||||
if(recover) {
|
||||
unlink(bootblkpath);
|
||||
if(havebackup) {
|
||||
fprintf(stderr, "renaming %s -> %s\n",
|
||||
backuppath, bootblkpath);
|
||||
rename(backuppath, bootblkpath);
|
||||
if (recover) {
|
||||
(void) unlink(bootblkpath);
|
||||
if (havebackup) {
|
||||
(void) fprintf(stderr, "renaming %s -> %s\n",
|
||||
backuppath, bootblkpath);
|
||||
(void) rename(backuppath, bootblkpath);
|
||||
}
|
||||
} else if(havebackup) {
|
||||
if(verbose)
|
||||
fprintf(stderr, "deleting %s\n", backuppath);
|
||||
unlink(backuppath);
|
||||
} else if (havebackup) {
|
||||
if (verbose)
|
||||
(void) fprintf(stderr, "deleting %s\n", backuppath);
|
||||
(void) unlink(backuppath);
|
||||
}
|
||||
|
||||
cleanupmount(mntpoint);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: getmount.c,v 1.4 1998/06/01 14:13:34 kleink Exp $ */
|
||||
/* $NetBSD: getmount.c,v 1.5 1998/07/28 20:10:54 drochner Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996
|
||||
@ -46,6 +46,9 @@
|
||||
|
||||
static int tempmounted = 0;
|
||||
|
||||
static char *getbdev __P((char *));
|
||||
static char *dotempmount __P((char *));
|
||||
|
||||
/* make block device name from character device name */
|
||||
static char *
|
||||
getbdev(dev)
|
||||
@ -57,7 +60,7 @@ getbdev(dev)
|
||||
warnx("bad device name %s", dev);
|
||||
return (0);
|
||||
}
|
||||
sprintf(bdiskdev, "/dev/%s", dev + 6);
|
||||
(void) sprintf(bdiskdev, "/dev/%s", dev + 6);
|
||||
return (bdiskdev);
|
||||
}
|
||||
|
||||
@ -69,15 +72,12 @@ static char *
|
||||
dotempmount(bdiskdev)
|
||||
char *bdiskdev;
|
||||
{
|
||||
static char dir[] = "/tmp/installbootXXXXXX";
|
||||
static char dirtmpl[] = "/tmp/installbootXXXXXX";
|
||||
char *dir;
|
||||
struct ufs_args data;
|
||||
|
||||
if (mktemp(dir) == NULL) {
|
||||
warnx("mktemp failed");
|
||||
return (0);
|
||||
}
|
||||
if (mkdir(dir, 0700)) {
|
||||
warn("could not create temporary dir %s", dir);
|
||||
if ((dir = mkdtemp(dirtmpl)) == NULL) {
|
||||
warnx("mkdtemp failed");
|
||||
return (0);
|
||||
}
|
||||
bzero(&data, sizeof(data));
|
||||
@ -86,11 +86,11 @@ dotempmount(bdiskdev)
|
||||
/* this code if FFS only */
|
||||
if (mount(MOUNT_FFS, dir, 0, &data) == -1) {
|
||||
warn("mount %s->%s failed", bdiskdev, dir);
|
||||
rmdir(dir);
|
||||
(void) rmdir(dir);
|
||||
return (0);
|
||||
}
|
||||
if (verbose)
|
||||
fprintf(stderr, "mounted %s at %s\n", bdiskdev, dir);
|
||||
(void) fprintf(stderr, "mounted %s at %s\n", bdiskdev, dir);
|
||||
tempmounted = 1;
|
||||
return (dir);
|
||||
}
|
||||
@ -139,7 +139,7 @@ getmountpoint(diskdev)
|
||||
return (buf[i].f_mntonname);
|
||||
}
|
||||
if (verbose)
|
||||
fprintf(stderr, "%s is not mounted\n", bdiskdev);
|
||||
(void) fprintf(stderr, "%s is not mounted\n", bdiskdev);
|
||||
return (dotempmount(bdiskdev));
|
||||
}
|
||||
|
||||
@ -149,9 +149,9 @@ cleanupmount(dir)
|
||||
{
|
||||
if (tempmounted) {
|
||||
if (verbose)
|
||||
fprintf(stderr, "unmounting\n");
|
||||
unmount(dir, 0);
|
||||
rmdir(dir);
|
||||
(void) fprintf(stderr, "unmounting\n");
|
||||
(void) unmount(dir, 0);
|
||||
(void) rmdir(dir);
|
||||
tempmounted = 0;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: installboot.c,v 1.5 1997/11/01 06:49:50 lukem Exp $ */
|
||||
/* $NetBSD: installboot.c,v 1.6 1998/07/28 20:10:54 drochner Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1994 Paul Kranenburg
|
||||
@ -61,6 +61,13 @@
|
||||
|
||||
#define DEFBBLKNAME "boot"
|
||||
|
||||
char *loadprotoblocks __P((char *, size_t *));
|
||||
static int devread __P((int, void *, daddr_t, size_t, char *));
|
||||
static int add_fsblk __P((struct fs *, daddr_t, int));
|
||||
int loadblocknums __P((char *, ino_t));
|
||||
static void usage __P((void));
|
||||
int main __P((int, char **));
|
||||
|
||||
struct fraglist *fraglist;
|
||||
|
||||
struct nlist nl[] = {
|
||||
@ -74,7 +81,7 @@ int verbose = 0;
|
||||
char *
|
||||
loadprotoblocks(fname, size)
|
||||
char *fname;
|
||||
long *size;
|
||||
size_t *size;
|
||||
{
|
||||
int fd;
|
||||
size_t tdsize; /* text+data size */
|
||||
@ -114,7 +121,7 @@ loadprotoblocks(fname, size)
|
||||
/*
|
||||
* We need only text and data.
|
||||
*/
|
||||
tdsize = eh.a_text + eh.a_data;
|
||||
tdsize = (size_t)(eh.a_text + eh.a_data);
|
||||
bbsize = roundup(tdsize, DEV_BSIZE);
|
||||
|
||||
if ((bp = calloc(bbsize, 1)) == NULL) {
|
||||
@ -128,6 +135,7 @@ loadprotoblocks(fname, size)
|
||||
}
|
||||
*size = bbsize; /* aligned to DEV_BSIZE */
|
||||
|
||||
/* NOSTRICT */
|
||||
fraglist = (struct fraglist *) (bp + nl[X_fraglist].n_value);
|
||||
|
||||
if (fraglist->magic != FRAGLISTMAGIC) {
|
||||
@ -135,19 +143,22 @@ loadprotoblocks(fname, size)
|
||||
goto bad;
|
||||
}
|
||||
if (verbose) {
|
||||
fprintf(stderr, "%s: entry point %#lx\n", fname, eh.a_entry);
|
||||
fprintf(stderr, "proto bootblock size %ld\n", *size);
|
||||
fprintf(stderr, "room for %d filesystem blocks at %#lx\n",
|
||||
fraglist->maxentries, nl[X_fraglist].n_value);
|
||||
(void) fprintf(stderr, "%s: entry point %#lx\n", fname,
|
||||
eh.a_entry);
|
||||
(void) fprintf(stderr, "proto bootblock size %ld\n",
|
||||
(long)*size);
|
||||
(void) fprintf(stderr, "room for %d filesystem blocks"
|
||||
" at %#lx\n", fraglist->maxentries,
|
||||
nl[X_fraglist].n_value);
|
||||
}
|
||||
close(fd);
|
||||
(void) close(fd);
|
||||
return bp;
|
||||
|
||||
bad:
|
||||
if (bp)
|
||||
free(bp);
|
||||
if (fd >= 0)
|
||||
close(fd);
|
||||
(void) close(fd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -159,7 +170,7 @@ devread(fd, buf, blk, size, msg)
|
||||
size_t size;
|
||||
char *msg;
|
||||
{
|
||||
if (lseek(fd, dbtob(blk), SEEK_SET) != dbtob(blk)) {
|
||||
if (lseek(fd, (off_t)dbtob(blk), SEEK_SET) != dbtob(blk)) {
|
||||
warn("%s: devread: lseek", msg);
|
||||
return (1);
|
||||
}
|
||||
@ -186,7 +197,7 @@ add_fsblk(fs, blk, blcnt)
|
||||
nblk = blcnt;
|
||||
|
||||
if (verbose)
|
||||
fprintf(stderr, "dblk: %d, num: %d\n", blk, nblk);
|
||||
(void) fprintf(stderr, "dblk: %d, num: %d\n", blk, nblk);
|
||||
|
||||
/* start new entry or append to previous? */
|
||||
if (!fraglist->numentries ||
|
||||
@ -196,7 +207,7 @@ add_fsblk(fs, blk, blcnt)
|
||||
/* need new entry */
|
||||
if (fraglist->numentries > fraglist->maxentries - 1) {
|
||||
errx(1, "not enough fragment space in bootcode\n");
|
||||
return(-1);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
fraglist->entries[fraglist->numentries].offset = blk;
|
||||
@ -207,7 +218,10 @@ add_fsblk(fs, blk, blcnt)
|
||||
return (blcnt - nblk);
|
||||
}
|
||||
|
||||
static char sblock[SBSIZE];
|
||||
static union {
|
||||
char c[SBSIZE];
|
||||
struct fs s;
|
||||
} sblock;
|
||||
|
||||
int
|
||||
loadblocknums(diskdev, inode)
|
||||
@ -228,31 +242,31 @@ loadblocknums(diskdev, inode)
|
||||
return (1);
|
||||
}
|
||||
/* Read superblock */
|
||||
if (devread(devfd, sblock, SBLOCK, SBSIZE, "superblock"))
|
||||
if (devread(devfd, &sblock, SBLOCK, SBSIZE, "superblock"))
|
||||
goto out;
|
||||
fs = (struct fs *) sblock;
|
||||
fs = &sblock.s;
|
||||
|
||||
if (fs->fs_magic != FS_MAGIC) {
|
||||
warnx("invalid super block");
|
||||
goto out;
|
||||
}
|
||||
/* Read inode */
|
||||
if ((buf = malloc(fs->fs_bsize)) == NULL) {
|
||||
if ((buf = malloc((size_t)fs->fs_bsize)) == NULL) {
|
||||
warnx("No memory for filesystem block");
|
||||
goto out;
|
||||
}
|
||||
blk = fsbtodb(fs, ino_to_fsba(fs, inode));
|
||||
if (devread(devfd, buf, blk, fs->fs_bsize, "inode"))
|
||||
if (devread(devfd, buf, blk, (size_t)fs->fs_bsize, "inode"))
|
||||
goto out;
|
||||
ip = (struct dinode *) (buf) + ino_to_fsbo(fs, inode);
|
||||
ip = (struct dinode *)buf + ino_to_fsbo(fs, inode);
|
||||
|
||||
/*
|
||||
* Have the inode. Figure out how many blocks we need.
|
||||
*/
|
||||
ndb = ip->di_size / DEV_BSIZE; /* size is rounded! */
|
||||
ndb = (int)(ip->di_size / DEV_BSIZE); /* size is rounded! */
|
||||
|
||||
if (verbose)
|
||||
fprintf(stderr, "Will load %d blocks.\n", ndb);
|
||||
(void) fprintf(stderr, "Will load %d blocks.\n", ndb);
|
||||
|
||||
/*
|
||||
* Get the block numbers, first direct blocks
|
||||
@ -267,7 +281,8 @@ loadblocknums(diskdev, inode)
|
||||
* for more in the 1st-level bootblocks anyway.
|
||||
*/
|
||||
blk = fsbtodb(fs, ip->di_ib[0]);
|
||||
if (devread(devfd, buf, blk, fs->fs_bsize, "indirect block"))
|
||||
if (devread(devfd, buf, blk, (size_t)fs->fs_bsize,
|
||||
"indirect block"))
|
||||
goto out;
|
||||
ap = (daddr_t *) buf;
|
||||
for (; i < NINDIR(fs) && *ap && ndb > 0; i++, ap++) {
|
||||
@ -288,15 +303,15 @@ out:
|
||||
if (buf)
|
||||
free(buf);
|
||||
if (devfd >= 0)
|
||||
close(devfd);
|
||||
(void) close(devfd);
|
||||
return (!allok);
|
||||
}
|
||||
|
||||
static void
|
||||
usage()
|
||||
{
|
||||
fprintf(stderr,
|
||||
"usage: installboot [-n] [-v] [-f] <boot> <device>\n");
|
||||
(void) fprintf(stderr,
|
||||
"usage: installboot [-n] [-v] [-f] <boot> <device>\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@ -305,8 +320,9 @@ main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
char c, *bp = 0;
|
||||
long size;
|
||||
int c;
|
||||
char *bp = 0;
|
||||
size_t size;
|
||||
ino_t inode = (ino_t) -1;
|
||||
int devfd = -1;
|
||||
struct disklabel dl;
|
||||
@ -357,7 +373,7 @@ main(argc, argv)
|
||||
|
||||
/* paranoia */
|
||||
sync();
|
||||
sleep(3);
|
||||
(void) sleep(3);
|
||||
|
||||
if (loadblocknums(argv[optind + 1], inode))
|
||||
goto out;
|
||||
@ -384,16 +400,17 @@ main(argc, argv)
|
||||
goto out;
|
||||
}
|
||||
} else {
|
||||
char c = argv[optind + 1][strlen(argv[optind + 1]) - 1];
|
||||
char p = argv[optind + 1][strlen(argv[optind + 1]) - 1];
|
||||
#define isvalidpart(c) ((c) >= 'a' && (c) <= 'z')
|
||||
if(!isvalidpart(c) || (c - 'a') >= dl.d_npartitions) {
|
||||
if (!isvalidpart(p) || (p - 'a') >= dl.d_npartitions) {
|
||||
warnx("invalid partition");
|
||||
goto out;
|
||||
}
|
||||
bsdoffs = dl.d_partitions[c - 'a'].p_offset;
|
||||
}
|
||||
if (verbose)
|
||||
fprintf(stderr, "BSD partition starts at sector %d\n", bsdoffs);
|
||||
(void) fprintf(stderr, "BSD partition starts at sector %d\n",
|
||||
bsdoffs);
|
||||
|
||||
/*
|
||||
* add offset of BSD partition to fraglist entries
|
||||
@ -406,13 +423,13 @@ main(argc, argv)
|
||||
* write first blocks (max loadsz) to start of BSD partition,
|
||||
* skip disklabel (in second disk block)
|
||||
*/
|
||||
lseek(devfd, 0, SEEK_SET);
|
||||
(void) lseek(devfd, (off_t)0, SEEK_SET);
|
||||
res = write(devfd, bp, DEV_BSIZE);
|
||||
if (res < 0) {
|
||||
warn("final write1");
|
||||
goto out;
|
||||
}
|
||||
lseek(devfd, 2 * DEV_BSIZE, SEEK_SET);
|
||||
(void) lseek(devfd, (off_t)(2 * DEV_BSIZE), SEEK_SET);
|
||||
res = write(devfd, bp + 2 * DEV_BSIZE, size - 2 * DEV_BSIZE);
|
||||
if (res < 0) {
|
||||
warn("final write2");
|
||||
@ -423,7 +440,7 @@ main(argc, argv)
|
||||
|
||||
out:
|
||||
if (devfd >= 0)
|
||||
close(devfd);
|
||||
(void) close(devfd);
|
||||
if (bp)
|
||||
free(bp);
|
||||
if (inode != (ino_t) - 1) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* $NetBSD: installboot.h,v 1.3 1998/01/05 07:02:57 perry Exp $ */
|
||||
/* $NetBSD: installboot.h,v 1.4 1998/07/28 20:10:54 drochner Exp $ */
|
||||
|
||||
ino_t createfileondev __P((char *, char *, char *, int));
|
||||
ino_t createfileondev __P((char *, char *, char *, unsigned int));
|
||||
void cleanupfileondev __P((char *, char *, int));
|
||||
|
||||
char *getmountpoint __P((char *));
|
||||
|
Loading…
x
Reference in New Issue
Block a user