xref: /openbmc/linux/tools/perf/trace/beauty/statx.c (revision 6d99a79c)
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 
14 size_t syscall_arg__scnprintf_statx_flags(char *bf, size_t size, struct syscall_arg *arg)
15 {
16 	int printed = 0, flags = arg->val;
17 
18 	if (flags == 0)
19 		return scnprintf(bf, size, "SYNC_AS_STAT");
20 #define	P_FLAG(n) \
21 	if (flags & AT_##n) { \
22 		printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \
23 		flags &= ~AT_##n; \
24 	}
25 
26 	P_FLAG(SYMLINK_NOFOLLOW);
27 	P_FLAG(REMOVEDIR);
28 	P_FLAG(SYMLINK_FOLLOW);
29 	P_FLAG(NO_AUTOMOUNT);
30 	P_FLAG(EMPTY_PATH);
31 	P_FLAG(STATX_FORCE_SYNC);
32 	P_FLAG(STATX_DONT_SYNC);
33 
34 #undef P_FLAG
35 
36 	if (flags)
37 		printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags);
38 
39 	return printed;
40 }
41 
42 size_t syscall_arg__scnprintf_statx_mask(char *bf, size_t size, struct syscall_arg *arg)
43 {
44 	int printed = 0, flags = arg->val;
45 
46 #define	P_FLAG(n) \
47 	if (flags & STATX_##n) { \
48 		printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \
49 		flags &= ~STATX_##n; \
50 	}
51 
52 	P_FLAG(TYPE);
53 	P_FLAG(MODE);
54 	P_FLAG(NLINK);
55 	P_FLAG(UID);
56 	P_FLAG(GID);
57 	P_FLAG(ATIME);
58 	P_FLAG(MTIME);
59 	P_FLAG(CTIME);
60 	P_FLAG(INO);
61 	P_FLAG(SIZE);
62 	P_FLAG(BLOCKS);
63 	P_FLAG(BTIME);
64 
65 #undef P_FLAG
66 
67 	if (flags)
68 		printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags);
69 
70 	return printed;
71 }
72