18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: LGPL-2.1
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * trace/beauty/statx.c
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci *  Copyright (C) 2017, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#include "trace/beauty/beauty.h"
98c2ecf20Sopenharmony_ci#include <linux/kernel.h>
108c2ecf20Sopenharmony_ci#include <sys/types.h>
118c2ecf20Sopenharmony_ci#include <uapi/linux/fcntl.h>
128c2ecf20Sopenharmony_ci#include <uapi/linux/stat.h>
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_cisize_t syscall_arg__scnprintf_statx_flags(char *bf, size_t size, struct syscall_arg *arg)
158c2ecf20Sopenharmony_ci{
168c2ecf20Sopenharmony_ci	bool show_prefix = arg->show_string_prefix;
178c2ecf20Sopenharmony_ci	const char *prefix = "AT_";
188c2ecf20Sopenharmony_ci	int printed = 0, flags = arg->val;
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci	if (flags == 0)
218c2ecf20Sopenharmony_ci		return scnprintf(bf, size, "%s%s", show_prefix ? "AT_STATX_" : "", "SYNC_AS_STAT");
228c2ecf20Sopenharmony_ci#define	P_FLAG(n) \
238c2ecf20Sopenharmony_ci	if (flags & AT_##n) { \
248c2ecf20Sopenharmony_ci		printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", show_prefix ? prefix : "", #n); \
258c2ecf20Sopenharmony_ci		flags &= ~AT_##n; \
268c2ecf20Sopenharmony_ci	}
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci	P_FLAG(SYMLINK_NOFOLLOW);
298c2ecf20Sopenharmony_ci	P_FLAG(REMOVEDIR);
308c2ecf20Sopenharmony_ci	P_FLAG(SYMLINK_FOLLOW);
318c2ecf20Sopenharmony_ci	P_FLAG(NO_AUTOMOUNT);
328c2ecf20Sopenharmony_ci	P_FLAG(EMPTY_PATH);
338c2ecf20Sopenharmony_ci	P_FLAG(STATX_FORCE_SYNC);
348c2ecf20Sopenharmony_ci	P_FLAG(STATX_DONT_SYNC);
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#undef P_FLAG
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci	if (flags)
398c2ecf20Sopenharmony_ci		printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags);
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci	return printed;
428c2ecf20Sopenharmony_ci}
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_cisize_t syscall_arg__scnprintf_statx_mask(char *bf, size_t size, struct syscall_arg *arg)
458c2ecf20Sopenharmony_ci{
468c2ecf20Sopenharmony_ci	bool show_prefix = arg->show_string_prefix;
478c2ecf20Sopenharmony_ci	const char *prefix = "STATX_";
488c2ecf20Sopenharmony_ci	int printed = 0, flags = arg->val;
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci#define	P_FLAG(n) \
518c2ecf20Sopenharmony_ci	if (flags & STATX_##n) { \
528c2ecf20Sopenharmony_ci		printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", show_prefix ? prefix : "", #n); \
538c2ecf20Sopenharmony_ci		flags &= ~STATX_##n; \
548c2ecf20Sopenharmony_ci	}
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci	P_FLAG(TYPE);
578c2ecf20Sopenharmony_ci	P_FLAG(MODE);
588c2ecf20Sopenharmony_ci	P_FLAG(NLINK);
598c2ecf20Sopenharmony_ci	P_FLAG(UID);
608c2ecf20Sopenharmony_ci	P_FLAG(GID);
618c2ecf20Sopenharmony_ci	P_FLAG(ATIME);
628c2ecf20Sopenharmony_ci	P_FLAG(MTIME);
638c2ecf20Sopenharmony_ci	P_FLAG(CTIME);
648c2ecf20Sopenharmony_ci	P_FLAG(INO);
658c2ecf20Sopenharmony_ci	P_FLAG(SIZE);
668c2ecf20Sopenharmony_ci	P_FLAG(BLOCKS);
678c2ecf20Sopenharmony_ci	P_FLAG(BTIME);
688c2ecf20Sopenharmony_ci	P_FLAG(MNT_ID);
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci#undef P_FLAG
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci	if (flags)
738c2ecf20Sopenharmony_ci		printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags);
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci	return printed;
768c2ecf20Sopenharmony_ci}
77