Index: head/sbin/newfs_msdos/mkfs_msdos.c =================================================================== --- head/sbin/newfs_msdos/mkfs_msdos.c +++ head/sbin/newfs_msdos/mkfs_msdos.c @@ -31,10 +31,15 @@ #endif /* not lint */ #include +#ifdef MAKEFS +/* In the makefs case we only want struct disklabel */ +#include +#else #include #include #include #include +#endif #include #include @@ -285,14 +290,18 @@ if (!S_ISREG(sb.st_mode)) warnx("warning, %s is not a regular file", fname); } else { -#ifndef MAKEFS +#ifdef MAKEFS + errx(1, "o.create_size must be set!"); +#else if (!S_ISCHR(sb.st_mode)) warnx("warning, %s is not a character device", fname); #endif } +#ifndef MAKEFS if (!o.no_create) if (check_mounted(fname, sb.st_mode) == -1) goto done; +#endif if (o.offset && o.offset != lseek(fd, o.offset, SEEK_SET)) { warnx("cannot seek to %jd", (intmax_t)o.offset); goto done; @@ -621,10 +630,12 @@ bpb.bpbBigFATsecs) * bpb.bpbFATs; memset(&si_sa, 0, sizeof(si_sa)); si_sa.sa_handler = infohandler; +#ifdef SIGINFO if (sigaction(SIGINFO, &si_sa, NULL) == -1) { warn("sigaction SIGINFO"); goto done; } +#endif for (lsn = 0; lsn < dir + (fat == 32 ? bpb.bpbSecPerClust : rds); lsn++) { if (got_siginfo) { fprintf(stderr,"%s: writing sector %u of %u (%u%%)\n", @@ -766,6 +777,11 @@ static int check_mounted(const char *fname, mode_t mode) { +/* + * If getmntinfo() is not available (e.g. Linux) don't check. This should + * not be a problem since we will only be using makefs to create images. + */ +#if !defined(MAKEFS) struct statfs *mp; const char *s1, *s2; size_t len; @@ -790,6 +806,7 @@ return -1; } } +#endif return 0; } @@ -811,6 +828,23 @@ return 0; } +static void +compute_geometry_from_file(int fd, const char *fname, struct disklabel *lp) +{ + struct stat st; + off_t ms; + + if (fstat(fd, &st)) + err(1, "cannot get disk size"); + if (!S_ISREG(st.st_mode)) + errx(1, "%s is not a regular file", fname); + ms = st.st_size; + lp->d_secsize = 512; + lp->d_nsectors = 63; + lp->d_ntracks = 255; + lp->d_secperunit = ms / lp->d_secsize; +} + /* * Get disk slice, partition, and geometry information. */ @@ -819,8 +853,10 @@ struct bpb *bpb) { struct disklabel *lp, dlp; + off_t hs = 0; +#ifndef MAKEFS + off_t ms; struct fd_type type; - off_t ms, hs = 0; lp = NULL; @@ -832,16 +868,8 @@ /* Maybe it's a floppy drive */ if (lp == NULL) { if (ioctl(fd, DIOCGMEDIASIZE, &ms) == -1) { - struct stat st; - - if (fstat(fd, &st)) - err(1, "cannot get disk size"); /* create a fake geometry for a file image */ - ms = st.st_size; - dlp.d_secsize = 512; - dlp.d_nsectors = 63; - dlp.d_ntracks = 255; - dlp.d_secperunit = ms / dlp.d_secsize; + compute_geometry_from_file(fd, fname, &dlp); lp = &dlp; } else if (ioctl(fd, FD_GTYPE, &type) != -1) { dlp.d_secsize = 128 << type.secsize; @@ -881,6 +909,11 @@ hs = (ms / dlp.d_secsize) - dlp.d_secperunit; lp = &dlp; } +#else + /* In the makefs case we only support image files: */ + compute_geometry_from_file(fd, fname, &dlp); + lp = &dlp; +#endif if (bpb->bpbBytesPerSec == 0) { if (ckgeom(fname, lp->d_secsize, "bytes/sector") == -1) Index: head/sys/fs/msdosfs/msdosfsmount.h =================================================================== --- head/sys/fs/msdosfs/msdosfsmount.h +++ head/sys/fs/msdosfs/msdosfsmount.h @@ -56,8 +56,10 @@ #if defined (_KERNEL) || defined(MAKEFS) #include +#ifndef MAKEFS #include #include +#endif #include #ifdef MALLOC_DECLARE @@ -110,7 +112,9 @@ void *pm_w2u; /* Unicode->Local iconv handle */ void *pm_u2d; /* Unicode->DOS iconv handle */ void *pm_d2u; /* DOS->Local iconv handle */ +#ifndef MAKEFS struct lock pm_fatlock; /* lockmgr protecting allocations */ +#endif }; /* Index: head/tools/build/Makefile =================================================================== --- head/tools/build/Makefile +++ head/tools/build/Makefile @@ -4,11 +4,16 @@ LIB= egacy SRC= -INCSGROUPS= INCS SYSINCS CASPERINC +INCSGROUPS= INCS SYSINCS CASPERINC UFSINCS FFSINCS MSDOSFSINCS DISKINCS INCS= SYSINCSDIR= ${INCLUDEDIR}/sys CASPERINCDIR= ${INCLUDEDIR}/casper +# Also add ufs/ffs/msdosfs/disk headers to allow building makefs as a bootstrap tool +UFSINCSDIR= ${INCLUDEDIR}/ufs/ufs +FFSINCSDIR= ${INCLUDEDIR}/ufs/ffs +MSDOSFSINCSDIR= ${INCLUDEDIR}/fs/msdosfs +DISKINCSDIR= ${INCLUDEDIR}/sys/disk BOOTSTRAPPING?= 0 @@ -69,6 +74,19 @@ .if defined(CROSS_BUILD_TESTING) SUBDIR= cross-build .endif + +# To allow bootstrapping makefs on FreeBSD 11 or non-FreeBSD systems: +UFSINCS+= ${SRCTOP}/sys/ufs/ufs/dinode.h +UFSINCS+= ${SRCTOP}/sys/ufs/ufs/dir.h +FFSINCS+= ${SRCTOP}/sys/ufs/ffs/fs.h + +MSDOSFSINCS+= ${SRCTOP}/sys/fs/msdosfs/bootsect.h +MSDOSFSINCS+= ${SRCTOP}/sys/fs/msdosfs/bpb.h +MSDOSFSINCS+= ${SRCTOP}/sys/fs/msdosfs/denode.h +MSDOSFSINCS+= ${SRCTOP}/sys/fs/msdosfs/direntry.h +MSDOSFSINCS+= ${SRCTOP}/sys/fs/msdosfs/fat.h +MSDOSFSINCS+= ${SRCTOP}/sys/fs/msdosfs/msdosfsmount.h +DISKINCS+= ${SRCTOP}/sys/sys/disk/bsd.h # Needed to build config (since it uses libnv) SYSINCS+= ${SRCTOP}/sys/sys/nv.h ${SRCTOP}/sys/sys/cnv.h \ Index: head/usr.sbin/makefs/msdos/msdosfs_denode.c =================================================================== --- head/usr.sbin/makefs/msdos/msdosfs_denode.c +++ head/usr.sbin/makefs/msdos/msdosfs_denode.c @@ -54,7 +54,6 @@ #include #include -#include #include #include @@ -288,10 +287,7 @@ return (error); } memset(bp->b_data + boff, 0, pmp->pm_bpcluster - boff); - if (flags & IO_SYNC) bwrite(bp); - else - bdwrite(bp); } } Index: head/usr.sbin/makefs/msdos/msdosfs_vnops.c =================================================================== --- head/usr.sbin/makefs/msdos/msdosfs_vnops.c +++ head/usr.sbin/makefs/msdos/msdosfs_vnops.c @@ -103,7 +103,11 @@ if (stampst.st_ino) st = &stampst; +#ifdef HAVE_STRUCT_STAT_BIRTHTIME unix2fattime(&st->st_birthtim, &dep->de_CDate, &dep->de_CTime); +#else + unix2fattime(&st->st_ctim, &dep->de_CDate, &dep->de_CTime); +#endif unix2fattime(&st->st_atim, &dep->de_ADate, NULL); unix2fattime(&st->st_mtim, &dep->de_MDate, &dep->de_MTime); }