Author: arichardson
Date: Tue Jan 16 21:43:46 2018
New Revision: 328064
URL: https://svnweb.freebsd.org/changeset/base/328064

Log:
  Allow xinstall and makefs to be crossbuilt on Linux and Mac
  
  I need these tools in order to install the crossbuilt FreeBSD and create a
  disk image. Linux does not have a st_flags in struct stat so unfortunately
  I need a bunch of ugly ifdefs. The resulting binaries allow me to
  sucessfully install a MIPS64 world and create a disk-image that boots.
  
  Reviewed By:  brooks, bdrewery, emaste
  Approved By:  jhb (mentor)
  Differential Revision: https://reviews.freebsd.org/D13307

Modified:
  head/usr.bin/xinstall/Makefile
  head/usr.bin/xinstall/xinstall.c
  head/usr.sbin/makefs/ffs.c
  head/usr.sbin/makefs/mtree.c

Modified: head/usr.bin/xinstall/Makefile
==============================================================================
--- head/usr.bin/xinstall/Makefile      Tue Jan 16 21:43:36 2018        
(r328063)
+++ head/usr.bin/xinstall/Makefile      Tue Jan 16 21:43:46 2018        
(r328064)
@@ -11,6 +11,7 @@ MAN=          install.1
 .PATH:         ${SRCTOP}/contrib/mtree
 CFLAGS+=       -I${SRCTOP}/contrib/mtree
 CFLAGS+=       -I${SRCTOP}/lib/libnetbsd
+CFLAGS+=       -DHAVE_STRUCT_STAT_ST_FLAGS=1
 
 LIBADD=        md
 

Modified: head/usr.bin/xinstall/xinstall.c
==============================================================================
--- head/usr.bin/xinstall/xinstall.c    Tue Jan 16 21:43:36 2018        
(r328063)
+++ head/usr.bin/xinstall/xinstall.c    Tue Jan 16 21:43:46 2018        
(r328064)
@@ -533,9 +533,11 @@ do_link(const char *from_name, const char *to_name,
                                unlink(tmpl);
                                err(EX_OSERR, "%s", to_name);
                        }
+#if HAVE_STRUCT_STAT_ST_FLAGS
                        if (target_sb->st_flags & NOCHANGEBITS)
                                (void)chflags(to_name, target_sb->st_flags &
                                     ~NOCHANGEBITS);
+#endif
                        if (verbose)
                                printf("install: link %s -> %s\n",
                                    from_name, to_name);
@@ -579,9 +581,11 @@ do_symlink(const char *from_name, const char *to_name,
                        (void)unlink(tmpl);
                        err(EX_OSERR, "%s", to_name);
                }
+#if HAVE_STRUCT_STAT_ST_FLAGS
                if (target_sb->st_flags & NOCHANGEBITS)
                        (void)chflags(to_name, target_sb->st_flags &
                             ~NOCHANGEBITS);
+#endif
                if (verbose)
                        printf("install: symlink %s -> %s\n",
                            from_name, to_name);
