Hi,

this adds a 32bit version field after the magic. I choose 200709061 as a 
starting version, where the last 1 is a counter ranging to 9, thus there can be 
9 different version per day (lol).

It is not going to try any backward compatibility or workaround based on 
version, just bail out or skip when a different version than we are running is 
encountered.

It might be a better idea grouping len and offset fields after or before 
version field, and make then fixed by design, so we can do correct skipping 
instead the 16-byte aligned walking.

Note: the "/* NOTE -- This and the user-mode lar.h are NOT IN SYNC. Be careful. 
*/" message (which is present both in include/lar.h and utils/lar/lar.h) is not 
valid anymore.
--
Alex

Signed-off-by: Alex Beregszaszi <[EMAIL PROTECTED]>

Index: include/lar.h
===================================================================
--- include/lar.h	(revision 494)
+++ include/lar.h	(working copy)
@@ -54,10 +54,12 @@
 
 /* see note in lib/lar.c as to why this is ARCHIVE and not LARCHIVE */
 #define MAGIC "LARCHIVE"
+#define LAR_VERSION 200709061
 #define MAX_PATHLEN 1024
 /* NOTE -- This and the user-mode lar.h are NOT IN SYNC. Be careful. */
 struct lar_header {
 	char magic[8];
+	u32 version;
 	u32 len;
 	u32 reallen;
 	u32 checksum;
Index: lib/lar.c
===================================================================
--- lib/lar.c	(revision 494)
+++ lib/lar.c	(working copy)
@@ -96,6 +96,11 @@
 			continue;
 
 		header = (struct lar_header *)walk;
+		if (ntohl(header->version) != LAR_VERSION) {
+			printk(BIOS_SPEW, "LAR: unsupported version %d, skipping\n",
+			    ntohl(header->version));
+			continue;
+		}
 		fullname = walk + sizeof(struct lar_header);
 
 		printk(BIOS_SPEW, "LAR: search for %s\n", fullname);
Index: util/lar/lar.h
===================================================================
--- util/lar/lar.h	(revision 494)
+++ util/lar/lar.h	(working copy)
@@ -51,6 +51,7 @@
 #include <stdint.h>
 
 #define MAGIC "LARCHIVE"
+#define LAR_VERSION 200709061
 #define MAX_PATHLEN 1024
 #define BOOTBLOCK_SIZE 16384
 
@@ -64,6 +65,7 @@
 /* NOTE -- This and the linuxbios lar.h are NOT IN SYNC. Be careful. */
 struct lar_header {
 	char magic[8];
+	u32 version;
 	u32 len;
 	u32 reallen;
 	u32 checksum;
Index: util/lar/stream.c
===================================================================
--- util/lar/stream.c	(revision 494)
+++ util/lar/stream.c	(working copy)
@@ -229,6 +229,7 @@
 	header = (struct lar_header *) offset;
 
 	memcpy(header->magic, MAGIC, 8);
+	header->version = htonl(LAR_VERSION);
 	header->reallen = htonl(BOOTBLOCK_SIZE);
 	header->len = htonl(BOOTBLOCK_SIZE);
 	header->offset = htonl(sizeof(struct lar_header) + BOOTBLOCK_NAME_LEN);
@@ -238,7 +239,7 @@
 
 	offset += BOOTBLOCK_NAME_LEN;
 
-	/* If a file waas specified, then load it, and read it directly
+	/* If a file was specified, then load it, and read it directly
 	 * into place */
 
 	if (bootblock != NULL) {
@@ -509,6 +510,9 @@
 
 		if (strncmp(header->magic, MAGIC, 8))
 			break;
+		
+		if (ntohl(header->version) != LAR_VERSION)
+			printf("Warning: unsupported version, results might be invalid.\n");
 
 		filename = (char *) (ptr + sizeof(struct lar_header));
 
@@ -577,7 +581,7 @@
 	ret = write(fd, buffer, len);
 
 	if (ret != len)
-		err("Error writingthe file %s\n", filename);
+		err("Error writing the file %s\n", filename);
 
 	close(fd);
 	return (ret == len) ? 0 : -1;
@@ -605,6 +609,11 @@
 		if (strncmp(header->magic, MAGIC, 8))
 			break;
 
+		if (ntohl(header->version) != LAR_VERSION) {
+			err("Unsupported version: %d\n", ntohl(header->version));
+			return -1;
+		}
+
 		filename = (char *) (ptr + sizeof(struct lar_header));
 
 		if (file_in_list(files, filename)) {
@@ -798,6 +807,7 @@
 	header = (struct lar_header *) (lar->map + offset);
 
 	memcpy(header, MAGIC, 8);
+	header->version = htonl(LAR_VERSION);
 	header->compression = htonl(thisalgo);
 	header->reallen = htonl(reallen);
 	header->len = htonl(complen);
-- 
linuxbios mailing list
linuxbios@linuxbios.org
http://www.linuxbios.org/mailman/listinfo/linuxbios

Reply via email to