Skip to contentSkip to conversation

linux-user: implement FS_IOC_FIEMAP ioctl

PATCH New Peter Maydell 1 participant 3 messages Jan 6, 2011

lore
Share & tools
lore
#0 lore raw

cover linux-user: implement FS_IOC_FIEMAP ioctl

This patchset implements support for the Linux FS_IOC_FIEMAP ioctl. This is used by apt (or possibly one of the programs it runs) when it is installing packages. The major effect of this fix is that qemu no longer spits out warnings about the ioctl being unimplemented when you use it to install new packages into an Ubuntu ARM chroot.

Peter Maydell (2):
linux-user: Support ioctls whose parameter size is not constant
linux-user: Implement FS_IOC_FIEMAP ioctl

 linux-user/ioctls.h        |    4 ++
 linux-user/syscall.c       |  106 ++++++++++++++++++++++++++++++++++++++++++-
 linux-user/syscall_defs.h  |    1 +
 linux-user/syscall_types.h |   16 +++++++
 4 files changed, 124 insertions(+), 3 deletions(-)
#1 lore raw

PATCH 1/2 linux-user: Support ioctls whose parameter size is not constant

Some ioctls (for example FS_IOC_FIEMAP) use structures whose size is not constant. The generic argument conversion code in do_ioctl() cannot handle this, so add support for implementing a special-case handler for a particular ioctl which does the conversion itself.

---
 linux-user/syscall.c |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)
linux-user/syscall.c +15 -3
index c3e8706..7436c3f 100644
@@ -2965,13 +2965,19 @@ enum {
 #undef STRUCT
 #undef STRUCT_SPECIAL
 
-typedef struct IOCTLEntry {
+typedef struct IOCTLEntry IOCTLEntry;
+
+typedef abi_long do_ioctl_fn(const IOCTLEntry *ie, uint8_t *buf_temp,
+                             int fd, abi_long cmd, abi_long arg);
+
+struct IOCTLEntry {
     unsigned int target_cmd;
     unsigned int host_cmd;
     const char *name;
     int access;
+    do_ioctl_fn *do_ioctl;
     const argtype arg_type[5];
-} IOCTLEntry;
+};
 
 #define IOC_R 0x0001
 #define IOC_W 0x0002
@@ -2981,7 +2987,9 @@ typedef struct IOCTLEntry {
 
 static IOCTLEntry ioctl_entries[] = {
 #define IOCTL(cmd, access, ...) \
-    { TARGET_ ## cmd, cmd, #cmd, access, {  __VA_ARGS__ } },
+    { TARGET_ ## cmd, cmd, #cmd, access, 0, {  __VA_ARGS__ } },
+#define IOCTL_SPECIAL(cmd, access, dofn, ...)                      \
+    { TARGET_ ## cmd, cmd, #cmd, access, dofn, {  __VA_ARGS__ } },
 #include "ioctls.h"
     { 0, 0, },
 };
@@ -3011,6 +3019,10 @@ static abi_long do_ioctl(int fd, abi_long cmd, abi_long arg)
 #if defined(DEBUG)
     gemu_log("ioctl: cmd=0x%04lx (%s)\n", (long)cmd, ie->name);
 #endif
+    if (ie->do_ioctl) {
+        return ie->do_ioctl(ie, buf_temp, fd, cmd, arg);
+    }
+
     switch(arg_type[0]) {
     case TYPE_NULL:
         /* no argument */
Signature · 1 line
1.6.3.3
#2 lore raw

PATCH 2/2 linux-user: Implement FS_IOC_FIEMAP ioctl

In reply to Peter Maydell

Implement the FS_IOC_FIEMAP ioctl using the new support for custom handling of ioctls; this is needed because the struct that is passed includes a variable-length array.

---
 linux-user/ioctls.h        |    4 ++
 linux-user/syscall.c       |   88 ++++++++++++++++++++++++++++++++++++++++++++
 linux-user/syscall_defs.h  |    1 +
 linux-user/syscall_types.h |   16 ++++++++
 4 files changed, 109 insertions(+), 0 deletions(-)
linux-user/ioctls.h +4 -0
index 769e1bc..538e257 100644
@@ -76,6 +76,10 @@
 #ifdef FIGETBSZ
      IOCTL(FIGETBSZ, IOC_R, MK_PTR(TYPE_LONG))
 #endif
+#ifdef FS_IOC_FIEMAP
+     IOCTL_SPECIAL(FS_IOC_FIEMAP, IOC_W | IOC_R, do_ioctl_fs_ioc_fiemap,
+                   MK_PTR(MK_STRUCT(STRUCT_fiemap)))
+#endif
 
   IOCTL(SIOCATMARK, 0, TYPE_NULL)
   IOCTL(SIOCADDRT, IOC_W, MK_PTR(MK_STRUCT(STRUCT_rtentry)))
linux-user/syscall.c +88 -0

100 lines not on this page · raw message

linux-user/syscall_defs.h +1 -0
index 20c93d0..d02a9bf 100644
@@ -783,6 +783,7 @@ struct target_pollfd {
 #define TARGET_BLKGETSIZE64 TARGET_IOR(0x12,114,sizeof(uint64_t)) /* return device size in bytes (u64 *arg) */
 #define TARGET_FIBMAP     TARGET_IO(0x00,1)  /* bmap access */
 #define TARGET_FIGETBSZ   TARGET_IO(0x00,2)  /* get the block size used for bmap */
+#define TARGET_FS_IOC_FIEMAP TARGET_IOWR('f',11,struct fiemap)
 
 /* cdrom commands */
 #define TARGET_CDROMPAUSE		0x5301 /* Pause Audio Operation */
linux-user/syscall_types.h +16 -0
index 340dbd3..0e67cd8 100644
@@ -165,3 +165,19 @@ STRUCT(vt_stat,
        TYPE_SHORT, /* v_active */
        TYPE_SHORT, /* v_signal */
        TYPE_SHORT) /* v_state */
+
+STRUCT(fiemap_extent,
+       TYPE_ULONGLONG, /* fe_logical */
+       TYPE_ULONGLONG, /* fe_physical */
+       TYPE_ULONGLONG, /* fe_length */
+       MK_ARRAY(TYPE_ULONGLONG, 2), /* fe_reserved64[2] */
+       TYPE_INT, /* fe_flags */
+       MK_ARRAY(TYPE_INT, 3)) /* fe_reserved[3] */
+
+STRUCT(fiemap,
+       TYPE_ULONGLONG, /* fm_start */
+       TYPE_ULONGLONG, /* fm_length */
+       TYPE_INT, /* fm_flags */
+       TYPE_INT, /* fm_mapped_extents */
+       TYPE_INT, /* fm_extent_count */
+       TYPE_INT) /* fm_reserved */
Signature · 1 line
1.6.3.3