From mboxrd@z Thu Jan 1 00:00:00 1970 From: Josef 'Jeff' Sipek Subject: [PATCH 09/12] cmsfs: misc helpers Date: Sun, 21 Sep 2008 21:29:25 -0400 Message-ID: <1222046968-3364-10-git-send-email-jeffpc@josefsipek.net> References: <1222046968-3364-1-git-send-email-jeffpc@josefsipek.net> Cc: hch@infradead.org, Josef 'Jeff' Sipek To: linux-fsdevel@vger.kernel.org Return-path: Received: from [148.100.96.56] ([148.100.96.56]:54343 "EHLO ldave2.osdl.marist.edu" rhost-flags-FAIL-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752842AbYIVBrf (ORCPT ); Sun, 21 Sep 2008 21:47:35 -0400 In-Reply-To: <1222046968-3364-1-git-send-email-jeffpc@josefsipek.net> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: Signed-off-by: Josef 'Jeff' Sipek --- fs/cmsfs/helpers.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 78 insertions(+), 0 deletions(-) create mode 100644 fs/cmsfs/helpers.c diff --git a/fs/cmsfs/helpers.c b/fs/cmsfs/helpers.c new file mode 100644 index 0000000..93800b3 --- /dev/null +++ b/fs/cmsfs/helpers.c @@ -0,0 +1,78 @@ +/* + * CMSFS + * + * (C) 2008 Josef 'Jeff' Sipek + * + * Based on cmsfs from 2.4.12-ac6: + * + * (C) 2001 Rick Troth + * (C) 2001 BMC Software, Inc., Houston, Texas, USA + * + */ + +#include +#include + +#include "cmsfs.h" + +void munge_name(__u8 *name, char *outname) +{ + __u8 *p = name; + char *orig_outname = outname; + + if (!name) + return; + + /* + * NOTE: + * '\x40' is a space in EBCDIC + * '\x4b' is a period in EBCDIC + */ + + /* file name */ + while(*p != '\x40' && (p - name < 8)) + *outname++ = *p++; + + *outname++ = '\x4b'; + + p = name+8; + + while(*p != '\x40' && (p - name < 16)) + *outname++ = *p++; + + *outname = '\0'; + + EBC2ASC(orig_outname, 17); +} + +/** + * cmsfs_read_block - read a single disk block + * @sb: superblock to read from + * @buf: buffer to fill + * @block: block number to read + * @blocksize: blocksize to use + */ +int cmsfs_read_block(struct super_block *sb, void *buf, int block, + unsigned blocksize) +{ + struct buffer_head * bh; + + /* for the moment, we only deal with physical blocks */ + BUG_ON(blocksize != sb->s_blocksize); + + /* We could maybe handle that case by breaking-up this call into + multiple bread() calls, but that'll be a later driver rev. */ + + /* Call the system-level __bread() */ + bh = __bread(sb->s_bdev, block, blocksize); + if (!bh) { + printk(KERN_WARNING "cmsfs: system bread() failed.\n"); + return -EIO; + } + + /* copy the data part, then release the VFS buffer */ + memmove(buf, bh->b_data, blocksize); + brelse(bh); + + return blocksize; +} -- 1.5.6.3