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 "trace.h" 13 #ifdef CONFIG_CIFS_DFS_UPCALL 14 #include "dfs_cache.h" 15 #endif 16 17 struct statfs; 18 struct smb_rqst; 19 struct smb3_fs_context; 20 21 /* 22 ***************************************************************** 23 * All Prototypes 24 ***************************************************************** 25 */ 26 27 extern struct smb_hdr *cifs_buf_get(void); 28 extern void cifs_buf_release(void *); 29 extern struct smb_hdr *cifs_small_buf_get(void); 30 extern void cifs_small_buf_release(void *); 31 extern void free_rsp_buf(int, void *); 32 extern int smb_send(struct TCP_Server_Info *, struct smb_hdr *, 33 unsigned int /* length */); 34 extern unsigned int _get_xid(void); 35 extern void _free_xid(unsigned int); 36 #define get_xid() \ 37 ({ \ 38 unsigned int __xid = _get_xid(); \ 39 cifs_dbg(FYI, "VFS: in %s as Xid: %u with uid: %d\n", \ 40 __func__, __xid, \ 41 from_kuid(&init_user_ns, current_fsuid())); \ 42 trace_smb3_enter(__xid, __func__); \ 43 __xid; \ 44 }) 45 46 #define free_xid(curr_xid) \ 47 do { \ 48 _free_xid(curr_xid); \ 49 cifs_dbg(FYI, "VFS: leaving %s (xid = %u) rc = %d\n", \ 50 __func__, curr_xid, (int)rc); \ 51 if (rc) \ 52 trace_smb3_exit_err(curr_xid, __func__, (int)rc); \ 53 else \ 54 trace_smb3_exit_done(curr_xid, __func__); \ 55 } while (0) 56 extern int init_cifs_idmap(void); 57 extern void exit_cifs_idmap(void); 58 extern int init_cifs_spnego(void); 59 extern void exit_cifs_spnego(void); 60 extern const char *build_path_from_dentry(struct dentry *, void *); 61 char *__build_path_from_dentry_optional_prefix(struct dentry *direntry, void *page, 62 const char *tree, int tree_len, 63 bool prefix); 64 extern char *build_path_from_dentry_optional_prefix(struct dentry *direntry, 65 void *page, bool prefix); 66 static inline void *alloc_dentry_path(void) 67 { 68 return __getname(); 69 } 70 71 static inline void free_dentry_path(void *page) 72 { 73 if (page) 74 __putname(page); 75 } 76 77 extern char *cifs_build_path_to_root(struct smb3_fs_context *ctx, 78 struct cifs_sb_info *cifs_sb, 79 struct cifs_tcon *tcon, 80 int add_treename); 81 extern char *build_wildcard_path_from_dentry(struct dentry *direntry); 82 char *cifs_build_devname(char *nodename, const char *prepath); 83 extern void delete_mid(struct mid_q_entry *mid); 84 extern void release_mid(struct mid_q_entry *mid); 85 extern void cifs_wake_up_task(struct mid_q_entry *mid); 86 extern int cifs_handle_standard(struct TCP_Server_Info *server, 87 struct mid_q_entry *mid); 88 extern int smb3_parse_devname(const char *devname, struct smb3_fs_context *ctx); 89 extern int smb3_parse_opt(const char *options, const char *key, char **val); 90 extern bool cifs_match_ipaddr(struct sockaddr *srcaddr, struct sockaddr *rhs); 91 extern int cifs_discard_remaining_data(struct TCP_Server_Info *server); 92 extern int cifs_call_async(struct TCP_Server_Info *server, 93 struct smb_rqst *rqst, 94 mid_receive_t *receive, mid_callback_t *callback, 95 mid_handle_t *handle, void *cbdata, const int flags, 96 const struct cifs_credits *exist_credits); 97 extern struct TCP_Server_Info *cifs_pick_channel(struct cifs_ses *ses); 98 extern int cifs_send_recv(const unsigned int xid, struct cifs_ses *ses, 99 struct TCP_Server_Info *server, 100 struct smb_rqst *rqst, int *resp_buf_type, 101 const int flags, struct kvec *resp_iov); 102 extern int compound_send_recv(const unsigned int xid, struct cifs_ses *ses, 103 struct TCP_Server_Info *server, 104 const int flags, const int num_rqst, 105 struct smb_rqst *rqst, int *resp_buf_type, 106 struct kvec *resp_iov); 107 extern int SendReceive(const unsigned int /* xid */ , struct cifs_ses *, 108 struct smb_hdr * /* input */ , 109 struct smb_hdr * /* out */ , 110 int * /* bytes returned */ , const int); 111 extern int SendReceiveNoRsp(const unsigned int xid, struct cifs_ses *ses, 112 char *in_buf, int flags); 113 extern struct mid_q_entry *cifs_setup_request(struct cifs_ses *, 114 struct TCP_Server_Info *, 115 struct smb_rqst *); 116 extern struct mid_q_entry *cifs_setup_async_request(struct TCP_Server_Info *, 117 struct smb_rqst *); 118 extern int cifs_check_receive(struct mid_q_entry *mid, 119 struct TCP_Server_Info *server, bool log_error); 120 extern int cifs_wait_mtu_credits(struct TCP_Server_Info *server, 121 unsigned int size, unsigned int *num, 122 struct cifs_credits *credits); 123 extern int SendReceive2(const unsigned int /* xid */ , struct cifs_ses *, 124 struct kvec *, int /* nvec to send */, 125 int * /* type of buf returned */, const int flags, 126 struct kvec * /* resp vec */); 127 extern int SendReceiveBlockingLock(const unsigned int xid, 128 struct cifs_tcon *ptcon, 129 struct smb_hdr *in_buf, 130 struct smb_hdr *out_buf, 131 int *bytes_returned); 132 void 133 cifs_signal_cifsd_for_reconnect(struct TCP_Server_Info *server, 134 bool all_channels); 135 void 136 cifs_mark_tcp_ses_conns_for_reconnect(struct TCP_Server_Info *server, 137 bool mark_smb_session); 138 extern int cifs_reconnect(struct TCP_Server_Info *server, 139 bool mark_smb_session); 140 extern int checkSMB(char *buf, unsigned int len, struct TCP_Server_Info *srvr); 141 extern bool is_valid_oplock_break(char *, struct TCP_Server_Info *); 142 extern bool backup_cred(struct cifs_sb_info *); 143 extern bool is_size_safe_to_change(struct cifsInodeInfo *, __u64 eof); 144 extern void cifs_update_eof(struct cifsInodeInfo *cifsi, loff_t offset, 145 unsigned int bytes_written); 146 extern struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *, int); 147 extern int cifs_get_writable_file(struct cifsInodeInfo *cifs_inode, 148 int flags, 149 struct cifsFileInfo **ret_file); 150 extern int cifs_get_writable_path(struct cifs_tcon *tcon, const char *name, 151 int flags, 152 struct cifsFileInfo **ret_file); 153 extern struct cifsFileInfo *find_readable_file(struct cifsInodeInfo *, bool); 154 extern int cifs_get_readable_path(struct cifs_tcon *tcon, const char *name, 155 struct cifsFileInfo **ret_file); 156 extern unsigned int smbCalcSize(void *buf); 157 extern int decode_negTokenInit(unsigned char *security_blob, int length, 158 struct TCP_Server_Info *server); 159 extern int cifs_convert_address(struct sockaddr *dst, const char *src, int len); 160 extern void cifs_set_port(struct sockaddr *addr, const unsigned short int port); 161 extern int map_smb_to_linux_error(char *buf, bool logErr); 162 extern int map_and_check_smb_error(struct mid_q_entry *mid, bool logErr); 163 extern void header_assemble(struct smb_hdr *, char /* command */ , 164 const struct cifs_tcon *, int /* length of 165 fixed section (word count) in two byte units */); 166 extern int small_smb_init_no_tc(const int smb_cmd, const int wct, 167 struct cifs_ses *ses, 168 void **request_buf); 169 extern enum securityEnum select_sectype(struct TCP_Server_Info *server, 170 enum securityEnum requested); 171 extern int CIFS_SessSetup(const unsigned int xid, struct cifs_ses *ses, 172 struct TCP_Server_Info *server, 173 const struct nls_table *nls_cp); 174 extern struct timespec64 cifs_NTtimeToUnix(__le64 utc_nanoseconds_since_1601); 175 extern u64 cifs_UnixTimeToNT(struct timespec64); 176 extern struct timespec64 cnvrtDosUnixTm(__le16 le_date, __le16 le_time, 177 int offset); 178 extern void cifs_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock); 179 extern int cifs_get_writer(struct cifsInodeInfo *cinode); 180 extern void cifs_put_writer(struct cifsInodeInfo *cinode); 181 extern void cifs_done_oplock_break(struct cifsInodeInfo *cinode); 182 extern int cifs_unlock_range(struct cifsFileInfo *cfile, 183 struct file_lock *flock, const unsigned int xid); 184 extern int cifs_push_mandatory_locks(struct cifsFileInfo *cfile); 185 186 extern void cifs_down_write(struct rw_semaphore *sem); 187 struct cifsFileInfo *cifs_new_fileinfo(struct cifs_fid *fid, struct file *file, 188 struct tcon_link *tlink, __u32 oplock, 189 const char *symlink_target); 190 extern int cifs_posix_open(const char *full_path, struct inode **inode, 191 struct super_block *sb, int mode, 192 unsigned int f_flags, __u32 *oplock, __u16 *netfid, 193 unsigned int xid); 194 void cifs_fill_uniqueid(struct super_block *sb, struct cifs_fattr *fattr); 195 extern void cifs_unix_basic_to_fattr(struct cifs_fattr *fattr, 196 FILE_UNIX_BASIC_INFO *info, 197 struct cifs_sb_info *cifs_sb); 198 extern void cifs_dir_info_to_fattr(struct cifs_fattr *, FILE_DIRECTORY_INFO *, 199 struct cifs_sb_info *); 200 extern int cifs_fattr_to_inode(struct inode *inode, struct cifs_fattr *fattr); 201 extern struct inode *cifs_iget(struct super_block *sb, 202 struct cifs_fattr *fattr); 203 204 int cifs_get_inode_info(struct inode **inode, const char *full_path, 205 struct cifs_open_info_data *data, struct super_block *sb, int xid, 206 const struct cifs_fid *fid); 207 extern int smb311_posix_get_inode_info(struct inode **pinode, const char *search_path, 208 struct super_block *sb, unsigned int xid); 209 extern int cifs_get_inode_info_unix(struct inode **pinode, 210 const unsigned char *search_path, 211 struct super_block *sb, unsigned int xid); 212 extern int cifs_set_file_info(struct inode *inode, struct iattr *attrs, 213 unsigned int xid, const char *full_path, __u32 dosattr); 214 extern int cifs_rename_pending_delete(const char *full_path, 215 struct dentry *dentry, 216 const unsigned int xid); 217 extern int sid_to_id(struct cifs_sb_info *cifs_sb, struct cifs_sid *psid, 218 struct cifs_fattr *fattr, uint sidtype); 219 extern int cifs_acl_to_fattr(struct cifs_sb_info *cifs_sb, 220 struct cifs_fattr *fattr, struct inode *inode, 221 bool get_mode_from_special_sid, 222 const char *path, const struct cifs_fid *pfid); 223 extern int id_mode_to_cifs_acl(struct inode *inode, const char *path, __u64 *pnmode, 224 kuid_t uid, kgid_t gid); 225 extern struct cifs_ntsd *get_cifs_acl(struct cifs_sb_info *, struct inode *, 226 const char *, u32 *, u32); 227 extern struct cifs_ntsd *get_cifs_acl_by_fid(struct cifs_sb_info *, 228 const struct cifs_fid *, u32 *, u32); 229 extern struct posix_acl *cifs_get_acl(struct mnt_idmap *idmap, 230 struct dentry *dentry, int type); 231 extern int cifs_set_acl(struct mnt_idmap *idmap, 232 struct dentry *dentry, struct posix_acl *acl, int type); 233 extern int set_cifs_acl(struct cifs_ntsd *, __u32, struct inode *, 234 const char *, int); 235 extern unsigned int setup_authusers_ACE(struct cifs_ace *pace); 236 extern unsigned int setup_special_mode_ACE(struct cifs_ace *pace, __u64 nmode); 237 extern unsigned int setup_special_user_owner_ACE(struct cifs_ace *pace); 238 239 extern void dequeue_mid(struct mid_q_entry *mid, bool malformed); 240 extern int cifs_read_from_socket(struct TCP_Server_Info *server, char *buf, 241 unsigned int to_read); 242 extern ssize_t cifs_discard_from_socket(struct TCP_Server_Info *server, 243 size_t to_read); 244 extern int cifs_read_page_from_socket(struct TCP_Server_Info *server, 245 struct page *page, 246 unsigned int page_offset, 247 unsigned int to_read); 248 int cifs_read_iter_from_socket(struct TCP_Server_Info *server, 249 struct iov_iter *iter, 250 unsigned int to_read); 251 extern int cifs_setup_cifs_sb(struct cifs_sb_info *cifs_sb); 252 void cifs_mount_put_conns(struct cifs_mount_ctx *mnt_ctx); 253 int cifs_mount_get_session(struct cifs_mount_ctx *mnt_ctx); 254 int cifs_is_path_remote(struct cifs_mount_ctx *mnt_ctx); 255 int cifs_mount_get_tcon(struct cifs_mount_ctx *mnt_ctx); 256 extern int cifs_match_super(struct super_block *, void *); 257 extern int cifs_mount(struct cifs_sb_info *cifs_sb, struct smb3_fs_context *ctx); 258 extern void cifs_umount(struct cifs_sb_info *); 259 extern void cifs_mark_open_files_invalid(struct cifs_tcon *tcon); 260 extern void cifs_reopen_persistent_handles(struct cifs_tcon *tcon); 261 262 extern bool cifs_find_lock_conflict(struct cifsFileInfo *cfile, __u64 offset, 263 __u64 length, __u8 type, __u16 flags, 264 struct cifsLockInfo **conf_lock, 265 int rw_check); 266 extern void cifs_add_pending_open(struct cifs_fid *fid, 267 struct tcon_link *tlink, 268 struct cifs_pending_open *open); 269 extern void cifs_add_pending_open_locked(struct cifs_fid *fid, 270 struct tcon_link *tlink, 271 struct cifs_pending_open *open); 272 extern void cifs_del_pending_open(struct cifs_pending_open *open); 273 274 extern bool cifs_is_deferred_close(struct cifsFileInfo *cfile, 275 struct cifs_deferred_close **dclose); 276 277 extern void cifs_add_deferred_close(struct cifsFileInfo *cfile, 278 struct cifs_deferred_close *dclose); 279 280 extern void cifs_del_deferred_close(struct cifsFileInfo *cfile); 281 282 extern void cifs_close_deferred_file(struct cifsInodeInfo *cifs_inode); 283 284 extern void cifs_close_all_deferred_files(struct cifs_tcon *cifs_tcon); 285 286 extern void cifs_close_deferred_file_under_dentry(struct cifs_tcon *cifs_tcon, 287 const char *path); 288 extern struct TCP_Server_Info * 289 cifs_get_tcp_session(struct smb3_fs_context *ctx, 290 struct TCP_Server_Info *primary_server); 291 extern void cifs_put_tcp_session(struct TCP_Server_Info *server, 292 int from_reconnect); 293 extern void cifs_put_tcon(struct cifs_tcon *tcon); 294 295 #if IS_ENABLED(CONFIG_CIFS_DFS_UPCALL) 296 extern void cifs_dfs_release_automount_timer(void); 297 #else /* ! IS_ENABLED(CONFIG_CIFS_DFS_UPCALL) */ 298 #define cifs_dfs_release_automount_timer() do { } while (0) 299 #endif /* ! IS_ENABLED(CONFIG_CIFS_DFS_UPCALL) */ 300 301 void cifs_proc_init(void); 302 void cifs_proc_clean(void); 303 304 extern void cifs_move_llist(struct list_head *source, struct list_head *dest); 305 extern void cifs_free_llist(struct list_head *llist); 306 extern void cifs_del_lock_waiters(struct cifsLockInfo *lock); 307 308 extern int cifs_tree_connect(const unsigned int xid, struct cifs_tcon *tcon, 309 const struct nls_table *nlsc); 310 311 extern int cifs_negotiate_protocol(const unsigned int xid, 312 struct cifs_ses *ses, 313 struct TCP_Server_Info *server); 314 extern int cifs_setup_session(const unsigned int xid, struct cifs_ses *ses, 315 struct TCP_Server_Info *server, 316 struct nls_table *nls_info); 317 extern int cifs_enable_signing(struct TCP_Server_Info *server, bool mnt_sign_required); 318 extern int CIFSSMBNegotiate(const unsigned int xid, 319 struct cifs_ses *ses, 320 struct TCP_Server_Info *server); 321 322 extern int CIFSTCon(const unsigned int xid, struct cifs_ses *ses, 323 const char *tree, struct cifs_tcon *tcon, 324 const struct nls_table *); 325 326 extern int CIFSFindFirst(const unsigned int xid, struct cifs_tcon *tcon, 327 const char *searchName, struct cifs_sb_info *cifs_sb, 328 __u16 *searchHandle, __u16 search_flags, 329 struct cifs_search_info *psrch_inf, 330 bool msearch); 331 332 extern int CIFSFindNext(const unsigned int xid, struct cifs_tcon *tcon, 333 __u16 searchHandle, __u16 search_flags, 334 struct cifs_search_info *psrch_inf); 335 336 extern int CIFSFindClose(const unsigned int xid, struct cifs_tcon *tcon, 337 const __u16 search_handle); 338 339 extern int CIFSSMBQFileInfo(const unsigned int xid, struct cifs_tcon *tcon, 340 u16 netfid, FILE_ALL_INFO *pFindData); 341 extern int CIFSSMBQPathInfo(const unsigned int xid, struct cifs_tcon *tcon, 342 const char *search_Name, FILE_ALL_INFO *data, 343 int legacy /* whether to use old info level */, 344 const struct nls_table *nls_codepage, int remap); 345 extern int SMBQueryInformation(const unsigned int xid, struct cifs_tcon *tcon, 346 const char *search_name, FILE_ALL_INFO *data, 347 const struct nls_table *nls_codepage, int remap); 348 349 extern int CIFSSMBUnixQFileInfo(const unsigned int xid, struct cifs_tcon *tcon, 350 u16 netfid, FILE_UNIX_BASIC_INFO *pFindData); 351 extern int CIFSSMBUnixQPathInfo(const unsigned int xid, 352 struct cifs_tcon *tcon, 353 const unsigned char *searchName, 354 FILE_UNIX_BASIC_INFO *pFindData, 355 const struct nls_table *nls_codepage, int remap); 356 357 extern int CIFSGetDFSRefer(const unsigned int xid, struct cifs_ses *ses, 358 const char *search_name, 359 struct dfs_info3_param **target_nodes, 360 unsigned int *num_of_nodes, 361 const struct nls_table *nls_codepage, int remap); 362 363 extern int parse_dfs_referrals(struct get_dfs_referral_rsp *rsp, u32 rsp_size, 364 unsigned int *num_of_nodes, 365 struct dfs_info3_param **target_nodes, 366 const struct nls_table *nls_codepage, int remap, 367 const char *searchName, bool is_unicode); 368 extern void reset_cifs_unix_caps(unsigned int xid, struct cifs_tcon *tcon, 369 struct cifs_sb_info *cifs_sb, 370 struct smb3_fs_context *ctx); 371 extern int CIFSSMBQFSInfo(const unsigned int xid, struct cifs_tcon *tcon, 372 struct kstatfs *FSData); 373 extern int SMBOldQFSInfo(const unsigned int xid, struct cifs_tcon *tcon, 374 struct kstatfs *FSData); 375 extern int CIFSSMBSetFSUnixInfo(const unsigned int xid, struct cifs_tcon *tcon, 376 __u64 cap); 377 378 extern int CIFSSMBQFSAttributeInfo(const unsigned int xid, 379 struct cifs_tcon *tcon); 380 extern int CIFSSMBQFSDeviceInfo(const unsigned int xid, struct cifs_tcon *tcon); 381 extern int CIFSSMBQFSUnixInfo(const unsigned int xid, struct cifs_tcon *tcon); 382 extern int CIFSSMBQFSPosixInfo(const unsigned int xid, struct cifs_tcon *tcon, 383 struct kstatfs *FSData); 384 385 extern int CIFSSMBSetPathInfo(const unsigned int xid, struct cifs_tcon *tcon, 386 const char *fileName, const FILE_BASIC_INFO *data, 387 const struct nls_table *nls_codepage, 388 struct cifs_sb_info *cifs_sb); 389 extern int CIFSSMBSetFileInfo(const unsigned int xid, struct cifs_tcon *tcon, 390 const FILE_BASIC_INFO *data, __u16 fid, 391 __u32 pid_of_opener); 392 extern int CIFSSMBSetFileDisposition(const unsigned int xid, 393 struct cifs_tcon *tcon, 394 bool delete_file, __u16 fid, 395 __u32 pid_of_opener); 396 extern int CIFSSMBSetEOF(const unsigned int xid, struct cifs_tcon *tcon, 397 const char *file_name, __u64 size, 398 struct cifs_sb_info *cifs_sb, bool set_allocation); 399 extern int CIFSSMBSetFileSize(const unsigned int xid, struct cifs_tcon *tcon, 400 struct cifsFileInfo *cfile, __u64 size, 401 bool set_allocation); 402 403 struct cifs_unix_set_info_args { 404 __u64 ctime; 405 __u64 atime; 406 __u64 mtime; 407 __u64 mode; 408 kuid_t uid; 409 kgid_t gid; 410 dev_t device; 411 }; 412 413 extern int CIFSSMBUnixSetFileInfo(const unsigned int xid, 414 struct cifs_tcon *tcon, 415 const struct cifs_unix_set_info_args *args, 416 u16 fid, u32 pid_of_opener); 417 418 extern int CIFSSMBUnixSetPathInfo(const unsigned int xid, 419 struct cifs_tcon *tcon, const char *file_name, 420 const struct cifs_unix_set_info_args *args, 421 const struct nls_table *nls_codepage, 422 int remap); 423 424 extern int CIFSSMBMkDir(const unsigned int xid, struct inode *inode, 425 umode_t mode, struct cifs_tcon *tcon, 426 const char *name, struct cifs_sb_info *cifs_sb); 427 extern int CIFSSMBRmDir(const unsigned int xid, struct cifs_tcon *tcon, 428 const char *name, struct cifs_sb_info *cifs_sb); 429 extern int CIFSPOSIXDelFile(const unsigned int xid, struct cifs_tcon *tcon, 430 const char *name, __u16 type, 431 const struct nls_table *nls_codepage, 432 int remap_special_chars); 433 extern int CIFSSMBDelFile(const unsigned int xid, struct cifs_tcon *tcon, 434 const char *name, struct cifs_sb_info *cifs_sb); 435 extern int CIFSSMBRename(const unsigned int xid, struct cifs_tcon *tcon, 436 const char *from_name, const char *to_name, 437 struct cifs_sb_info *cifs_sb); 438 extern int CIFSSMBRenameOpenFile(const unsigned int xid, struct cifs_tcon *tcon, 439 int netfid, const char *target_name, 440 const struct nls_table *nls_codepage, 441 int remap_special_chars); 442 extern int CIFSCreateHardLink(const unsigned int xid, struct cifs_tcon *tcon, 443 const char *from_name, const char *to_name, 444 struct cifs_sb_info *cifs_sb); 445 extern int CIFSUnixCreateHardLink(const unsigned int xid, 446 struct cifs_tcon *tcon, 447 const char *fromName, const char *toName, 448 const struct nls_table *nls_codepage, 449 int remap_special_chars); 450 extern int CIFSUnixCreateSymLink(const unsigned int xid, 451 struct cifs_tcon *tcon, 452 const char *fromName, const char *toName, 453 const struct nls_table *nls_codepage, int remap); 454 extern int CIFSSMBUnixQuerySymLink(const unsigned int xid, 455 struct cifs_tcon *tcon, 456 const unsigned char *searchName, char **syminfo, 457 const struct nls_table *nls_codepage, int remap); 458 extern int CIFSSMBQuerySymLink(const unsigned int xid, struct cifs_tcon *tcon, 459 __u16 fid, char **symlinkinfo, 460 const struct nls_table *nls_codepage); 461 extern int CIFSSMB_set_compression(const unsigned int xid, 462 struct cifs_tcon *tcon, __u16 fid); 463 extern int CIFS_open(const unsigned int xid, struct cifs_open_parms *oparms, 464 int *oplock, FILE_ALL_INFO *buf); 465 extern int SMBLegacyOpen(const unsigned int xid, struct cifs_tcon *tcon, 466 const char *fileName, const int disposition, 467 const int access_flags, const int omode, 468 __u16 *netfid, int *pOplock, FILE_ALL_INFO *, 469 const struct nls_table *nls_codepage, int remap); 470 extern int CIFSPOSIXCreate(const unsigned int xid, struct cifs_tcon *tcon, 471 u32 posix_flags, __u64 mode, __u16 *netfid, 472 FILE_UNIX_BASIC_INFO *pRetData, 473 __u32 *pOplock, const char *name, 474 const struct nls_table *nls_codepage, int remap); 475 extern int CIFSSMBClose(const unsigned int xid, struct cifs_tcon *tcon, 476 const int smb_file_id); 477 478 extern int CIFSSMBFlush(const unsigned int xid, struct cifs_tcon *tcon, 479 const int smb_file_id); 480 481 extern int CIFSSMBRead(const unsigned int xid, struct cifs_io_parms *io_parms, 482 unsigned int *nbytes, char **buf, 483 int *return_buf_type); 484 extern int CIFSSMBWrite(const unsigned int xid, struct cifs_io_parms *io_parms, 485 unsigned int *nbytes, const char *buf); 486 extern int CIFSSMBWrite2(const unsigned int xid, struct cifs_io_parms *io_parms, 487 unsigned int *nbytes, struct kvec *iov, const int nvec); 488 extern int CIFSGetSrvInodeNumber(const unsigned int xid, struct cifs_tcon *tcon, 489 const char *search_name, __u64 *inode_number, 490 const struct nls_table *nls_codepage, 491 int remap); 492 493 extern int cifs_lockv(const unsigned int xid, struct cifs_tcon *tcon, 494 const __u16 netfid, const __u8 lock_type, 495 const __u32 num_unlock, const __u32 num_lock, 496 LOCKING_ANDX_RANGE *buf); 497 extern int CIFSSMBLock(const unsigned int xid, struct cifs_tcon *tcon, 498 const __u16 netfid, const __u32 netpid, const __u64 len, 499 const __u64 offset, const __u32 numUnlock, 500 const __u32 numLock, const __u8 lockType, 501 const bool waitFlag, const __u8 oplock_level); 502 extern int CIFSSMBPosixLock(const unsigned int xid, struct cifs_tcon *tcon, 503 const __u16 smb_file_id, const __u32 netpid, 504 const loff_t start_offset, const __u64 len, 505 struct file_lock *, const __u16 lock_type, 506 const bool waitFlag); 507 extern int CIFSSMBTDis(const unsigned int xid, struct cifs_tcon *tcon); 508 extern int CIFSSMBEcho(struct TCP_Server_Info *server); 509 extern int CIFSSMBLogoff(const unsigned int xid, struct cifs_ses *ses); 510 511 extern struct cifs_ses *sesInfoAlloc(void); 512 extern void sesInfoFree(struct cifs_ses *); 513 extern struct cifs_tcon *tconInfoAlloc(void); 514 extern void tconInfoFree(struct cifs_tcon *); 515 516 extern int cifs_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server, 517 __u32 *pexpected_response_sequence_number); 518 extern int cifs_sign_smbv(struct kvec *iov, int n_vec, struct TCP_Server_Info *, 519 __u32 *); 520 extern int cifs_sign_smb(struct smb_hdr *, struct TCP_Server_Info *, __u32 *); 521 extern int cifs_verify_signature(struct smb_rqst *rqst, 522 struct TCP_Server_Info *server, 523 __u32 expected_sequence_number); 524 extern int setup_ntlmv2_rsp(struct cifs_ses *, const struct nls_table *); 525 extern void cifs_crypto_secmech_release(struct TCP_Server_Info *server); 526 extern int calc_seckey(struct cifs_ses *); 527 extern int generate_smb30signingkey(struct cifs_ses *ses, 528 struct TCP_Server_Info *server); 529 extern int generate_smb311signingkey(struct cifs_ses *ses, 530 struct TCP_Server_Info *server); 531 532 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY 533 extern int CIFSSMBCopy(unsigned int xid, 534 struct cifs_tcon *source_tcon, 535 const char *fromName, 536 const __u16 target_tid, 537 const char *toName, const int flags, 538 const struct nls_table *nls_codepage, 539 int remap_special_chars); 540 extern ssize_t CIFSSMBQAllEAs(const unsigned int xid, struct cifs_tcon *tcon, 541 const unsigned char *searchName, 542 const unsigned char *ea_name, char *EAData, 543 size_t bufsize, struct cifs_sb_info *cifs_sb); 544 extern int CIFSSMBSetEA(const unsigned int xid, struct cifs_tcon *tcon, 545 const char *fileName, const char *ea_name, 546 const void *ea_value, const __u16 ea_value_len, 547 const struct nls_table *nls_codepage, 548 struct cifs_sb_info *cifs_sb); 549 extern int CIFSSMBGetCIFSACL(const unsigned int xid, struct cifs_tcon *tcon, 550 __u16 fid, struct cifs_ntsd **acl_inf, __u32 *buflen); 551 extern int CIFSSMBSetCIFSACL(const unsigned int, struct cifs_tcon *, __u16, 552 struct cifs_ntsd *, __u32, int); 553 extern int cifs_do_get_acl(const unsigned int xid, struct cifs_tcon *tcon, 554 const unsigned char *searchName, 555 struct posix_acl **acl, const int acl_type, 556 const struct nls_table *nls_codepage, int remap); 557 extern int cifs_do_set_acl(const unsigned int xid, struct cifs_tcon *tcon, 558 const unsigned char *fileName, 559 const struct posix_acl *acl, const int acl_type, 560 const struct nls_table *nls_codepage, int remap); 561 extern int CIFSGetExtAttr(const unsigned int xid, struct cifs_tcon *tcon, 562 const int netfid, __u64 *pExtAttrBits, __u64 *pMask); 563 #endif /* CIFS_ALLOW_INSECURE_LEGACY */ 564 extern void cifs_autodisable_serverino(struct cifs_sb_info *cifs_sb); 565 extern bool couldbe_mf_symlink(const struct cifs_fattr *fattr); 566 extern int check_mf_symlink(unsigned int xid, struct cifs_tcon *tcon, 567 struct cifs_sb_info *cifs_sb, 568 struct cifs_fattr *fattr, 569 const unsigned char *path); 570 extern int E_md4hash(const unsigned char *passwd, unsigned char *p16, 571 const struct nls_table *codepage); 572 573 extern struct TCP_Server_Info * 574 cifs_find_tcp_session(struct smb3_fs_context *ctx); 575 576 void __cifs_put_smb_ses(struct cifs_ses *ses); 577 578 extern struct cifs_ses * 579 cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb3_fs_context *ctx); 580 581 void cifs_readdata_release(struct kref *refcount); 582 int cifs_async_readv(struct cifs_readdata *rdata); 583 int cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid); 584 585 int cifs_async_writev(struct cifs_writedata *wdata, 586 void (*release)(struct kref *kref)); 587 void cifs_writev_complete(struct work_struct *work); 588 struct cifs_writedata *cifs_writedata_alloc(work_func_t complete); 589 void cifs_writedata_release(struct kref *refcount); 590 int cifs_query_mf_symlink(unsigned int xid, struct cifs_tcon *tcon, 591 struct cifs_sb_info *cifs_sb, 592 const unsigned char *path, char *pbuf, 593 unsigned int *pbytes_read); 594 int cifs_create_mf_symlink(unsigned int xid, struct cifs_tcon *tcon, 595 struct cifs_sb_info *cifs_sb, 596 const unsigned char *path, char *pbuf, 597 unsigned int *pbytes_written); 598 int __cifs_calc_signature(struct smb_rqst *rqst, 599 struct TCP_Server_Info *server, char *signature, 600 struct shash_desc *shash); 601 enum securityEnum cifs_select_sectype(struct TCP_Server_Info *, 602 enum securityEnum); 603 struct cifs_aio_ctx *cifs_aio_ctx_alloc(void); 604 void cifs_aio_ctx_release(struct kref *refcount); 605 606 int cifs_alloc_hash(const char *name, struct shash_desc **sdesc); 607 void cifs_free_hash(struct shash_desc **sdesc); 608 609 struct cifs_chan * 610 cifs_ses_find_chan(struct cifs_ses *ses, struct TCP_Server_Info *server); 611 int cifs_try_adding_channels(struct cifs_sb_info *cifs_sb, struct cifs_ses *ses); 612 bool is_server_using_iface(struct TCP_Server_Info *server, 613 struct cifs_server_iface *iface); 614 bool is_ses_using_iface(struct cifs_ses *ses, struct cifs_server_iface *iface); 615 void cifs_ses_mark_for_reconnect(struct cifs_ses *ses); 616 617 unsigned int 618 cifs_ses_get_chan_index(struct cifs_ses *ses, 619 struct TCP_Server_Info *server); 620 void 621 cifs_chan_set_in_reconnect(struct cifs_ses *ses, 622 struct TCP_Server_Info *server); 623 void 624 cifs_chan_clear_in_reconnect(struct cifs_ses *ses, 625 struct TCP_Server_Info *server); 626 bool 627 cifs_chan_in_reconnect(struct cifs_ses *ses, 628 struct TCP_Server_Info *server); 629 void 630 cifs_chan_set_need_reconnect(struct cifs_ses *ses, 631 struct TCP_Server_Info *server); 632 void 633 cifs_chan_clear_need_reconnect(struct cifs_ses *ses, 634 struct TCP_Server_Info *server); 635 bool 636 cifs_chan_needs_reconnect(struct cifs_ses *ses, 637 struct TCP_Server_Info *server); 638 bool 639 cifs_chan_is_iface_active(struct cifs_ses *ses, 640 struct TCP_Server_Info *server); 641 int 642 cifs_chan_update_iface(struct cifs_ses *ses, struct TCP_Server_Info *server); 643 int 644 SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon, bool in_mount); 645 646 void extract_unc_hostname(const char *unc, const char **h, size_t *len); 647 int copy_path_name(char *dst, const char *src); 648 int smb2_parse_query_directory(struct cifs_tcon *tcon, struct kvec *rsp_iov, 649 int resp_buftype, 650 struct cifs_search_info *srch_inf); 651 652 struct super_block *cifs_get_tcp_super(struct TCP_Server_Info *server); 653 void cifs_put_tcp_super(struct super_block *sb); 654 int cifs_update_super_prepath(struct cifs_sb_info *cifs_sb, char *prefix); 655 char *extract_hostname(const char *unc); 656 char *extract_sharename(const char *unc); 657 658 #ifdef CONFIG_CIFS_DFS_UPCALL 659 static inline int get_dfs_path(const unsigned int xid, struct cifs_ses *ses, 660 const char *old_path, 661 const struct nls_table *nls_codepage, 662 struct dfs_info3_param *referral, int remap) 663 { 664 return dfs_cache_find(xid, ses, nls_codepage, remap, old_path, 665 referral, NULL); 666 } 667 668 int match_target_ip(struct TCP_Server_Info *server, 669 const char *share, size_t share_len, 670 bool *result); 671 int cifs_inval_name_dfs_link_error(const unsigned int xid, 672 struct cifs_tcon *tcon, 673 struct cifs_sb_info *cifs_sb, 674 const char *full_path, 675 bool *islink); 676 #else 677 static inline int cifs_inval_name_dfs_link_error(const unsigned int xid, 678 struct cifs_tcon *tcon, 679 struct cifs_sb_info *cifs_sb, 680 const char *full_path, 681 bool *islink) 682 { 683 *islink = false; 684 return 0; 685 } 686 #endif 687 688 static inline int cifs_create_options(struct cifs_sb_info *cifs_sb, int options) 689 { 690 if (cifs_sb && (backup_cred(cifs_sb))) 691 return options | CREATE_OPEN_BACKUP_INTENT; 692 else 693 return options; 694 } 695 696 struct super_block *cifs_get_tcon_super(struct cifs_tcon *tcon); 697 void cifs_put_tcon_super(struct super_block *sb); 698 int cifs_wait_for_server_reconnect(struct TCP_Server_Info *server, bool retry); 699 700 /* Put references of @ses and @ses->dfs_root_ses */ 701 static inline void cifs_put_smb_ses(struct cifs_ses *ses) 702 { 703 struct cifs_ses *rses = ses->dfs_root_ses; 704 705 __cifs_put_smb_ses(ses); 706 if (rses) 707 __cifs_put_smb_ses(rses); 708 } 709 710 /* Get an active reference of @ses and @ses->dfs_root_ses. 711 * 712 * NOTE: make sure to call this function when incrementing reference count of 713 * @ses to ensure that any DFS root session attached to it (@ses->dfs_root_ses) 714 * will also get its reference count incremented. 715 * 716 * cifs_put_smb_ses() will put both references, so call it when you're done. 717 */ 718 static inline void cifs_smb_ses_inc_refcount(struct cifs_ses *ses) 719 { 720 lockdep_assert_held(&cifs_tcp_ses_lock); 721 722 ses->ses_count++; 723 if (ses->dfs_root_ses) 724 ses->dfs_root_ses->ses_count++; 725 } 726 727 static inline bool dfs_src_pathname_equal(const char *s1, const char *s2) 728 { 729 if (strlen(s1) != strlen(s2)) 730 return false; 731 for (; *s1; s1++, s2++) { 732 if (*s1 == '/' || *s1 == '\\') { 733 if (*s2 != '/' && *s2 != '\\') 734 return false; 735 } else if (tolower(*s1) != tolower(*s2)) 736 return false; 737 } 738 return true; 739 } 740 741 #endif /* _CIFSPROTO_H */ 742