login
Header Space

 
 

[PATCH 6/7] omfs: add checksumming routines

Previous thread: [PATCH 2/7] omfs: add inode routines by Bob Copeland on Saturday, April 12, 2008 - 6:58 pm. (8 messages)

Next thread: [PATCH 0/7] OMFS filesystem version 3 by Bob Copeland on Saturday, April 12, 2008 - 6:58 pm. (86 messages)
To: <linux-kernel@...>
Cc: <linux-fsdevel@...>, <akpm@...>, Bob Copeland <me@...>
Date: Saturday, April 12, 2008 - 6:58 pm

OMFS checksums the metadata of all filesystem objects.  This change adds
    the necessary functions to do so.

    Signed-off-by: Bob Copeland &lt;me@bobcopeland.com&gt;
---
 fs/omfs/checksum.c |   31 +++++++++++++++++++++++++++++++
 1 files changed, 31 insertions(+), 0 deletions(-)
 create mode 100644 fs/omfs/checksum.c

diff --git a/fs/omfs/checksum.c b/fs/omfs/checksum.c
new file mode 100644
index 0000000..cbd0471
--- /dev/null
+++ b/fs/omfs/checksum.c
@@ -0,0 +1,31 @@
+#include &lt;linux/fs.h&gt;
+#include &lt;linux/buffer_head.h&gt;
+#include &lt;linux/crc-itu-t.h&gt;
+#include "omfs.h"
+
+/*
+ * Update the header checksums for a dirty inode based on its contents.
+ * Caller is expected to hold the buffer head underlying oi and mark it
+ * dirty.
+ */
+int omfs_update_checksums(struct omfs_inode *oi)
+{
+	int ret = 0;
+	int xor, i, ofs = 0, count;
+	u16 crc = 0;
+	unsigned char *ptr = (unsigned char *) oi;
+
+	count = be32_to_cpu(oi-&gt;i_head.h_body_size);
+	ofs = sizeof(struct omfs_header);
+
+	crc = crc_itu_t(crc, ptr + ofs, count);
+	oi-&gt;i_head.h_crc = cpu_to_be16(crc);
+
+	xor = ptr[0];
+	for (i = 1; i &lt; OMFS_XOR_COUNT; i++)
+		xor ^= ptr[i];
+
+	oi-&gt;i_head.h_check_xor = xor;
+
+	return ret;
+}
-- 
1.5.4.2


--
To: Bob Copeland <me@...>
Cc: <linux-kernel@...>, <linux-fsdevel@...>, <akpm@...>
Date: Sunday, April 13, 2008 - 4:09 am

Looks good, but do we really need a separate source file for this one
routine?

--
Previous thread: [PATCH 2/7] omfs: add inode routines by Bob Copeland on Saturday, April 12, 2008 - 6:58 pm. (8 messages)

Next thread: [PATCH 0/7] OMFS filesystem version 3 by Bob Copeland on Saturday, April 12, 2008 - 6:58 pm. (86 messages)
speck-geostationary