]> granicus.if.org Git - strace/blobdiff - block.c
Move ioctl syscall parser to ioctl.c
[strace] / block.c
diff --git a/block.c b/block.c
index 599e5840ec0d45cec55f6401e3659497435fecf5..a84b1e3408e2cddc6bdf4cf698cef32f2a97007b 100644 (file)
--- a/block.c
+++ b/block.c
@@ -26,8 +26,6 @@
  */
 
 #include "defs.h"
-#include <stdint.h>
-#include <inttypes.h>
 #include <linux/blkpg.h>
 #include <linux/fs.h>
 #include <linux/hdreg.h>
@@ -81,11 +79,7 @@ struct blk_user_trace_setup {
 #define BLKSECDISCARD _IO(0x12,125)
 #endif
 
-static const struct xlat blkpg_ops[] = {
-       { BLKPG_ADD_PARTITION,  "BLKPG_ADD_PARTITION", },
-       { BLKPG_DEL_PARTITION,  "BLKPG_DEL_PARTITION", },
-       { 0,                    NULL },
-};
+#include "xlat/blkpg_ops.h"
 
 static void
 print_blkpg_req(struct tcb *tcp, struct blkpg_ioctl_arg *blkpg)
@@ -100,16 +94,20 @@ print_blkpg_req(struct tcb *tcp, struct blkpg_ioctl_arg *blkpg)
 
        if (umove(tcp, (long) blkpg->data, &p) < 0)
                tprintf("%#lx}", (long) blkpg->data);
-       else
-               tprintf("{start=%lld, length=%lld, pno=%d, "
-                       "devname=\"%.*s\", volname=\"%.*s\"}}",
-                       p.start, p.length, p.pno,
-                       (int) sizeof(p.devname), p.devname,
-                       (int) sizeof(p.volname), p.volname);
+       else {
+               tprintf("{start=%lld, length=%lld, pno=%d, devname=",
+                       p.start, p.length, p.pno);
+               print_quoted_string(p.devname, sizeof(p.devname),
+                                   QUOTE_0_TERMINATED);
+               tprints(", volname=");
+               print_quoted_string(p.volname, sizeof(p.volname),
+                                   QUOTE_0_TERMINATED);
+               tprints("}}");
+       }
 }
 
 int
-block_ioctl(struct tcb *tcp, long code, long arg)
+block_ioctl(struct tcb *tcp, const unsigned int code, long arg)
 {
        switch (code) {
        /* take arg as a value, not as a pointer */
@@ -122,6 +120,11 @@ block_ioctl(struct tcb *tcp, long code, long arg)
        /* take a signed int */
        case BLKROSET:
        case BLKBSZSET:
+#ifdef FIFREEZE
+       /* First seen in linux-2.6.29 */
+       case FIFREEZE:
+       case FITHAW:
+#endif
                if (entering(tcp)) {
                        int val;
                        if (umove(tcp, arg, &val) < 0)
@@ -138,7 +141,7 @@ block_ioctl(struct tcb *tcp, long code, long arg)
                        if (syserror(tcp) || umove(tcp, arg, &val) < 0)
                                tprintf(", %#lx", arg);
                        else
-                               tprintf(", %hu", val);
+                               tprintf(", %u", (unsigned)val);
                }
                break;
 
@@ -190,7 +193,7 @@ block_ioctl(struct tcb *tcp, long code, long arg)
                                tprintf(", %#lx", arg);
                        else
                                tprintf(", %lu", val);
-                       }
+               }
                break;
 
 #ifdef HAVE_BLKGETSIZE64
@@ -225,10 +228,12 @@ block_ioctl(struct tcb *tcp, long code, long arg)
                        if (syserror(tcp) || umove(tcp, arg, &geo) < 0)
                                tprintf(", %#lx", arg);
                        else
-                               tprintf(", {heads=%hhu, sectors=%hhu, "
-                                       "cylinders=%hu, start=%lu}",
-                                       geo.heads, geo.sectors,
-                                       geo.cylinders, geo.start);
+                               tprintf(", {heads=%u, sectors=%u, "
+                                       "cylinders=%u, start=%lu}",
+                                       (unsigned)geo.heads,
+                                       (unsigned)geo.sectors,
+                                       (unsigned)geo.cylinders,
+                                       geo.start);
                }
                break;
 
@@ -250,10 +255,10 @@ block_ioctl(struct tcb *tcp, long code, long arg)
                        if (umove(tcp, arg, &buts) < 0)
                                tprintf(", %#lx", arg);
                        else
-                               tprintf(", {act_mask=%hu, buf_size=%u, "
+                               tprintf(", {act_mask=%u, buf_size=%u, "
                                        "buf_nr=%u, start_lba=%" PRIu64 ", "
                                        "end_lba=%" PRIu64 ", pid=%u}",
-                                       buts.act_mask, buts.buf_size,
+                                       (unsigned)buts.act_mask, buts.buf_size,
                                        buts.buf_nr, buts.start_lba,
                                        buts.end_lba, buts.pid);
                }
@@ -261,11 +266,29 @@ block_ioctl(struct tcb *tcp, long code, long arg)
                        struct blk_user_trace_setup buts;
                        if (syserror(tcp) || umove(tcp, arg, &buts) < 0)
                                tprintf(", %#lx", arg);
+                       else {
+                               tprints(", {name=");
+                               print_quoted_string(buts.name, sizeof(buts.name),
+                                                   QUOTE_0_TERMINATED);
+                               tprints("}");
+                       }
+               }
+               break;
+
+#ifdef FITRIM
+       /* First seen in linux-2.6.37 */
+       case FITRIM:
+               if (entering(tcp)) {
+                       struct fstrim_range fstrim;
+                       if (umove(tcp, arg, &fstrim))
+                               tprintf(", %#lx", arg);
                        else
-                               tprintf(", {name=\"%.*s\"}",
-                                       (int) sizeof(buts.name), buts.name);
+                               tprintf(", {start=%#" PRIx64 ", len=%#" PRIx64 ", "
+                                       "minlen=%#" PRIx64 "}", (uint64_t) fstrim.start,
+                                       (uint64_t) fstrim.len, (uint64_t) fstrim.minlen);
                }
                break;
+#endif
 
        /* No arguments or unhandled */
        case BLKTRACESTART: