From: joern@logfs.org
To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-mtd@lists.infradead.org
Cc: Jens Axboe <jens.axboe@oracle.com>
Subject: [patch 14/15] fs/logfs/dev_bdev.c
Date: Tue, 01 Apr 2008 20:13:08 +0200 [thread overview]
Message-ID: <20080401181332.853833014@logfs.org> (raw)
In-Reply-To: 20080401181308.512473173@logfs.org
--- /dev/null 2008-03-30 12:15:48.586669308 +0200
+++ linux-2.6.24logfs/fs/logfs/dev_bdev.c 2008-03-28 20:04:13.961033452 +0100
@@ -0,0 +1,146 @@
+/*
+ * fs/logfs/dev_bdev.c - Device access methods for block devices
+ *
+ * As should be obvious for Linux kernel code, license is GPLv2
+ *
+ * Copyright (c) 2005-2007 Joern Engel <joern@logfs.org>
+ */
+#include "logfs.h"
+#include <linux/buffer_head.h>
+
+#define PAGE_OFS(ofs) ((ofs) & (PAGE_SIZE-1))
+
+static int bdev_read(struct super_block *sb, loff_t from, size_t len, void *buf)
+{
+ struct block_device *bdev = logfs_super(sb)->s_bdev;
+ struct address_space *mapping = bdev->bd_inode->i_mapping;
+ struct page *page;
+ long index = from >> PAGE_SHIFT;
+ long offset = from & (PAGE_SIZE-1);
+ long copylen;
+
+ while (len) {
+ copylen = min((ulong)len, PAGE_SIZE - offset);
+
+ page = read_cache_page(mapping, index,
+ (filler_t *)mapping->a_ops->readpage, NULL);
+ if (!page)
+ return -ENOMEM;
+ if (IS_ERR(page))
+ return PTR_ERR(page);
+
+ memcpy(buf, page_address(page) + offset, copylen);
+ page_cache_release(page);
+
+ buf += copylen;
+ len -= copylen;
+ offset = 0;
+ index++;
+ }
+ return 0;
+}
+
+static int bdev_write(struct super_block *sb, loff_t to, size_t len, void *buf)
+{
+ struct block_device *bdev = logfs_super(sb)->s_bdev;
+ struct address_space *mapping = bdev->bd_inode->i_mapping;
+ struct page *page;
+ long index = to >> PAGE_SHIFT;
+ long offset = to & (PAGE_SIZE-1);
+ long copylen;
+
+ if (logfs_super(sb)->s_flags & LOGFS_SB_FLAG_RO)
+ return -EROFS;
+
+ while (len) {
+ copylen = min((ulong)len, PAGE_SIZE - offset);
+
+ page = read_cache_page(mapping, index,
+ (filler_t *)mapping->a_ops->readpage, NULL);
+ if (!page)
+ return -ENOMEM;
+ if (IS_ERR(page))
+ return PTR_ERR(page);
+ lock_page(page);
+ memcpy(page_address(page) + offset, buf, copylen);
+ set_page_dirty(page);
+ unlock_page(page);
+ page_cache_release(page);
+
+ buf += copylen;
+ len -= copylen;
+ offset = 0;
+ index++;
+ }
+ return 0;
+}
+
+static int bdev_erase(struct super_block *sb, loff_t to, size_t len)
+{
+ struct block_device *bdev = logfs_super(sb)->s_bdev;
+ struct address_space *mapping = bdev->bd_inode->i_mapping;
+ struct page *page;
+ long index = to >> PAGE_SHIFT;
+ long offset = to & (PAGE_SIZE-1);
+ long copylen;
+
+ if (logfs_super(sb)->s_flags & LOGFS_SB_FLAG_RO)
+ return -EROFS;
+
+ while (len) {
+ copylen = min((ulong)len, PAGE_SIZE - offset);
+
+ page = read_cache_page(mapping, index,
+ (filler_t *)mapping->a_ops->readpage, NULL);
+ if (!page)
+ return -ENOMEM;
+ if (IS_ERR(page))
+ return PTR_ERR(page);
+ lock_page(page);
+ memset(page_address(page) + offset, 0xFF, copylen);
+ set_page_dirty(page);
+ unlock_page(page);
+ page_cache_release(page);
+
+ len -= copylen;
+ offset = 0;
+ index++;
+ }
+ return 0;
+}
+
+static void bdev_sync(struct super_block *sb)
+{
+ sync_blockdev(logfs_super(sb)->s_bdev);
+}
+
+static s64 bdev_find_sb(struct super_block *sb)
+{
+ return 0;
+}
+
+static const struct logfs_device_ops bd_devops = {
+ .find_sb = bdev_find_sb,
+ .read = bdev_read,
+ .write = bdev_write,
+ .erase = bdev_erase,
+ .sync = bdev_sync,
+};
+
+int logfs_get_sb_bdev(struct file_system_type *type, int flags,
+ const char *devname, struct vfsmount *mnt)
+{
+ struct block_device *bdev;
+
+ bdev = open_bdev_excl(devname, O_RDWR, NULL);
+ if (IS_ERR(bdev))
+ return PTR_ERR(bdev);
+
+ if (MAJOR(bdev->bd_dev) == MTD_BLOCK_MAJOR) {
+ int mtdnr = MINOR(bdev->bd_dev);
+ close_bdev_excl(bdev);
+ return logfs_get_sb_mtd(type, flags, mtdnr, mnt);
+ }
+
+ return logfs_get_sb_device(type, flags, NULL, bdev, &bd_devops, mnt);
+}
next prev parent reply other threads:[~2008-04-03 17:28 UTC|newest]
Thread overview: 85+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-01 18:13 [patch 0/15] LogFS take five joern
2008-04-01 18:13 ` joern
2008-04-01 18:13 ` [patch 6/15] fs/logfs/file.c joern
2008-04-01 18:13 ` [patch 8/15] fs/logfs/inode.c joern
2008-04-04 6:57 ` Kyungmin Park
2008-04-04 6:57 ` Kyungmin Park
2008-04-07 11:12 ` Jörn Engel
2008-04-07 11:12 ` Jörn Engel
2008-04-07 11:12 ` Jörn Engel
2008-04-01 18:13 ` [patch 3/15] fs/logfs/logfs.h joern
2008-04-08 0:35 ` Arnd Bergmann
2008-04-08 0:35 ` Arnd Bergmann
2008-04-08 0:35 ` Arnd Bergmann
2008-04-08 9:41 ` Jörn Engel
2008-04-08 9:41 ` Jörn Engel
2008-04-08 9:41 ` Jörn Engel
2008-04-01 18:13 ` [patch 11/15] fs/logfs/readwrite.c joern
2008-04-01 18:13 ` [patch 5/15] fs/logfs/dir.c joern
2008-04-04 6:22 ` Kyungmin Park
2008-04-04 6:22 ` Kyungmin Park
2008-04-01 18:13 ` [patch 9/15] fs/logfs/journal.c joern
2008-04-01 18:13 ` joern [this message]
2008-04-01 18:13 ` [patch 13/15] fs/logfs/super.c joern
2008-04-01 18:13 ` [patch 1/15] Makefiles and Kconfig joern
2008-04-07 8:28 ` Christian Borntraeger
2008-04-07 8:28 ` Christian Borntraeger
2008-04-07 8:40 ` Jörn Engel
2008-04-07 8:40 ` Jörn Engel
2008-04-07 8:40 ` Jörn Engel
2008-04-08 0:30 ` Arnd Bergmann
2008-04-08 0:30 ` Arnd Bergmann
2008-04-08 8:33 ` Jörn Engel
2008-04-08 8:33 ` Jörn Engel
2008-04-08 8:33 ` Jörn Engel
2008-04-08 13:41 ` Arnd Bergmann
2008-04-08 13:41 ` Arnd Bergmann
2008-04-08 13:41 ` Arnd Bergmann
2008-04-08 13:52 ` Jörn Engel
2008-04-08 13:52 ` Jörn Engel
2008-04-08 13:52 ` Jörn Engel
2008-04-01 18:13 ` [patch 10/15] fs/logfs/memtree.c joern
2008-04-10 14:07 ` Arnd Bergmann
2008-04-10 14:07 ` Arnd Bergmann
2008-04-10 14:07 ` Arnd Bergmann
2008-04-11 10:37 ` Jörn Engel
2008-04-11 10:37 ` Jörn Engel
2008-04-11 10:37 ` Jörn Engel
2008-04-01 18:13 ` [patch 7/15] fs/logfs/gc.c joern
2008-04-01 18:13 ` [patch 2/15] fs/logfs/logfs_abi.h joern
2008-04-08 0:24 ` Arnd Bergmann
2008-04-08 0:24 ` Arnd Bergmann
2008-04-08 0:24 ` Arnd Bergmann
2008-04-08 9:39 ` Jörn Engel
2008-04-08 9:39 ` Jörn Engel
2008-04-08 9:39 ` Jörn Engel
2008-04-08 21:52 ` Andres Salomon
2008-04-08 21:52 ` Andres Salomon
2008-04-09 12:08 ` Jörn Engel
2008-04-09 12:08 ` Jörn Engel
2008-04-09 12:08 ` Jörn Engel
2008-04-01 18:13 ` [patch 12/15] fs/logfs/segment.c joern
2008-04-01 18:13 ` [patch 15/15] fs/logfs/dev_mtd.c joern
2008-04-01 18:13 ` [patch 4/15] fs/logfs/compr.c joern
2008-04-10 14:13 ` Arnd Bergmann
2008-04-10 14:13 ` Arnd Bergmann
2008-04-10 14:13 ` Arnd Bergmann
2008-04-11 10:41 ` Jörn Engel
2008-04-11 10:41 ` Jörn Engel
2008-04-03 17:13 ` [patch 0/15] LogFS take five^Wsix Jörn Engel
2008-04-03 17:13 ` Jörn Engel
2008-04-03 17:13 ` Jörn Engel
2008-04-04 11:46 ` [patch 0/15] LogFS take five Jens Axboe
2008-04-04 11:46 ` Jens Axboe
2008-04-07 8:22 ` Jörn Engel
2008-04-07 8:22 ` Jörn Engel
2008-04-07 8:22 ` Jörn Engel
2008-04-07 8:28 ` Jens Axboe
2008-04-07 8:28 ` Jens Axboe
2008-04-07 8:28 ` Jens Axboe
2008-04-07 9:10 ` Jörn Engel
2008-04-07 9:10 ` Jörn Engel
2008-04-07 9:10 ` Jörn Engel
2008-04-07 9:17 ` Jens Axboe
2008-04-07 9:17 ` Jens Axboe
2008-04-07 9:17 ` Jens Axboe
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=20080401181332.853833014@logfs.org \
--to=joern@logfs.org \
--cc=jens.axboe@oracle.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.