From: sandeen@sandeen.net
To: xfs@oss.sgi.com
Cc: hch@infradead.org
Subject: [patch 04/11] Add compat handlers for swapext ioctl
Date: Tue, 18 Nov 2008 22:44:05 -0600 [thread overview]
Message-ID: <20081119044908.948703484@sandeen.net> (raw)
In-Reply-To: 20081119044401.573365619@sandeen.net
[-- Attachment #1: compat_ioctl_swapext --]
[-- Type: text/plain, Size: 4467 bytes --]
The big hitter here was the bstat field, which contains
different sized time_t on 32 vs. 64 bit. Add a copyin
function to translate the 32-bit arg to 64-bit, and
call the native ioctl.
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
--
Index: linux-2.6-xfs/fs/xfs/linux-2.6/xfs_ioctl32.c
===================================================================
--- linux-2.6-xfs.orig/fs/xfs/linux-2.6/xfs_ioctl32.c
+++ linux-2.6-xfs/fs/xfs/linux-2.6/xfs_ioctl32.c
@@ -136,6 +136,65 @@ xfs_inumbers_fmt_compat(
#endif
+/* tv_sec differs on 64 vs. 32 */
+STATIC int
+xfs_ioctl32_bstime_copyin(
+ xfs_bstime_t __user *p,
+ compat_xfs_bstime_t __user *p32)
+{
+ compat_time_t sec32;
+ s32 nsec;
+
+ if (get_user(sec32, &p32->tv_sec) ||
+ put_user(sec32, &p->tv_sec) ||
+ get_user(nsec, &p32->tv_nsec)||
+ put_user(nsec, &p->tv_nsec))
+ return -XFS_ERROR(EFAULT);
+ return 0;
+}
+
+/* xfs_bstat_t has differing alignment on intel, & bstime_t sizes everywhere */
+STATIC int
+xfs_ioctl32_bstat_copyin(
+ xfs_bstat_t __user *p,
+ compat_xfs_bstat_t __user *p32)
+{
+ if (copy_in_user(&p->bs_ino, &p32->bs_ino, sizeof(u64)) ||
+ copy_in_user(&p->bs_mode, &p32->bs_mode, sizeof(u16)) ||
+ copy_in_user(&p->bs_nlink, &p32->bs_nlink, sizeof(u16)) ||
+ copy_in_user(&p->bs_uid, &p32->bs_uid, sizeof(u32)) ||
+ copy_in_user(&p->bs_gid, &p32->bs_gid, sizeof(u32)) ||
+ copy_in_user(&p->bs_rdev, &p32->bs_rdev, sizeof(u32)) ||
+ copy_in_user(&p->bs_blksize, &p32->bs_blksize, sizeof(s32)) ||
+ copy_in_user(&p->bs_size, &p32->bs_size, sizeof(s64)) ||
+ xfs_ioctl32_bstime_copyin(&p->bs_atime, &p32->bs_atime) ||
+ xfs_ioctl32_bstime_copyin(&p->bs_mtime, &p32->bs_mtime) ||
+ xfs_ioctl32_bstime_copyin(&p->bs_ctime, &p32->bs_ctime) ||
+ copy_in_user(&p->bs_blocks, &p32->bs_size, sizeof(s64)) ||
+ copy_in_user(&p->bs_xflags, &p32->bs_size, sizeof(u32)) ||
+ copy_in_user(&p->bs_extsize, &p32->bs_extsize, sizeof(s32)) ||
+ copy_in_user(&p->bs_extents, &p32->bs_extents, sizeof(s32)) ||
+ copy_in_user(&p->bs_gen, &p32->bs_gen, sizeof(u32)) ||
+ copy_in_user(&p->bs_projid, &p32->bs_projid, sizeof(u16)) ||
+ copy_in_user(&p->bs_dmevmask, &p32->bs_dmevmask, sizeof(u32)) ||
+ copy_in_user(&p->bs_dmstate, &p32->bs_dmstate, sizeof(u16)) ||
+ copy_in_user(&p->bs_aextents, &p32->bs_aextents, sizeof(u16)))
+ return -XFS_ERROR(EFAULT);
+ return 0;
+}
+
+STATIC unsigned long
+xfs_ioctl32_swapext_copyin(unsigned long arg)
+{
+ compat_xfs_swapext_t __user *p32 = (void __user *)arg;
+ xfs_swapext_t __user *p = compat_alloc_user_space(sizeof(*p));
+
+ if (copy_in_user(p, p32, offsetof(xfs_swapext_t, sx_stat)) ||
+ xfs_ioctl32_bstat_copyin(&p->sx_stat, &p32->sx_stat))
+ return -XFS_ERROR(EFAULT);
+ return (unsigned long)p;
+}
+
/* XFS_IOC_FSBULKSTAT and friends */
STATIC int
@@ -351,11 +410,11 @@ xfs_compat_ioctl(
case XFS_IOC_UNRESVSP64:
case XFS_IOC_FSGEOMETRY_V1:
break;
- /* xfs_bstat_t still has wrong u32 vs u64 alignment */
- case XFS_IOC_SWAPEXT:
- break;
-
#endif
+ case XFS_IOC_SWAPEXT_32:
+ arg = xfs_ioctl32_swapext_copyin(arg);
+ cmd = _NATIVE_IOC(cmd, struct xfs_swapext);
+ break;
case XFS_IOC_FSBULKSTAT_32:
case XFS_IOC_FSBULKSTAT_SINGLE_32:
case XFS_IOC_FSINUMBERS_32:
Index: linux-2.6-xfs/fs/xfs/linux-2.6/xfs_ioctl32.h
===================================================================
--- linux-2.6-xfs.orig/fs/xfs/linux-2.6/xfs_ioctl32.h
+++ linux-2.6-xfs/fs/xfs/linux-2.6/xfs_ioctl32.h
@@ -105,6 +105,20 @@ typedef struct compat_xfs_fsop_handlereq
#define XFS_IOC_READLINK_BY_HANDLE_32 \
_IOWR('X', 108, struct compat_xfs_fsop_handlereq)
+/* The bstat field in the swapext struct needs translation */
+typedef struct compat_xfs_swapext
+{
+ __int64_t sx_version; /* version */
+ __int64_t sx_fdtarget; /* fd of target file */
+ __int64_t sx_fdtmp; /* fd of tmp file */
+ xfs_off_t sx_offset; /* offset into file */
+ xfs_off_t sx_length; /* leng from offset */
+ char sx_pad[16]; /* pad space, unused */
+ compat_xfs_bstat_t sx_stat; /* stat of target b4 copy */
+} _PACKED compat_xfs_swapext_t;
+
+#define XFS_IOC_SWAPEXT_32 _IOWR('X', 109, struct compat_xfs_swapext)
+
#ifdef BROKEN_X86_ALIGNMENT
/* on ia32 l_start is on a 32-bit boundary */
typedef struct compat_xfs_flock64 {
--
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
next prev parent reply other threads:[~2008-11-19 5:17 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-19 4:44 [patch 00/11] RFC: compat ioctl fixes/cleanups/additions sandeen
2008-11-19 4:44 ` [patch 01/11] Move compat ioctl structs & numbers into xfs_ioctl32.h sandeen
[not found] ` <20081119145941.GA13050@infradead.org>
2008-11-19 15:24 ` Eric Sandeen
2008-11-20 1:54 ` Eric Sandeen
2008-11-19 4:44 ` [patch 02/11] Fix the compat XFS_IOC_FSGEOMETRY_V1 ioctl sandeen
2008-11-19 4:44 ` [patch 03/11] Add compat handlers for data & rt growfs ioctls sandeen
2008-11-19 4:44 ` sandeen [this message]
2008-11-19 4:44 ` [patch 05/11] Make the bulkstat_one compat ioctl handling more sane sandeen
2008-11-19 4:44 ` [patch 06/11] Fix xfs_bulkstat_one size checks & error handling sandeen
2008-11-19 4:44 ` [patch 07/11] Fix compat XFS_IOC_FSBULKSTAT_SINGLE ioctl sandeen
2008-11-19 4:44 ` [patch 08/11] Hook up compat XFS_IOC_ATTRLIST_BY_HANDLE ioctl handler sandeen
2008-11-19 4:44 ` [patch 09/11] Hook up compat XFS_IOC_ATTRMULTI_BY_HANDLE " sandeen
[not found] ` <20081119151628.GI13050@infradead.org>
2008-11-19 15:30 ` Eric Sandeen
2008-11-19 4:44 ` [patch 10/11] Hook up compat XFS_IOC_FSSETDM_BY_HANDLE " sandeen
2008-11-19 4:44 ` [patch 11/11] Reorder xfs_ioctl32.c for some tidiness sandeen
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=20081119044908.948703484@sandeen.net \
--to=sandeen@sandeen.net \
--cc=hch@infradead.org \
--cc=xfs@oss.sgi.com \
/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