Commit eb0ee450 authored by Eric Andersen's avatar Eric Andersen
Browse files

Finish implementing fakeroot handling so mksquashfs properly

inherits device table settings and device nodes, exactly as
per mkfs* applications that support device tables natively.
parent afcdf8a0
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -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

+35 −23
Original line number Diff line number Diff line
@@ -25,7 +25,9 @@
#include <pwd.h>
#include <grp.h>
#include <unistd.h>
#include <ctype.h>
#include <errno.h>
#include <libgen.h>
#include <stdarg.h>
#include <sys/stat.h>
#include <sys/types.h>
@@ -97,13 +99,6 @@ FILE *bb_xfopen(const char *path, const char *mode)
	return fp;
}

int bb_make_directory (char *path, long mode, int flags)
{
	mode_t mask;
	const char *fail_msg;
	char *s = path;
	char c;
	struct stat st;
enum {
	FILEUTILS_PRESERVE_STATUS = 1,
	FILEUTILS_DEREFERENCE = 2,
@@ -111,6 +106,13 @@ int bb_make_directory (char *path, long mode, int flags)
	FILEUTILS_FORCE = 8,
	FILEUTILS_INTERACTIVE = 16
};
int bb_make_directory (char *path, long mode, int flags)
{
	mode_t mask;
	const char *fail_msg;
	char *s = path;
	char c;
	struct stat st;

	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;
				}
			}
+4 −3
Original line number Diff line number Diff line
@@ -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
+15 −9
Original line number Diff line number Diff line
@@ -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