linux/include/linux/fs_parser.h

/* SPDX-License-Identifier: GPL-2.0-or-later */
/* Filesystem parameter description and parser
 *
 * Copyright (C) 2018 Red Hat, Inc. All Rights Reserved.
 * Written by David Howells ([email protected])
 */

#ifndef _LINUX_FS_PARSER_H
#define _LINUX_FS_PARSER_H

#include <linux/fs_context.h>

struct path;

struct constant_table {};

struct fs_parameter_spec;
struct fs_parse_result;
fs_param_type;
/*
 * The type of parameter expected.
 */
fs_param_type fs_param_is_bool, fs_param_is_u32, fs_param_is_s32, fs_param_is_u64,
	fs_param_is_enum, fs_param_is_string, fs_param_is_blob, fs_param_is_blockdev,
	fs_param_is_path, fs_param_is_fd, fs_param_is_uid, fs_param_is_gid;

/*
 * Specification of the type of value a parameter wants.
 *
 * Note that the fsparam_flag(), fsparam_string(), fsparam_u32(), ... macros
 * should be used to generate elements of this type.
 */
struct fs_parameter_spec {};

/*
 * Result of parse.
 */
struct fs_parse_result {};

extern int __fs_parse(struct p_log *log,
		    const struct fs_parameter_spec *desc,
		    struct fs_parameter *value,
		    struct fs_parse_result *result);

static inline int fs_parse(struct fs_context *fc,
	     const struct fs_parameter_spec *desc,
	     struct fs_parameter *param,
	     struct fs_parse_result *result)
{}

extern int fs_lookup_param(struct fs_context *fc,
			   struct fs_parameter *param,
			   bool want_bdev,
			   unsigned int flags,
			   struct path *_path);

extern int lookup_constant(const struct constant_table tbl[], const char *name, int not_found);

#ifdef CONFIG_VALIDATE_FS_PARSER
extern bool validate_constant_table(const struct constant_table *tbl, size_t tbl_size,
				    int low, int high, int special);
extern bool fs_validate_description(const char *name,
				    const struct fs_parameter_spec *desc);
#else
static inline bool validate_constant_table(const struct constant_table *tbl, size_t tbl_size,
					   int low, int high, int special)
{ return true; }
static inline bool fs_validate_description(const char *name,
					   const struct fs_parameter_spec *desc)
{ return true; }
#endif

/*
 * Parameter type, name, index and flags element constructors.  Use as:
 *
 *  fsparam_xxxx("foo", Opt_foo)
 *
 * If existing helpers are not enough, direct use of __fsparam() would
 * work, but any such case is probably a sign that new helper is needed.
 * Helpers will remain stable; low-level implementation may change.
 */
#define __fsparam(TYPE, NAME, OPT, FLAGS, DATA)

#define fsparam_flag(NAME, OPT)
#define fsparam_flag_no(NAME, OPT)
#define fsparam_bool(NAME, OPT)
#define fsparam_u32(NAME, OPT)
#define fsparam_u32oct(NAME, OPT)
#define fsparam_u32hex(NAME, OPT)
#define fsparam_s32(NAME, OPT)
#define fsparam_u64(NAME, OPT)
#define fsparam_enum(NAME, OPT, array)
#define fsparam_string(NAME, OPT)
#define fsparam_blob(NAME, OPT)
#define fsparam_bdev(NAME, OPT)
#define fsparam_path(NAME, OPT)
#define fsparam_fd(NAME, OPT)
#define fsparam_uid(NAME, OPT)
#define fsparam_gid(NAME, OPT)

/* String parameter that allows empty argument */
#define fsparam_string_empty(NAME, OPT)

#endif /* _LINUX_FS_PARSER_H */