@@ -779,9 +783,11 @@ install(const char *from_name, const char *to_name, u_
                if (target && !safecopy) {
                        if (to_sb.st_mode & S_IFDIR && rmdir(to_name) == -1)
                                err(EX_OSERR, "%s", to_name);
+#if HAVE_STRUCT_STAT_ST_FLAGS
                        if (to_sb.st_flags & NOCHANGEBITS)
                                (void)chflags(to_name,
                                    to_sb.st_flags & ~NOCHANGEBITS);
+#endif
                        unlink(to_name);
                }
                makelink(from_name, to_name, target ? &to_sb : NULL);
@@ -893,9 +899,11 @@ install(const char *from_name, const char *to_name, u_
         * and the files are different (or just not compared).
         */
        if (tempcopy && !files_match) {
+#if HAVE_STRUCT_STAT_ST_FLAGS
                /* Try to turn off the immutable bits. */
                if (to_sb.st_flags & NOCHANGEBITS)
                        (void)chflags(to_name, to_sb.st_flags & ~NOCHANGEBITS);
+#endif
                if (dobackup) {
                        if ((size_t)snprintf(backup, MAXPATHLEN, "%s%s", 
to_name,
                            suffix) != strlen(to_name) + strlen(suffix)) {
@@ -907,8 +915,10 @@ install(const char *from_name, const char *to_name, u_
                                (void)printf("install: %s -> %s\n", to_name, 
backup);
                        if (unlink(backup) < 0 && errno != ENOENT) {
                                serrno = errno;
+#if HAVE_STRUCT_STAT_ST_FLAGS
                                if (to_sb.st_flags & NOCHANGEBITS)
                                        (void)chflags(to_name, to_sb.st_flags);
+#endif
                                unlink(tempfile);
                                errno = serrno;
                                err(EX_OSERR, "unlink: %s", backup);
@@ -916,8 +926,10 @@ install(const char *from_name, const char *to_name, u_
                        if (link(to_name, backup) < 0) {
                                serrno = errno;
                                unlink(tempfile);
+#if HAVE_STRUCT_STAT_ST_FLAGS
                                if (to_sb.st_flags & NOCHANGEBITS)
                                        (void)chflags(to_name, to_sb.st_flags);
+#endif
                                errno = serrno;
                                err(EX_OSERR, "link: %s to %s", to_name,
                                     backup);
@@ -962,9 +974,11 @@ install(const char *from_name, const char *to_name, u_
        if (!dounpriv && ((gid != (gid_t)-1 && gid != to_sb.st_gid) ||
            (uid != (uid_t)-1 && uid != to_sb.st_uid) ||
            (mode != (to_sb.st_mode & ALLPERMS)))) {
+#if HAVE_STRUCT_STAT_ST_FLAGS
                /* Try to turn off the immutable bits. */
                if (to_sb.st_flags & NOCHANGEBITS)
                        (void)fchflags(to_fd, to_sb.st_flags & ~NOCHANGEBITS);
+#endif
        }
 
        if (!dounpriv & 
@@ -986,7 +1000,7 @@ install(const char *from_name, const char *to_name, u_
                        err(EX_OSERR, "%s: chmod", to_name);
                }
        }
-
+#if HAVE_STRUCT_STAT_ST_FLAGS
        /*
         * If provided a set of flags, set them, otherwise, preserve the
         * flags, except for the dump flag.
@@ -1009,6 +1023,7 @@ install(const char *from_name, const char *to_name, u_
                        }
                }
        }
+#endif
 
        (void)close(to_fd);
        if (!devnull)
@@ -1135,15 +1150,19 @@ create_newfile(const char *path, int target, struct st
                 * off the append/immutable bits -- if we fail, go ahead,
                 * it might work.
                 */
+#if HAVE_STRUCT_STAT_ST_FLAGS
                if (sbp->st_flags & NOCHANGEBITS)
                        (void)chflags(path, sbp->st_flags & ~NOCHANGEBITS);
+#endif
 
                if (dobackup) {
                        if ((size_t)snprintf(backup, MAXPATHLEN, "%s%s",
                            path, suffix) != strlen(path) + strlen(suffix)) {
                                saved_errno = errno;
+#if HAVE_STRUCT_STAT_ST_FLAGS
                                if (sbp->st_flags & NOCHANGEBITS)
                                        (void)chflags(path, sbp->st_flags);
+#endif
                                errno = saved_errno;
                                errx(EX_OSERR, "%s: backup filename too long",
                                    path);
@@ -1155,8 +1174,10 @@ create_newfile(const char *path, int target, struct st
                                    path, backup);
                        if (rename(path, backup) < 0) {
                                saved_errno = errno;
+#if HAVE_STRUCT_STAT_ST_FLAGS
                                if (sbp->st_flags & NOCHANGEBITS)
                                        (void)chflags(path, sbp->st_flags);
+#endif
                                errno = saved_errno;
                                err(EX_OSERR, "rename: %s to %s", path, backup);
                        }

Modified: head/usr.sbin/makefs/ffs.c
==============================================================================
--- head/usr.sbin/makefs/ffs.c  Tue Jan 16 21:43:36 2018        (r328063)
+++ head/usr.sbin/makefs/ffs.c  Tue Jan 16 21:43:46 2018        (r328064)
@@ -70,6 +70,10 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
 #include <sys/param.h>
 
 #include <sys/mount.h>
@@ -315,7 +319,7 @@ static void
 ffs_validate(const char *dir, fsnode *root, fsinfo_t *fsopts)
 {
        int32_t ncg = 1;
-#if notyet
+#ifdef notyet
        int32_t spc, nspf, ncyl, fssize;
 #endif
        ffs_opt_t       *ffs_opts = fsopts->fs_specific;

Modified: head/usr.sbin/makefs/mtree.c
==============================================================================
--- head/usr.sbin/makefs/mtree.c        Tue Jan 16 21:43:36 2018        
(r328063)
+++ head/usr.sbin/makefs/mtree.c        Tue Jan 16 21:43:46 2018        
(r328064)
@@ -25,6 +25,10 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
@@ -532,11 +536,13 @@ read_mtree_keywords(FILE *fp, fsnode *node)
                                        break;
                                }
                                flset = flclr = 0;
+#if HAVE_STRUCT_STAT_ST_FLAGS
                                if (!strtofflags(&value, &flset, &flclr)) {
                                        st->st_flags &= ~flclr;
                                        st->st_flags |= flset;
                                } else
                                        error = errno;
+#endif
                        } else
                                error = ENOSYS;
                        break;
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to