FILE
cifsproto.h
File preview with syntax highlighting.
linux-6.19.14/fs/smb/client/cifsproto.h
1/* SPDX-License-Identifier: LGPL-2.1 */ 2/* 3 * 4 * Copyright (c) International Business Machines Corp., 2002,2008 5 * Author(s): Steve French (sfrench@us.ibm.com) 6 * 7 */ 8#ifndef _CIFSPROTO_H 9#define _CIFSPROTO_H 10#include <linux/nls.h> 11#include <linux/ctype.h> 12#include "cifsglob.h" 13#include "trace.h" 14#ifdef CONFIG_CIFS_DFS_UPCALL 15#include "dfs_cache.h" 16#endif 17 18struct statfs; 19struct smb_rqst; 20struct smb3_fs_context; 21 22/* 23 ***************************************************************** 24 * All Prototypes 25 ***************************************************************** 26 */ 27 28extern struct smb_hdr *cifs_buf_get(void); 29extern void cifs_buf_release(void *); 30extern struct smb_hdr *cifs_small_buf_get(void); 31extern void cifs_small_buf_release(void *); 32extern void free_rsp_buf(int, void *); 33extern int smb_send_kvec(struct TCP_Server_Info *server, 34 struct msghdr *msg, 35 size_t *sent); 36extern unsigned int _get_xid(void); 37extern void _free_xid(unsigned int); 38#define get_xid() \ 39({ \ 40 unsigned int __xid = _get_xid(); \ 41 cifs_dbg(FYI, "VFS: in %s as Xid: %u with uid: %d\n", \ 42 __func__, __xid, \ 43 from_kuid(&init_user_ns, current_fsuid())); \ 44 trace_smb3_enter(__xid, __func__); \ 45 __xid; \ 46}) 47 48#define free_xid(curr_xid) \ 49do { \ 50 _free_xid(curr_xid); \ 51 cifs_dbg(FYI, "VFS: leaving %s (xid = %u) rc = %d\n", \ 52 __func__, curr_xid, (int)rc); \ 53 if (rc) \ 54 trace_smb3_exit_err(curr_xid, __func__, (int)rc); \ 55 else \ 56 trace_smb3_exit_done(curr_xid, __func__); \ 57} while (0) 58extern int init_cifs_idmap(void); 59extern void exit_cifs_idmap(void); 60extern int init_cifs_spnego(void); 61extern void exit_cifs_spnego(void); 62extern const char *build_path_from_dentry(struct dentry *, void *); 63char *__build_path_from_dentry_optional_prefix(struct dentry *direntry, void *page, 64 const char *tree, int tree_len, 65 bool prefix); 66extern char *build_path_from_dentry_optional_prefix(struct dentry *direntry, 67 void *page, bool prefix); 68static inline void *alloc_dentry_path(void) 69{ 70 return __getname(); 71} 72 73static inline void free_dentry_path(void *page) 74{ 75 if (page) 76 __putname(page); 77} 78 79extern char *cifs_build_path_to_root(struct smb3_fs_context *ctx, 80 struct cifs_sb_info *cifs_sb, 81 struct cifs_tcon *tcon, 82 int add_treename); 83char *cifs_build_devname(char *nodename, const char *prepath); 84void delete_mid(struct TCP_Server_Info *server, struct mid_q_entry *mid); 85void __release_mid(struct TCP_Server_Info *server, struct mid_q_entry *mid); 86void cifs_wake_up_task(struct TCP_Server_Info *server, struct mid_q_entry *mid); 87extern int cifs_handle_standard(struct TCP_Server_Info *server, 88 struct mid_q_entry *mid); 89extern char *smb3_fs_context_fullpath(const struct smb3_fs_context *ctx, 90 char dirsep); 91extern int smb3_parse_devname(const char *devname, struct smb3_fs_context *ctx); 92extern int smb3_parse_opt(const char *options, const char *key, char **val); 93extern int cifs_ipaddr_cmp(struct sockaddr *srcaddr, struct sockaddr *rhs); 94extern bool cifs_match_ipaddr(struct sockaddr *srcaddr, struct sockaddr *rhs); 95extern int cifs_discard_remaining_data(struct TCP_Server_Info *server); 96extern int cifs_call_async(struct TCP_Server_Info *server, 97 struct smb_rqst *rqst, 98 mid_receive_t receive, mid_callback_t callback, 99 mid_handle_t handle, void *cbdata, const int flags, 100 const struct cifs_credits *exist_credits); 101extern struct TCP_Server_Info *cifs_pick_channel(struct cifs_ses *ses); 102extern int cifs_send_recv(const unsigned int xid, struct cifs_ses *ses, 103 struct TCP_Server_Info *server, 104 struct smb_rqst *rqst, int *resp_buf_type, 105 const int flags, struct kvec *resp_iov); 106extern int compound_send_recv(const unsigned int xid, struct cifs_ses *ses, 107 struct TCP_Server_Info *server, 108 const int flags, const int num_rqst, 109 struct smb_rqst *rqst, int *resp_buf_type, 110 struct kvec *resp_iov); 111int SendReceive(const unsigned int xid, struct cifs_ses *ses, 112 struct smb_hdr *in_buf, unsigned int in_len, 113 struct smb_hdr *out_buf, int *pbytes_returned, const int flags); 114int SendReceiveNoRsp(const unsigned int xid, struct cifs_ses *ses, 115 char *in_buf, unsigned int in_len, int flags); 116int cifs_sync_mid_result(struct mid_q_entry *mid, struct TCP_Server_Info *server); 117struct mid_q_entry *cifs_setup_request(struct cifs_ses *ses, struct TCP_Server_Info *ignored, 118 struct smb_rqst *rqst); 119struct mid_q_entry *cifs_setup_async_request(struct TCP_Server_Info *server, 120 struct smb_rqst *rqst); 121int __smb_send_rqst(struct TCP_Server_Info *server, int num_rqst, 122 struct smb_rqst *rqst); 123extern int cifs_check_receive(struct mid_q_entry *mid, 124 struct TCP_Server_Info *server, bool log_error); 125int wait_for_free_request(struct TCP_Server_Info *server, const int flags, 126 unsigned int *instance); 127extern int cifs_wait_mtu_credits(struct TCP_Server_Info *server, 128 size_t size, size_t *num, 129 struct cifs_credits *credits); 130 131static inline int 132send_cancel(struct cifs_ses *ses, struct TCP_Server_Info *server, 133 struct smb_rqst *rqst, struct mid_q_entry *mid, 134 unsigned int xid) 135{ 136 return server->ops->send_cancel ? 137 server->ops->send_cancel(ses, server, rqst, mid, xid) : 0; 138} 139 140int wait_for_response(struct TCP_Server_Info *server, struct mid_q_entry *midQ); 141extern int SendReceive2(const unsigned int /* xid */ , struct cifs_ses *, 142 struct kvec *, int /* nvec to send */, 143 int * /* type of buf returned */, const int flags, 144 struct kvec * /* resp vec */); 145 146void smb2_query_server_interfaces(struct work_struct *work); 147void 148cifs_signal_cifsd_for_reconnect(struct TCP_Server_Info *server, 149 bool all_channels); 150void 151cifs_mark_tcp_ses_conns_for_reconnect(struct TCP_Server_Info *server, 152 bool mark_smb_session); 153extern int cifs_reconnect(struct TCP_Server_Info *server, 154 bool mark_smb_session); 155int checkSMB(char *buf, unsigned int pdu_len, unsigned int len, 156 struct TCP_Server_Info *srvr); 157extern bool is_valid_oplock_break(char *, struct TCP_Server_Info *); 158extern bool backup_cred(struct cifs_sb_info *); 159extern bool is_size_safe_to_change(struct cifsInodeInfo *cifsInode, __u64 eof, 160 bool from_readdir); 161void cifs_write_subrequest_terminated(struct cifs_io_subrequest *wdata, ssize_t result); 162extern struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *, int); 163extern int cifs_get_writable_file(struct cifsInodeInfo *cifs_inode, 164 int flags, 165 struct cifsFileInfo **ret_file); 166extern int cifs_get_writable_path(struct cifs_tcon *tcon, const char *name, 167 int flags, 168 struct cifsFileInfo **ret_file); 169extern struct cifsFileInfo *find_readable_file(struct cifsInodeInfo *, bool); 170extern int cifs_get_readable_path(struct cifs_tcon *tcon, const char *name, 171 struct cifsFileInfo **ret_file); 172extern int cifs_get_hardlink_path(struct cifs_tcon *tcon, struct inode *inode, 173 struct file *file); 174extern unsigned int smbCalcSize(void *buf); 175extern int decode_negTokenInit(unsigned char *security_blob, int length, 176 struct TCP_Server_Info *server); 177extern int cifs_convert_address(struct sockaddr *dst, const char *src, int len); 178extern void cifs_set_port(struct sockaddr *addr, const unsigned short int port); 179extern int map_smb_to_linux_error(char *buf, bool logErr); 180extern int map_and_check_smb_error(struct TCP_Server_Info *server, 181 struct mid_q_entry *mid, bool logErr); 182unsigned int header_assemble(struct smb_hdr *buffer, char smb_command, 183 const struct cifs_tcon *treeCon, int word_count 184 /* length of fixed section word count in two byte units */); 185extern int small_smb_init_no_tc(const int smb_cmd, const int wct, 186 struct cifs_ses *ses, 187 void **request_buf); 188extern int CIFS_SessSetup(const unsigned int xid, struct cifs_ses *ses, 189 struct TCP_Server_Info *server, 190 const struct nls_table *nls_cp); 191extern struct timespec64 cifs_NTtimeToUnix(__le64 utc_nanoseconds_since_1601); 192extern u64 cifs_UnixTimeToNT(struct timespec64); 193extern struct timespec64 cnvrtDosUnixTm(__le16 le_date, __le16 le_time, 194 int offset); 195extern void cifs_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock); 196extern int cifs_get_writer(struct cifsInodeInfo *cinode); 197extern void cifs_put_writer(struct cifsInodeInfo *cinode); 198extern void cifs_done_oplock_break(struct cifsInodeInfo *cinode); 199extern int cifs_unlock_range(struct cifsFileInfo *cfile, 200 struct file_lock *flock, const unsigned int xid); 201extern int cifs_push_mandatory_locks(struct cifsFileInfo *cfile); 202 203extern void cifs_down_write(struct rw_semaphore *sem); 204struct cifsFileInfo *cifs_new_fileinfo(struct cifs_fid *fid, struct file *file, 205 struct tcon_link *tlink, __u32 oplock, 206 const char *symlink_target); 207extern int cifs_posix_open(const char *full_path, struct inode **inode, 208 struct super_block *sb, int mode, 209 unsigned int f_flags, __u32 *oplock, __u16 *netfid, 210 unsigned int xid); 211void cifs_fill_uniqueid(struct super_block *sb, struct cifs_fattr *fattr); 212extern void cifs_unix_basic_to_fattr(struct cifs_fattr *fattr, 213 FILE_UNIX_BASIC_INFO *info, 214 struct cifs_sb_info *cifs_sb); 215extern void cifs_dir_info_to_fattr(struct cifs_fattr *, FILE_DIRECTORY_INFO *, 216 struct cifs_sb_info *); 217extern int cifs_fattr_to_inode(struct inode *inode, struct cifs_fattr *fattr, 218 bool from_readdir); 219extern struct inode *cifs_iget(struct super_block *sb, 220 struct cifs_fattr *fattr); 221 222int cifs_get_inode_info(struct inode **inode, const char *full_path, 223 struct cifs_open_info_data *data, struct super_block *sb, int xid, 224 const struct cifs_fid *fid); 225extern int smb311_posix_get_inode_info(struct inode **inode, 226 const char *full_path, 227 struct cifs_open_info_data *data, 228 struct super_block *sb, 229 const unsigned int xid); 230extern int cifs_get_inode_info_unix(struct inode **pinode, 231 const unsigned char *search_path, 232 struct super_block *sb, unsigned int xid); 233extern int cifs_set_file_info(struct inode *inode, struct iattr *attrs, 234 unsigned int xid, const char *full_path, __u32 dosattr); 235extern int cifs_rename_pending_delete(const char *full_path, 236 struct dentry *dentry, 237 const unsigned int xid); 238extern int sid_to_id(struct cifs_sb_info *cifs_sb, struct smb_sid *psid, 239 struct cifs_fattr *fattr, uint sidtype); 240extern int cifs_acl_to_fattr(struct cifs_sb_info *cifs_sb, 241 struct cifs_fattr *fattr, struct inode *inode, 242 bool get_mode_from_special_sid, 243 const char *path, const struct cifs_fid *pfid); 244extern int id_mode_to_cifs_acl(struct inode *inode, const char *path, __u64 *pnmode, 245 kuid_t uid, kgid_t gid); 246extern struct smb_ntsd *get_cifs_acl(struct cifs_sb_info *cifssmb, struct inode *ino, 247 const char *path, u32 *plen, u32 info); 248extern struct smb_ntsd *get_cifs_acl_by_fid(struct cifs_sb_info *cifssb, 249 const struct cifs_fid *pfid, u32 *plen, u32 info); 250extern struct posix_acl *cifs_get_acl(struct mnt_idmap *idmap, 251 struct dentry *dentry, int type); 252extern int cifs_set_acl(struct mnt_idmap *idmap, 253 struct dentry *dentry, struct posix_acl *acl, int type); 254extern int set_cifs_acl(struct smb_ntsd *pntsd, __u32 len, struct inode *ino, 255 const char *path, int flag); 256extern unsigned int setup_authusers_ACE(struct smb_ace *pace); 257extern unsigned int setup_special_mode_ACE(struct smb_ace *pace, 258 bool posix, 259 __u64 nmode); 260extern unsigned int setup_special_user_owner_ACE(struct smb_ace *pace); 261 262void dequeue_mid(struct TCP_Server_Info *server, struct mid_q_entry *mid, bool malformed); 263extern int cifs_read_from_socket(struct TCP_Server_Info *server, char *buf, 264 unsigned int to_read); 265extern ssize_t cifs_discard_from_socket(struct TCP_Server_Info *server, 266 size_t to_read); 267int cifs_read_iter_from_socket(struct TCP_Server_Info *server, 268 struct iov_iter *iter, 269 unsigned int to_read); 270extern int cifs_setup_cifs_sb(struct cifs_sb_info *cifs_sb); 271void cifs_mount_put_conns(struct cifs_mount_ctx *mnt_ctx); 272int cifs_mount_get_session(struct cifs_mount_ctx *mnt_ctx); 273int cifs_is_path_remote(struct cifs_mount_ctx *mnt_ctx); 274int cifs_mount_get_tcon(struct cifs_mount_ctx *mnt_ctx); 275extern int cifs_match_super(struct super_block *, void *); 276extern int cifs_mount(struct cifs_sb_info *cifs_sb, struct smb3_fs_context *ctx); 277extern void cifs_umount(struct cifs_sb_info *); 278extern void cifs_mark_open_files_invalid(struct cifs_tcon *tcon); 279extern void cifs_reopen_persistent_handles(struct cifs_tcon *tcon); 280 281extern bool cifs_find_lock_conflict(struct cifsFileInfo *cfile, __u64 offset, 282 __u64 length, __u8 type, __u16 flags, 283 struct cifsLockInfo **conf_lock, 284 int rw_check); 285extern void cifs_add_pending_open(struct cifs_fid *fid, 286 struct tcon_link *tlink, 287 struct cifs_pending_open *open); 288extern void cifs_add_pending_open_locked(struct cifs_fid *fid, 289 struct tcon_link *tlink, 290 struct cifs_pending_open *open); 291extern void cifs_del_pending_open(struct cifs_pending_open *open); 292 293extern bool cifs_is_deferred_close(struct cifsFileInfo *cfile, 294 struct cifs_deferred_close **dclose); 295 296extern void cifs_add_deferred_close(struct cifsFileInfo *cfile, 297 struct cifs_deferred_close *dclose); 298 299extern void cifs_del_deferred_close(struct cifsFileInfo *cfile); 300 301extern void cifs_close_deferred_file(struct cifsInodeInfo *cifs_inode); 302 303extern void cifs_close_all_deferred_files(struct cifs_tcon *cifs_tcon); 304 305void cifs_close_all_deferred_files_sb(struct cifs_sb_info *cifs_sb); 306void cifs_close_deferred_file_under_dentry(struct cifs_tcon *cifs_tcon, 307 struct dentry *dentry); 308 309extern void cifs_mark_open_handles_for_deleted_file(struct inode *inode, 310 const char *path); 311 312extern struct TCP_Server_Info * 313cifs_get_tcp_session(struct smb3_fs_context *ctx, 314 struct TCP_Server_Info *primary_server); 315extern void cifs_put_tcp_session(struct TCP_Server_Info *server, 316 int from_reconnect); 317extern void cifs_put_tcon(struct cifs_tcon *tcon, enum smb3_tcon_ref_trace trace); 318 319extern void cifs_release_automount_timer(void); 320 321void cifs_proc_init(void); 322void cifs_proc_clean(void); 323 324extern void cifs_move_llist(struct list_head *source, struct list_head *dest); 325extern void cifs_free_llist(struct list_head *llist); 326extern void cifs_del_lock_waiters(struct cifsLockInfo *lock); 327 328int cifs_tree_connect(const unsigned int xid, struct cifs_tcon *tcon); 329 330extern int cifs_negotiate_protocol(const unsigned int xid, 331 struct cifs_ses *ses, 332 struct TCP_Server_Info *server); 333extern int cifs_setup_session(const unsigned int xid, struct cifs_ses *ses, 334 struct TCP_Server_Info *server, 335 struct nls_table *nls_info); 336extern int cifs_enable_signing(struct TCP_Server_Info *server, bool mnt_sign_required); 337extern int CIFSSMBNegotiate(const unsigned int xid, 338 struct cifs_ses *ses, 339 struct TCP_Server_Info *server); 340 341extern int CIFSTCon(const unsigned int xid, struct cifs_ses *ses, 342 const char *tree, struct cifs_tcon *tcon, 343 const struct nls_table *); 344 345extern int CIFSFindFirst(const unsigned int xid, struct cifs_tcon *tcon, 346 const char *searchName, struct cifs_sb_info *cifs_sb, 347 __u16 *searchHandle, __u16 search_flags, 348 struct cifs_search_info *psrch_inf, 349 bool msearch); 350 351extern int CIFSFindNext(const unsigned int xid, struct cifs_tcon *tcon, 352 __u16 searchHandle, __u16 search_flags, 353 struct cifs_search_info *psrch_inf); 354 355extern int CIFSFindClose(const unsigned int xid, struct cifs_tcon *tcon, 356 const __u16 search_handle); 357 358extern int CIFSSMBQFileInfo(const unsigned int xid, struct cifs_tcon *tcon, 359 u16 netfid, FILE_ALL_INFO *pFindData); 360extern int CIFSSMBQPathInfo(const unsigned int xid, struct cifs_tcon *tcon, 361 const char *search_Name, FILE_ALL_INFO *data, 362 int legacy /* whether to use old info level */, 363 const struct nls_table *nls_codepage, int remap); 364extern int SMBQueryInformation(const unsigned int xid, struct cifs_tcon *tcon, 365 const char *search_name, FILE_ALL_INFO *data, 366 const struct nls_table *nls_codepage, int remap); 367 368extern int CIFSSMBUnixQFileInfo(const unsigned int xid, struct cifs_tcon *tcon, 369 u16 netfid, FILE_UNIX_BASIC_INFO *pFindData); 370extern int CIFSSMBUnixQPathInfo(const unsigned int xid, 371 struct cifs_tcon *tcon, 372 const unsigned char *searchName, 373 FILE_UNIX_BASIC_INFO *pFindData, 374 const struct nls_table *nls_codepage, int remap); 375 376extern int CIFSGetDFSRefer(const unsigned int xid, struct cifs_ses *ses, 377 const char *search_name, 378 struct dfs_info3_param **target_nodes, 379 unsigned int *num_of_nodes, 380 const struct nls_table *nls_codepage, int remap); 381 382extern int parse_dfs_referrals(struct get_dfs_referral_rsp *rsp, u32 rsp_size, 383 unsigned int *num_of_nodes, 384 struct dfs_info3_param **target_nodes, 385 const struct nls_table *nls_codepage, int remap, 386 const char *searchName, bool is_unicode); 387extern void reset_cifs_unix_caps(unsigned int xid, struct cifs_tcon *tcon, 388 struct cifs_sb_info *cifs_sb, 389 struct smb3_fs_context *ctx); 390extern int CIFSSMBQFSInfo(const unsigned int xid, struct cifs_tcon *tcon, 391 struct kstatfs *FSData); 392extern int SMBOldQFSInfo(const unsigned int xid, struct cifs_tcon *tcon, 393 struct kstatfs *FSData); 394extern int CIFSSMBSetFSUnixInfo(const unsigned int xid, struct cifs_tcon *tcon, 395 __u64 cap); 396 397extern int CIFSSMBQFSAttributeInfo(const unsigned int xid, 398 struct cifs_tcon *tcon); 399extern int CIFSSMBQFSDeviceInfo(const unsigned int xid, struct cifs_tcon *tcon); 400extern int CIFSSMBQFSUnixInfo(const unsigned int xid, struct cifs_tcon *tcon); 401extern int CIFSSMBQFSPosixInfo(const unsigned int xid, struct cifs_tcon *tcon, 402 struct kstatfs *FSData); 403 404extern int SMBSetInformation(const unsigned int xid, struct cifs_tcon *tcon, 405 const char *fileName, __le32 attributes, __le64 write_time, 406 const struct nls_table *nls_codepage, 407 struct cifs_sb_info *cifs_sb); 408extern int CIFSSMBSetPathInfo(const unsigned int xid, struct cifs_tcon *tcon, 409 const char *fileName, const FILE_BASIC_INFO *data, 410 const struct nls_table *nls_codepage, 411 struct cifs_sb_info *cifs_sb); 412extern int CIFSSMBSetFileInfo(const unsigned int xid, struct cifs_tcon *tcon, 413 const FILE_BASIC_INFO *data, __u16 fid, 414 __u32 pid_of_opener); 415extern int CIFSSMBSetFileDisposition(const unsigned int xid, 416 struct cifs_tcon *tcon, 417 bool delete_file, __u16 fid, 418 __u32 pid_of_opener); 419extern int CIFSSMBSetEOF(const unsigned int xid, struct cifs_tcon *tcon, 420 const char *file_name, __u64 size, 421 struct cifs_sb_info *cifs_sb, bool set_allocation, 422 struct dentry *dentry); 423extern int CIFSSMBSetFileSize(const unsigned int xid, struct cifs_tcon *tcon, 424 struct cifsFileInfo *cfile, __u64 size, 425 bool set_allocation); 426 427struct cifs_unix_set_info_args { 428 __u64 ctime; 429 __u64 atime; 430 __u64 mtime; 431 __u64 mode; 432 kuid_t uid; 433 kgid_t gid; 434 dev_t device; 435}; 436 437extern int CIFSSMBUnixSetFileInfo(const unsigned int xid, 438 struct cifs_tcon *tcon, 439 const struct cifs_unix_set_info_args *args, 440 u16 fid, u32 pid_of_opener); 441 442extern int CIFSSMBUnixSetPathInfo(const unsigned int xid, 443 struct cifs_tcon *tcon, const char *file_name, 444 const struct cifs_unix_set_info_args *args, 445 const struct nls_table *nls_codepage, 446 int remap); 447 448extern int CIFSSMBMkDir(const unsigned int xid, struct inode *inode, 449 umode_t mode, struct cifs_tcon *tcon, 450 const char *name, struct cifs_sb_info *cifs_sb); 451extern int CIFSSMBRmDir(const unsigned int xid, struct cifs_tcon *tcon, 452 const char *name, struct cifs_sb_info *cifs_sb); 453extern int CIFSPOSIXDelFile(const unsigned int xid, struct cifs_tcon *tcon, 454 const char *name, __u16 type, 455 const struct nls_table *nls_codepage, 456 int remap_special_chars); 457extern int CIFSSMBDelFile(const unsigned int xid, struct cifs_tcon *tcon, 458 const char *name, struct cifs_sb_info *cifs_sb, 459 struct dentry *dentry); 460int CIFSSMBRename(const unsigned int xid, struct cifs_tcon *tcon, 461 struct dentry *source_dentry, 462 const char *from_name, const char *to_name, 463 struct cifs_sb_info *cifs_sb); 464extern int CIFSSMBRenameOpenFile(const unsigned int xid, struct cifs_tcon *tcon, 465 int netfid, const char *target_name, 466 const struct nls_table *nls_codepage, 467 int remap_special_chars); 468int CIFSCreateHardLink(const unsigned int xid, 469 struct cifs_tcon *tcon, 470 struct dentry *source_dentry, 471 const char *from_name, const char *to_name, 472 struct cifs_sb_info *cifs_sb); 473extern int CIFSUnixCreateHardLink(const unsigned int xid, 474 struct cifs_tcon *tcon, 475 const char *fromName, const char *toName, 476 const struct nls_table *nls_codepage, 477 int remap_special_chars); 478extern int CIFSUnixCreateSymLink(const unsigned int xid, 479 struct cifs_tcon *tcon, 480 const char *fromName, const char *toName, 481 const struct nls_table *nls_codepage, int remap); 482extern int CIFSSMBUnixQuerySymLink(const unsigned int xid, 483 struct cifs_tcon *tcon, 484 const unsigned char *searchName, char **syminfo, 485 const struct nls_table *nls_codepage, int remap); 486extern int cifs_query_reparse_point(const unsigned int xid, 487 struct cifs_tcon *tcon, 488 struct cifs_sb_info *cifs_sb, 489 const char *full_path, 490 u32 *tag, struct kvec *rsp, 491 int *rsp_buftype); 492extern struct inode *cifs_create_reparse_inode(struct cifs_open_info_data *data, 493 struct super_block *sb, 494 const unsigned int xid, 495 struct cifs_tcon *tcon, 496 const char *full_path, 497 bool directory, 498 struct kvec *reparse_iov, 499 struct kvec *xattr_iov); 500extern int CIFSSMB_set_compression(const unsigned int xid, 501 struct cifs_tcon *tcon, __u16 fid); 502extern int CIFS_open(const unsigned int xid, struct cifs_open_parms *oparms, 503 int *oplock, FILE_ALL_INFO *buf); 504extern int SMBLegacyOpen(const unsigned int xid, struct cifs_tcon *tcon, 505 const char *fileName, const int disposition, 506 const int access_flags, const int omode, 507 __u16 *netfid, int *pOplock, FILE_ALL_INFO *, 508 const struct nls_table *nls_codepage, int remap); 509extern int CIFSPOSIXCreate(const unsigned int xid, struct cifs_tcon *tcon, 510 u32 posix_flags, __u64 mode, __u16 *netfid, 511 FILE_UNIX_BASIC_INFO *pRetData, 512 __u32 *pOplock, const char *name, 513 const struct nls_table *nls_codepage, int remap); 514extern int CIFSSMBClose(const unsigned int xid, struct cifs_tcon *tcon, 515 const int smb_file_id); 516 517extern int CIFSSMBFlush(const unsigned int xid, struct cifs_tcon *tcon, 518 const int smb_file_id); 519 520extern int CIFSSMBRead(const unsigned int xid, struct cifs_io_parms *io_parms, 521 unsigned int *nbytes, char **buf, 522 int *return_buf_type); 523extern int CIFSSMBWrite(const unsigned int xid, struct cifs_io_parms *io_parms, 524 unsigned int *nbytes, const char *buf); 525extern int CIFSSMBWrite2(const unsigned int xid, struct cifs_io_parms *io_parms, 526 unsigned int *nbytes, struct kvec *iov, const int nvec); 527extern int CIFSGetSrvInodeNumber(const unsigned int xid, struct cifs_tcon *tcon, 528 const char *search_name, __u64 *inode_number, 529 const struct nls_table *nls_codepage, 530 int remap); 531 532extern int cifs_lockv(const unsigned int xid, struct cifs_tcon *tcon, 533 const __u16 netfid, const __u8 lock_type, 534 const __u32 num_unlock, const __u32 num_lock, 535 LOCKING_ANDX_RANGE *buf); 536extern int CIFSSMBLock(const unsigned int xid, struct cifs_tcon *tcon, 537 const __u16 netfid, const __u32 netpid, const __u64 len, 538 const __u64 offset, const __u32 numUnlock, 539 const __u32 numLock, const __u8 lockType, 540 const bool waitFlag, const __u8 oplock_level); 541extern int CIFSSMBPosixLock(const unsigned int xid, struct cifs_tcon *tcon, 542 const __u16 smb_file_id, const __u32 netpid, 543 const loff_t start_offset, const __u64 len, 544 struct file_lock *, const __u16 lock_type, 545 const bool waitFlag); 546extern int CIFSSMBTDis(const unsigned int xid, struct cifs_tcon *tcon); 547extern int CIFSSMBEcho(struct TCP_Server_Info *server); 548extern int CIFSSMBLogoff(const unsigned int xid, struct cifs_ses *ses); 549 550extern struct cifs_ses *sesInfoAlloc(void); 551extern void sesInfoFree(struct cifs_ses *); 552extern struct cifs_tcon *tcon_info_alloc(bool dir_leases_enabled, 553 enum smb3_tcon_ref_trace trace); 554extern void tconInfoFree(struct cifs_tcon *tcon, enum smb3_tcon_ref_trace trace); 555 556extern int cifs_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server, 557 __u32 *pexpected_response_sequence_number); 558int cifs_verify_signature(struct smb_rqst *rqst, 559 struct TCP_Server_Info *server, 560 __u32 expected_sequence_number); 561extern int setup_ntlmv2_rsp(struct cifs_ses *, const struct nls_table *); 562extern void cifs_crypto_secmech_release(struct TCP_Server_Info *server); 563extern int calc_seckey(struct cifs_ses *); 564extern int generate_smb30signingkey(struct cifs_ses *ses, 565 struct TCP_Server_Info *server); 566extern int generate_smb311signingkey(struct cifs_ses *ses, 567 struct TCP_Server_Info *server); 568 569#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY 570extern ssize_t CIFSSMBQAllEAs(const unsigned int xid, struct cifs_tcon *tcon, 571 const unsigned char *searchName, 572 const unsigned char *ea_name, char *EAData, 573 size_t bufsize, struct cifs_sb_info *cifs_sb); 574extern int CIFSSMBSetEA(const unsigned int xid, struct cifs_tcon *tcon, 575 const char *fileName, const char *ea_name, 576 const void *ea_value, const __u16 ea_value_len, 577 const struct nls_table *nls_codepage, 578 struct cifs_sb_info *cifs_sb); 579extern int CIFSSMBGetCIFSACL(const unsigned int xid, struct cifs_tcon *tcon, 580 __u16 fid, struct smb_ntsd **acl_inf, __u32 *buflen, __u32 info); 581extern int CIFSSMBSetCIFSACL(const unsigned int, struct cifs_tcon *, __u16, 582 struct smb_ntsd *pntsd, __u32 len, int aclflag); 583extern int cifs_do_get_acl(const unsigned int xid, struct cifs_tcon *tcon, 584 const unsigned char *searchName, 585 struct posix_acl **acl, const int acl_type, 586 const struct nls_table *nls_codepage, int remap); 587extern int cifs_do_set_acl(const unsigned int xid, struct cifs_tcon *tcon, 588 const unsigned char *fileName, 589 const struct posix_acl *acl, const int acl_type, 590 const struct nls_table *nls_codepage, int remap); 591extern int CIFSGetExtAttr(const unsigned int xid, struct cifs_tcon *tcon, 592 const int netfid, __u64 *pExtAttrBits, __u64 *pMask); 593#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */ 594extern void cifs_autodisable_serverino(struct cifs_sb_info *cifs_sb); 595extern bool couldbe_mf_symlink(const struct cifs_fattr *fattr); 596extern int check_mf_symlink(unsigned int xid, struct cifs_tcon *tcon, 597 struct cifs_sb_info *cifs_sb, 598 struct cifs_fattr *fattr, 599 const unsigned char *path); 600extern int E_md4hash(const unsigned char *passwd, unsigned char *p16, 601 const struct nls_table *codepage); 602 603extern struct TCP_Server_Info * 604cifs_find_tcp_session(struct smb3_fs_context *ctx); 605 606struct cifs_tcon *cifs_setup_ipc(struct cifs_ses *ses, bool seal); 607 608void __cifs_put_smb_ses(struct cifs_ses *ses); 609 610extern struct cifs_ses * 611cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb3_fs_context *ctx); 612 613int cifs_async_readv(struct cifs_io_subrequest *rdata); 614int cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid); 615 616void cifs_async_writev(struct cifs_io_subrequest *wdata); 617int cifs_query_mf_symlink(unsigned int xid, struct cifs_tcon *tcon, 618 struct cifs_sb_info *cifs_sb, 619 const unsigned char *path, char *pbuf, 620 unsigned int *pbytes_read); 621int cifs_create_mf_symlink(unsigned int xid, struct cifs_tcon *tcon, 622 struct cifs_sb_info *cifs_sb, 623 const unsigned char *path, char *pbuf, 624 unsigned int *pbytes_written); 625int __cifs_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server, 626 char *signature, struct cifs_calc_sig_ctx *ctx); 627enum securityEnum cifs_select_sectype(struct TCP_Server_Info *, 628 enum securityEnum); 629 630int cifs_alloc_hash(const char *name, struct shash_desc **sdesc); 631void cifs_free_hash(struct shash_desc **sdesc); 632 633int cifs_try_adding_channels(struct cifs_ses *ses); 634int smb3_update_ses_channels(struct cifs_ses *ses, struct TCP_Server_Info *server, 635 bool from_reconnect, bool disable_mchan); 636bool is_ses_using_iface(struct cifs_ses *ses, struct cifs_server_iface *iface); 637 638int 639cifs_ses_get_chan_index(struct cifs_ses *ses, 640 struct TCP_Server_Info *server); 641void 642cifs_chan_set_in_reconnect(struct cifs_ses *ses, 643 struct TCP_Server_Info *server); 644void 645cifs_chan_clear_in_reconnect(struct cifs_ses *ses, 646 struct TCP_Server_Info *server); 647void 648cifs_chan_set_need_reconnect(struct cifs_ses *ses, 649 struct TCP_Server_Info *server); 650void 651cifs_chan_clear_need_reconnect(struct cifs_ses *ses, 652 struct TCP_Server_Info *server); 653bool 654cifs_chan_needs_reconnect(struct cifs_ses *ses, 655 struct TCP_Server_Info *server); 656bool 657cifs_chan_is_iface_active(struct cifs_ses *ses, 658 struct TCP_Server_Info *server); 659void 660cifs_decrease_secondary_channels(struct cifs_ses *ses, bool disable_mchan); 661void 662cifs_chan_update_iface(struct cifs_ses *ses, struct TCP_Server_Info *server); 663int 664SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon, bool in_mount); 665 666void extract_unc_hostname(const char *unc, const char **h, size_t *len); 667int copy_path_name(char *dst, const char *src); 668int smb2_parse_query_directory(struct cifs_tcon *tcon, struct kvec *rsp_iov, 669 int resp_buftype, 670 struct cifs_search_info *srch_inf); 671 672struct super_block *cifs_get_dfs_tcon_super(struct cifs_tcon *tcon); 673void cifs_put_tcp_super(struct super_block *sb); 674int cifs_update_super_prepath(struct cifs_sb_info *cifs_sb, char *prefix); 675char *extract_hostname(const char *unc); 676char *extract_sharename(const char *unc); 677int parse_reparse_point(struct reparse_data_buffer *buf, 678 u32 plen, struct cifs_sb_info *cifs_sb, 679 const char *full_path, 680 struct cifs_open_info_data *data); 681int __cifs_sfu_make_node(unsigned int xid, struct inode *inode, 682 struct dentry *dentry, struct cifs_tcon *tcon, 683 const char *full_path, umode_t mode, dev_t dev, 684 const char *symname); 685int cifs_sfu_make_node(unsigned int xid, struct inode *inode, 686 struct dentry *dentry, struct cifs_tcon *tcon, 687 const char *full_path, umode_t mode, dev_t dev); 688umode_t wire_mode_to_posix(u32 wire, bool is_dir); 689 690#ifdef CONFIG_CIFS_DFS_UPCALL 691static inline int get_dfs_path(const unsigned int xid, struct cifs_ses *ses, 692 const char *old_path, 693 const struct nls_table *nls_codepage, 694 struct dfs_info3_param *referral, int remap) 695{ 696 return dfs_cache_find(xid, ses, nls_codepage, remap, old_path, 697 referral, NULL); 698} 699 700int match_target_ip(struct TCP_Server_Info *server, 701 const char *host, size_t hostlen, 702 bool *result); 703int cifs_inval_name_dfs_link_error(const unsigned int xid, 704 struct cifs_tcon *tcon, 705 struct cifs_sb_info *cifs_sb, 706 const char *full_path, 707 bool *islink); 708#else 709static inline int cifs_inval_name_dfs_link_error(const unsigned int xid, 710 struct cifs_tcon *tcon, 711 struct cifs_sb_info *cifs_sb, 712 const char *full_path, 713 bool *islink) 714{ 715 *islink = false; 716 return 0; 717} 718#endif 719 720static inline int cifs_create_options(struct cifs_sb_info *cifs_sb, int options) 721{ 722 if (cifs_sb && (backup_cred(cifs_sb))) 723 return options | CREATE_OPEN_BACKUP_INTENT; 724 else 725 return options; 726} 727 728int cifs_wait_for_server_reconnect(struct TCP_Server_Info *server, bool retry); 729 730static inline void cifs_put_smb_ses(struct cifs_ses *ses) 731{ 732 __cifs_put_smb_ses(ses); 733} 734 735/* Get an active reference of @ses and its children. 736 * 737 * NOTE: make sure to call this function when incrementing reference count of 738 * @ses to ensure that any DFS root session attached to it (@ses->dfs_root_ses) 739 * will also get its reference count incremented. 740 * 741 * cifs_put_smb_ses() will put all references, so call it when you're done. 742 */ 743static inline void cifs_smb_ses_inc_refcount(struct cifs_ses *ses) 744{ 745 lockdep_assert_held(&cifs_tcp_ses_lock); 746 ses->ses_count++; 747} 748 749static inline bool dfs_src_pathname_equal(const char *s1, const char *s2) 750{ 751 if (strlen(s1) != strlen(s2)) 752 return false; 753 for (; *s1; s1++, s2++) { 754 if (*s1 == '/' || *s1 == '\\') { 755 if (*s2 != '/' && *s2 != '\\') 756 return false; 757 } else if (tolower(*s1) != tolower(*s2)) 758 return false; 759 } 760 return true; 761} 762 763static inline void smb_get_mid(struct mid_q_entry *mid) 764{ 765 refcount_inc(&mid->refcount); 766} 767 768static inline void release_mid(struct TCP_Server_Info *server, struct mid_q_entry *mid) 769{ 770 if (refcount_dec_and_test(&mid->refcount)) 771 __release_mid(server, mid); 772} 773 774static inline void cifs_free_open_info(struct cifs_open_info_data *data) 775{ 776 kfree(data->symlink_target); 777 free_rsp_buf(data->reparse.io.buftype, data->reparse.io.iov.iov_base); 778 memset(data, 0, sizeof(*data)); 779} 780 781static inline int smb_EIO(enum smb_eio_trace trace) 782{ 783 trace_smb3_eio(trace, 0, 0); 784 return -EIO; 785} 786 787static inline int smb_EIO1(enum smb_eio_trace trace, unsigned long info) 788{ 789 trace_smb3_eio(trace, info, 0); 790 return -EIO; 791} 792 793static inline int smb_EIO2(enum smb_eio_trace trace, unsigned long info, unsigned long info2) 794{ 795 trace_smb3_eio(trace, info, info2); 796 return -EIO; 797} 798 799static inline int cifs_get_num_sgs(const struct smb_rqst *rqst, 800 int num_rqst, 801 const u8 *sig) 802{ 803 unsigned int len, skip; 804 unsigned int nents = 0; 805 unsigned long addr; 806 size_t data_size; 807 int i, j; 808 809 /* 810 * The first rqst has a transform header where the first 20 bytes are 811 * not part of the encrypted blob. 812 */ 813 skip = 20; 814 815 /* Assumes the first rqst has a transform header as the first iov. 816 * I.e. 817 * rqst[0].rq_iov[0] is transform header 818 * rqst[0].rq_iov[1+] data to be encrypted/decrypted 819 * rqst[1+].rq_iov[0+] data to be encrypted/decrypted 820 */ 821 for (i = 0; i < num_rqst; i++) { 822 data_size = iov_iter_count(&rqst[i].rq_iter); 823 824 /* We really don't want a mixture of pinned and unpinned pages 825 * in the sglist. It's hard to keep track of which is what. 826 * Instead, we convert to a BVEC-type iterator higher up. 827 */ 828 if (data_size && 829 WARN_ON_ONCE(user_backed_iter(&rqst[i].rq_iter))) 830 return smb_EIO(smb_eio_trace_user_iter); 831 832 /* We also don't want to have any extra refs or pins to clean 833 * up in the sglist. 834 */ 835 if (data_size && 836 WARN_ON_ONCE(iov_iter_extract_will_pin(&rqst[i].rq_iter))) 837 return smb_EIO(smb_eio_trace_extract_will_pin); 838 839 for (j = 0; j < rqst[i].rq_nvec; j++) { 840 struct kvec *iov = &rqst[i].rq_iov[j]; 841 842 addr = (unsigned long)iov->iov_base + skip; 843 if (is_vmalloc_or_module_addr((void *)addr)) { 844 len = iov->iov_len - skip; 845 nents += DIV_ROUND_UP(offset_in_page(addr) + len, 846 PAGE_SIZE); 847 } else { 848 nents++; 849 } 850 skip = 0; 851 } 852 if (data_size) 853 nents += iov_iter_npages(&rqst[i].rq_iter, INT_MAX); 854 } 855 nents += DIV_ROUND_UP(offset_in_page(sig) + SMB2_SIGNATURE_SIZE, PAGE_SIZE); 856 return nents; 857} 858 859/* We can not use the normal sg_set_buf() as we will sometimes pass a 860 * stack object as buf. 861 */ 862static inline void cifs_sg_set_buf(struct sg_table *sgtable, 863 const void *buf, 864 unsigned int buflen) 865{ 866 unsigned long addr = (unsigned long)buf; 867 unsigned int off = offset_in_page(addr); 868 869 addr &= PAGE_MASK; 870 if (is_vmalloc_or_module_addr((void *)addr)) { 871 do { 872 unsigned int len = min_t(unsigned int, buflen, PAGE_SIZE - off); 873 874 sg_set_page(&sgtable->sgl[sgtable->nents++], 875 vmalloc_to_page((void *)addr), len, off); 876 877 off = 0; 878 addr += PAGE_SIZE; 879 buflen -= len; 880 } while (buflen); 881 } else { 882 sg_set_page(&sgtable->sgl[sgtable->nents++], 883 virt_to_page((void *)addr), buflen, off); 884 } 885} 886 887#endif /* _CIFSPROTO_H */
~/
Read-only file preview.