Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at ee9dce44362b2d8132c32964656ab6dff7dfbc6a 139 lines 4.6 kB view raw
1/* SPDX-License-Identifier: GPL-2.0-or-later */ 2/* Filesystem parameter description and parser 3 * 4 * Copyright (C) 2018 Red Hat, Inc. All Rights Reserved. 5 * Written by David Howells (dhowells@redhat.com) 6 */ 7 8#ifndef _LINUX_FS_PARSER_H 9#define _LINUX_FS_PARSER_H 10 11#include <linux/fs_context.h> 12 13struct path; 14 15struct constant_table { 16 const char *name; 17 int value; 18}; 19 20struct fs_parameter_spec; 21struct fs_parse_result; 22typedef int fs_param_type(struct p_log *, 23 const struct fs_parameter_spec *, 24 struct fs_parameter *, 25 struct fs_parse_result *); 26/* 27 * The type of parameter expected. 28 */ 29fs_param_type fs_param_is_bool, fs_param_is_u32, fs_param_is_s32, fs_param_is_u64, 30 fs_param_is_enum, fs_param_is_string, fs_param_is_blockdev, 31 fs_param_is_fd, fs_param_is_uid, fs_param_is_gid, 32 fs_param_is_file_or_string; 33 34/* 35 * Specification of the type of value a parameter wants. 36 * 37 * Note that the fsparam_flag(), fsparam_string(), fsparam_u32(), ... macros 38 * should be used to generate elements of this type. 39 */ 40struct fs_parameter_spec { 41 const char *name; 42 fs_param_type *type; /* The desired parameter type */ 43 u8 opt; /* Option number (returned by fs_parse()) */ 44 unsigned short flags; 45#define fs_param_neg_with_no 0x0002 /* "noxxx" is negative param */ 46#define fs_param_can_be_empty 0x0004 /* "xxx=" is allowed */ 47#define fs_param_deprecated 0x0008 /* The param is deprecated */ 48 const void *data; 49}; 50 51/* 52 * Result of parse. 53 */ 54struct fs_parse_result { 55 bool negated; /* T if param was "noxxx" */ 56 union { 57 bool boolean; /* For spec_bool */ 58 int int_32; /* For spec_s32/spec_enum */ 59 unsigned int uint_32; /* For spec_u32{,_octal,_hex}/spec_enum */ 60 u64 uint_64; /* For spec_u64 */ 61 kuid_t uid; 62 kgid_t gid; 63 }; 64}; 65 66extern int __fs_parse(struct p_log *log, 67 const struct fs_parameter_spec *desc, 68 struct fs_parameter *value, 69 struct fs_parse_result *result); 70 71static inline int fs_parse(struct fs_context *fc, 72 const struct fs_parameter_spec *desc, 73 struct fs_parameter *param, 74 struct fs_parse_result *result) 75{ 76 return __fs_parse(&fc->log, desc, param, result); 77} 78 79extern int fs_lookup_param(struct fs_context *fc, 80 struct fs_parameter *param, 81 bool want_bdev, 82 unsigned int flags, 83 struct path *_path); 84 85extern int lookup_constant(const struct constant_table tbl[], const char *name, int not_found); 86 87#ifdef CONFIG_VALIDATE_FS_PARSER 88extern bool fs_validate_description(const char *name, 89 const struct fs_parameter_spec *desc); 90#else 91static inline bool fs_validate_description(const char *name, 92 const struct fs_parameter_spec *desc) 93{ return true; } 94#endif 95 96/* 97 * Parameter type, name, index and flags element constructors. Use as: 98 * 99 * fsparam_xxxx("foo", Opt_foo) 100 * 101 * If existing helpers are not enough, direct use of __fsparam() would 102 * work, but any such case is probably a sign that new helper is needed. 103 * Helpers will remain stable; low-level implementation may change. 104 */ 105#define __fsparam(TYPE, NAME, OPT, FLAGS, DATA) \ 106 { \ 107 .name = NAME, \ 108 .opt = OPT, \ 109 .type = TYPE, \ 110 .flags = FLAGS, \ 111 .data = DATA \ 112 } 113 114#define fsparam_flag(NAME, OPT) __fsparam(NULL, NAME, OPT, 0, NULL) 115#define fsparam_flag_no(NAME, OPT) \ 116 __fsparam(NULL, NAME, OPT, fs_param_neg_with_no, NULL) 117#define fsparam_bool(NAME, OPT) __fsparam(fs_param_is_bool, NAME, OPT, 0, NULL) 118#define fsparam_u32(NAME, OPT) __fsparam(fs_param_is_u32, NAME, OPT, 0, NULL) 119#define fsparam_u32oct(NAME, OPT) \ 120 __fsparam(fs_param_is_u32, NAME, OPT, 0, (void *)8) 121#define fsparam_u32hex(NAME, OPT) \ 122 __fsparam(fs_param_is_u32, NAME, OPT, 0, (void *)16) 123#define fsparam_s32(NAME, OPT) __fsparam(fs_param_is_s32, NAME, OPT, 0, NULL) 124#define fsparam_u64(NAME, OPT) __fsparam(fs_param_is_u64, NAME, OPT, 0, NULL) 125#define fsparam_enum(NAME, OPT, array) __fsparam(fs_param_is_enum, NAME, OPT, 0, array) 126#define fsparam_string(NAME, OPT) \ 127 __fsparam(fs_param_is_string, NAME, OPT, 0, NULL) 128#define fsparam_bdev(NAME, OPT) __fsparam(fs_param_is_blockdev, NAME, OPT, 0, NULL) 129#define fsparam_fd(NAME, OPT) __fsparam(fs_param_is_fd, NAME, OPT, 0, NULL) 130#define fsparam_file_or_string(NAME, OPT) \ 131 __fsparam(fs_param_is_file_or_string, NAME, OPT, 0, NULL) 132#define fsparam_uid(NAME, OPT) __fsparam(fs_param_is_uid, NAME, OPT, 0, NULL) 133#define fsparam_gid(NAME, OPT) __fsparam(fs_param_is_gid, NAME, OPT, 0, NULL) 134 135/* String parameter that allows empty argument */ 136#define fsparam_string_empty(NAME, OPT) \ 137 __fsparam(fs_param_is_string, NAME, OPT, fs_param_can_be_empty, NULL) 138 139#endif /* _LINUX_FS_PARSER_H */