linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bob Copeland <me@bobcopeland.com>
To: linux-fsdevel@vger.kernel.org
Cc: Bob Copeland <me@bobcopeland.com>
Subject: [RFC][PATCH 6/7] omfs: checksumming routines
Date: Wed, 15 Mar 2006 22:01:45 -0500	[thread overview]
Message-ID: <11424781052948-git-send-email-me@bobcopeland.com> (raw)
In-Reply-To: <11424781043264-git-send-email-me@bobcopeland.com>

This patch adds routines to compute checksums that are stored in the
headers of all filesystem entities in OMFS.
---

 fs/omfs/checksum.c |   60 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 60 insertions(+), 0 deletions(-)
 create mode 100644 fs/omfs/checksum.c

e1a3b6f48ad0d0f0d69fcc35c890f92afaffb38f
diff --git a/fs/omfs/checksum.c b/fs/omfs/checksum.c
new file mode 100644
index 0000000..212e8b5
--- /dev/null
+++ b/fs/omfs/checksum.c
@@ -0,0 +1,60 @@
+#include <linux/config.h>
+#include <linux/fs.h>
+#include <linux/buffer_head.h>
+#include "omfs.h"
+
+#define POLY 0x1021
+
+/*
+ * crc-ccitt with MSB first (i.e., backwards), so we can't use the
+ * kernel table as-is.  
+ */
+#ifdef OMFS_WRITE
+static u16 omfs_crc(u16 crc, unsigned char *buf, int count)
+{
+	int i, j;
+	printk(KERN_DEBUG "omfs: in crc for count %x\n", count);
+	for (i=0; i<count; i++) {
+		crc ^= buf[i] << 8;
+		for (j = 0; j < 8; j++)
+			crc = (crc << 1) ^ ((crc & 0x8000) ? POLY : 0);
+	}
+	return crc;
+}
+#endif
+
+/*
+ * 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, struct super_block *sb, 
+		ino_t ino)
+{
+	int ret=0;
+#ifdef OMFS_WRITE
+	int xor, i, ofs=0, count;
+	u16 crc=0;
+	unsigned char *ptr = (unsigned char *) oi;
+
+	count = be32_to_cpu(oi->i_head.h_body_size);
+	ofs = sizeof(struct omfs_header);
+
+	printk(KERN_DEBUG "omfs: body size is %x\n", count);
+
+	crc = omfs_crc(crc, ptr + ofs, count);
+	oi->i_head.h_crc = cpu_to_be16(crc);
+
+	xor = ptr[0];
+	for (i=1; i<OMFS_XOR_COUNT; i++)
+		xor ^= ptr[i];
+
+	oi->i_head.h_check_xor = xor;
+
+	printk(KERN_DEBUG "Calculated checksum for %lx as %x\n", 
+		ino, crc);
+#endif
+	return ret;
+}
+
+
-- 
1.2.1



  reply	other threads:[~2006-03-16  3:01 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-16  3:01 [RFC][PATCH 0/7] Optimized MPEG file system Bob Copeland
2006-03-16  3:01 ` [RFC][PATCH 1/7] omfs: filesystem headers Bob Copeland
2006-03-16  3:01   ` [RFC][PATCH 2/7] omfs: inode and superblock routines Bob Copeland
2006-03-16  3:01     ` [RFC][PATCH 3/7] omfs: directory routines Bob Copeland
2006-03-16  3:01       ` [RFC][PATCH 4/7] omfs: file routines Bob Copeland
2006-03-16  3:01         ` [RFC][PATCH 5/7] omfs: bitmap / block allocation routines Bob Copeland
2006-03-16  3:01           ` Bob Copeland [this message]
2006-03-16  3:01             ` [RFC][PATCH 7/7] omfs: kbuild updates Bob Copeland
2006-03-16  4:33 ` [RFC][PATCH 0/7] Optimized MPEG file system Brad Boyer
2006-03-16 18:33   ` Bob Copeland

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=11424781052948-git-send-email-me@bobcopeland.com \
    --to=me@bobcopeland.com \
    --cc=linux-fsdevel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).