mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mike Waychison <mikew@google.com>
To: linux-fsdevel@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Mike Waychison <mikew@google.com>
Subject: [patch 5/6][RFC] Introduce FIBMAP64
Date: Fri, 26 Oct 2007 16:37:37 -0700	[thread overview]
Message-ID: <20071026233848.939953744@crlf.corp.google.com> (raw)
In-Reply-To: <20071026233732.568575496@crlf.corp.google.com>

[-- Attachment #1: add_fibmap64.patch --]
[-- Type: text/plain, Size: 4090 bytes --]

Introduce FIBMAP64.  This is the same as FIBMAP, but takes a u64.

This new routine requires filesystems to implement bmap64 if they want to support > 2^31 blocks in a logical file.  We do this to give time for filesystems to be properly audited.

Signed-off-by: Mike Waychison <mikew@google.com>

 fs/compat_ioctl.c  |    2 ++
 fs/ioctl.c         |   34 +++++++++++++++++++++++++++++++++-
 include/linux/fs.h |    7 +++++++
 3 files changed, 42 insertions(+), 1 deletion(-)

Index: linux-2.6.23/fs/ioctl.c
===================================================================
--- linux-2.6.23.orig/fs/ioctl.c	2007-10-26 15:28:28.000000000 -0700
+++ linux-2.6.23/fs/ioctl.c	2007-10-26 16:16:28.000000000 -0700
@@ -44,11 +44,24 @@ static int do_fibmap(struct address_spac
 		     sector_t *phys_block)
 {
 	struct inode *inode = mapping->host;
+	sector_t (*bmap)(struct address_space *, sector_t);
 
 	if (!capable(CAP_SYS_RAWIO))
 		return -EPERM;
-	if (!mapping->a_ops->bmap)
+
+	if (mapping->a_ops->bmap64) {
+		/* Filesystem has bmap path audited for 64bit. */
+		bmap = mapping->a_ops->bmap64;
+	} else if (mapping->a_ops->bmap) {
+		bmap = mapping->a_ops->bmap;
+		/* Need to verify that the input looks sane when sector_t is
+		 * 64bit and the filesystem has only been audited for 32bit. */
+		if ((s32)block < 0)
+			return -EFBIG;
+	} else {
+		/* no FIBMAP support */
 		return -EINVAL;
+	}
 
 	lock_kernel();
 	/* Avoid races with truncate */
@@ -95,6 +108,25 @@ static int file_ioctl(struct file *filp,
 			res = phys_block;
 			return put_user(res, p);
 		}
+		case FIBMAP64:
+		{
+			struct address_space *mapping = filp->f_mapping;
+			sector_t phys_block;
+			u64 block;
+
+			if ((error = get_user(block, p)) != 0)
+				return error;
+
+			/* Make sure that the logical block fits in sector_t */
+			if ((sector_t)-1 < block)
+				return -EFBIG;
+
+			error = do_fibmap(mapping, block, &phys_block);
+			if (error)
+				return error;
+
+			return put_user(block, p);
+		}
 		case FIGETBSZ:
 			return put_user(inode->i_sb->s_blocksize, p);
 		case FIONREAD:
Index: linux-2.6.23/include/linux/fs.h
===================================================================
--- linux-2.6.23.orig/include/linux/fs.h	2007-10-26 15:25:47.000000000 -0700
+++ linux-2.6.23/include/linux/fs.h	2007-10-26 15:29:00.000000000 -0700
@@ -220,6 +220,7 @@ extern int dir_notify_enable;
 #define BMAP_IOCTL 1		/* obsolete - kept for compatibility */
 #define FIBMAP	   _IO(0x00,1)	/* bmap access */
 #define FIGETBSZ   _IO(0x00,2)	/* get the block size used for bmap */
+#define FIBMAP64   _IO(0x00,3)	/* bmap access - 64 bit sector numbers */
 
 #define	FS_IOC_GETFLAGS			_IOR('f', 1, long)
 #define	FS_IOC_SETFLAGS			_IOW('f', 2, long)
@@ -423,6 +424,12 @@ struct address_space_operations {
 	int (*commit_write)(struct file *, struct page *, unsigned, unsigned);
 	/* Unfortunately this kludge is needed for FIBMAP. Don't use it */
 	sector_t (*bmap)(struct address_space *, sector_t);
+	/*
+	 * Version of bmap for filesystems that can safely handle 64bit
+	 * sector_t.  Once all filesystems are converted to this, we can drop
+	 * bmap().
+	 */
+	sector_t (*bmap64)(struct address_space *, sector_t);
 	void (*invalidatepage) (struct page *, unsigned long);
 	int (*releasepage) (struct page *, gfp_t);
 	ssize_t (*direct_IO)(int, struct kiocb *, const struct iovec *iov,
Index: linux-2.6.23/fs/compat_ioctl.c
===================================================================
--- linux-2.6.23.orig/fs/compat_ioctl.c	2007-10-26 15:25:47.000000000 -0700
+++ linux-2.6.23/fs/compat_ioctl.c	2007-10-26 15:29:00.000000000 -0700
@@ -2506,6 +2506,7 @@ COMPATIBLE_IOCTL(FIONREAD)  /* This is a
 /* 0x00 */
 COMPATIBLE_IOCTL(FIBMAP)
 COMPATIBLE_IOCTL(FIGETBSZ)
+COMPATIBLE_IOCTL(FIBMAP64)
 /* 0x03 -- HD/IDE ioctl's used by hdparm and friends.
  *         Some need translations, these do not.
  */
@@ -3597,6 +3598,7 @@ asmlinkage long compat_sys_ioctl(unsigne
 
 	case FIBMAP:
 	case FIGETBSZ:
+	case FIBMAP64:
 	case FIONREAD:
 		if (S_ISREG(filp->f_path.dentry->d_inode->i_mode))
 			break;

--

  parent reply	other threads:[~2007-10-26 23:42 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-26 23:37 [patch 0/6][RFC] Cleanup FIBMAP Mike Waychison
2007-10-26 23:37 ` [patch 1/6][RFC] Keep FIBMAP from looking at negative block nrs Mike Waychison
2007-10-26 23:37 ` [patch 2/6][RFC] Allow FIBMAP to return EFBIG on large filesystems Mike Waychison
2007-10-26 23:37 ` [patch 3/6][RFC] Move FIBMAP logic Mike Waychison
2007-10-26 23:37 ` [patch 4/6][RFC] Attempt to plug race with truncate Mike Waychison
2007-10-29 13:36   ` Chris Mason
2007-10-26 23:37 ` Mike Waychison [this message]
2007-10-29 13:45   ` [patch 5/6][RFC] Introduce FIBMAP64 Chris Mason
2007-10-26 23:37 ` [patch 6/6][RFC] Drop CAP_SYS_RAWIO requirement on FIBMAP Mike Waychison
2007-10-27 17:57 ` [patch 0/6][RFC] Cleanup FIBMAP Anton Altaparmakov
2007-10-27 21:45   ` Szabolcs Szakacsits
2007-10-29 14:10   ` Chris Mason
2007-10-29 16:30     ` Zach Brown
2007-10-29 19:18       ` Mike Waychison
2007-10-29 19:46         ` Chris Mason
2007-10-29 20:01           ` Zach Brown
2007-10-29 20:00         ` Zach Brown
2007-10-31 11:06           ` Ric Wheeler
2007-10-31 16:16             ` Zach Brown
2007-10-31 17:17               ` Ric Wheeler
2007-10-29 19:16     ` Mike Waychison
2007-10-29 19:47       ` Andreas Dilger
2007-10-28  0:43 ` H. Peter Anvin

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=20071026233848.939953744@crlf.corp.google.com \
    --to=mikew@google.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@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

Powered by JetHome