fs_context.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright (C) 2020, Microsoft Corporation.
  4. *
  5. * Author(s): Steve French <stfrench@microsoft.com>
  6. * David Howells <dhowells@redhat.com>
  7. */
  8. #ifndef _FS_CONTEXT_H
  9. #define _FS_CONTEXT_H
  10. #include "cifsglob.h"
  11. #include <linux/parser.h>
  12. #include <linux/fs_parser.h>
  13. /* Log errors in fs_context (new mount api) but also in dmesg (old style) */
  14. #define cifs_errorf(fc, fmt, ...) \
  15. do { \
  16. errorf(fc, fmt, ## __VA_ARGS__); \
  17. cifs_dbg(VFS, fmt, ## __VA_ARGS__); \
  18. } while (0)
  19. enum smb_version {
  20. Smb_1 = 1,
  21. Smb_20,
  22. Smb_21,
  23. Smb_30,
  24. Smb_302,
  25. Smb_311,
  26. Smb_3any,
  27. Smb_default,
  28. Smb_version_err
  29. };
  30. enum {
  31. Opt_cache_loose,
  32. Opt_cache_strict,
  33. Opt_cache_none,
  34. Opt_cache_ro,
  35. Opt_cache_rw,
  36. Opt_cache_err
  37. };
  38. enum cifs_reparse_parm {
  39. Opt_reparse_default,
  40. Opt_reparse_nfs,
  41. Opt_reparse_wsl,
  42. Opt_reparse_err
  43. };
  44. enum cifs_sec_param {
  45. Opt_sec_krb5,
  46. Opt_sec_krb5i,
  47. Opt_sec_krb5p,
  48. Opt_sec_ntlmsspi,
  49. Opt_sec_ntlmssp,
  50. Opt_sec_ntlmv2,
  51. Opt_sec_ntlmv2i,
  52. Opt_sec_none,
  53. Opt_sec_err
  54. };
  55. enum cifs_upcall_target_param {
  56. Opt_upcall_target_mount,
  57. Opt_upcall_target_application,
  58. Opt_upcall_target_err
  59. };
  60. enum cifs_param {
  61. /* Mount options that take no arguments */
  62. Opt_user_xattr,
  63. Opt_forceuid,
  64. Opt_forcegid,
  65. Opt_noblocksend,
  66. Opt_noautotune,
  67. Opt_nolease,
  68. Opt_nosparse,
  69. Opt_hard,
  70. Opt_soft,
  71. Opt_perm,
  72. Opt_nodelete,
  73. Opt_mapposix,
  74. Opt_mapchars,
  75. Opt_nomapchars,
  76. Opt_sfu,
  77. Opt_nodfs,
  78. Opt_posixpaths,
  79. Opt_unix,
  80. Opt_nocase,
  81. Opt_brl,
  82. Opt_handlecache,
  83. Opt_forcemandatorylock,
  84. Opt_setuidfromacl,
  85. Opt_setuids,
  86. Opt_dynperm,
  87. Opt_intr,
  88. Opt_strictsync,
  89. Opt_serverino,
  90. Opt_rwpidforward,
  91. Opt_cifsacl,
  92. Opt_acl,
  93. Opt_locallease,
  94. Opt_sign,
  95. Opt_ignore_signature,
  96. Opt_seal,
  97. Opt_noac,
  98. Opt_fsc,
  99. Opt_mfsymlinks,
  100. Opt_multiuser,
  101. Opt_sloppy,
  102. Opt_nosharesock,
  103. Opt_persistent,
  104. Opt_resilient,
  105. Opt_tcp_nodelay,
  106. Opt_domainauto,
  107. Opt_rdma,
  108. Opt_modesid,
  109. Opt_rootfs,
  110. Opt_multichannel,
  111. Opt_compress,
  112. Opt_witness,
  113. Opt_is_upcall_target_mount,
  114. Opt_is_upcall_target_application,
  115. /* Mount options which take numeric value */
  116. Opt_backupuid,
  117. Opt_backupgid,
  118. Opt_uid,
  119. Opt_cruid,
  120. Opt_gid,
  121. Opt_port,
  122. Opt_file_mode,
  123. Opt_dirmode,
  124. Opt_min_enc_offload,
  125. Opt_retrans,
  126. Opt_blocksize,
  127. Opt_rasize,
  128. Opt_rsize,
  129. Opt_wsize,
  130. Opt_actimeo,
  131. Opt_acdirmax,
  132. Opt_acregmax,
  133. Opt_closetimeo,
  134. Opt_echo_interval,
  135. Opt_max_credits,
  136. Opt_max_cached_dirs,
  137. Opt_snapshot,
  138. Opt_max_channels,
  139. Opt_handletimeout,
  140. /* Mount options which take string value */
  141. Opt_source,
  142. Opt_user,
  143. Opt_pass,
  144. Opt_pass2,
  145. Opt_ip,
  146. Opt_domain,
  147. Opt_srcaddr,
  148. Opt_iocharset,
  149. Opt_netbiosname,
  150. Opt_servern,
  151. Opt_ver,
  152. Opt_vers,
  153. Opt_sec,
  154. Opt_cache,
  155. Opt_reparse,
  156. Opt_upcalltarget,
  157. /* Mount options to be ignored */
  158. Opt_ignore,
  159. Opt_err
  160. };
  161. struct smb3_fs_context {
  162. bool forceuid_specified;
  163. bool forcegid_specified;
  164. bool uid_specified;
  165. bool cruid_specified;
  166. bool gid_specified;
  167. bool sloppy;
  168. bool got_ip;
  169. bool got_version;
  170. bool got_rsize;
  171. bool got_wsize;
  172. bool got_bsize;
  173. unsigned short port;
  174. char *username;
  175. char *password;
  176. char *password2;
  177. char *domainname;
  178. char *source;
  179. char *server_hostname;
  180. char *UNC;
  181. char *nodename;
  182. char workstation_name[CIFS_MAX_WORKSTATION_LEN];
  183. char *iocharset; /* local code page for mapping to and from Unicode */
  184. char source_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL]; /* clnt nb name */
  185. char target_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL]; /* srvr nb name */
  186. kuid_t cred_uid;
  187. kuid_t linux_uid;
  188. kgid_t linux_gid;
  189. kuid_t backupuid;
  190. kgid_t backupgid;
  191. umode_t file_mode;
  192. umode_t dir_mode;
  193. enum securityEnum sectype; /* sectype requested via mnt opts */
  194. enum upcall_target_enum upcall_target; /* where to upcall for mount */
  195. bool sign; /* was signing requested via mnt opts? */
  196. bool ignore_signature:1;
  197. bool retry:1;
  198. bool intr:1;
  199. bool setuids:1;
  200. bool setuidfromacl:1;
  201. bool override_uid:1;
  202. bool override_gid:1;
  203. bool dynperm:1;
  204. bool noperm:1;
  205. bool nodelete:1;
  206. bool mode_ace:1;
  207. bool no_psx_acl:1; /* set if posix acl support should be disabled */
  208. bool cifs_acl:1;
  209. bool backupuid_specified; /* mount option backupuid is specified */
  210. bool backupgid_specified; /* mount option backupgid is specified */
  211. bool no_xattr:1; /* set if xattr (EA) support should be disabled*/
  212. bool server_ino:1; /* use inode numbers from server ie UniqueId */
  213. bool direct_io:1;
  214. bool strict_io:1; /* strict cache behavior */
  215. bool cache_ro:1;
  216. bool cache_rw:1;
  217. bool remap:1; /* set to remap seven reserved chars in filenames */
  218. bool sfu_remap:1; /* remap seven reserved chars ala SFU */
  219. bool posix_paths:1; /* unset to not ask for posix pathnames. */
  220. bool no_linux_ext:1;
  221. bool linux_ext:1;
  222. bool sfu_emul:1;
  223. bool nullauth:1; /* attempt to authenticate with null user */
  224. bool nocase:1; /* request case insensitive filenames */
  225. bool nobrl:1; /* disable sending byte range locks to srv */
  226. bool nohandlecache:1; /* disable caching dir handles if srvr probs */
  227. bool mand_lock:1; /* send mandatory not posix byte range lock reqs */
  228. bool seal:1; /* request transport encryption on share */
  229. bool nodfs:1; /* Do not request DFS, even if available */
  230. bool local_lease:1; /* check leases only on local system, not remote */
  231. bool noblocksnd:1;
  232. bool noautotune:1;
  233. bool nostrictsync:1; /* do not force expensive SMBflush on every sync */
  234. bool no_lease:1; /* disable requesting leases */
  235. bool no_sparse:1; /* do not attempt to set files sparse */
  236. bool fsc:1; /* enable fscache */
  237. bool mfsymlinks:1; /* use Minshall+French Symlinks */
  238. bool multiuser:1;
  239. bool rwpidforward:1; /* pid forward for read/write operations */
  240. bool nosharesock:1;
  241. bool persistent:1;
  242. bool nopersistent:1;
  243. bool resilient:1; /* noresilient not required since not fored for CA */
  244. bool domainauto:1;
  245. bool rdma:1;
  246. bool multichannel:1;
  247. bool use_client_guid:1;
  248. /* reuse existing guid for multichannel */
  249. u8 client_guid[SMB2_CLIENT_GUID_SIZE];
  250. /* User-specified original r/wsize value */
  251. unsigned int vol_rsize;
  252. unsigned int vol_wsize;
  253. unsigned int bsize;
  254. unsigned int rasize;
  255. unsigned int rsize;
  256. unsigned int wsize;
  257. unsigned int min_offload;
  258. unsigned int retrans;
  259. bool sockopt_tcp_nodelay:1;
  260. /* attribute cache timeout for files and directories in jiffies */
  261. unsigned long acregmax;
  262. unsigned long acdirmax;
  263. /* timeout for deferred close of files in jiffies */
  264. unsigned long closetimeo;
  265. struct smb_version_operations *ops;
  266. struct smb_version_values *vals;
  267. char *prepath;
  268. struct sockaddr_storage dstaddr; /* destination address */
  269. struct sockaddr_storage srcaddr; /* allow binding to a local IP */
  270. struct nls_table *local_nls; /* This is a copy of the pointer in cifs_sb */
  271. unsigned int echo_interval; /* echo interval in secs */
  272. __u64 snapshot_time; /* needed for timewarp tokens */
  273. __u32 handle_timeout; /* persistent and durable handle timeout in ms */
  274. unsigned int max_credits; /* smb3 max_credits 10 < credits < 60000 */
  275. unsigned int max_channels;
  276. unsigned int max_cached_dirs;
  277. bool compress; /* enable SMB2 messages (READ/WRITE) de/compression */
  278. bool rootfs:1; /* if it's a SMB root file system */
  279. bool witness:1; /* use witness protocol */
  280. char *leaf_fullpath;
  281. struct cifs_ses *dfs_root_ses;
  282. bool dfs_automount:1; /* set for dfs automount only */
  283. enum cifs_reparse_type reparse_type;
  284. bool dfs_conn:1; /* set for dfs mounts */
  285. };
  286. extern const struct fs_parameter_spec smb3_fs_parameters[];
  287. extern int smb3_init_fs_context(struct fs_context *fc);
  288. extern void smb3_cleanup_fs_context_contents(struct smb3_fs_context *ctx);
  289. extern void smb3_cleanup_fs_context(struct smb3_fs_context *ctx);
  290. static inline struct smb3_fs_context *smb3_fc2context(const struct fs_context *fc)
  291. {
  292. return fc->fs_private;
  293. }
  294. extern int smb3_fs_context_dup(struct smb3_fs_context *new_ctx, struct smb3_fs_context *ctx);
  295. extern int smb3_sync_session_ctx_passwords(struct cifs_sb_info *cifs_sb, struct cifs_ses *ses);
  296. extern void smb3_update_mnt_flags(struct cifs_sb_info *cifs_sb);
  297. /*
  298. * max deferred close timeout (jiffies) - 2^30
  299. */
  300. #define SMB3_MAX_DCLOSETIMEO (1 << 30)
  301. #define SMB3_DEF_DCLOSETIMEO (1 * HZ) /* even 1 sec enough to help eg open/write/close/open/read */
  302. #define MAX_CACHED_FIDS 16
  303. extern char *cifs_sanitize_prepath(char *prepath, gfp_t gfp);
  304. extern struct mutex cifs_mount_mutex;
  305. static inline void cifs_mount_lock(void)
  306. {
  307. mutex_lock(&cifs_mount_mutex);
  308. }
  309. static inline void cifs_mount_unlock(void)
  310. {
  311. mutex_unlock(&cifs_mount_mutex);
  312. }
  313. #endif