162306a36Sopenharmony_ci// SPDX-License-Identifier: LGPL-2.1
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * trace/beauty/mount_flags.c
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci *  Copyright (C) 2018, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#include "trace/beauty/beauty.h"
962306a36Sopenharmony_ci#include <linux/compiler.h>
1062306a36Sopenharmony_ci#include <linux/kernel.h>
1162306a36Sopenharmony_ci#include <linux/log2.h>
1262306a36Sopenharmony_ci#include <sys/mount.h>
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_cistatic size_t mount__scnprintf_flags(unsigned long flags, char *bf, size_t size, bool show_prefix)
1562306a36Sopenharmony_ci{
1662306a36Sopenharmony_ci#include "trace/beauty/generated/mount_flags_array.c"
1762306a36Sopenharmony_ci	static DEFINE_STRARRAY(mount_flags, "MS_");
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci	return strarray__scnprintf_flags(&strarray__mount_flags, bf, size, show_prefix, flags);
2062306a36Sopenharmony_ci}
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ciunsigned long syscall_arg__mask_val_mount_flags(struct syscall_arg *arg __maybe_unused, unsigned long flags)
2362306a36Sopenharmony_ci{
2462306a36Sopenharmony_ci	// do_mount in fs/namespace.c:
2562306a36Sopenharmony_ci	/*
2662306a36Sopenharmony_ci	 * Pre-0.97 versions of mount() didn't have a flags word.  When the
2762306a36Sopenharmony_ci	 * flags word was introduced its top half was required to have the
2862306a36Sopenharmony_ci	 * magic value 0xC0ED, and this remained so until 2.4.0-test9.
2962306a36Sopenharmony_ci	 * Therefore, if this magic number is present, it carries no
3062306a36Sopenharmony_ci	 * information and must be discarded.
3162306a36Sopenharmony_ci	 */
3262306a36Sopenharmony_ci	if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
3362306a36Sopenharmony_ci		flags &= ~MS_MGC_MSK;
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci	return flags;
3662306a36Sopenharmony_ci}
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_cisize_t syscall_arg__scnprintf_mount_flags(char *bf, size_t size, struct syscall_arg *arg)
3962306a36Sopenharmony_ci{
4062306a36Sopenharmony_ci	unsigned long flags = arg->val;
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci	return mount__scnprintf_flags(flags, bf, size, arg->show_string_prefix);
4362306a36Sopenharmony_ci}
44