* [patch 01/11] Move compat ioctl structs & numbers into xfs_ioctl32.h
2008-11-19 4:44 [patch 00/11] RFC: compat ioctl fixes/cleanups/additions sandeen
@ 2008-11-19 4:44 ` sandeen
[not found] ` <20081119145941.GA13050@infradead.org>
2008-11-19 4:44 ` [patch 02/11] Fix the compat XFS_IOC_FSGEOMETRY_V1 ioctl sandeen
` (9 subsequent siblings)
10 siblings, 1 reply; 15+ messages in thread
From: sandeen @ 2008-11-19 4:44 UTC (permalink / raw)
To: xfs; +Cc: hch
[-- Attachment #1: move_compat_ioctl_structs --]
[-- Type: text/plain, Size: 18012 bytes --]
This makes the c file less cluttered and a bit more
readable Consistently name the ioctl number
macros with "_32" and the compatibility stuctures
with "_compat." Rename the helpers which simply
copy in the arg with "_copyin" for easy identification.
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
@@ -49,36 +49,11 @@
#define _NATIVE_IOC(cmd, type) \
_IOC(_IOC_DIR(cmd), _IOC_TYPE(cmd), _IOC_NR(cmd), sizeof(type))
-#if defined(CONFIG_IA64) || defined(CONFIG_X86_64)
-#define BROKEN_X86_ALIGNMENT
-#define _PACKED __attribute__((packed))
-/* on ia32 l_start is on a 32-bit boundary */
-typedef struct xfs_flock64_32 {
- __s16 l_type;
- __s16 l_whence;
- __s64 l_start __attribute__((packed));
- /* len == 0 means until end of file */
- __s64 l_len __attribute__((packed));
- __s32 l_sysid;
- __u32 l_pid;
- __s32 l_pad[4]; /* reserve area */
-} xfs_flock64_32_t;
-
-#define XFS_IOC_ALLOCSP_32 _IOW ('X', 10, struct xfs_flock64_32)
-#define XFS_IOC_FREESP_32 _IOW ('X', 11, struct xfs_flock64_32)
-#define XFS_IOC_ALLOCSP64_32 _IOW ('X', 36, struct xfs_flock64_32)
-#define XFS_IOC_FREESP64_32 _IOW ('X', 37, struct xfs_flock64_32)
-#define XFS_IOC_RESVSP_32 _IOW ('X', 40, struct xfs_flock64_32)
-#define XFS_IOC_UNRESVSP_32 _IOW ('X', 41, struct xfs_flock64_32)
-#define XFS_IOC_RESVSP64_32 _IOW ('X', 42, struct xfs_flock64_32)
-#define XFS_IOC_UNRESVSP64_32 _IOW ('X', 43, struct xfs_flock64_32)
-
-/* just account for different alignment */
+#ifdef BROKEN_X86_ALIGNMENT
STATIC unsigned long
-xfs_ioctl32_flock(
- unsigned long arg)
+xfs_ioctl32_flock_copyin(unsigned long arg)
{
- xfs_flock64_32_t __user *p32 = (void __user *)arg;
+ compat_xfs_flock64_t __user *p32 = (void __user *)arg;
xfs_flock64_t __user *p = compat_alloc_user_space(sizeof(*p));
if (copy_in_user(&p->l_type, &p32->l_type, sizeof(s16)) ||
@@ -88,54 +63,24 @@ xfs_ioctl32_flock(
copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
- return -EFAULT;
+ return -XFS_ERROR(EFAULT);
return (unsigned long)p;
}
-typedef struct compat_xfs_fsop_geom_v1 {
- __u32 blocksize; /* filesystem (data) block size */
- __u32 rtextsize; /* realtime extent size */
- __u32 agblocks; /* fsblocks in an AG */
- __u32 agcount; /* number of allocation groups */
- __u32 logblocks; /* fsblocks in the log */
- __u32 sectsize; /* (data) sector size, bytes */
- __u32 inodesize; /* inode size in bytes */
- __u32 imaxpct; /* max allowed inode space(%) */
- __u64 datablocks; /* fsblocks in data subvolume */
- __u64 rtblocks; /* fsblocks in realtime subvol */
- __u64 rtextents; /* rt extents in realtime subvol*/
- __u64 logstart; /* starting fsblock of the log */
- unsigned char uuid[16]; /* unique id of the filesystem */
- __u32 sunit; /* stripe unit, fsblocks */
- __u32 swidth; /* stripe width, fsblocks */
- __s32 version; /* structure version */
- __u32 flags; /* superblock version flags */
- __u32 logsectsize; /* log sector size, bytes */
- __u32 rtsectsize; /* realtime sector size, bytes */
- __u32 dirblocksize; /* directory block size, bytes */
-} __attribute__((packed)) compat_xfs_fsop_geom_v1_t;
-
-#define XFS_IOC_FSGEOMETRY_V1_32 \
- _IOR ('X', 100, struct compat_xfs_fsop_geom_v1)
-
-STATIC unsigned long xfs_ioctl32_geom_v1(unsigned long arg)
+STATIC unsigned long
+xfs_ioctl32_geom_v1_copyin(unsigned long arg)
{
compat_xfs_fsop_geom_v1_t __user *p32 = (void __user *)arg;
xfs_fsop_geom_v1_t __user *p = compat_alloc_user_space(sizeof(*p));
if (copy_in_user(p, p32, sizeof(*p32)))
- return -EFAULT;
+ return -XFS_ERROR(EFAULT);
return (unsigned long)p;
}
-typedef struct compat_xfs_inogrp {
- __u64 xi_startino; /* starting inode number */
- __s32 xi_alloccount; /* # bits set in allocmask */
- __u64 xi_allocmask; /* mask of allocated inodes */
-} __attribute__((packed)) compat_xfs_inogrp_t;
-
-STATIC int xfs_inumbers_fmt_compat(
+STATIC int
+xfs_inumbers_fmt_compat(
void __user *ubuffer,
const xfs_inogrp_t *buffer,
long count,
@@ -148,7 +93,7 @@ STATIC int xfs_inumbers_fmt_compat(
if (put_user(buffer[i].xi_startino, &p32[i].xi_startino) ||
put_user(buffer[i].xi_alloccount, &p32[i].xi_alloccount) ||
put_user(buffer[i].xi_allocmask, &p32[i].xi_allocmask))
- return -EFAULT;
+ return -XFS_ERROR(EFAULT);
}
*written = count * sizeof(*p32);
return 0;
@@ -163,49 +108,22 @@ STATIC int xfs_inumbers_fmt_compat(
/* XFS_IOC_FSBULKSTAT and friends */
-typedef struct compat_xfs_bstime {
- __s32 tv_sec; /* seconds */
- __s32 tv_nsec; /* and nanoseconds */
-} compat_xfs_bstime_t;
-
-STATIC int xfs_bstime_store_compat(
+STATIC int
+xfs_bstime_store_compat(
compat_xfs_bstime_t __user *p32,
const xfs_bstime_t *p)
{
- __s32 sec32;
+ compat_time_t sec32;
sec32 = p->tv_sec;
if (put_user(sec32, &p32->tv_sec) ||
put_user(p->tv_nsec, &p32->tv_nsec))
- return -EFAULT;
+ return -XFS_ERROR(EFAULT);
return 0;
}
-typedef struct compat_xfs_bstat {
- __u64 bs_ino; /* inode number */
- __u16 bs_mode; /* type and mode */
- __u16 bs_nlink; /* number of links */
- __u32 bs_uid; /* user id */
- __u32 bs_gid; /* group id */
- __u32 bs_rdev; /* device value */
- __s32 bs_blksize; /* block size */
- __s64 bs_size; /* file size */
- compat_xfs_bstime_t bs_atime; /* access time */
- compat_xfs_bstime_t bs_mtime; /* modify time */
- compat_xfs_bstime_t bs_ctime; /* inode change time */
- int64_t bs_blocks; /* number of blocks */
- __u32 bs_xflags; /* extended flags */
- __s32 bs_extsize; /* extent size */
- __s32 bs_extents; /* number of extents */
- __u32 bs_gen; /* generation count */
- __u16 bs_projid; /* project id */
- unsigned char bs_pad[14]; /* pad space, unused */
- __u32 bs_dmevmask; /* DMIG event mask */
- __u16 bs_dmstate; /* DMIG state info */
- __u16 bs_aextents; /* attribute number of extents */
-} _PACKED compat_xfs_bstat_t;
-
-STATIC int xfs_bulkstat_one_fmt_compat(
+STATIC int
+xfs_bulkstat_one_fmt_compat(
void __user *ubuffer,
const xfs_bstat_t *buffer)
{
@@ -231,26 +149,10 @@ STATIC int xfs_bulkstat_one_fmt_compat(
put_user(buffer->bs_dmevmask, &p32->bs_dmevmask) ||
put_user(buffer->bs_dmstate, &p32->bs_dmstate) ||
put_user(buffer->bs_aextents, &p32->bs_aextents))
- return -EFAULT;
+ return -XFS_ERROR(EFAULT);
return sizeof(*p32);
}
-
-
-typedef struct compat_xfs_fsop_bulkreq {
- compat_uptr_t lastip; /* last inode # pointer */
- __s32 icount; /* count of entries in buffer */
- compat_uptr_t ubuffer; /* user buffer for inode desc. */
- compat_uptr_t ocount; /* output count pointer */
-} compat_xfs_fsop_bulkreq_t;
-
-#define XFS_IOC_FSBULKSTAT_32 \
- _IOWR('X', 101, struct compat_xfs_fsop_bulkreq)
-#define XFS_IOC_FSBULKSTAT_SINGLE_32 \
- _IOWR('X', 102, struct compat_xfs_fsop_bulkreq)
-#define XFS_IOC_FSINUMBERS_32 \
- _IOWR('X', 103, struct compat_xfs_fsop_bulkreq)
-
/* copied from xfs_ioctl.c */
STATIC int
xfs_ioc_bulkstat_compat(
@@ -270,20 +172,20 @@ xfs_ioc_bulkstat_compat(
/* should be called again (unused here, but used in dmapi) */
if (!capable(CAP_SYS_ADMIN))
- return -EPERM;
+ return -XFS_ERROR(EPERM);
if (XFS_FORCED_SHUTDOWN(mp))
return -XFS_ERROR(EIO);
if (get_user(addr, &p32->lastip))
- return -EFAULT;
+ return -XFS_ERROR(EFAULT);
bulkreq.lastip = compat_ptr(addr);
if (get_user(bulkreq.icount, &p32->icount) ||
get_user(addr, &p32->ubuffer))
- return -EFAULT;
+ return -XFS_ERROR(EFAULT);
bulkreq.ubuffer = compat_ptr(addr);
if (get_user(addr, &p32->ocount))
- return -EFAULT;
+ return -XFS_ERROR(EFAULT);
bulkreq.ocount = compat_ptr(addr);
if (copy_from_user(&inlast, bulkreq.lastip, sizeof(__s64)))
@@ -310,41 +212,16 @@ xfs_ioc_bulkstat_compat(
return -error;
if (bulkreq.ocount != NULL) {
- if (copy_to_user(bulkreq.lastip, &inlast,
- sizeof(xfs_ino_t)))
- return -XFS_ERROR(EFAULT);
-
- if (copy_to_user(bulkreq.ocount, &count, sizeof(count)))
+ if (copy_to_user(bulkreq.lastip, &inlast, sizeof(xfs_ino_t)) ||
+ copy_to_user(bulkreq.ocount, &count, sizeof(count)))
return -XFS_ERROR(EFAULT);
}
return 0;
}
-
-
-typedef struct compat_xfs_fsop_handlereq {
- __u32 fd; /* fd for FD_TO_HANDLE */
- compat_uptr_t path; /* user pathname */
- __u32 oflags; /* open flags */
- compat_uptr_t ihandle; /* user supplied handle */
- __u32 ihandlen; /* user supplied length */
- compat_uptr_t ohandle; /* user buffer for handle */
- compat_uptr_t ohandlen; /* user buffer length */
-} compat_xfs_fsop_handlereq_t;
-
-#define XFS_IOC_PATH_TO_FSHANDLE_32 \
- _IOWR('X', 104, struct compat_xfs_fsop_handlereq)
-#define XFS_IOC_PATH_TO_HANDLE_32 \
- _IOWR('X', 105, struct compat_xfs_fsop_handlereq)
-#define XFS_IOC_FD_TO_HANDLE_32 \
- _IOWR('X', 106, struct compat_xfs_fsop_handlereq)
-#define XFS_IOC_OPEN_BY_HANDLE_32 \
- _IOWR('X', 107, struct compat_xfs_fsop_handlereq)
-#define XFS_IOC_READLINK_BY_HANDLE_32 \
- _IOWR('X', 108, struct compat_xfs_fsop_handlereq)
-
-STATIC unsigned long xfs_ioctl32_fshandle(unsigned long arg)
+STATIC unsigned long
+xfs_ioctl32_fshandle_copyin(unsigned long arg)
{
compat_xfs_fsop_handlereq_t __user *p32 = (void __user *)arg;
xfs_fsop_handlereq_t __user *p = compat_alloc_user_space(sizeof(*p));
@@ -361,12 +238,11 @@ STATIC unsigned long xfs_ioctl32_fshandl
put_user(compat_ptr(addr), &p->ohandle) ||
get_user(addr, &p32->ohandlen) ||
put_user(compat_ptr(addr), &p->ohandlen))
- return -EFAULT;
+ return -XFS_ERROR(EFAULT);
return (unsigned long)p;
}
-
STATIC long
xfs_compat_ioctl(
int mode,
@@ -405,9 +281,9 @@ xfs_compat_ioctl(
case XFS_IOC_ERROR_CLEARALL:
break;
- case XFS_IOC32_GETXFLAGS:
- case XFS_IOC32_SETXFLAGS:
- case XFS_IOC32_GETVERSION:
+ case XFS_IOC_GETXFLAGS_32:
+ case XFS_IOC_SETXFLAGS_32:
+ case XFS_IOC_GETVERSION_32:
cmd = _NATIVE_IOC(cmd, long);
break;
#ifdef BROKEN_X86_ALIGNMENT
@@ -420,11 +296,11 @@ xfs_compat_ioctl(
case XFS_IOC_UNRESVSP_32:
case XFS_IOC_RESVSP64_32:
case XFS_IOC_UNRESVSP64_32:
- arg = xfs_ioctl32_flock(arg);
+ arg = xfs_ioctl32_flock_copyin(arg);
cmd = _NATIVE_IOC(cmd, struct xfs_flock64);
break;
case XFS_IOC_FSGEOMETRY_V1_32:
- arg = xfs_ioctl32_geom_v1(arg);
+ arg = xfs_ioctl32_geom_v1_copyin(arg);
cmd = _NATIVE_IOC(cmd, struct xfs_fsop_geom_v1);
break;
@@ -456,11 +332,11 @@ xfs_compat_ioctl(
case XFS_IOC_PATH_TO_FSHANDLE_32:
case XFS_IOC_OPEN_BY_HANDLE_32:
case XFS_IOC_READLINK_BY_HANDLE_32:
- arg = xfs_ioctl32_fshandle(arg);
+ arg = xfs_ioctl32_fshandle_copyin(arg);
cmd = _NATIVE_IOC(cmd, struct xfs_fsop_handlereq);
break;
default:
- return -ENOIOCTLCMD;
+ return -XFS_ERROR(ENOIOCTLCMD);
}
error = xfs_ioctl(XFS_I(inode), file, mode, cmd, (void __user *)arg);
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
@@ -18,7 +18,147 @@
#ifndef __XFS_IOCTL32_H__
#define __XFS_IOCTL32_H__
+#include <linux/compat.h>
+
extern long xfs_file_compat_ioctl(struct file *, unsigned, unsigned long);
extern long xfs_file_compat_invis_ioctl(struct file *, unsigned, unsigned long);
+/*
+ * on 32-bit arches, ioctl argument structures may have different sizes
+ * and/or alignment. We define compat structures which match the
+ * 32-bit sizes/alignments here, and their associated ioctl numbers.
+ *
+ * xfs_ioctl32.c contains routines to copy these structures in and out.
+ */
+
+/*
+ * On intel, even if sizes match, alignment and/or padding may differ.
+ */
+#if defined(CONFIG_IA64) || defined(CONFIG_X86_64)
+#define BROKEN_X86_ALIGNMENT
+#define _PACKED __attribute__((packed))
+#else
+#define _PACKED
+#endif
+
+typedef struct compat_xfs_bstime {
+ compat_time_t tv_sec; /* seconds */
+ __s32 tv_nsec; /* and nanoseconds */
+} compat_xfs_bstime_t;
+
+typedef struct compat_xfs_bstat {
+ __u64 bs_ino; /* inode number */
+ __u16 bs_mode; /* type and mode */
+ __u16 bs_nlink; /* number of links */
+ __u32 bs_uid; /* user id */
+ __u32 bs_gid; /* group id */
+ __u32 bs_rdev; /* device value */
+ __s32 bs_blksize; /* block size */
+ __s64 bs_size; /* file size */
+ compat_xfs_bstime_t bs_atime; /* access time */
+ compat_xfs_bstime_t bs_mtime; /* modify time */
+ compat_xfs_bstime_t bs_ctime; /* inode change time */
+ int64_t bs_blocks; /* number of blocks */
+ __u32 bs_xflags; /* extended flags */
+ __s32 bs_extsize; /* extent size */
+ __s32 bs_extents; /* number of extents */
+ __u32 bs_gen; /* generation count */
+ __u16 bs_projid; /* project id */
+ unsigned char bs_pad[14]; /* pad space, unused */
+ __u32 bs_dmevmask; /* DMIG event mask */
+ __u16 bs_dmstate; /* DMIG state info */
+ __u16 bs_aextents; /* attribute number of extents */
+} _PACKED compat_xfs_bstat_t;
+
+typedef struct compat_xfs_fsop_bulkreq {
+ compat_uptr_t lastip; /* last inode # pointer */
+ __s32 icount; /* count of entries in buffer */
+ compat_uptr_t ubuffer; /* user buffer for inode desc. */
+ compat_uptr_t ocount; /* output count pointer */
+} compat_xfs_fsop_bulkreq_t;
+
+#define XFS_IOC_FSBULKSTAT_32 \
+ _IOWR('X', 101, struct compat_xfs_fsop_bulkreq)
+#define XFS_IOC_FSBULKSTAT_SINGLE_32 \
+ _IOWR('X', 102, struct compat_xfs_fsop_bulkreq)
+#define XFS_IOC_FSINUMBERS_32 \
+ _IOWR('X', 103, struct compat_xfs_fsop_bulkreq)
+
+typedef struct compat_xfs_fsop_handlereq {
+ __u32 fd; /* fd for FD_TO_HANDLE */
+ compat_uptr_t path; /* user pathname */
+ __u32 oflags; /* open flags */
+ compat_uptr_t ihandle; /* user supplied handle */
+ __u32 ihandlen; /* user supplied length */
+ compat_uptr_t ohandle; /* user buffer for handle */
+ compat_uptr_t ohandlen; /* user buffer length */
+} compat_xfs_fsop_handlereq_t;
+
+#define XFS_IOC_PATH_TO_FSHANDLE_32 \
+ _IOWR('X', 104, struct compat_xfs_fsop_handlereq)
+#define XFS_IOC_PATH_TO_HANDLE_32 \
+ _IOWR('X', 105, struct compat_xfs_fsop_handlereq)
+#define XFS_IOC_FD_TO_HANDLE_32 \
+ _IOWR('X', 106, struct compat_xfs_fsop_handlereq)
+#define XFS_IOC_OPEN_BY_HANDLE_32 \
+ _IOWR('X', 107, struct compat_xfs_fsop_handlereq)
+#define XFS_IOC_READLINK_BY_HANDLE_32 \
+ _IOWR('X', 108, struct compat_xfs_fsop_handlereq)
+
+#ifdef BROKEN_X86_ALIGNMENT
+/* on ia32 l_start is on a 32-bit boundary */
+typedef struct compat_xfs_flock64 {
+ __s16 l_type;
+ __s16 l_whence;
+ __s64 l_start __attribute__((packed));
+ /* len == 0 means until end of file */
+ __s64 l_len __attribute__((packed));
+ __s32 l_sysid;
+ __u32 l_pid;
+ __s32 l_pad[4]; /* reserve area */
+} compat_xfs_flock64_t;
+
+#define XFS_IOC_ALLOCSP_32 _IOW('X', 10, struct compat_xfs_flock64)
+#define XFS_IOC_FREESP_32 _IOW('X', 11, struct compat_xfs_flock64)
+#define XFS_IOC_ALLOCSP64_32 _IOW('X', 36, struct compat_xfs_flock64)
+#define XFS_IOC_FREESP64_32 _IOW('X', 37, struct compat_xfs_flock64)
+#define XFS_IOC_RESVSP_32 _IOW('X', 40, struct compat_xfs_flock64)
+#define XFS_IOC_UNRESVSP_32 _IOW('X', 41, struct compat_xfs_flock64)
+#define XFS_IOC_RESVSP64_32 _IOW('X', 42, struct compat_xfs_flock64)
+#define XFS_IOC_UNRESVSP64_32 _IOW('X', 43, struct compat_xfs_flock64)
+
+typedef struct compat_xfs_fsop_geom_v1 {
+ __u32 blocksize; /* filesystem (data) block size */
+ __u32 rtextsize; /* realtime extent size */
+ __u32 agblocks; /* fsblocks in an AG */
+ __u32 agcount; /* number of allocation groups */
+ __u32 logblocks; /* fsblocks in the log */
+ __u32 sectsize; /* (data) sector size, bytes */
+ __u32 inodesize; /* inode size in bytes */
+ __u32 imaxpct; /* max allowed inode space(%) */
+ __u64 datablocks; /* fsblocks in data subvolume */
+ __u64 rtblocks; /* fsblocks in realtime subvol */
+ __u64 rtextents; /* rt extents in realtime subvol*/
+ __u64 logstart; /* starting fsblock of the log */
+ unsigned char uuid[16]; /* unique id of the filesystem */
+ __u32 sunit; /* stripe unit, fsblocks */
+ __u32 swidth; /* stripe width, fsblocks */
+ __s32 version; /* structure version */
+ __u32 flags; /* superblock version flags */
+ __u32 logsectsize; /* log sector size, bytes */
+ __u32 rtsectsize; /* realtime sector size, bytes */
+ __u32 dirblocksize; /* directory block size, bytes */
+} __attribute__((packed)) compat_xfs_fsop_geom_v1_t;
+
+#define XFS_IOC_FSGEOMETRY_V1_32 \
+ _IOR('X', 100, struct compat_xfs_fsop_geom_v1)
+
+typedef struct compat_xfs_inogrp {
+ __u64 xi_startino; /* starting inode number */
+ __s32 xi_alloccount; /* # bits set in allocmask */
+ __u64 xi_allocmask; /* mask of allocated inodes */
+} __attribute__((packed)) compat_xfs_inogrp_t;
+
+#endif /* BROKEN_X86_ALIGNMENT */
+
#endif /* __XFS_IOCTL32_H__ */
Index: linux-2.6-xfs/fs/xfs/xfs_fs.h
===================================================================
--- linux-2.6-xfs.orig/fs/xfs/xfs_fs.h
+++ linux-2.6-xfs/fs/xfs/xfs_fs.h
@@ -427,9 +427,9 @@ typedef struct xfs_handle {
#define XFS_IOC_SETXFLAGS FS_IOC_SETFLAGS
#define XFS_IOC_GETVERSION FS_IOC_GETVERSION
/* 32-bit compat counterparts */
-#define XFS_IOC32_GETXFLAGS FS_IOC32_GETFLAGS
-#define XFS_IOC32_SETXFLAGS FS_IOC32_SETFLAGS
-#define XFS_IOC32_GETVERSION FS_IOC32_GETVERSION
+#define XFS_IOC_GETXFLAGS_32 FS_IOC32_GETFLAGS
+#define XFS_IOC_SETXFLAGS_32 FS_IOC32_SETFLAGS
+#define XFS_IOC_GETVERSION_32 FS_IOC32_GETVERSION
/*
* ioctl commands that replace IRIX fcntl()'s
--
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 15+ messages in thread* [patch 02/11] Fix the compat XFS_IOC_FSGEOMETRY_V1 ioctl
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
@ 2008-11-19 4:44 ` sandeen
2008-11-19 4:44 ` [patch 03/11] Add compat handlers for data & rt growfs ioctls sandeen
` (8 subsequent siblings)
10 siblings, 0 replies; 15+ messages in thread
From: sandeen @ 2008-11-19 4:44 UTC (permalink / raw)
To: xfs; +Cc: hch
[-- Attachment #1: fix_compat_fsgeometry_v1 --]
[-- Type: text/plain, Size: 2178 bytes --]
This ioctl copies kernel data to the user, so we
must have a compat helper to copy it out to the
32-bit structure; the current code had it backward,
and translated the 32-bit arg to 64-bit, and called
the native ioctl, which copied it back as if it were
talking to 64-bit userspace. Because the 64-bit arg
has padding on the end on intel, I think this risked
corruption in userspace..
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
@@ -44,6 +44,7 @@
#include "xfs_error.h"
#include "xfs_dfrag.h"
#include "xfs_vnodeops.h"
+#include "xfs_fsops.h"
#include "xfs_ioctl32.h"
#define _NATIVE_IOC(cmd, type) \
@@ -68,15 +69,22 @@ xfs_ioctl32_flock_copyin(unsigned long a
return (unsigned long)p;
}
-STATIC unsigned long
-xfs_ioctl32_geom_v1_copyin(unsigned long arg)
+/* This handles a copy-out, where the 32-bit user struct lacks padding */
+STATIC int
+xfs_ioc_fsgeometry_v1_compat(
+ xfs_mount_t *mp,
+ void __user *arg)
{
- compat_xfs_fsop_geom_v1_t __user *p32 = (void __user *)arg;
- xfs_fsop_geom_v1_t __user *p = compat_alloc_user_space(sizeof(*p));
+ xfs_fsop_geom_v1_t fsgeo;
+ int error;
- if (copy_in_user(p, p32, sizeof(*p32)))
+ error = xfs_fs_geometry(mp, (xfs_fsop_geom_t *)&fsgeo, 3);
+ if (error)
+ return -error;
+
+ if (copy_to_user(arg, &fsgeo, sizeof(struct compat_xfs_fsop_geom_v1)))
return -XFS_ERROR(EFAULT);
- return (unsigned long)p;
+ return 0;
}
STATIC int
@@ -300,9 +308,8 @@ xfs_compat_ioctl(
cmd = _NATIVE_IOC(cmd, struct xfs_flock64);
break;
case XFS_IOC_FSGEOMETRY_V1_32:
- arg = xfs_ioctl32_geom_v1_copyin(arg);
- cmd = _NATIVE_IOC(cmd, struct xfs_fsop_geom_v1);
- break;
+ return xfs_ioc_fsgeometry_v1_compat(XFS_I(inode)->i_mount,
+ (void __user*)arg);
#else /* These are handled fine if no alignment issues */
case XFS_IOC_ALLOCSP:
--
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 15+ messages in thread* [patch 03/11] Add compat handlers for data & rt growfs ioctls
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
2008-11-19 4:44 ` [patch 02/11] Fix the compat XFS_IOC_FSGEOMETRY_V1 ioctl sandeen
@ 2008-11-19 4:44 ` sandeen
2008-11-19 4:44 ` [patch 04/11] Add compat handlers for swapext ioctl sandeen
` (7 subsequent siblings)
10 siblings, 0 replies; 15+ messages in thread
From: sandeen @ 2008-11-19 4:44 UTC (permalink / raw)
To: xfs; +Cc: hch
[-- Attachment #1: compat_ioctl_growfs --]
[-- Type: text/plain, Size: 3159 bytes --]
The args for XFS_IOC_FSGROWFSDATA and XFS_IOC_FSGROWFSRTA
have padding on the end on intel, so add arg copyin functions,
and then just 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
@@ -87,6 +87,28 @@ xfs_ioc_fsgeometry_v1_compat(
return 0;
}
+STATIC unsigned long
+xfs_ioctl32_growfs_data_copyin(unsigned long arg)
+{
+ compat_xfs_growfs_data_t __user *p32 = (void __user *)arg;
+ xfs_growfs_data_t __user *p = compat_alloc_user_space(sizeof(*p));
+
+ if (copy_in_user(p, p32, sizeof(*p32)))
+ return -XFS_ERROR(EFAULT);
+ return (unsigned long)p;
+}
+
+STATIC unsigned long
+xfs_ioctl32_growfs_rt_copyin(unsigned long arg)
+{
+ compat_xfs_growfs_rt_t __user *p32 = (void __user *)arg;
+ xfs_growfs_rt_t __user *p = compat_alloc_user_space(sizeof(*p));
+
+ if (copy_in_user(p, p32, sizeof(*p32)))
+ return -XFS_ERROR(EFAULT);
+ return (unsigned long)p;
+}
+
STATIC int
xfs_inumbers_fmt_compat(
void __user *ubuffer,
@@ -310,7 +332,14 @@ xfs_compat_ioctl(
case XFS_IOC_FSGEOMETRY_V1_32:
return xfs_ioc_fsgeometry_v1_compat(XFS_I(inode)->i_mount,
(void __user*)arg);
-
+ case XFS_IOC_FSGROWFSDATA_32:
+ arg = xfs_ioctl32_growfs_data_copyin(arg);
+ cmd = _NATIVE_IOC(cmd, struct xfs_growfs_data);
+ break;
+ case XFS_IOC_FSGROWFSRT_32:
+ arg = xfs_ioctl32_growfs_rt_copyin(arg);
+ cmd = _NATIVE_IOC(cmd, struct xfs_growfs_rt);
+ break;
#else /* These are handled fine if no alignment issues */
case XFS_IOC_ALLOCSP:
case XFS_IOC_FREESP:
@@ -322,7 +351,6 @@ 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;
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
@@ -159,6 +159,20 @@ typedef struct compat_xfs_inogrp {
__u64 xi_allocmask; /* mask of allocated inodes */
} __attribute__((packed)) compat_xfs_inogrp_t;
+/* These growfs input structures have padding on the end, so must translate */
+typedef struct compat_xfs_growfs_data {
+ __u64 newblocks; /* new data subvol size, fsblocks */
+ __u32 imaxpct; /* new inode space percentage limit */
+} __attribute__((packed)) compat_xfs_growfs_data_t;
+
+typedef struct compat_xfs_growfs_rt {
+ __u64 newblocks; /* new realtime size, fsblocks */
+ __u32 extsize; /* new realtime extent size, fsblocks */
+} __attribute__((packed)) compat_xfs_growfs_rt_t;
+
+#define XFS_IOC_FSGROWFSDATA_32 _IOW ('X', 110, struct compat_xfs_growfs_data)
+#define XFS_IOC_FSGROWFSRT_32 _IOW ('X', 112, struct compat_xfs_growfs_rt)
+
#endif /* BROKEN_X86_ALIGNMENT */
#endif /* __XFS_IOCTL32_H__ */
--
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 15+ messages in thread* [patch 04/11] Add compat handlers for swapext ioctl
2008-11-19 4:44 [patch 00/11] RFC: compat ioctl fixes/cleanups/additions sandeen
` (2 preceding siblings ...)
2008-11-19 4:44 ` [patch 03/11] Add compat handlers for data & rt growfs ioctls sandeen
@ 2008-11-19 4:44 ` sandeen
2008-11-19 4:44 ` [patch 05/11] Make the bulkstat_one compat ioctl handling more sane sandeen
` (6 subsequent siblings)
10 siblings, 0 replies; 15+ messages in thread
From: sandeen @ 2008-11-19 4:44 UTC (permalink / raw)
To: xfs; +Cc: hch
[-- 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
^ permalink raw reply [flat|nested] 15+ messages in thread* [patch 05/11] Make the bulkstat_one compat ioctl handling more sane
2008-11-19 4:44 [patch 00/11] RFC: compat ioctl fixes/cleanups/additions sandeen
` (3 preceding siblings ...)
2008-11-19 4:44 ` [patch 04/11] Add compat handlers for swapext ioctl sandeen
@ 2008-11-19 4:44 ` sandeen
2008-11-19 4:44 ` [patch 06/11] Fix xfs_bulkstat_one size checks & error handling sandeen
` (5 subsequent siblings)
10 siblings, 0 replies; 15+ messages in thread
From: sandeen @ 2008-11-19 4:44 UTC (permalink / raw)
To: xfs; +Cc: hch
[-- Attachment #1: compat_ioctl_bulkstat_sanity --]
[-- Type: text/plain, Size: 5037 bytes --]
Currently the compat formatter was handled by passing
in "private_data" for the xfs_bulkstat_one formatter,
which was really just another formatter... IMHO this
got confusing.
Instead, just make a new xfs_bulkstat_one_compat
formatter for xfs_bulkstat, and call it via a wrapper.
Also, don't translate the ioctl nrs into their native
counterparts, that just clouds the issue; we're in a
compat handler anyway, just switch on the 32-bit cmds.
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
@@ -242,6 +242,23 @@ xfs_bulkstat_one_fmt_compat(
return sizeof(*p32);
}
+STATIC int
+xfs_bulkstat_one_compat(
+ xfs_mount_t *mp, /* mount point for filesystem */
+ xfs_ino_t ino, /* inode number to get data for */
+ void __user *buffer, /* buffer to place output in */
+ int ubsize, /* size of buffer */
+ void *private_data, /* my private data */
+ xfs_daddr_t bno, /* starting bno of inode cluster */
+ int *ubused, /* bytes used by me */
+ void *dibuff, /* on-disk inode buffer */
+ int *stat) /* BULKSTAT_RV_... */
+{
+ return xfs_bulkstat_one_int(mp, ino, buffer, ubsize,
+ xfs_bulkstat_one_fmt_compat, bno,
+ ubused, dibuff, stat);
+}
+
/* copied from xfs_ioctl.c */
STATIC int
xfs_ioc_bulkstat_compat(
@@ -286,14 +303,12 @@ xfs_ioc_bulkstat_compat(
if (bulkreq.ubuffer == NULL)
return -XFS_ERROR(EINVAL);
- if (cmd == XFS_IOC_FSINUMBERS)
+ if (cmd == XFS_IOC_FSINUMBERS_32)
error = xfs_inumbers(mp, &inlast, &count,
bulkreq.ubuffer, xfs_inumbers_fmt_compat);
else {
- /* declare a var to get a warning in case the type changes */
- bulkstat_one_fmt_pf formatter = xfs_bulkstat_one_fmt_compat;
error = xfs_bulkstat(mp, &inlast, &count,
- xfs_bulkstat_one, formatter,
+ xfs_bulkstat_one_compat, NULL,
sizeof(compat_xfs_bstat_t), bulkreq.ubuffer,
BULKSTAT_FG_QUICK, &done);
}
@@ -418,7 +433,6 @@ xfs_compat_ioctl(
case XFS_IOC_FSBULKSTAT_32:
case XFS_IOC_FSBULKSTAT_SINGLE_32:
case XFS_IOC_FSINUMBERS_32:
- cmd = _NATIVE_IOC(cmd, struct xfs_fsop_bulkreq);
return xfs_ioc_bulkstat_compat(XFS_I(inode)->i_mount,
cmd, (void __user*)arg);
case XFS_IOC_FD_TO_HANDLE_32:
Index: linux-2.6-xfs/fs/xfs/xfs_itable.c
===================================================================
--- linux-2.6-xfs.orig/fs/xfs/xfs_itable.c
+++ linux-2.6-xfs/fs/xfs/xfs_itable.c
@@ -206,13 +206,13 @@ xfs_bulkstat_one_fmt(
* Return stat information for one inode.
* Return 0 if ok, else errno.
*/
-int /* error status */
-xfs_bulkstat_one(
+int /* error status */
+xfs_bulkstat_one_int(
xfs_mount_t *mp, /* mount point for filesystem */
xfs_ino_t ino, /* inode number to get data for */
void __user *buffer, /* buffer to place output in */
int ubsize, /* size of buffer */
- void *private_data, /* my private data */
+ bulkstat_one_fmt_pf formatter, /* formatter, copy to user */
xfs_daddr_t bno, /* starting bno of inode cluster */
int *ubused, /* bytes used by me */
void *dibuff, /* on-disk inode buffer */
@@ -221,7 +221,6 @@ xfs_bulkstat_one(
xfs_bstat_t *buf; /* return buffer */
int error = 0; /* error value */
xfs_dinode_t *dip; /* dinode inode pointer */
- bulkstat_one_fmt_pf formatter = private_data ? : xfs_bulkstat_one_fmt;
dip = (xfs_dinode_t *)dibuff;
*stat = BULKSTAT_RV_NOTHING;
@@ -259,6 +258,23 @@ xfs_bulkstat_one(
return error;
}
+int
+xfs_bulkstat_one(
+ xfs_mount_t *mp, /* mount point for filesystem */
+ xfs_ino_t ino, /* inode number to get data for */
+ void __user *buffer, /* buffer to place output in */
+ int ubsize, /* size of buffer */
+ void *private_data, /* my private data */
+ xfs_daddr_t bno, /* starting bno of inode cluster */
+ int *ubused, /* bytes used by me */
+ void *dibuff, /* on-disk inode buffer */
+ int *stat) /* BULKSTAT_RV_... */
+{
+ return xfs_bulkstat_one_int(mp, ino, buffer, ubsize,
+ xfs_bulkstat_one_fmt, bno,
+ ubused, dibuff, stat);
+}
+
/*
* Test to see whether we can use the ondisk inode directly, based
* on the given bulkstat flags, filling in dipp accordingly.
Index: linux-2.6-xfs/fs/xfs/xfs_itable.h
===================================================================
--- linux-2.6-xfs.orig/fs/xfs/xfs_itable.h
+++ linux-2.6-xfs/fs/xfs/xfs_itable.h
@@ -74,6 +74,18 @@ typedef int (*bulkstat_one_fmt_pf)( /*
const xfs_bstat_t *buffer); /* buffer to read from */
int
+xfs_bulkstat_one_int(
+ xfs_mount_t *mp,
+ xfs_ino_t ino,
+ void __user *buffer,
+ int ubsize,
+ bulkstat_one_fmt_pf formatter,
+ xfs_daddr_t bno,
+ int *ubused,
+ void *dibuff,
+ int *stat);
+
+int
xfs_bulkstat_one(
xfs_mount_t *mp,
xfs_ino_t ino,
--
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 15+ messages in thread* [patch 06/11] Fix xfs_bulkstat_one size checks & error handling
2008-11-19 4:44 [patch 00/11] RFC: compat ioctl fixes/cleanups/additions sandeen
` (4 preceding siblings ...)
2008-11-19 4:44 ` [patch 05/11] Make the bulkstat_one compat ioctl handling more sane sandeen
@ 2008-11-19 4:44 ` sandeen
2008-11-19 4:44 ` [patch 07/11] Fix compat XFS_IOC_FSBULKSTAT_SINGLE ioctl sandeen
` (4 subsequent siblings)
10 siblings, 0 replies; 15+ messages in thread
From: sandeen @ 2008-11-19 4:44 UTC (permalink / raw)
To: xfs; +Cc: hch
[-- Attachment #1: bulkstat_one_size_and_error_fixes --]
[-- Type: text/plain, Size: 3638 bytes --]
The 32-bit xfs_blkstat_one handler was failing because
a size check checked whether the remaining (32-bit)
user buffer was less than the (64-bit) bulkstat buffer,
and failed with ENOMEM if so. Move this check
into the respective handlers so that they check the
correct sizes.
Also, the formatters were returning negative errors
or positive bytes copied; this was odd in the positive
error value world of xfs, and handled wrong by at least
some of the callers, which treated the bytes returned
as an error value. Move the bytes-used assignment
into the formatters.
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
@@ -211,13 +211,18 @@ xfs_bstime_store_compat(
return 0;
}
+/* Return 0 on success or positive error (to xfs_bulkstat()) */
STATIC int
xfs_bulkstat_one_fmt_compat(
void __user *ubuffer,
+ int ubsize,
+ int *ubused,
const xfs_bstat_t *buffer)
{
compat_xfs_bstat_t __user *p32 = ubuffer;
+ if (ubsize < sizeof(*p32))
+ return XFS_ERROR(ENOMEM);
if (put_user(buffer->bs_ino, &p32->bs_ino) ||
put_user(buffer->bs_mode, &p32->bs_mode) ||
put_user(buffer->bs_nlink, &p32->bs_nlink) ||
@@ -238,8 +243,10 @@ xfs_bulkstat_one_fmt_compat(
put_user(buffer->bs_dmevmask, &p32->bs_dmevmask) ||
put_user(buffer->bs_dmstate, &p32->bs_dmstate) ||
put_user(buffer->bs_aextents, &p32->bs_aextents))
- return -XFS_ERROR(EFAULT);
- return sizeof(*p32);
+ return XFS_ERROR(EFAULT);
+ if (ubused)
+ *ubused = sizeof(*p32);
+ return 0;
}
STATIC int
Index: linux-2.6-xfs/fs/xfs/xfs_itable.c
===================================================================
--- linux-2.6-xfs.orig/fs/xfs/xfs_itable.c
+++ linux-2.6-xfs/fs/xfs/xfs_itable.c
@@ -192,14 +192,21 @@ xfs_bulkstat_one_dinode(
}
}
+/* Return 0 on success or positive error */
STATIC int
xfs_bulkstat_one_fmt(
void __user *ubuffer,
+ int ubsize,
+ int *ubused,
const xfs_bstat_t *buffer)
{
+ if (ubsize < sizeof(*buffer))
+ return XFS_ERROR(ENOMEM);
if (copy_to_user(ubuffer, buffer, sizeof(*buffer)))
- return -EFAULT;
- return sizeof(*buffer);
+ return XFS_ERROR(EFAULT);
+ if (ubused)
+ *ubused = sizeof(*buffer);
+ return 0;
}
/*
@@ -227,8 +234,6 @@ xfs_bulkstat_one_int(
if (!buffer || xfs_internal_inum(mp, ino))
return XFS_ERROR(EINVAL);
- if (ubsize < sizeof(*buf))
- return XFS_ERROR(ENOMEM);
buf = kmem_alloc(sizeof(*buf), KM_SLEEP);
@@ -243,15 +248,11 @@ xfs_bulkstat_one_int(
xfs_bulkstat_one_dinode(mp, ino, dip, buf);
}
- error = formatter(buffer, buf);
- if (error < 0) {
- error = EFAULT;
+ error = formatter(buffer, ubsize, ubused, buf);
+ if (error)
goto out_free;
- }
*stat = BULKSTAT_RV_DIDONE;
- if (ubused)
- *ubused = error;
out_free:
kmem_free(buf);
Index: linux-2.6-xfs/fs/xfs/xfs_itable.h
===================================================================
--- linux-2.6-xfs.orig/fs/xfs/xfs_itable.h
+++ linux-2.6-xfs/fs/xfs/xfs_itable.h
@@ -71,6 +71,8 @@ xfs_bulkstat_single(
typedef int (*bulkstat_one_fmt_pf)( /* used size in bytes or negative error */
void __user *ubuffer, /* buffer to write to */
+ int ubsize, /* remaining user buffer sz */
+ int *ubused, /* bytes used by formatter */
const xfs_bstat_t *buffer); /* buffer to read from */
int
--
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 15+ messages in thread* [patch 07/11] Fix compat XFS_IOC_FSBULKSTAT_SINGLE ioctl
2008-11-19 4:44 [patch 00/11] RFC: compat ioctl fixes/cleanups/additions sandeen
` (5 preceding siblings ...)
2008-11-19 4:44 ` [patch 06/11] Fix xfs_bulkstat_one size checks & error handling sandeen
@ 2008-11-19 4:44 ` sandeen
2008-11-19 4:44 ` [patch 08/11] Hook up compat XFS_IOC_ATTRLIST_BY_HANDLE ioctl handler sandeen
` (3 subsequent siblings)
10 siblings, 0 replies; 15+ messages in thread
From: sandeen @ 2008-11-19 4:44 UTC (permalink / raw)
To: xfs; +Cc: hch
[-- Attachment #1: compat_ioctl_bulkstat_single_fix --]
[-- Type: text/plain, Size: 1879 bytes --]
The XFS_IOC_FSBULKSTAT_SINGLE ioctl passes in the
desired inode number, while XFS_IOC_FSBULKSTAT passes
in the previous/last-stat'd inode number. The
compat handler wasn't differentiating these, so
when a XFS_IOC_FSBULKSTAT_SINGLE request for inode
128 was sent in, stat information for 131 was sent out.
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
@@ -279,7 +279,7 @@ xfs_ioc_bulkstat_compat(
int count; /* # of records returned */
xfs_ino_t inlast; /* last inode number */
int done;
- int error;
+ int error = EINVAL;
/* done = 1 if there are more stats to get and if bulkstat */
/* should be called again (unused here, but used in dmapi) */
@@ -310,17 +310,23 @@ xfs_ioc_bulkstat_compat(
if (bulkreq.ubuffer == NULL)
return -XFS_ERROR(EINVAL);
- if (cmd == XFS_IOC_FSINUMBERS_32)
+ if (cmd == XFS_IOC_FSINUMBERS_32) {
error = xfs_inumbers(mp, &inlast, &count,
bulkreq.ubuffer, xfs_inumbers_fmt_compat);
- else {
+ } else if (cmd == XFS_IOC_FSBULKSTAT_SINGLE_32) {
+ int res;
+
+ error = xfs_bulkstat_one_compat(mp, inlast, bulkreq.ubuffer,
+ sizeof(compat_xfs_bstat_t),
+ NULL, 0, NULL, NULL, &res);
+ } else if (cmd == XFS_IOC_FSBULKSTAT_32) {
error = xfs_bulkstat(mp, &inlast, &count,
xfs_bulkstat_one_compat, NULL,
sizeof(compat_xfs_bstat_t), bulkreq.ubuffer,
BULKSTAT_FG_QUICK, &done);
}
if (error)
- return -error;
+ return -XFS_ERROR(error);
if (bulkreq.ocount != NULL) {
if (copy_to_user(bulkreq.lastip, &inlast, sizeof(xfs_ino_t)) ||
--
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 15+ messages in thread* [patch 08/11] Hook up compat XFS_IOC_ATTRLIST_BY_HANDLE ioctl handler
2008-11-19 4:44 [patch 00/11] RFC: compat ioctl fixes/cleanups/additions sandeen
` (6 preceding siblings ...)
2008-11-19 4:44 ` [patch 07/11] Fix compat XFS_IOC_FSBULKSTAT_SINGLE ioctl sandeen
@ 2008-11-19 4:44 ` sandeen
2008-11-19 4:44 ` [patch 09/11] Hook up compat XFS_IOC_ATTRMULTI_BY_HANDLE " sandeen
` (2 subsequent siblings)
10 siblings, 0 replies; 15+ messages in thread
From: sandeen @ 2008-11-19 4:44 UTC (permalink / raw)
To: xfs; +Cc: hch
[-- Attachment #1: compat_ioctl_attrlist --]
[-- Type: text/plain, Size: 5604 bytes --]
Add a compat handler for XFS_IOC_ATTRLIST_BY_HANDLE
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
--
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
@@ -119,6 +119,18 @@ typedef struct compat_xfs_swapext
#define XFS_IOC_SWAPEXT_32 _IOWR('X', 109, struct compat_xfs_swapext)
+typedef struct compat_xfs_fsop_attrlist_handlereq {
+ struct compat_xfs_fsop_handlereq hreq; /* handle interface structure */
+ struct xfs_attrlist_cursor pos; /* opaque cookie, list offset */
+ __u32 flags; /* which namespace to use */
+ __u32 buflen; /* length of buffer supplied */
+ compat_uptr_t buffer; /* returned names */
+} _PACKED compat_xfs_fsop_attrlist_handlereq_t;
+
+/* Note: actually this is read/write */
+#define XFS_IOC_ATTRLIST_BY_HANDLE_32 \
+ _IOW ('X', 122, struct compat_xfs_fsop_attrlist_handlereq)
+
#ifdef BROKEN_X86_ALIGNMENT
/* on ia32 l_start is on a 32-bit boundary */
typedef struct compat_xfs_flock64 {
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
@@ -45,6 +45,7 @@
#include "xfs_dfrag.h"
#include "xfs_vnodeops.h"
#include "xfs_fsops.h"
+#include "xfs_attr.h"
#include "xfs_ioctl32.h"
#define _NATIVE_IOC(cmd, type) \
@@ -360,6 +361,138 @@ xfs_ioctl32_fshandle_copyin(unsigned lon
return (unsigned long)p;
}
+/*
+ * Convert userspace handle data into inode.
+ *
+ * We use the fact that all the fsop_handlereq ioctl calls have a data
+ * structure argument whose first component is always a xfs_fsop_handlereq_t,
+ * so we can pass that sub structure into this handy, shared routine.
+ *
+ * If no error, caller must always iput the returned inode.
+ */
+STATIC int
+xfs_vget_fsop_handlereq_compat(
+ xfs_mount_t *mp,
+ struct inode *parinode, /* parent inode pointer */
+ compat_xfs_fsop_handlereq_t *hreq,
+ struct inode **inode)
+{
+ void __user *hanp;
+ size_t hlen;
+ xfs_fid_t *xfid;
+ xfs_handle_t *handlep;
+ xfs_handle_t handle;
+ xfs_inode_t *ip;
+ xfs_ino_t ino;
+ __u32 igen;
+ int error;
+
+ /*
+ * Only allow handle opens under a directory.
+ */
+ if (!S_ISDIR(parinode->i_mode))
+ return XFS_ERROR(ENOTDIR);
+
+ hanp = compat_ptr(hreq->ihandle);
+ hlen = hreq->ihandlen;
+ handlep = &handle;
+
+ if (hlen < sizeof(handlep->ha_fsid) || hlen > sizeof(*handlep))
+ return XFS_ERROR(EINVAL);
+ if (copy_from_user(handlep, hanp, hlen))
+ return XFS_ERROR(EFAULT);
+ if (hlen < sizeof(*handlep))
+ memset(((char *)handlep) + hlen, 0, sizeof(*handlep) - hlen);
+ if (hlen > sizeof(handlep->ha_fsid)) {
+ if (handlep->ha_fid.fid_len !=
+ (hlen - sizeof(handlep->ha_fsid) -
+ sizeof(handlep->ha_fid.fid_len)) ||
+ handlep->ha_fid.fid_pad)
+ return XFS_ERROR(EINVAL);
+ }
+
+ /*
+ * Crack the handle, obtain the inode # & generation #
+ */
+ xfid = (struct xfs_fid *)&handlep->ha_fid;
+ if (xfid->fid_len == sizeof(*xfid) - sizeof(xfid->fid_len)) {
+ ino = xfid->fid_ino;
+ igen = xfid->fid_gen;
+ } else {
+ return XFS_ERROR(EINVAL);
+ }
+
+ /*
+ * Get the XFS inode, building a Linux inode to go with it.
+ */
+ error = xfs_iget(mp, NULL, ino, 0, XFS_ILOCK_SHARED, &ip, 0);
+ if (error)
+ return error;
+ if (ip == NULL)
+ return XFS_ERROR(EIO);
+ if (ip->i_d.di_gen != igen) {
+ xfs_iput_new(ip, XFS_ILOCK_SHARED);
+ return XFS_ERROR(ENOENT);
+ }
+
+ xfs_iunlock(ip, XFS_ILOCK_SHARED);
+
+ *inode = VFS_I(ip);
+ return 0;
+}
+
+STATIC int
+xfs_attrlist_by_handle_compat(
+ void __user *arg,
+ struct inode *parinode)
+{
+ int error;
+ attrlist_cursor_kern_t *cursor;
+ compat_xfs_fsop_attrlist_handlereq_t al_hreq;
+ struct inode *inode;
+ char *kbuf;
+ xfs_mount_t *mp = XFS_I(parinode)->i_mount;
+
+ if (!capable(CAP_SYS_ADMIN))
+ return -XFS_ERROR(EPERM);
+ if (copy_from_user(&al_hreq, arg,
+ sizeof(compat_xfs_fsop_attrlist_handlereq_t)))
+ return -XFS_ERROR(EFAULT);
+ if (al_hreq.buflen > XATTR_LIST_MAX)
+ return -XFS_ERROR(EINVAL);
+
+ /*
+ * Reject flags, only allow namespaces.
+ */
+ if (al_hreq.flags & ~(ATTR_ROOT | ATTR_SECURE))
+ return -XFS_ERROR(EINVAL);
+
+ error = xfs_vget_fsop_handlereq_compat(mp, parinode, &al_hreq.hreq,
+ &inode);
+ if (error)
+ goto out;
+
+ kbuf = kmalloc(al_hreq.buflen, GFP_KERNEL);
+ if (!kbuf)
+ goto out_vn_rele;
+
+ cursor = (attrlist_cursor_kern_t *)&al_hreq.pos;
+ error = xfs_attr_list(XFS_I(inode), kbuf, al_hreq.buflen,
+ al_hreq.flags, cursor);
+ if (error)
+ goto out_kfree;
+
+ if (copy_to_user(compat_ptr(al_hreq.buffer), kbuf, al_hreq.buflen))
+ error = -EFAULT;
+
+ out_kfree:
+ kfree(kbuf);
+ out_vn_rele:
+ iput(inode);
+ out:
+ return -error;
+}
+
STATIC long
xfs_compat_ioctl(
int mode,
@@ -382,7 +515,6 @@ xfs_compat_ioctl(
case XFS_IOC_GETBMAPX:
/* not handled
case XFS_IOC_FSSETDM_BY_HANDLE:
- case XFS_IOC_ATTRLIST_BY_HANDLE:
case XFS_IOC_ATTRMULTI_BY_HANDLE:
*/
case XFS_IOC_FSCOUNTS:
@@ -456,6 +588,8 @@ xfs_compat_ioctl(
arg = xfs_ioctl32_fshandle_copyin(arg);
cmd = _NATIVE_IOC(cmd, struct xfs_fsop_handlereq);
break;
+ case XFS_IOC_ATTRLIST_BY_HANDLE_32:
+ return xfs_attrlist_by_handle_compat((void __user*)arg, inode);
default:
return -XFS_ERROR(ENOIOCTLCMD);
}
--
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 15+ messages in thread* [patch 09/11] Hook up compat XFS_IOC_ATTRMULTI_BY_HANDLE ioctl handler
2008-11-19 4:44 [patch 00/11] RFC: compat ioctl fixes/cleanups/additions sandeen
` (7 preceding siblings ...)
2008-11-19 4:44 ` [patch 08/11] Hook up compat XFS_IOC_ATTRLIST_BY_HANDLE ioctl handler sandeen
@ 2008-11-19 4:44 ` sandeen
[not found] ` <20081119151628.GI13050@infradead.org>
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
10 siblings, 1 reply; 15+ messages in thread
From: sandeen @ 2008-11-19 4:44 UTC (permalink / raw)
To: xfs; +Cc: hch
[-- Attachment #1: compat_ioctl_attrmulti --]
[-- Type: text/plain, Size: 5431 bytes --]
Add a compat handler for XFS_IOC_ATTRMULTI_BY_HANDLE
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
@@ -493,6 +493,98 @@ xfs_attrlist_by_handle_compat(
return -error;
}
+extern int
+xfs_attrmulti_attr_get(struct inode *, char *, char __user *,
+ __uint32_t *, __uint32_t);
+extern int
+xfs_attrmulti_attr_set(struct inode *, char *, const char __user *,
+ __uint32_t, __uint32_t);
+extern int
+xfs_attrmulti_attr_remove(struct inode *, char *, __uint32_t);
+
+STATIC int
+xfs_attrmulti_by_handle_compat(
+ void __user *arg,
+ struct inode *parinode)
+{
+ int error;
+ compat_xfs_attr_multiop_t *ops;
+ compat_xfs_fsop_attrmulti_handlereq_t am_hreq;
+ struct inode *inode;
+ unsigned int i, size;
+ char *attr_name;
+ xfs_mount_t *mp = XFS_I(parinode)->i_mount;
+
+ if (!capable(CAP_SYS_ADMIN))
+ return -XFS_ERROR(EPERM);
+ if (copy_from_user(&am_hreq, arg, sizeof(compat_xfs_fsop_attrmulti_handlereq_t)))
+ return -XFS_ERROR(EFAULT);
+
+ error = xfs_vget_fsop_handlereq_compat(mp, parinode, &am_hreq.hreq, &inode);
+ if (error)
+ goto out;
+
+ error = E2BIG;
+ size = am_hreq.opcount * sizeof(compat_xfs_attr_multiop_t);
+ if (!size || size > 16 * PAGE_SIZE)
+ goto out_vn_rele;
+
+ error = ENOMEM;
+ ops = kmalloc(size, GFP_KERNEL);
+ if (!ops)
+ goto out_vn_rele;
+
+ error = EFAULT;
+ if (copy_from_user(ops, compat_ptr(am_hreq.ops), size))
+ goto out_kfree_ops;
+
+ attr_name = kmalloc(MAXNAMELEN, GFP_KERNEL);
+ if (!attr_name)
+ goto out_kfree_ops;
+
+
+ error = 0;
+ for (i = 0; i < am_hreq.opcount; i++) {
+ ops[i].am_error = strncpy_from_user(attr_name,
+ compat_ptr(ops[i].am_attrname),
+ MAXNAMELEN);
+ if (ops[i].am_error == 0 || ops[i].am_error == MAXNAMELEN)
+ error = -ERANGE;
+ if (ops[i].am_error < 0)
+ break;
+
+ switch (ops[i].am_opcode) {
+ case ATTR_OP_GET:
+ ops[i].am_error = xfs_attrmulti_attr_get(inode,
+ attr_name, compat_ptr(ops[i].am_attrvalue),
+ &ops[i].am_length, ops[i].am_flags);
+ break;
+ case ATTR_OP_SET:
+ ops[i].am_error = xfs_attrmulti_attr_set(inode,
+ attr_name, compat_ptr(ops[i].am_attrvalue),
+ ops[i].am_length, ops[i].am_flags);
+ break;
+ case ATTR_OP_REMOVE:
+ ops[i].am_error = xfs_attrmulti_attr_remove(inode,
+ attr_name, ops[i].am_flags);
+ break;
+ default:
+ ops[i].am_error = EINVAL;
+ }
+ }
+
+ if (copy_to_user(compat_ptr(am_hreq.ops), ops, size))
+ error = XFS_ERROR(EFAULT);
+
+ kfree(attr_name);
+ out_kfree_ops:
+ kfree(ops);
+ out_vn_rele:
+ iput(inode);
+ out:
+ return -error;
+}
+
STATIC long
xfs_compat_ioctl(
int mode,
@@ -513,10 +605,7 @@ xfs_compat_ioctl(
case XFS_IOC_GETBMAP:
case XFS_IOC_GETBMAPA:
case XFS_IOC_GETBMAPX:
-/* not handled
- case XFS_IOC_FSSETDM_BY_HANDLE:
- case XFS_IOC_ATTRMULTI_BY_HANDLE:
-*/
+/* case XFS_IOC_FSSETDM_BY_HANDLE: not handled */
case XFS_IOC_FSCOUNTS:
case XFS_IOC_SET_RESBLKS:
case XFS_IOC_GET_RESBLKS:
@@ -590,6 +679,8 @@ xfs_compat_ioctl(
break;
case XFS_IOC_ATTRLIST_BY_HANDLE_32:
return xfs_attrlist_by_handle_compat((void __user*)arg, inode);
+ case XFS_IOC_ATTRMULTI_BY_HANDLE_32:
+ return xfs_attrmulti_by_handle_compat((void __user*)arg, inode);
default:
return -XFS_ERROR(ENOIOCTLCMD);
}
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
@@ -131,6 +131,26 @@ typedef struct compat_xfs_fsop_attrlist_
#define XFS_IOC_ATTRLIST_BY_HANDLE_32 \
_IOW ('X', 122, struct compat_xfs_fsop_attrlist_handlereq)
+/* am_opcodes defined in xfs_fs.h */
+typedef struct compat_xfs_attr_multiop {
+ __u32 am_opcode;
+ __s32 am_error;
+ compat_uptr_t am_attrname;
+ compat_uptr_t am_attrvalue;
+ __u32 am_length;
+ __u32 am_flags;
+} compat_xfs_attr_multiop_t;
+
+typedef struct compat_xfs_fsop_attrmulti_handlereq {
+ struct compat_xfs_fsop_handlereq hreq; /* handle interface structure */
+ __u32 opcount;/* count of following multiop */
+ /* ptr to compat_xfs_attr_multiop */
+ compat_uptr_t ops; /* attr_multi data */
+} compat_xfs_fsop_attrmulti_handlereq_t;
+
+#define XFS_IOC_ATTRMULTI_BY_HANDLE_32 \
+ _IOW ('X', 123, struct compat_xfs_fsop_attrmulti_handlereq)
+
#ifdef BROKEN_X86_ALIGNMENT
/* on ia32 l_start is on a 32-bit boundary */
typedef struct compat_xfs_flock64 {
Index: linux-2.6-xfs/fs/xfs/linux-2.6/xfs_ioctl.c
===================================================================
--- linux-2.6-xfs.orig/fs/xfs/linux-2.6/xfs_ioctl.c
+++ linux-2.6-xfs/fs/xfs/linux-2.6/xfs_ioctl.c
@@ -501,7 +501,7 @@ xfs_attrlist_by_handle(
return -error;
}
-STATIC int
+int
xfs_attrmulti_attr_get(
struct inode *inode,
char *name,
@@ -530,7 +530,7 @@ xfs_attrmulti_attr_get(
return error;
}
-STATIC int
+int
xfs_attrmulti_attr_set(
struct inode *inode,
char *name,
@@ -560,7 +560,7 @@ xfs_attrmulti_attr_set(
return error;
}
-STATIC int
+int
xfs_attrmulti_attr_remove(
struct inode *inode,
char *name,
--
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 15+ messages in thread* [patch 10/11] Hook up compat XFS_IOC_FSSETDM_BY_HANDLE ioctl handler
2008-11-19 4:44 [patch 00/11] RFC: compat ioctl fixes/cleanups/additions sandeen
` (8 preceding siblings ...)
2008-11-19 4:44 ` [patch 09/11] Hook up compat XFS_IOC_ATTRMULTI_BY_HANDLE " sandeen
@ 2008-11-19 4:44 ` sandeen
2008-11-19 4:44 ` [patch 11/11] Reorder xfs_ioctl32.c for some tidiness sandeen
10 siblings, 0 replies; 15+ messages in thread
From: sandeen @ 2008-11-19 4:44 UTC (permalink / raw)
To: xfs; +Cc: hch
[-- Attachment #1: compat_ioctl_dmidata --]
[-- Type: text/plain, Size: 2992 bytes --]
Add a compat handler for XFS_IOC_FSSETDM_BY_HANDLE.
I haven't tested this, lacking dmapi tools to do so
(unless xfsqa magically gets this somehow?)
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
@@ -585,6 +585,44 @@ xfs_attrmulti_by_handle_compat(
return -error;
}
+STATIC int
+compat_xfs_fssetdm_by_handle(
+ void __user *arg,
+ struct inode *parinode)
+{
+ int error;
+ struct fsdmidata fsd;
+ compat_xfs_fsop_setdm_handlereq_t dmhreq;
+ struct inode *inode;
+ xfs_mount_t *mp = XFS_I(parinode)->i_mount;
+
+ if (!capable(CAP_MKNOD))
+ return -XFS_ERROR(EPERM);
+ if (copy_from_user(&dmhreq, arg, sizeof(compat_xfs_fsop_setdm_handlereq_t)))
+ return -XFS_ERROR(EFAULT);
+
+ error = xfs_vget_fsop_handlereq_compat(mp, parinode, &dmhreq.hreq, &inode);
+ if (error)
+ return -error;
+
+ if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) {
+ error = -XFS_ERROR(EPERM);
+ goto out;
+ }
+
+ if (copy_from_user(&fsd, compat_ptr(dmhreq.data), sizeof(fsd))) {
+ error = -XFS_ERROR(EFAULT);
+ goto out;
+ }
+
+ error = -xfs_set_dmattrs(XFS_I(inode), fsd.fsd_dmevmask,
+ fsd.fsd_dmstate);
+
+out:
+ iput(inode);
+ return error;
+}
+
STATIC long
xfs_compat_ioctl(
int mode,
@@ -605,7 +643,6 @@ xfs_compat_ioctl(
case XFS_IOC_GETBMAP:
case XFS_IOC_GETBMAPA:
case XFS_IOC_GETBMAPX:
-/* case XFS_IOC_FSSETDM_BY_HANDLE: not handled */
case XFS_IOC_FSCOUNTS:
case XFS_IOC_SET_RESBLKS:
case XFS_IOC_GET_RESBLKS:
@@ -681,6 +718,8 @@ xfs_compat_ioctl(
return xfs_attrlist_by_handle_compat((void __user*)arg, inode);
case XFS_IOC_ATTRMULTI_BY_HANDLE_32:
return xfs_attrmulti_by_handle_compat((void __user*)arg, inode);
+ case XFS_IOC_FSSETDM_BY_HANDLE_32:
+ return compat_xfs_fssetdm_by_handle((void __user*)arg, inode);
default:
return -XFS_ERROR(ENOIOCTLCMD);
}
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
@@ -151,6 +151,15 @@ typedef struct compat_xfs_fsop_attrmulti
#define XFS_IOC_ATTRMULTI_BY_HANDLE_32 \
_IOW ('X', 123, struct compat_xfs_fsop_attrmulti_handlereq)
+typedef struct compat_xfs_fsop_setdm_handlereq {
+ struct compat_xfs_fsop_handlereq hreq; /* handle information */
+ /* ptr to struct fsdmidata */
+ compat_uptr_t data; /* DMAPI data */
+} compat_xfs_fsop_setdm_handlereq_t;
+
+#define XFS_IOC_FSSETDM_BY_HANDLE_32 \
+ _IOW ('X', 121, struct compat_xfs_fsop_setdm_handlereq)
+
#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
^ permalink raw reply [flat|nested] 15+ messages in thread* [patch 11/11] Reorder xfs_ioctl32.c for some tidiness
2008-11-19 4:44 [patch 00/11] RFC: compat ioctl fixes/cleanups/additions sandeen
` (9 preceding siblings ...)
2008-11-19 4:44 ` [patch 10/11] Hook up compat XFS_IOC_FSSETDM_BY_HANDLE " sandeen
@ 2008-11-19 4:44 ` sandeen
10 siblings, 0 replies; 15+ messages in thread
From: sandeen @ 2008-11-19 4:44 UTC (permalink / raw)
To: xfs; +Cc: hch
[-- Attachment #1: compat_ioctl_tidy --]
[-- Type: text/plain, Size: 3523 bytes --]
Put things in IMHO a more readable order, now
that it's all done; add some comments.
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
@@ -634,6 +634,7 @@ xfs_compat_ioctl(
int error;
switch (cmd) {
+ /* No size or alignment issues with any of these on any arch */
case XFS_IOC_DIOINFO:
case XFS_IOC_FSGEOMETRY:
case XFS_IOC_FSGETXATTR:
@@ -655,14 +656,18 @@ xfs_compat_ioctl(
case XFS_IOC_ERROR_INJECTION:
case XFS_IOC_ERROR_CLEARALL:
break;
-
- case XFS_IOC_GETXFLAGS_32:
- case XFS_IOC_SETXFLAGS_32:
- case XFS_IOC_GETVERSION_32:
- cmd = _NATIVE_IOC(cmd, long);
+#ifndef BROKEN_X86_ALIGNMENT /* handled fine if no alignment issues */
+ case XFS_IOC_ALLOCSP:
+ case XFS_IOC_FREESP:
+ case XFS_IOC_RESVSP:
+ case XFS_IOC_UNRESVSP:
+ case XFS_IOC_ALLOCSP64:
+ case XFS_IOC_FREESP64:
+ case XFS_IOC_RESVSP64:
+ case XFS_IOC_UNRESVSP64:
+ case XFS_IOC_FSGEOMETRY_V1:
break;
-#ifdef BROKEN_X86_ALIGNMENT
- /* xfs_flock_t has wrong u32 vs u64 alignment */
+#else /* BROKEN_X86_ALIGNMENT */
case XFS_IOC_ALLOCSP_32:
case XFS_IOC_FREESP_32:
case XFS_IOC_ALLOCSP64_32:
@@ -674,9 +679,6 @@ xfs_compat_ioctl(
arg = xfs_ioctl32_flock_copyin(arg);
cmd = _NATIVE_IOC(cmd, struct xfs_flock64);
break;
- case XFS_IOC_FSGEOMETRY_V1_32:
- return xfs_ioc_fsgeometry_v1_compat(XFS_I(inode)->i_mount,
- (void __user*)arg);
case XFS_IOC_FSGROWFSDATA_32:
arg = xfs_ioctl32_growfs_data_copyin(arg);
cmd = _NATIVE_IOC(cmd, struct xfs_growfs_data);
@@ -684,28 +686,21 @@ xfs_compat_ioctl(
case XFS_IOC_FSGROWFSRT_32:
arg = xfs_ioctl32_growfs_rt_copyin(arg);
cmd = _NATIVE_IOC(cmd, struct xfs_growfs_rt);
+ case XFS_IOC_FSGEOMETRY_V1_32:
+ return xfs_ioc_fsgeometry_v1_compat(XFS_I(inode)->i_mount,
+ (void __user*)arg);
break;
-#else /* These are handled fine if no alignment issues */
- case XFS_IOC_ALLOCSP:
- case XFS_IOC_FREESP:
- case XFS_IOC_RESVSP:
- case XFS_IOC_UNRESVSP:
- case XFS_IOC_ALLOCSP64:
- case XFS_IOC_FREESP64:
- case XFS_IOC_RESVSP64:
- case XFS_IOC_UNRESVSP64:
- case XFS_IOC_FSGEOMETRY_V1:
- break;
#endif
+ /* long varies in size, but xfs only ever copies out 32 bits */
+ case XFS_IOC_GETXFLAGS_32:
+ case XFS_IOC_SETXFLAGS_32:
+ case XFS_IOC_GETVERSION_32:
+ cmd = _NATIVE_IOC(cmd, long);
+ break;
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:
- return xfs_ioc_bulkstat_compat(XFS_I(inode)->i_mount,
- cmd, (void __user*)arg);
case XFS_IOC_FD_TO_HANDLE_32:
case XFS_IOC_PATH_TO_HANDLE_32:
case XFS_IOC_PATH_TO_FSHANDLE_32:
@@ -714,6 +709,11 @@ xfs_compat_ioctl(
arg = xfs_ioctl32_fshandle_copyin(arg);
cmd = _NATIVE_IOC(cmd, struct xfs_fsop_handlereq);
break;
+ case XFS_IOC_FSBULKSTAT_32:
+ case XFS_IOC_FSBULKSTAT_SINGLE_32:
+ case XFS_IOC_FSINUMBERS_32:
+ return xfs_ioc_bulkstat_compat(XFS_I(inode)->i_mount,
+ cmd, (void __user*)arg);
case XFS_IOC_ATTRLIST_BY_HANDLE_32:
return xfs_attrlist_by_handle_compat((void __user*)arg, inode);
case XFS_IOC_ATTRMULTI_BY_HANDLE_32:
--
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 15+ messages in thread