From: Eugene Syromyatnikov Date: Mon, 26 Dec 2016 12:25:35 +0000 (+0300) Subject: Move device number printing code into a separate routine X-Git-Tag: v4.16~126 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=32e813144c3ebb078d8da9d5325255b6aa933a9b;hp=54f2397c84f18a666d9e300f342141caf79c2a61;p=strace Move device number printing code into a separate routine * print_dev_t.c: New file. * Makefile.am (strace_SOURCES): Add it. * defs.h (print_dev_t): New prototype. * dm.c: Do not include . (dm_decode_device, dm_print_dev, dm_decode_dm_name_list): Use print_dev_t function for printing device numbers. * mknod.c: Do not include . (decode_mknod): Use print_dev_t function for printing device number. * print_struct_stat.c: Do not include . (print_struct_stat): Use print_dev_t function for printing device numbers. Co-authored-by: Dmitry V. Levin --- diff --git a/Makefile.am b/Makefile.am index 4840b937..2b01d3dc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -182,6 +182,7 @@ strace_SOURCES = \ pkeys.c \ poll.c \ prctl.c \ + print_dev_t.c \ print_mq_attr.c \ print_msgbuf.c \ print_sigevent.c \ diff --git a/defs.h b/defs.h index 9591e171..1e056068 100644 --- a/defs.h +++ b/defs.h @@ -581,6 +581,7 @@ extern const char *sprinttime(time_t); extern void print_symbolic_mode_t(unsigned int); extern void print_numeric_umode_t(unsigned short); extern void print_numeric_long_umask(unsigned long); +extern void print_dev_t(unsigned long long dev); extern void dumpiov_in_msghdr(struct tcb *, kernel_ulong_t addr, kernel_ulong_t data_size); diff --git a/dm.c b/dm.c index 7a1dc3c2..41380041 100644 --- a/dm.c +++ b/dm.c @@ -5,8 +5,6 @@ # include # include -# include - # if DM_VERSION_MAJOR == 4 /* Definitions for command which have been added later */ @@ -31,9 +29,10 @@ dm_decode_device(const unsigned int code, const struct dm_ioctl *ioc) case DM_LIST_VERSIONS: break; default: - if (ioc->dev) - tprintf(", dev=makedev(%u, %u)", - major(ioc->dev), minor(ioc->dev)); + if (ioc->dev) { + tprints(", dev="); + print_dev_t(ioc->dev); + } if (ioc->name[0]) { tprints(", name="); print_quoted_string(ioc->name, DM_NAME_LEN, @@ -171,7 +170,7 @@ dm_print_dev(struct tcb *tcp, void *dev_ptr, size_t dev_size, void *dummy) { uint64_t *dev = (uint64_t *) dev_ptr; - tprintf("makedev(%u, %u)", major(*dev), minor(*dev)); + print_dev_t(*dev); return 1; } @@ -255,8 +254,10 @@ dm_decode_dm_name_list(struct tcb *const tcp, const kernel_ulong_t addr, break; } - tprintf("{dev=makedev(%u, %u), name=", major(s.dev), - minor(s.dev)); + tprints("{dev="); + print_dev_t(s.dev); + + tprints("name="); printstr_ex(tcp, addr + offset_end, ioc->data_size - offset_end, QUOTE_0_TERMINATED); tprints("}"); diff --git a/mknod.c b/mknod.c index 9b903116..3edcd848 100644 --- a/mknod.c +++ b/mknod.c @@ -35,7 +35,6 @@ #include #include -#include static void decode_mknod(struct tcb *tcp, int offset) @@ -50,7 +49,8 @@ decode_mknod(struct tcb *tcp, int offset) case S_IFCHR: case S_IFBLK: dev = tcp->u_arg[offset + 2]; - tprintf(", makedev(%u, %u)", major(dev), minor(dev)); + tprints(", "); + print_dev_t(dev); break; } } diff --git a/print_dev_t.c b/print_dev_t.c new file mode 100644 index 00000000..9b62f842 --- /dev/null +++ b/print_dev_t.c @@ -0,0 +1,37 @@ +/* + * Device number printing routine. + * + * Copyright (c) 2016 The strace developers. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "defs.h" +#include + +void +print_dev_t(const unsigned long long dev) +{ + tprintf("makedev(%u, %u)", major(dev), minor(dev)); +} diff --git a/print_struct_stat.c b/print_struct_stat.c index 7b23ec8a..7e9e2338 100644 --- a/print_struct_stat.c +++ b/print_struct_stat.c @@ -34,7 +34,6 @@ #include "defs.h" #include -#include #include "stat.h" void @@ -42,10 +41,9 @@ print_struct_stat(struct tcb *tcp, const struct strace_stat *const st) { tprints("{"); if (!abbrev(tcp)) { - tprintf("st_dev=makedev(%u, %u), st_ino=%llu, st_mode=", - (unsigned int) major(st->dev), - (unsigned int) minor(st->dev), - st->ino); + tprints("st_dev="); + print_dev_t(st->dev); + tprintf(", st_ino=%llu, st_mode=", st->ino); print_symbolic_mode_t(st->mode); tprintf(", st_nlink=%llu, st_uid=%llu, st_gid=%llu", st->nlink, st->uid, st->gid); @@ -58,9 +56,8 @@ print_struct_stat(struct tcb *tcp, const struct strace_stat *const st) switch (st->mode & S_IFMT) { case S_IFCHR: case S_IFBLK: - tprintf(", st_rdev=makedev(%u, %u)", - (unsigned int) major(st->rdev), - (unsigned int) minor(st->rdev)); + tprints(", st_rdev="); + print_dev_t(st->rdev); break; default: tprintf(", st_size=%llu", st->size);