Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /* Test the statx() system call.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Note that the output of this program is intended to look like the output of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * /bin/stat where possible.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Copyright (C) 2015 Red Hat, Inc. All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Written by David Howells (dhowells@redhat.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #define _GNU_SOURCE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #define _ATFILE_SOURCE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <stdio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <stdlib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <sys/syscall.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <sys/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define statx foo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define statx_timestamp foo_timestamp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) struct statx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) struct statx_timestamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <sys/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #undef statx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #undef statx_timestamp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define AT_STATX_SYNC_TYPE	0x6000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define AT_STATX_SYNC_AS_STAT	0x0000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define AT_STATX_FORCE_SYNC	0x2000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define AT_STATX_DONT_SYNC	0x4000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #ifndef __NR_statx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define __NR_statx -1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) static __attribute__((unused))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) ssize_t statx(int dfd, const char *filename, unsigned flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	      unsigned int mask, struct statx *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	return syscall(__NR_statx, dfd, filename, flags, mask, buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) static void print_time(const char *field, struct statx_timestamp *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	struct tm tm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	time_t tim;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	char buffer[100];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	tim = ts->tv_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	if (!localtime_r(&tim, &tm)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		perror("localtime_r");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		exit(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	len = strftime(buffer, 100, "%F %T", &tm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	if (len == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		perror("strftime");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		exit(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	printf("%s", field);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	fwrite(buffer, 1, len, stdout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	printf(".%09u", ts->tv_nsec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	len = strftime(buffer, 100, "%z", &tm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	if (len == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		perror("strftime2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		exit(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	fwrite(buffer, 1, len, stdout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	printf("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) static void dump_statx(struct statx *stx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	char buffer[256], ft = '?';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	printf("results=%x\n", stx->stx_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	printf(" ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	if (stx->stx_mask & STATX_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		printf(" Size: %-15llu", (unsigned long long)stx->stx_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	if (stx->stx_mask & STATX_BLOCKS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		printf(" Blocks: %-10llu", (unsigned long long)stx->stx_blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	printf(" IO Block: %-6llu", (unsigned long long)stx->stx_blksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	if (stx->stx_mask & STATX_TYPE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		switch (stx->stx_mode & S_IFMT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		case S_IFIFO:	printf("  FIFO\n");			ft = 'p'; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		case S_IFCHR:	printf("  character special file\n");	ft = 'c'; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		case S_IFDIR:	printf("  directory\n");		ft = 'd'; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		case S_IFBLK:	printf("  block special file\n");	ft = 'b'; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		case S_IFREG:	printf("  regular file\n");		ft = '-'; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		case S_IFLNK:	printf("  symbolic link\n");		ft = 'l'; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		case S_IFSOCK:	printf("  socket\n");			ft = 's'; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			printf(" unknown type (%o)\n", stx->stx_mode & S_IFMT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		printf(" no type\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	sprintf(buffer, "%02x:%02x", stx->stx_dev_major, stx->stx_dev_minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	printf("Device: %-15s", buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	if (stx->stx_mask & STATX_INO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		printf(" Inode: %-11llu", (unsigned long long) stx->stx_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	if (stx->stx_mask & STATX_NLINK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		printf(" Links: %-5u", stx->stx_nlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	if (stx->stx_mask & STATX_TYPE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		switch (stx->stx_mode & S_IFMT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		case S_IFBLK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		case S_IFCHR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 			printf(" Device type: %u,%u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 			       stx->stx_rdev_major, stx->stx_rdev_minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	printf("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	if (stx->stx_mask & STATX_MODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		printf("Access: (%04o/%c%c%c%c%c%c%c%c%c%c)  ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		       stx->stx_mode & 07777,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		       ft,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		       stx->stx_mode & S_IRUSR ? 'r' : '-',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		       stx->stx_mode & S_IWUSR ? 'w' : '-',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		       stx->stx_mode & S_IXUSR ? 'x' : '-',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		       stx->stx_mode & S_IRGRP ? 'r' : '-',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		       stx->stx_mode & S_IWGRP ? 'w' : '-',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		       stx->stx_mode & S_IXGRP ? 'x' : '-',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		       stx->stx_mode & S_IROTH ? 'r' : '-',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		       stx->stx_mode & S_IWOTH ? 'w' : '-',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		       stx->stx_mode & S_IXOTH ? 'x' : '-');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	if (stx->stx_mask & STATX_UID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		printf("Uid: %5d   ", stx->stx_uid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	if (stx->stx_mask & STATX_GID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		printf("Gid: %5d\n", stx->stx_gid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	if (stx->stx_mask & STATX_ATIME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		print_time("Access: ", &stx->stx_atime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	if (stx->stx_mask & STATX_MTIME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		print_time("Modify: ", &stx->stx_mtime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	if (stx->stx_mask & STATX_CTIME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		print_time("Change: ", &stx->stx_ctime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	if (stx->stx_mask & STATX_BTIME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		print_time(" Birth: ", &stx->stx_btime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	if (stx->stx_attributes_mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		unsigned char bits, mbits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		int loop, byte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		static char attr_representation[64 + 1] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 			/* STATX_ATTR_ flags: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 			"????????"	/* 63-56 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 			"????????"	/* 55-48 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			"????????"	/* 47-40 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 			"????????"	/* 39-32 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 			"????????"	/* 31-24	0x00000000-ff000000 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 			"????????"	/* 23-16	0x00000000-00ff0000 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 			"???me???"	/* 15- 8	0x00000000-0000ff00 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 			"?dai?c??"	/*  7- 0	0x00000000-000000ff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 			;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		printf("Attributes: %016llx (",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		       (unsigned long long)stx->stx_attributes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		for (byte = 64 - 8; byte >= 0; byte -= 8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 			bits = stx->stx_attributes >> byte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 			mbits = stx->stx_attributes_mask >> byte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 			for (loop = 7; loop >= 0; loop--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 				int bit = byte + loop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 				if (!(mbits & 0x80))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 					putchar('.');	/* Not supported */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 				else if (bits & 0x80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 					putchar(attr_representation[63 - bit]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 				else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 					putchar('-');	/* Not set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 				bits <<= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 				mbits <<= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 			if (byte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 				putchar(' ');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		printf(")\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) static void dump_hex(unsigned long long *data, int from, int to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	unsigned offset, print_offset = 1, col = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	from /= 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	to = (to + 7) / 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	for (offset = from; offset < to; offset++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		if (print_offset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 			printf("%04x: ", offset * 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 			print_offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		printf("%016llx", data[offset]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		col++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		if ((col & 3) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 			printf("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 			print_offset = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 			printf(" ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	if (!print_offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		printf("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) int main(int argc, char **argv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	struct statx stx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	int ret, raw = 0, atflag = AT_SYMLINK_NOFOLLOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	unsigned int mask = STATX_BASIC_STATS | STATX_BTIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	for (argv++; *argv; argv++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		if (strcmp(*argv, "-F") == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 			atflag &= ~AT_STATX_SYNC_TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 			atflag |= AT_STATX_FORCE_SYNC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		if (strcmp(*argv, "-D") == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 			atflag &= ~AT_STATX_SYNC_TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 			atflag |= AT_STATX_DONT_SYNC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		if (strcmp(*argv, "-L") == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 			atflag &= ~AT_SYMLINK_NOFOLLOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		if (strcmp(*argv, "-O") == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 			mask &= ~STATX_BASIC_STATS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		if (strcmp(*argv, "-A") == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 			atflag |= AT_NO_AUTOMOUNT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		if (strcmp(*argv, "-R") == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 			raw = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		memset(&stx, 0xbf, sizeof(stx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		ret = statx(AT_FDCWD, *argv, atflag, mask, &stx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		printf("statx(%s) = %d\n", *argv, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 			perror(*argv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 			exit(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		if (raw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 			dump_hex((unsigned long long *)&stx, 0, sizeof(stx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		dump_statx(&stx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }