changeset 717:178ed445021d

tiffs-mkfs: journal creation implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 23 Aug 2020 03:40:10 +0000
parents 3713a349fb1e
children 098fea21ba13
files ffstools/tiffs-mkfs/ffsparam.c ffstools/tiffs-mkfs/globals.c ffstools/tiffs-mkfs/globals.h ffstools/tiffs-mkfs/main.c ffstools/tiffs-mkfs/output.c ffstools/tiffs-mkfs/struct.h
diffstat 6 files changed, 46 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/ffstools/tiffs-mkfs/ffsparam.c	Wed Jul 01 00:31:37 2020 +0000
+++ b/ffstools/tiffs-mkfs/ffsparam.c	Sun Aug 23 03:40:10 2020 +0000
@@ -70,15 +70,26 @@
 }
 
 void
-preen_block_files_max()
+preen_journal_size()
 {
-	unsigned journal_size;
-
-	if (block_files_max)
+	if (journal_size)
 		return;
 	/* default matching TI's code */
 	journal_size = ffs_sector_size >> 4;
 	if (journal_size < 1024)
 		journal_size = 1024;
-	block_files_max = (journal_size >> 4) - 6;
 }
+
+void
+preen_block_files_max()
+{
+	unsigned local_journal_size;
+
+	if (block_files_max)
+		return;
+	/* default matching TI's code */
+	local_journal_size = ffs_sector_size >> 4;
+	if (local_journal_size < 1024)
+		local_journal_size = 1024;
+	block_files_max = (local_journal_size >> 4) - 6;
+}
--- a/ffstools/tiffs-mkfs/globals.c	Wed Jul 01 00:31:37 2020 +0000
+++ b/ffstools/tiffs-mkfs/globals.c	Sun Aug 23 03:40:10 2020 +0000
@@ -9,7 +9,8 @@
 
 unsigned ffs_sector_size, ffs_nsectors;
 char *format_name;
-unsigned chunk_size_max, block_files_max;
+unsigned chunk_size_max, block_files_max, journal_size;
+int no_journal;
 u_char *inode_block, *data_block, *chunk_buffer;
 struct tiffs_inode *inode_array;
 unsigned inode_fill_level, data_fill_level, objects_in_block;
--- a/ffstools/tiffs-mkfs/globals.h	Wed Jul 01 00:31:37 2020 +0000
+++ b/ffstools/tiffs-mkfs/globals.h	Sun Aug 23 03:40:10 2020 +0000
@@ -5,7 +5,8 @@
 extern unsigned ffs_sector_size, ffs_nsectors;
 extern unsigned ffs_nsectors;
 extern char *format_name;
-extern unsigned chunk_size_max, block_files_max;
+extern unsigned chunk_size_max, block_files_max, journal_size;
+extern int no_journal;
 extern u_char *inode_block, *data_block, *chunk_buffer;
 extern struct tiffs_inode *inode_array;
 extern unsigned inode_fill_level, data_fill_level, objects_in_block;
--- a/ffstools/tiffs-mkfs/main.c	Wed Jul 01 00:31:37 2020 +0000
+++ b/ffstools/tiffs-mkfs/main.c	Sun Aug 23 03:40:10 2020 +0000
@@ -16,7 +16,7 @@
 	extern char *optarg;
 	int c;
 
-	while ((c = getopt(argc, argv, "c:f:m:")) != EOF)
+	while ((c = getopt(argc, argv, "c:f:j:Jm:")) != EOF)
 		switch (c) {
 		case 'c':
 			chunk_size_max = strtoul(optarg, 0, 0);
@@ -29,6 +29,12 @@
 			}
 			format_name = optarg;
 			continue;
+		case 'j':
+			journal_size = strtoul(optarg, 0, 0);
+			continue;
+		case 'J':
+			no_journal = 1;
+			continue;
 		case 'm':
 			block_files_max = strtoul(optarg, 0, 0);
 			continue;
@@ -52,6 +58,7 @@
 	if (!format_name)
 		format_name = "/";
 	preen_chunk_size_max();
+	preen_journal_size();
 	preen_block_files_max();
 	/* input phase */
 	read_dir_level(&root, input_host_dir, 0);
@@ -61,6 +68,8 @@
 	open_output_file();
 	create_root_dir();
 	process_dir_level(&root);
+	if (!no_journal)
+		create_journal();
 	finish_output();
 	close(output_fd);
 	exit(0);
--- a/ffstools/tiffs-mkfs/output.c	Wed Jul 01 00:31:37 2020 +0000
+++ b/ffstools/tiffs-mkfs/output.c	Sun Aug 23 03:40:10 2020 +0000
@@ -96,7 +96,7 @@
 		size = strlen(name) + 1;
 	else
 		size = 0;
-	if (data)
+	if (datalen)
 		size += datalen + 1;
 	size = (size + 15) & ~15;
 	if (ffs_sector_size - data_fill_level < size ||
@@ -113,8 +113,9 @@
 		strcpy(dp, name);
 		dp += strlen(name) + 1;
 	}
-	if (data) {
-		bcopy(data, dp, datalen);
+	if (datalen) {
+		if (data)
+			bcopy(data, dp, datalen);
 		dp += datalen;
 		*dp++ = 0;
 	}
@@ -209,6 +210,17 @@
 }
 
 void
+create_journal()
+{
+	int ino;
+
+	ino = create_object(".journal", OBJTYPE_FILE_RO, (u_char *) 0,
+				journal_size);
+	*root.u.d.ffs_link_ptr = htole16(ino);
+	root.u.d.ffs_link_ptr = &inode_array[ino].sibling;
+}
+
+void
 finish_output()
 {
 	if (objects_in_block)
--- a/ffstools/tiffs-mkfs/struct.h	Wed Jul 01 00:31:37 2020 +0000
+++ b/ffstools/tiffs-mkfs/struct.h	Sun Aug 23 03:40:10 2020 +0000
@@ -33,6 +33,7 @@
 
 /* TIFFS object types */
 #define	OBJTYPE_FILE	0xF1
+#define	OBJTYPE_FILE_RO	0xE1
 #define	OBJTYPE_DIR	0xF2
 #define	OBJTYPE_SYMLINK	0xF3
 #define	OBJTYPE_SEGMENT	0xF4