18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: LGPL-2.1 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * trace/beauty/mount_flags.c 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2018, 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/compiler.h> 108c2ecf20Sopenharmony_ci#include <linux/kernel.h> 118c2ecf20Sopenharmony_ci#include <linux/log2.h> 128c2ecf20Sopenharmony_ci#include <sys/mount.h> 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_cistatic size_t mount__scnprintf_flags(unsigned long flags, char *bf, size_t size, bool show_prefix) 158c2ecf20Sopenharmony_ci{ 168c2ecf20Sopenharmony_ci#include "trace/beauty/generated/mount_flags_array.c" 178c2ecf20Sopenharmony_ci static DEFINE_STRARRAY(mount_flags, "MS_"); 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci return strarray__scnprintf_flags(&strarray__mount_flags, bf, size, show_prefix, flags); 208c2ecf20Sopenharmony_ci} 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ciunsigned long syscall_arg__mask_val_mount_flags(struct syscall_arg *arg __maybe_unused, unsigned long flags) 238c2ecf20Sopenharmony_ci{ 248c2ecf20Sopenharmony_ci // do_mount in fs/namespace.c: 258c2ecf20Sopenharmony_ci /* 268c2ecf20Sopenharmony_ci * Pre-0.97 versions of mount() didn't have a flags word. When the 278c2ecf20Sopenharmony_ci * flags word was introduced its top half was required to have the 288c2ecf20Sopenharmony_ci * magic value 0xC0ED, and this remained so until 2.4.0-test9. 298c2ecf20Sopenharmony_ci * Therefore, if this magic number is present, it carries no 308c2ecf20Sopenharmony_ci * information and must be discarded. 318c2ecf20Sopenharmony_ci */ 328c2ecf20Sopenharmony_ci if ((flags & MS_MGC_MSK) == MS_MGC_VAL) 338c2ecf20Sopenharmony_ci flags &= ~MS_MGC_MSK; 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci return flags; 368c2ecf20Sopenharmony_ci} 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_cisize_t syscall_arg__scnprintf_mount_flags(char *bf, size_t size, struct syscall_arg *arg) 398c2ecf20Sopenharmony_ci{ 408c2ecf20Sopenharmony_ci unsigned long flags = arg->val; 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci return mount__scnprintf_flags(flags, bf, size, arg->show_string_prefix); 438c2ecf20Sopenharmony_ci} 44