1
0
mirror of https://github.com/openbsd/src.git synced 2024-12-21 23:18:00 -08:00

use opendev() for fsck_ext2fs, based on code adding this to fsck_ffs

tweak (add strncmp()...blockcheck section) from martijn@
ok martijn@
This commit is contained in:
sthen 2024-12-18 10:36:05 +00:00
parent 76232002e5
commit dfd6150703
2 changed files with 28 additions and 16 deletions

View File

@ -1,10 +1,12 @@
# $OpenBSD: Makefile,v 1.8 2001/09/18 13:31:29 art Exp $
# $OpenBSD: Makefile,v 1.9 2024/12/18 10:36:05 sthen Exp $
PROG= fsck_ext2fs
MAN= fsck_ext2fs.8
MAN= fsck_ext2fs.8
SRCS= dir.c inode.c main.c pass1.c pass1b.c pass2.c pass3.c pass4.c \
pass5.c fsutil.c setup.c utilities.c ext2fs_bswap.c
.PATH: ${.CURDIR}/../../sys/ufs/ext2fs ${.CURDIR}/../fsck
CFLAGS+= -I${.CURDIR}/../fsck
DPADD+= ${LIBUTIL}
LDADD+= -lutil
.include <bsd.prog.mk>

View File

@ -1,4 +1,4 @@
/* $OpenBSD: setup.c,v 1.34 2024/07/15 13:32:50 martijn Exp $ */
/* $OpenBSD: setup.c,v 1.35 2024/12/18 10:36:05 sthen Exp $ */
/* $NetBSD: setup.c,v 1.1 1997/06/11 11:22:01 bouyer Exp $ */
/*
@ -46,6 +46,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <util.h>
#include <string.h>
#include <ctype.h>
#include <err.h>
@ -60,6 +61,7 @@ void badsb(int, char *);
int calcsb(char *, int, struct m_ext2fs *, struct disklabel *);
static struct disklabel *getdisklabel(char *, int);
static int readsb(int);
static char rdevname[PATH_MAX];
int
setup(char *dev)
@ -70,28 +72,36 @@ setup(char *dev)
off_t sizepb;
struct stat statb;
struct m_ext2fs proto;
char *realdev;
int doskipclean;
u_int64_t maxfilesize;
havesb = 0;
fswritefd = -1;
doskipclean = skipclean;
if (stat(dev, &statb) == -1) {
printf("Can't stat %s: %s\n", dev, strerror(errno));
return (0);
}
if (!S_ISCHR(statb.st_mode)) {
pfatal("%s is not a character device", dev);
if (reply("CONTINUE") == 0)
return (0);
}
if ((fsreadfd = open(dev, O_RDONLY)) == -1) {
if ((fsreadfd = opendev(dev, O_RDONLY, 0, &realdev)) == -1) {
printf("Can't open %s: %s\n", dev, strerror(errno));
return (0);
}
if (strncmp(dev, realdev, PATH_MAX) != 0) {
blockcheck(unrawname(realdev));
strlcpy(rdevname, realdev, sizeof(rdevname));
setcdevname(rdevname, dev, preen);
}
if (fstat(fsreadfd, &statb) == -1) {
printf("Can't stat %s: %s\n", realdev, strerror(errno));
return (0);
}
if (!S_ISCHR(statb.st_mode)) {
pfatal("%s is not a character device", realdev);
if (reply("CONTINUE") == 0) {
close(fsreadfd);
return (0);
}
}
if (preen == 0)
printf("** %s", dev);
if (nflag || (fswritefd = open(dev, O_WRONLY)) == -1) {
printf("** %s", realdev);
if (nflag || (fswritefd = opendev(dev, O_WRONLY, 0, NULL)) == -1) {
fswritefd = -1;
if (preen)
pfatal("NO WRITE ACCESS");
@ -126,7 +136,7 @@ setup(char *dev)
* Read in the superblock, looking for alternates if necessary
*/
if (readsb(1) == 0) {
if (bflag || preen || calcsb(dev, fsreadfd, &proto, lp) == 0)
if (bflag || preen || calcsb(realdev, fsreadfd, &proto, lp) == 0)
return(0);
if (reply("LOOK FOR ALTERNATE SUPERBLOCKS") == 0)
return (0);