1 // SPDX-License-Identifier: LGPL-2.1
2 /*
3  * trace/beauty/statx.c
4  *
5  *  Copyright (C) 2017, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
6  */
7 
8 #include "trace/beauty/beauty.h"
9 #include <linux/kernel.h>
10 #include <sys/types.h>
11 #include <uapi/linux/fcntl.h>
12 #include <uapi/linux/stat.h>
13 
syscall_arg__scnprintf_statx_flags(char * bf,size_t size,struct syscall_arg * arg)14 size_t syscall_arg__scnprintf_statx_flags(char *bf, size_t size, struct syscall_arg *arg)
15 {
16 	bool show_prefix = arg->show_string_prefix;
17 	const char *prefix = "AT_";
18 	int printed = 0, flags = arg->val;
19 
20 	if (flags == 0)
21 		return scnprintf(bf, size, "%s%s", show_prefix ? "AT_STATX_" : "", "SYNC_AS_STAT");
22 #define	P_FLAG(n) \
23 	if (flags & AT_##n) { \
24 		printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", show_prefix ? prefix : "", #n); \
25 		flags &= ~AT_##n; \
26 	}
27 
28 	P_FLAG(SYMLINK_NOFOLLOW);
29 	P_FLAG(REMOVEDIR);
30 	P_FLAG(SYMLINK_FOLLOW);
31 	P_FLAG(NO_AUTOMOUNT);
32 	P_FLAG(EMPTY_PATH);
33 	P_FLAG(STATX_FORCE_SYNC);
34 	P_FLAG(STATX_DONT_SYNC);
35 
36 #undef P_FLAG
37 
38 	if (flags)
39 		printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags);
40 
41 	return printed;
42 }
43 
syscall_arg__scnprintf_statx_mask(char * bf,size_t size,struct syscall_arg * arg)44 size_t syscall_arg__scnprintf_statx_mask(char *bf, size_t size, struct syscall_arg *arg)
45 {
46 	bool show_prefix = arg->show_string_prefix;
47 	const char *prefix = "STATX_";
48 	int printed = 0, flags = arg->val;
49 
50 #define	P_FLAG(n) \
51 	if (flags & STATX_##n) { \
52 		printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", show_prefix ? prefix : "", #n); \
53 		flags &= ~STATX_##n; \
54 	}
55 
56 	P_FLAG(TYPE);
57 	P_FLAG(MODE);
58 	P_FLAG(NLINK);
59 	P_FLAG(UID);
60 	P_FLAG(GID);
61 	P_FLAG(ATIME);
62 	P_FLAG(MTIME);
63 	P_FLAG(CTIME);
64 	P_FLAG(INO);
65 	P_FLAG(SIZE);
66 	P_FLAG(BLOCKS);
67 	P_FLAG(BTIME);
68 	P_FLAG(MNT_ID);
69 	P_FLAG(DIOALIGN);
70 
71 #undef P_FLAG
72 
73 	if (flags)
74 		printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags);
75 
76 	return printed;
77 }
78