(root)/
strace-6.5/
src/
print_struct_stat.c
       1  /*
       2   * Copyright (c) 1999-2003 Ulrich Drepper <drepper@redhat.com>
       3   * Copyright (c) 2004 David S. Miller <davem@nuts.davemloft.net>
       4   * Copyright (c) 2003-2005 Roland McGrath <roland@redhat.com>
       5   * Copyright (c) 2007 Jan Kratochvil <jan.kratochvil@redhat.com>
       6   * Copyright (c) 2009 Denys Vlasenko <dvlasenk@redhat.com>
       7   * Copyright (c) 2009-2010 Andreas Schwab <schwab@linux-m68k.org>
       8   * Copyright (c) 2012 H.J. Lu <hongjiu.lu@intel.com>
       9   * Copyright (c) 2005-2016 Dmitry V. Levin <ldv@strace.io>
      10   * Copyright (c) 2016-2021 The strace developers.
      11   * All rights reserved.
      12   *
      13   * SPDX-License-Identifier: LGPL-2.1-or-later
      14   */
      15  
      16  #include "defs.h"
      17  #include <sys/stat.h>
      18  #include "stat.h"
      19  
      20  /*
      21   * This series of #undef/#define was produced by the following script:
      22   * sed -n 's/.*[[:space:]]\([[:alpha:]_]\+\);$/\1/p' stat.h |
      23   * while read n; do
      24   * 	printf '#undef st_%s\n#define st_%s %s\n\n' "$n" "$n" "$n"
      25   * done
      26   */
      27  
      28  #undef st_dev
      29  #define st_dev dev
      30  
      31  #undef st_ino
      32  #define st_ino ino
      33  
      34  #undef st_rdev
      35  #define st_rdev rdev
      36  
      37  #undef st_size
      38  #define st_size size
      39  
      40  #undef st_blocks
      41  #define st_blocks blocks
      42  
      43  #undef st_blksize
      44  #define st_blksize blksize
      45  
      46  #undef st_mode
      47  #define st_mode mode
      48  
      49  #undef st_nlink
      50  #define st_nlink nlink
      51  
      52  #undef st_uid
      53  #define st_uid uid
      54  
      55  #undef st_gid
      56  #define st_gid gid
      57  
      58  #undef st_atime
      59  #define st_atime atime
      60  
      61  #undef st_ctime
      62  #define st_ctime ctime
      63  
      64  #undef st_mtime
      65  #define st_mtime mtime
      66  
      67  #undef st_atime_nsec
      68  #define st_atime_nsec atime_nsec
      69  
      70  #undef st_ctime_nsec
      71  #define st_ctime_nsec ctime_nsec
      72  
      73  #undef st_mtime_nsec
      74  #define st_mtime_nsec mtime_nsec
      75  
      76  void
      77  print_struct_stat(struct tcb *tcp, const struct strace_stat *const st)
      78  {
      79  	tprint_struct_begin();
      80  	if (!abbrev(tcp)) {
      81  		PRINT_FIELD_DEV(*st, st_dev);
      82  		tprint_struct_next();
      83  		PRINT_FIELD_U(*st, st_ino);
      84  		tprint_struct_next();
      85  		PRINT_FIELD_OBJ_VAL(*st, st_mode, print_symbolic_mode_t);
      86  		tprint_struct_next();
      87  		PRINT_FIELD_U(*st, st_nlink);
      88  		tprint_struct_next();
      89  		PRINT_FIELD_U(*st, st_uid);
      90  		tprint_struct_next();
      91  		PRINT_FIELD_U(*st, st_gid);
      92  		tprint_struct_next();
      93  		PRINT_FIELD_U(*st, st_blksize);
      94  		tprint_struct_next();
      95  		PRINT_FIELD_U(*st, st_blocks);
      96  	} else {
      97  		PRINT_FIELD_OBJ_VAL(*st, st_mode, print_symbolic_mode_t);
      98  	}
      99  
     100  	switch (st->st_mode & S_IFMT) {
     101  	case S_IFCHR: case S_IFBLK:
     102  		tprint_struct_next();
     103  		PRINT_FIELD_DEV(*st, st_rdev);
     104  		break;
     105  	default:
     106  		tprint_struct_next();
     107  		PRINT_FIELD_U(*st, st_size);
     108  		break;
     109  	}
     110  
     111  	if (!abbrev(tcp)) {
     112  		tprint_struct_next();
     113  		PRINT_FIELD_D(*st, st_atime);
     114  		tprints_comment(sprinttime_nsec(st->st_atime,
     115  						st->st_atime_nsec));
     116  		if (st->has_nsec) {
     117  			tprint_struct_next();
     118  			PRINT_FIELD_U(*st, st_atime_nsec);
     119  		}
     120  
     121  		tprint_struct_next();
     122  		PRINT_FIELD_D(*st, st_mtime);
     123  		tprints_comment(sprinttime_nsec(st->st_mtime,
     124  						st->st_mtime_nsec));
     125  		if (st->has_nsec) {
     126  			tprint_struct_next();
     127  			PRINT_FIELD_U(*st, st_mtime_nsec);
     128  		}
     129  
     130  		tprint_struct_next();
     131  		PRINT_FIELD_D(*st, st_ctime);
     132  		tprints_comment(sprinttime_nsec(st->st_ctime,
     133  						st->st_ctime_nsec));
     134  		if (st->has_nsec) {
     135  			tprint_struct_next();
     136  			PRINT_FIELD_U(*st, st_ctime_nsec);
     137  		}
     138  	} else {
     139  		tprint_struct_next();
     140  		tprint_more_data_follows();
     141  	}
     142  	tprint_struct_end();
     143  }