From 1462eeb400f103d31655e5bc637da6e78efb4fcb Mon Sep 17 00:00:00 2001 From: Sergey Date: Sun, 3 Aug 2014 15:53:53 -0700 Subject: [PATCH] Using manifest files to create root and user filesystems. --- Makefile | 76 ++++------------------------- filesys.manifest => rootfs.manifest | 11 +++-- tools/fsutil/fsutil.c | 63 +++++++++++++++++++----- tools/fsutil/mount.c | 2 + u/README.txt | 1 + userfs.manifest | 10 ++++ 6 files changed, 82 insertions(+), 81 deletions(-) rename filesys.manifest => rootfs.manifest (99%) create mode 100644 u/README.txt create mode 100644 userfs.manifest diff --git a/Makefile b/Makefile index f697606..cf9979c 100644 --- a/Makefile +++ b/Makefile @@ -60,55 +60,6 @@ TARGETDIR = $(shell dirname $(TARGET)) TARGETNAME = $(shell basename $(TARGET)) TOPSRC = $(shell pwd) CONFIG = $(TOPSRC)/tools/configsys/config -# -# Filesystem contents. -# -BIN_FILES := $(wildcard bin/*) -SBIN_FILES := $(wildcard sbin/*) -GAMES_FILES := $(shell find games -type f ! -path '*/.*') -LIBEXEC_FILES := $(wildcard libexec/*) -LIB_FILES := lib/crt0.o lib/retroImage $(wildcard lib/*.a) -ETC_FILES = etc/rc etc/rc.local etc/ttys etc/gettytab etc/group \ - etc/passwd etc/shadow etc/fstab etc/motd etc/shells \ - etc/termcap etc/MAKEDEV etc/phones etc/remote -INC_FILES = $(wildcard include/*.h) \ - $(wildcard include/sys/*.h) \ - $(wildcard include/machine/*.h) \ - $(wildcard include/smallc/*.h) \ - $(wildcard include/smallc/sys/*.h) \ - $(wildcard include/arpa/*.h) -SHARE_FILES = share/re.help share/emg.keys share/example/Makefile \ - share/example/ashello.S share/example/chello.c \ - share/example/blkjack.bas share/example/hilow.bas \ - share/example/stars.bas share/example/prime.scm \ - share/example/fact.fth share/example/echo.S \ - share/example/stdarg.c share/example/skeleton.c \ - $(wildcard share/smallc/*) -MANFILES = share/man/ share/man/cat1/ share/man/cat2/ share/man/cat3/ \ - share/man/cat4/ share/man/cat5/ share/man/cat6/ share/man/cat7/ \ - share/man/cat8/ $(wildcard share/man/cat?/*) -ALLFILES = $(SBIN_FILES) $(ETC_FILES) $(BIN_FILES) $(LIB_FILES) $(LIBEXEC_FILES) \ - $(INC_FILES) $(SHARE_FILES) $(GAMES_FILES) \ - var/log/messages var/log/wtmp .profile -ALLDIRS = games/ sbin/ bin/ dev/ etc/ tmp/ lib/ libexec/ share/ include/ \ - var/ u/ share/example/ share/misc/ share/smallc/ \ - var/run/ var/log/ var/lock/ games/ games/lib/ include/sys/ \ - include/machine/ include/arpa/ include/smallc/ \ - include/smallc/sys/ share/misc/ share/smallc/ include/sys/ \ - games/lib/ -BDEVS = dev/rd0!b0:0 dev/rd0a!b0:1 dev/rd0b!b0:2 dev/rd0c!b0:3 dev/rd0d!b0:4 -BDEVS += dev/rd1!b1:0 dev/rd1a!b1:1 dev/rd1b!b1:2 dev/rd1c!b1:3 dev/rd1d!b1:4 -BDEVS += dev/rd2!b2:0 dev/rd2a!b2:1 dev/rd2b!b2:2 dev/rd2c!b2:3 dev/rd2d!b2:4 -BDEVS += dev/rd3!b3:0 dev/rd3a!b3:1 dev/rd3b!b3:2 dev/rd3c!b3:3 dev/rd3d!b3:4 -BDEVS += dev/swap!b4:64 dev/swap0!b4:0 dev/swap1!b4:1 dev/swap2!b4:2 - -D_CONSOLE = dev/console!c0:0 -D_MEM = dev/mem!c1:0 dev/kmem!c1:1 dev/null!c1:2 dev/zero!c1:3 -D_TTY = dev/tty!c2:0 -D_FD = dev/stdin!c3:0 dev/stdout!c3:1 dev/stderr!c3:2 -D_TEMP = dev/temp0!c4:0 dev/temp1!c4:1 dev/temp2!c4:2 - -CDEVS = $(D_CONSOLE) $(D_MEM) $(D_TTY) $(D_FD) $(D_TEMP) all: tools build kernel $(MAKE) fs @@ -132,24 +83,17 @@ lib: build: tools lib $(MAKE) -C src install -filesys.img: $(FSUTIL) $(ALLFILES) +filesys.img: $(FSUTIL) rootfs.manifest #$(ALLFILES) rm -f $@ - $(FSUTIL) -n$(FS_KBYTES) $@ - $(FSUTIL) -a $@ $(ALLDIRS) - $(FSUTIL) -a $@ $(CDEVS) - $(FSUTIL) -a $@ $(BDEVS) - $(FSUTIL) -a $@ $(ALLFILES) - $(FSUTIL) -a $@ $(MANFILES) + $(FSUTIL) -n$(FS_KBYTES) -Mrootfs.manifest $@ . swap.img: dd if=/dev/zero of=$@ bs=1k count=$(SWAP_KBYTES) -user.img: $(FSUTIL) +user.img: $(FSUTIL) userfs.manifest ifneq ($(U_KBYTES), 0) rm -f $@ - $(FSUTIL) -n$(U_KBYTES) $@ - (cd u; find . -type d -exec ../$(FSUTIL) -a ../$@ '{}/' \;) - (cd u; find . -type f -exec ../$(FSUTIL) -a ../$@ '{}' \+) + $(FSUTIL) -n$(U_KBYTES) -Muserfs.manifest $@ u endif sdcard.rd: filesys.img swap.img user.img @@ -184,20 +128,20 @@ cleanall: clean rm -f var/log/aculog rm -rf var/lock -installfs: filesys.img +installfs: filesys.img ifdef SDCARD - sudo dd bs=32k if=sdcard.rd of=$(SDCARD) + sudo dd bs=32k if=sdcard.rd of=$(SDCARD) else - @echo "Error: No SDCARD defined." + @echo "Error: No SDCARD defined." endif # TODO: make it relative to Target installflash: - sudo pic32prog sys/pic32/fubarino/unix.hex + sudo pic32prog sys/pic32/fubarino/unix.hex # TODO: make it relative to Target installboot: - sudo pic32prog sys/pic32/fubarino/bootloader.hex + sudo pic32prog sys/pic32/fubarino/bootloader.hex -.profile: etc/root/dot.profile +.profile: etc/root/dot.profile cp etc/root/dot.profile .profile diff --git a/filesys.manifest b/rootfs.manifest similarity index 99% rename from filesys.manifest rename to rootfs.manifest index 6910753..47cc8d6 100644 --- a/filesys.manifest +++ b/rootfs.manifest @@ -34,12 +34,15 @@ minor 1 cdev /dev/null major 1 minor 2 +mode 666 cdev /dev/zero major 1 minor 3 +mode 666 cdev /dev/tty major 2 minor 0 +mode 666 cdev /dev/stdin major 3 minor 0 @@ -350,14 +353,14 @@ target /bin/chpass link /bin/chsh target /bin/chpass -file /bin/rb +link /bin/rb target /bin/rz -file /bin/rx +link /bin/rx target /bin/rz -file /bin/sb +link /bin/sb target /bin/sz -file /bin/sx +link /bin/sx target /bin/sz # diff --git a/tools/fsutil/fsutil.c b/tools/fsutil/fsutil.c index 721b467..ea3aa05 100644 --- a/tools/fsutil/fsutil.c +++ b/tools/fsutil/fsutil.c @@ -75,7 +75,7 @@ static void print_help (char *progname) printf ("%s\n", program_version); printf ("This program is free software; it comes with ABSOLUTELY NO WARRANTY;\n" - "see the GNU General Public License for more details.\n"); + "see the BSD 3-Clause License for more details.\n"); printf ("\n"); printf ("Usage:\n"); printf (" %s [--verbose] filesys.img\n", progname); @@ -474,6 +474,8 @@ void add_hardlink (fs_t *fs, const char *path, const char *link) fprintf (stderr, "%s: link failed\n", path); return; } + source.nlink++; + fs_inode_save (&source, 1); } /* @@ -521,6 +523,7 @@ void add_contents (fs_t *fs, const char *dirname, const char *manifest) void *cursor; char *path, *link; int filetype, mode, owner, group, majr, minr; + int ndirs = 0, nfiles = 0, nlinks = 0, nsymlinks = 0, ndevs = 0; if (manifest) { /* Load manifest from file. */ @@ -545,24 +548,34 @@ void add_contents (fs_t *fs, const char *dirname, const char *manifest) switch (filetype) { case 'd': add_directory (fs, path, mode, owner, group); + ndirs++; break; case 'f': add_file (fs, path, dirname, mode, owner, group); + nfiles++; break; case 'l': add_hardlink (fs, path, link); + nlinks++; break; case 's': add_symlink (fs, path, link, mode, owner, group); + nsymlinks++; break; case 'b': add_device (fs, path, mode, owner, group, 'b', majr, minr); + ndevs++; break; case 'c': add_device (fs, path, mode, owner, group, 'c', majr, minr); + ndevs++; break; } } + fs_sync (fs, 0); + fs_close (fs); + printf ("Installed %u directories, %u files, %u devices, %u links, %u symlinks\n", + ndirs, nfiles, ndevs, nlinks, nsymlinks); } int main (int argc, char **argv) @@ -574,7 +587,7 @@ int main (int argc, char **argv) const char *manifest = 0; for (;;) { - key = getopt_long (argc, argv, "vaxmMSn:cfs:", + key = getopt_long (argc, argv, "vaxmSn:cfs:M:", program_options, 0); if (key == -1) break; @@ -622,19 +635,23 @@ int main (int argc, char **argv) } } i = optind; - if ((! add && ! mount && ! newfs && i != argc-1) || - (add && i >= argc) || - (newfs && i != argc-1 && i != argc-2) || - (mount && i != argc-2) || - (extract + newfs + check + add + mount + scan > 1) || - (newfs && kbytes < BSDFS_BSIZE * 10 / 1024)) - { + if (extract + newfs + check + add + mount + scan > 1) { print_help (argv[0]); return -1; } if (newfs) { /* Create new filesystem. */ + if (i != argc-1 && i != argc-2) { + print_help (argv[0]); + return -1; + } + if (kbytes < BSDFS_BSIZE * 10 / 1024) { + /* Need at least 10 blocks. */ + fprintf (stderr, "%s: too small\n", argv[i]); + return -1; + } + if (! fs_create (&fs, argv[i], kbytes, swap_kbytes)) { fprintf (stderr, "%s: cannot create filesystem\n", argv[i]); return -1; @@ -652,6 +669,10 @@ int main (int argc, char **argv) if (check) { /* Check filesystem for errors, and optionally fix them. */ + if (i != argc-1) { + print_help (argv[0]); + return -1; + } if (! fs_open (&fs, argv[i], fix)) { fprintf (stderr, "%s: cannot open\n", argv[i]); return -1; @@ -663,6 +684,10 @@ int main (int argc, char **argv) if (scan) { /* Create a manifest from directory contents. */ + if (i != argc-1) { + print_help (argv[0]); + return -1; + } if (! manifest_scan (&m, argv[i])) { fprintf (stderr, "%s: cannot read\n", argv[i]); return -1; @@ -672,6 +697,10 @@ int main (int argc, char **argv) } /* Add or extract or info. */ + if (i >= argc) { + print_help (argv[0]); + return -1; + } if (! fs_open (&fs, argv[i], (add + mount != 0))) { fprintf (stderr, "%s: cannot open\n", argv[i]); return -1; @@ -679,6 +708,10 @@ int main (int argc, char **argv) if (extract) { /* Extract all files to current directory. */ + if (i != argc-1) { + print_help (argv[0]); + return -1; + } if (! fs_inode_get (&fs, &inode, BSDFS_ROOT_INODE)) { fprintf (stderr, "%s: cannot get inode 1\n", argv[i]); return -1; @@ -690,6 +723,10 @@ int main (int argc, char **argv) if (add) { /* Add files i+1..argc-1 to filesystem. */ + if (i >= argc) { + print_help (argv[0]); + return -1; + } while (++i < argc) add_object (&fs, argv[i]); fs_sync (&fs, 0); @@ -699,14 +736,18 @@ int main (int argc, char **argv) if (mount) { /* Mount the filesystem. */ - if (++i >= argc) { + if (i != argc-2) { print_help (argv[0]); return -1; } - return fs_mount(&fs, argv[i]); + return fs_mount(&fs, argv[i+1]); } /* Print the structure of flesystem. */ + if (i != argc-1) { + print_help (argv[0]); + return -1; + } fs_print (&fs, stdout); if (verbose) { printf ("--------\n"); diff --git a/tools/fsutil/mount.c b/tools/fsutil/mount.c index 69f5a60..fb4b256 100644 --- a/tools/fsutil/mount.c +++ b/tools/fsutil/mount.c @@ -465,6 +465,8 @@ int op_link(const char *path, const char *newpath) printlog("--- link failed\n"); return -EIO; } + source.nlink++; + fs_inode_save (&source, 1); return 0; } diff --git a/u/README.txt b/u/README.txt new file mode 100644 index 0000000..aa96d61 --- /dev/null +++ b/u/README.txt @@ -0,0 +1 @@ +User filesystem. diff --git a/userfs.manifest b/userfs.manifest new file mode 100644 index 0000000..4de6f25 --- /dev/null +++ b/userfs.manifest @@ -0,0 +1,10 @@ +# +# Manifest file for user filesystem. +# +default +owner 0 +group 0 +dirmode 0775 +filemode 0664 + +file README.txt