Home | History | Annotate | Download | only in strace
      1 /*
      2  * Copyright (c) 1999-2003 Ulrich Drepper <drepper (at) redhat.com>
      3  * Copyright (c) 2004 David S. Miller <davem (at) nuts.davemloft.net>
      4  * Copyright (c) 2003-2005 Roland McGrath <roland (at) redhat.com>
      5  * Copyright (c) 2007 Jan Kratochvil <jan.kratochvil (at) redhat.com>
      6  * Copyright (c) 2009 Denys Vlasenko <dvlasenk (at) redhat.com>
      7  * Copyright (c) 2009-2010 Andreas Schwab <schwab (at) linux-m68k.org>
      8  * Copyright (c) 2012 H.J. Lu <hongjiu.lu (at) intel.com>
      9  * Copyright (c) 2005-2016 Dmitry V. Levin <ldv (at) altlinux.org>
     10  * Copyright (c) 2016-2017 The strace developers.
     11  * All rights reserved.
     12  *
     13  * Redistribution and use in source and binary forms, with or without
     14  * modification, are permitted provided that the following conditions
     15  * are met:
     16  * 1. Redistributions of source code must retain the above copyright
     17  *    notice, this list of conditions and the following disclaimer.
     18  * 2. Redistributions in binary form must reproduce the above copyright
     19  *    notice, this list of conditions and the following disclaimer in the
     20  *    documentation and/or other materials provided with the distribution.
     21  * 3. The name of the author may not be used to endorse or promote products
     22  *    derived from this software without specific prior written permission.
     23  *
     24  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     25  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     26  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     27  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     29  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     33  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     34  */
     35 
     36 #include "defs.h"
     37 #include <sys/stat.h>
     38 #include "stat.h"
     39 
     40 void
     41 print_struct_stat(struct tcb *tcp, const struct strace_stat *const st)
     42 {
     43 	tprints("{");
     44 	if (!abbrev(tcp)) {
     45 		tprints("st_dev=");
     46 		print_dev_t(st->dev);
     47 		tprintf(", st_ino=%llu, st_mode=", st->ino);
     48 		print_symbolic_mode_t(st->mode);
     49 		tprintf(", st_nlink=%llu, st_uid=%llu, st_gid=%llu",
     50 			st->nlink, st->uid, st->gid);
     51 		tprintf(", st_blksize=%llu", st->blksize);
     52 		tprintf(", st_blocks=%llu", st->blocks);
     53 	} else {
     54 		tprints("st_mode=");
     55 		print_symbolic_mode_t(st->mode);
     56 	}
     57 
     58 	switch (st->mode & S_IFMT) {
     59 	case S_IFCHR: case S_IFBLK:
     60 		tprints(", st_rdev=");
     61 		print_dev_t(st->rdev);
     62 		break;
     63 	default:
     64 		tprintf(", st_size=%llu", st->size);
     65 		break;
     66 	}
     67 
     68 	if (!abbrev(tcp)) {
     69 #define PRINT_ST_TIME(field)						\
     70 	do {								\
     71 		tprintf(", st_" #field "=%lld", (long long) st->field);	\
     72 		tprints_comment(sprinttime_nsec(st->field,		\
     73 			zero_extend_signed_to_ull(st->field ## _nsec)));\
     74 		if (st->has_nsec)					\
     75 			tprintf(", st_" #field "_nsec=%llu",		\
     76 				zero_extend_signed_to_ull(		\
     77 					st->field ## _nsec));		\
     78 	} while (0)
     79 
     80 		PRINT_ST_TIME(atime);
     81 		PRINT_ST_TIME(mtime);
     82 		PRINT_ST_TIME(ctime);
     83 	} else {
     84 		tprints(", ...");
     85 	}
     86 	tprints("}");
     87 }
     88