From eb0ee4509d3112d80cbb210b44fb682ba7033385 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Fri, 24 Jun 2005 07:26:33 +0000 Subject: Finish implementing fakeroot handling so mksquashfs properly inherits device table settings and device nodes, exactly as per mkfs* applications that support device tables natively. --- package/fakeroot/fakeroot.mk | 3 +++ target/makedevs/makedevs.c | 58 +++++++++++++++++++++++++---------------- target/makedevs/makedevs.mk | 7 ++--- target/squashfs/squashfsroot.mk | 24 ++++++++++------- 4 files changed, 57 insertions(+), 35 deletions(-) diff --git a/package/fakeroot/fakeroot.mk b/package/fakeroot/fakeroot.mk index 3ab83dffa..07ed20657 100644 --- a/package/fakeroot/fakeroot.mk +++ b/package/fakeroot/fakeroot.mk @@ -40,6 +40,9 @@ $(FAKEROOT_DIR1)/faked: $(FAKEROOT_DIR1)/.configured $(STAGING_DIR)/usr/bin/fakeroot: $(FAKEROOT_DIR1)/faked $(MAKE) DESTDIR=$(STAGING_DIR) -C $(FAKEROOT_DIR1) install + $(SED) 's,^PREFIX=.*,PREFIX=$(STAGING_DIR)/usr,g' $(STAGING_DIR)/usr/bin/fakeroot + $(SED) 's,^BINDIR=.*,BINDIR=$(STAGING_DIR)/usr/bin,g' $(STAGING_DIR)/usr/bin/fakeroot + $(SED) 's,^PATHS=.*,PATHS=$(FAKEROOT_DIR1)/.libs:/lib:/usr/lib,g' $(STAGING_DIR)/usr/bin/fakeroot host-fakeroot: uclibc $(STAGING_DIR)/usr/bin/fakeroot diff --git a/target/makedevs/makedevs.c b/target/makedevs/makedevs.c index d2b3a2a74..bb3310761 100644 --- a/target/makedevs/makedevs.c +++ b/target/makedevs/makedevs.c @@ -25,7 +25,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -97,6 +99,13 @@ FILE *bb_xfopen(const char *path, const char *mode) return fp; } +enum { + FILEUTILS_PRESERVE_STATUS = 1, + FILEUTILS_DEREFERENCE = 2, + FILEUTILS_RECUR = 4, + FILEUTILS_FORCE = 8, + FILEUTILS_INTERACTIVE = 16 +}; int bb_make_directory (char *path, long mode, int flags) { mode_t mask; @@ -104,13 +113,6 @@ int bb_make_directory (char *path, long mode, int flags) char *s = path; char c; struct stat st; - enum { - FILEUTILS_PRESERVE_STATUS = 1, - FILEUTILS_DEREFERENCE = 2, - FILEUTILS_RECUR = 4, - FILEUTILS_FORCE = 8, - FILEUTILS_INTERACTIVE = 16 - }; mask = umask(0); if (mode == -1) { @@ -325,20 +327,20 @@ int main(int argc, char **argv) FILE *table = stdin; char *rootdir = "./"; char *line; + int linenum = 0; int ret = EXIT_SUCCESS; - bb_applet_name = argv[0]; + bb_applet_name = basename(argv[0]); + argc--; + argv++; - while ((opt = getopt(argc, argv, "d:r:")) != -1) { + while ((opt = getopt(argc, argv, "d:")) != -1) { switch(opt) { case 'd': table = bb_xfopen(optarg, "r"); break; - case 'n': - rootdir = optarg; - break; default: - fprintf(stderr, "%s: [-r rootdir] [device_table]\n\n", bb_applet_name); + fprintf(stderr, "%s: [-d device_table] rootdir\n\n", bb_applet_name); fprintf(stderr, "Creates a batch of special files as specified in a device table.\n"); fprintf(stderr, "Device table entries take the form of:\n"); fprintf(stderr, "type mode user group major minor start increment count\n\n"); @@ -370,8 +372,13 @@ int main(int argc, char **argv) } } + if (optind >= argc) { + bb_error_msg_and_die("root directory not speficied"); + } + rootdir = argv[optind]; + - if (chdir(rootdir) == -1) { + if (chdir(rootdir) != 0) { bb_perror_msg_and_die("Couldnt chdir to %s", rootdir); } @@ -392,11 +399,16 @@ int main(int argc, char **argv) uid_t uid; gid_t gid; + linenum++; + if ((2 > sscanf(line, "%40s %c %o %40s %40s %u %u %u %u %u", name, &type, &mode, user, group, &major, &minor, &start, &increment, &count)) || - ((major | minor | start | count | increment) > 255)) { - bb_error_msg("Ignoring invalid line\n%s\n", line); + ((major | minor | start | count | increment) > 255)) + { + if (*line=='\0' || *line=='#' || isspace(*line)) + continue; + bb_error_msg("line %d invalid: '%s'\n", linenum, line); ret = EXIT_FAILURE; continue; } @@ -416,9 +428,9 @@ int main(int argc, char **argv) full_name = concat_path_file(rootdir, name); if (type == 'd') { - bb_make_directory(full_name, mode | S_IFDIR, 0); + bb_make_directory(full_name, mode | S_IFDIR, FILEUTILS_RECUR); if (chown(full_name, uid, gid) == -1) { - bb_perror_msg("chown failed for %s", full_name); + bb_perror_msg("line %d: chown failed for %s", linenum, full_name); ret = EXIT_FAILURE; goto loop; } @@ -434,7 +446,7 @@ int main(int argc, char **argv) else if (type == 'b') { mode |= S_IFBLK; } else { - bb_error_msg("Unsupported file type %c", type); + bb_error_msg("line %d: Unsupported file type %c", linenum, type); ret = EXIT_FAILURE; goto loop; } @@ -448,11 +460,11 @@ int main(int argc, char **argv) sprintf(full_name_inc, "%s%d", full_name, i); rdev = (major << 8) + minor + (i * increment - start); if (mknod(full_name_inc, mode, rdev) == -1) { - bb_perror_msg("Couldnt create node %s", full_name_inc); + bb_perror_msg("line %d: Couldnt create node %s", linenum, full_name_inc); ret = EXIT_FAILURE; } else if (chown(full_name_inc, uid, gid) == -1) { - bb_perror_msg("chown failed for %s", full_name_inc); + bb_perror_msg("line %d: chown failed for %s", linenum, full_name_inc); ret = EXIT_FAILURE; } } @@ -460,11 +472,11 @@ int main(int argc, char **argv) } else { rdev = (major << 8) + minor; if (mknod(full_name, mode, rdev) == -1) { - bb_perror_msg("Couldnt create node %s", full_name); + bb_perror_msg("line %d: Couldnt create node %s", linenum, full_name); ret = EXIT_FAILURE; } else if (chown(full_name, uid, gid) == -1) { - bb_perror_msg("chown failed for %s", full_name); + bb_perror_msg("line %d: chown failed for %s", linenum, full_name); ret = EXIT_FAILURE; } } diff --git a/target/makedevs/makedevs.mk b/target/makedevs/makedevs.mk index cfc19d0ec..620b0cdcd 100644 --- a/target/makedevs/makedevs.mk +++ b/target/makedevs/makedevs.mk @@ -7,12 +7,13 @@ ############################################################# MAKEDEVS_DIR=$(BUILD_DIR)/makedevs -$(MAKEDEVS_DIR)/makedevs.c: +$(MAKEDEVS_DIR)/makedevs.c: target/makedevs/makedevs.c + rm -rf $(MAKEDEVS_DIR) mkdir $(MAKEDEVS_DIR) cp target/makedevs/makedevs.c $(MAKEDEVS_DIR) -$(MAKEDEVS_DIR)/makedevs: $(MAKEDEVS_DIR) - gcc -Wall -O2 makedevs.c -o makedevs +$(MAKEDEVS_DIR)/makedevs: $(MAKEDEVS_DIR)/makedevs.c + gcc -Wall -Werror -O2 $(MAKEDEVS_DIR)/makedevs.c -o $(MAKEDEVS_DIR)/makedevs touch -c $(MAKEDEVS_DIR)/makedevs $(STAGING_DIR)/bin/makedevs: $(MAKEDEVS_DIR)/makedevs diff --git a/target/squashfs/squashfsroot.mk b/target/squashfs/squashfsroot.mk index 50aaf58fe..4f4d76dba 100644 --- a/target/squashfs/squashfsroot.mk +++ b/target/squashfs/squashfsroot.mk @@ -35,22 +35,28 @@ squashfs-dirclean: ############################################################# squashfsroot: squashfs host-fakeroot makedevs + -@find $(TARGET_DIR) -type f -perm +111 | xargs $(STRIP) 2>/dev/null || true; + @rm -rf $(TARGET_DIR)/usr/man + @rm -rf $(TARGET_DIR)/usr/info + # Use fakeroot to munge permissions and do root-like things rm -f $(STAGING_DIR)/fakeroot.env touch $(STAGING_DIR)/fakeroot.env # Use fakeroot to pretend all target binaries are owned by root - $(STAGING_DIR)/usr/bin/fakeroot -i $(STAGING_DIR)/fakeroot.env \ + $(STAGING_DIR)/usr/bin/fakeroot \ + -i $(STAGING_DIR)/fakeroot.env \ -s $(STAGING_DIR)/fakeroot.env -- \ - find $(TARGET_DIR) | xargs chown -R root:root + chown -R root:root $(TARGET_DIR) # Use fakeroot to pretend to create all needed device nodes - $(STAGING_DIR)/usr/bin/fakeroot -i $(STAGING_DIR)/fakeroot.env \ + $(STAGING_DIR)/usr/bin/fakeroot \ + -i $(STAGING_DIR)/fakeroot.env \ -s $(STAGING_DIR)/fakeroot.env -- \ - $(STAGING_DIR)/bin/makedevs -r $(TARGET_DIR) \ - target/default/device_table.txt - -@find $(TARGET_DIR) -type f -perm +111 | xargs $(STRIP) 2>/dev/null || true; - @rm -rf $(TARGET_DIR)/usr/man - @rm -rf $(TARGET_DIR)/usr/info + $(STAGING_DIR)/bin/makedevs \ + -r $(TARGET_DIR) \ + -d target/generic/device_table.txt # Use fakeroot to fake out mksquashfs per the previous fakery - $(STAGING_DIR)/usr/bin/fakeroot -i $(STAGING_DIR)/fakeroot.env -- \ + $(STAGING_DIR)/usr/bin/fakeroot \ + -i $(STAGING_DIR)/fakeroot.env \ + -s $(STAGING_DIR)/fakeroot.env -- \ $(SQUASHFS_DIR)/squashfs-tools/mksquashfs $(TARGET_DIR) \ $(IMAGE).squashfs -noappend -- cgit v1.2.3