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