cifsglob.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. /*
  2. * fs/cifs/cifsglob.h
  3. *
  4. * Copyright (C) International Business Machines Corp., 2002,2006
  5. * Author(s): Steve French (sfrench@us.ibm.com)
  6. *
  7. * This library is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published
  9. * by the Free Software Foundation; either version 2.1 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  15. * the GNU Lesser General Public License for more details.
  16. *
  17. */
  18. #include <linux/in.h>
  19. #include <linux/in6.h>
  20. #include "cifs_fs_sb.h"
  21. /*
  22. * The sizes of various internal tables and strings
  23. */
  24. #define MAX_UID_INFO 16
  25. #define MAX_SES_INFO 2
  26. #define MAX_TCON_INFO 4
  27. #define MAX_TREE_SIZE 2 + MAX_SERVER_SIZE + 1 + MAX_SHARE_SIZE + 1
  28. #define MAX_SERVER_SIZE 15
  29. #define MAX_SHARE_SIZE 64 /* used to be 20 - this should still be enough */
  30. #define MAX_USERNAME_SIZE 32 /* 32 is to allow for 15 char names + null
  31. termination then *2 for unicode versions */
  32. #define MAX_PASSWORD_SIZE 16
  33. #define CIFS_MIN_RCV_POOL 4
  34. /*
  35. * MAX_REQ is the maximum number of requests that WE will send
  36. * on one socket concurently. It also matches the most common
  37. * value of max multiplex returned by servers. We may
  38. * eventually want to use the negotiated value (in case
  39. * future servers can handle more) when we are more confident that
  40. * we will not have problems oveloading the socket with pending
  41. * write data.
  42. */
  43. #define CIFS_MAX_REQ 50
  44. #define SERVER_NAME_LENGTH 15
  45. #define SERVER_NAME_LEN_WITH_NULL (SERVER_NAME_LENGTH + 1)
  46. /* used to define string lengths for reversing unicode strings */
  47. /* (256+1)*2 = 514 */
  48. /* (max path length + 1 for null) * 2 for unicode */
  49. #define MAX_NAME 514
  50. #include "cifspdu.h"
  51. #ifndef FALSE
  52. #define FALSE 0
  53. #endif
  54. #ifndef TRUE
  55. #define TRUE 1
  56. #endif
  57. #ifndef XATTR_DOS_ATTRIB
  58. #define XATTR_DOS_ATTRIB "user.DOSATTRIB"
  59. #endif
  60. /*
  61. * This information is kept on every Server we know about.
  62. *
  63. * Some things to note:
  64. *
  65. */
  66. #define SERVER_NAME_LEN_WITH_NULL (SERVER_NAME_LENGTH + 1)
  67. /*
  68. * CIFS vfs client Status information (based on what we know.)
  69. */
  70. /* associated with each tcp and smb session */
  71. enum statusEnum {
  72. CifsNew = 0,
  73. CifsGood,
  74. CifsExiting,
  75. CifsNeedReconnect
  76. };
  77. enum securityEnum {
  78. NTLM = 0, /* Legacy NTLM012 auth with NTLM hash */
  79. NTLMv2, /* Legacy NTLM auth with NTLMv2 hash */
  80. RawNTLMSSP, /* NTLMSSP without SPNEGO */
  81. NTLMSSP, /* NTLMSSP via SPNEGO */
  82. Kerberos /* Kerberos via SPNEGO */
  83. };
  84. enum protocolEnum {
  85. IPV4 = 0,
  86. IPV6,
  87. SCTP
  88. /* Netbios frames protocol not supported at this time */
  89. };
  90. /*
  91. *****************************************************************
  92. * Except the CIFS PDUs themselves all the
  93. * globally interesting structs should go here
  94. *****************************************************************
  95. */
  96. struct TCP_Server_Info {
  97. /* 15 character server name + 0x20 16th byte indicating type = srv */
  98. char server_RFC1001_name[SERVER_NAME_LEN_WITH_NULL];
  99. char unicode_server_Name[SERVER_NAME_LEN_WITH_NULL * 2];
  100. struct socket *ssocket;
  101. union {
  102. struct sockaddr_in sockAddr;
  103. struct sockaddr_in6 sockAddr6;
  104. } addr;
  105. wait_queue_head_t response_q;
  106. wait_queue_head_t request_q; /* if more than maxmpx to srvr must block*/
  107. struct list_head pending_mid_q;
  108. void *Server_NlsInfo; /* BB - placeholder for future NLS info */
  109. unsigned short server_codepage; /* codepage for the server */
  110. unsigned long ip_address; /* IP addr for the server if known */
  111. enum protocolEnum protocolType;
  112. char versionMajor;
  113. char versionMinor;
  114. unsigned svlocal:1; /* local server or remote */
  115. atomic_t socketUseCount; /* number of open cifs sessions on socket */
  116. atomic_t inFlight; /* number of requests on the wire to server */
  117. #ifdef CONFIG_CIFS_STATS2
  118. atomic_t inSend; /* requests trying to send */
  119. atomic_t num_waiters; /* blocked waiting to get in sendrecv */
  120. #endif
  121. enum statusEnum tcpStatus; /* what we think the status is */
  122. struct semaphore tcpSem;
  123. struct task_struct *tsk;
  124. char server_GUID[16];
  125. char secMode;
  126. enum securityEnum secType;
  127. unsigned int maxReq; /* Clients should submit no more */
  128. /* than maxReq distinct unanswered SMBs to the server when using */
  129. /* multiplexed reads or writes */
  130. unsigned int maxBuf; /* maxBuf specifies the maximum */
  131. /* message size the server can send or receive for non-raw SMBs */
  132. unsigned int maxRw; /* maxRw specifies the maximum */
  133. /* message size the server can send or receive for */
  134. /* SMB_COM_WRITE_RAW or SMB_COM_READ_RAW. */
  135. char sessid[4]; /* unique token id for this session */
  136. /* (returned on Negotiate */
  137. int capabilities; /* allow selective disabling of caps by smb sess */
  138. __u16 timeZone;
  139. __u16 CurrentMid; /* multiplex id - rotating counter */
  140. char cryptKey[CIFS_CRYPTO_KEY_SIZE];
  141. /* 16th byte of RFC1001 workstation name is always null */
  142. char workstation_RFC1001_name[SERVER_NAME_LEN_WITH_NULL];
  143. __u32 sequence_number; /* needed for CIFS PDU signature */
  144. char mac_signing_key[CIFS_SESSION_KEY_SIZE + 16];
  145. };
  146. /*
  147. * The following is our shortcut to user information. We surface the uid,
  148. * and name. We always get the password on the fly in case it
  149. * has changed. We also hang a list of sessions owned by this user off here.
  150. */
  151. struct cifsUidInfo {
  152. struct list_head userList;
  153. struct list_head sessionList; /* SMB sessions for this user */
  154. uid_t linux_uid;
  155. char user[MAX_USERNAME_SIZE + 1]; /* ascii name of user */
  156. /* BB may need ptr or callback for PAM or WinBind info */
  157. };
  158. /*
  159. * Session structure. One of these for each uid session with a particular host
  160. */
  161. struct cifsSesInfo {
  162. struct list_head cifsSessionList;
  163. struct semaphore sesSem;
  164. struct cifsUidInfo *uidInfo; /* pointer to user info */
  165. struct TCP_Server_Info *server; /* pointer to server info */
  166. atomic_t inUse; /* # of mounts (tree connections) on this ses */
  167. enum statusEnum status;
  168. __u16 ipc_tid; /* special tid for connection to IPC share */
  169. __u16 flags;
  170. char *serverOS; /* name of operating system underlying server */
  171. char *serverNOS; /* name of network operating system of server */
  172. char *serverDomain; /* security realm of server */
  173. int Suid; /* remote smb uid */
  174. uid_t linux_uid; /* local Linux uid */
  175. int capabilities;
  176. char serverName[SERVER_NAME_LEN_WITH_NULL * 2]; /* BB make bigger for
  177. TCP names - will ipv6 and sctp addresses fit? */
  178. char userName[MAX_USERNAME_SIZE + 1];
  179. char domainName[MAX_USERNAME_SIZE + 1];
  180. char * password;
  181. };
  182. /* session flags */
  183. #define CIFS_SES_NT4 1
  184. /*
  185. * there is one of these for each connection to a resource on a particular
  186. * session
  187. */
  188. struct cifsTconInfo {
  189. struct list_head cifsConnectionList;
  190. struct list_head openFileList;
  191. struct semaphore tconSem;
  192. struct cifsSesInfo *ses; /* pointer to session associated with */
  193. char treeName[MAX_TREE_SIZE + 1]; /* UNC name of resource (in ASCII not UTF) */
  194. char *nativeFileSystem;
  195. __u16 tid; /* The 2 byte tree id */
  196. __u16 Flags; /* optional support bits */
  197. enum statusEnum tidStatus;
  198. atomic_t useCount; /* how many mounts (explicit or implicit) to this share */
  199. #ifdef CONFIG_CIFS_STATS
  200. atomic_t num_smbs_sent;
  201. atomic_t num_writes;
  202. atomic_t num_reads;
  203. atomic_t num_oplock_brks;
  204. atomic_t num_opens;
  205. atomic_t num_closes;
  206. atomic_t num_deletes;
  207. atomic_t num_mkdirs;
  208. atomic_t num_rmdirs;
  209. atomic_t num_renames;
  210. atomic_t num_t2renames;
  211. atomic_t num_ffirst;
  212. atomic_t num_fnext;
  213. atomic_t num_fclose;
  214. atomic_t num_hardlinks;
  215. atomic_t num_symlinks;
  216. atomic_t num_locks;
  217. atomic_t num_acl_get;
  218. atomic_t num_acl_set;
  219. #ifdef CONFIG_CIFS_STATS2
  220. unsigned long long time_writes;
  221. unsigned long long time_reads;
  222. unsigned long long time_opens;
  223. unsigned long long time_deletes;
  224. unsigned long long time_closes;
  225. unsigned long long time_mkdirs;
  226. unsigned long long time_rmdirs;
  227. unsigned long long time_renames;
  228. unsigned long long time_t2renames;
  229. unsigned long long time_ffirst;
  230. unsigned long long time_fnext;
  231. unsigned long long time_fclose;
  232. #endif /* CONFIG_CIFS_STATS2 */
  233. __u64 bytes_read;
  234. __u64 bytes_written;
  235. spinlock_t stat_lock;
  236. #endif /* CONFIG_CIFS_STATS */
  237. FILE_SYSTEM_DEVICE_INFO fsDevInfo;
  238. FILE_SYSTEM_ATTRIBUTE_INFO fsAttrInfo; /* ok if file system name truncated */
  239. FILE_SYSTEM_UNIX_INFO fsUnixInfo;
  240. unsigned retry:1;
  241. unsigned nocase:1;
  242. /* BB add field for back pointer to sb struct? */
  243. };
  244. /*
  245. * This info hangs off the cifsFileInfo structure. This is used to track
  246. * byte stream locks on the file
  247. */
  248. struct cifsLockInfo {
  249. struct cifsLockInfo *next;
  250. int start;
  251. int length;
  252. int type;
  253. };
  254. /*
  255. * One of these for each open instance of a file
  256. */
  257. struct cifs_search_info {
  258. loff_t index_of_last_entry;
  259. __u16 entries_in_buffer;
  260. __u16 info_level;
  261. __u32 resume_key;
  262. char * ntwrk_buf_start;
  263. char * srch_entries_start;
  264. char * presume_name;
  265. unsigned int resume_name_len;
  266. unsigned endOfSearch:1;
  267. unsigned emptyDir:1;
  268. unsigned unicode:1;
  269. unsigned smallBuf:1; /* so we know which buf_release function to call */
  270. };
  271. struct cifsFileInfo {
  272. struct list_head tlist; /* pointer to next fid owned by tcon */
  273. struct list_head flist; /* next fid (file instance) for this inode */
  274. unsigned int uid; /* allows finding which FileInfo structure */
  275. __u32 pid; /* process id who opened file */
  276. __u16 netfid; /* file id from remote */
  277. /* BB add lock scope info here if needed */ ;
  278. /* lock scope id (0 if none) */
  279. struct file * pfile; /* needed for writepage */
  280. struct inode * pInode; /* needed for oplock break */
  281. unsigned closePend:1; /* file is marked to close */
  282. unsigned invalidHandle:1; /* file closed via session abend */
  283. atomic_t wrtPending; /* handle in use - defer close */
  284. struct semaphore fh_sem; /* prevents reopen race after dead ses*/
  285. char * search_resume_name; /* BB removeme BB */
  286. unsigned int resume_name_length; /* BB removeme - field renamed and moved BB */
  287. struct cifs_search_info srch_inf;
  288. };
  289. /*
  290. * One of these for each file inode
  291. */
  292. struct cifsInodeInfo {
  293. struct list_head lockList;
  294. /* BB add in lists for dirty pages - i.e. write caching info for oplock */
  295. struct list_head openFileList;
  296. int write_behind_rc;
  297. __u32 cifsAttrs; /* e.g. DOS archive bit, sparse, compressed, system */
  298. atomic_t inUse; /* num concurrent users (local openers cifs) of file*/
  299. unsigned long time; /* jiffies of last update/check of inode */
  300. unsigned clientCanCacheRead:1; /* read oplock */
  301. unsigned clientCanCacheAll:1; /* read and writebehind oplock */
  302. unsigned oplockPending:1;
  303. struct inode vfs_inode;
  304. };
  305. static inline struct cifsInodeInfo *
  306. CIFS_I(struct inode *inode)
  307. {
  308. return container_of(inode, struct cifsInodeInfo, vfs_inode);
  309. }
  310. static inline struct cifs_sb_info *
  311. CIFS_SB(struct super_block *sb)
  312. {
  313. return sb->s_fs_info;
  314. }
  315. static inline char CIFS_DIR_SEP(const struct cifs_sb_info *cifs_sb)
  316. {
  317. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)
  318. return '/';
  319. else
  320. return '\\';
  321. }
  322. #ifdef CONFIG_CIFS_STATS
  323. #define cifs_stats_inc atomic_inc
  324. static inline void cifs_stats_bytes_written(struct cifsTconInfo *tcon,
  325. unsigned int bytes)
  326. {
  327. if (bytes) {
  328. spin_lock(&tcon->stat_lock);
  329. tcon->bytes_written += bytes;
  330. spin_unlock(&tcon->stat_lock);
  331. }
  332. }
  333. static inline void cifs_stats_bytes_read(struct cifsTconInfo *tcon,
  334. unsigned int bytes)
  335. {
  336. spin_lock(&tcon->stat_lock);
  337. tcon->bytes_read += bytes;
  338. spin_unlock(&tcon->stat_lock);
  339. }
  340. #else
  341. #define cifs_stats_inc(field) do {} while(0)
  342. #define cifs_stats_bytes_written(tcon, bytes) do {} while(0)
  343. #define cifs_stats_bytes_read(tcon, bytes) do {} while(0)
  344. #endif
  345. /* one of these for every pending CIFS request to the server */
  346. struct mid_q_entry {
  347. struct list_head qhead; /* mids waiting on reply from this server */
  348. __u16 mid; /* multiplex id */
  349. __u16 pid; /* process id */
  350. __u32 sequence_number; /* for CIFS signing */
  351. unsigned long when_alloc; /* when mid was created */
  352. #ifdef CONFIG_CIFS_STATS2
  353. unsigned long when_sent; /* time when smb send finished */
  354. unsigned long when_received; /* when demux complete (taken off wire) */
  355. #endif
  356. struct cifsSesInfo *ses; /* smb was sent to this server */
  357. struct task_struct *tsk; /* task waiting for response */
  358. struct smb_hdr *resp_buf; /* response buffer */
  359. int midState; /* wish this were enum but can not pass to wait_event */
  360. __u8 command; /* smb command code */
  361. unsigned multiPart:1; /* multiple responses to one SMB request */
  362. unsigned largeBuf:1; /* if valid response, is pointer to large buf */
  363. unsigned multiResp:1; /* multiple trans2 responses for one request */
  364. };
  365. struct oplock_q_entry {
  366. struct list_head qhead;
  367. struct inode * pinode;
  368. struct cifsTconInfo * tcon;
  369. __u16 netfid;
  370. };
  371. /* for pending dnotify requests */
  372. struct dir_notify_req {
  373. struct list_head lhead;
  374. __le16 Pid;
  375. __le16 PidHigh;
  376. __u16 Mid;
  377. __u16 Tid;
  378. __u16 Uid;
  379. __u16 netfid;
  380. __u32 filter; /* CompletionFilter (for multishot) */
  381. int multishot;
  382. struct file * pfile;
  383. };
  384. #define MID_FREE 0
  385. #define MID_REQUEST_ALLOCATED 1
  386. #define MID_REQUEST_SUBMITTED 2
  387. #define MID_RESPONSE_RECEIVED 4
  388. #define MID_RETRY_NEEDED 8 /* session closed while this request out */
  389. #define MID_NO_RESP_NEEDED 0x10
  390. /* Types of response buffer returned from SendReceive2 */
  391. #define CIFS_NO_BUFFER 0 /* Response buffer not returned */
  392. #define CIFS_SMALL_BUFFER 1
  393. #define CIFS_LARGE_BUFFER 2
  394. #define CIFS_IOVEC 4 /* array of response buffers */
  395. /* Type of session setup needed */
  396. #define CIFS_PLAINTEXT 0
  397. #define CIFS_LANMAN 1
  398. #define CIFS_NTLM 2
  399. #define CIFS_NTLMSSP_NEG 3
  400. #define CIFS_NTLMSSP_AUTH 4
  401. #define CIFS_SPNEGO_INIT 5
  402. #define CIFS_SPNEGO_TARG 6
  403. /*
  404. *****************************************************************
  405. * All constants go here
  406. *****************************************************************
  407. */
  408. #define UID_HASH (16)
  409. /*
  410. * Note that ONE module should define _DECLARE_GLOBALS_HERE to cause the
  411. * following to be declared.
  412. */
  413. /****************************************************************************
  414. * Locking notes. All updates to global variables and lists should be
  415. * protected by spinlocks or semaphores.
  416. *
  417. * Spinlocks
  418. * ---------
  419. * GlobalMid_Lock protects:
  420. * list operations on pending_mid_q and oplockQ
  421. * updates to XID counters, multiplex id and SMB sequence numbers
  422. * GlobalSMBSesLock protects:
  423. * list operations on tcp and SMB session lists and tCon lists
  424. * f_owner.lock protects certain per file struct operations
  425. * mapping->page_lock protects certain per page operations
  426. *
  427. * Semaphores
  428. * ----------
  429. * sesSem operations on smb session
  430. * tconSem operations on tree connection
  431. * fh_sem file handle reconnection operations
  432. *
  433. ****************************************************************************/
  434. #ifdef DECLARE_GLOBALS_HERE
  435. #define GLOBAL_EXTERN
  436. #else
  437. #define GLOBAL_EXTERN extern
  438. #endif
  439. /*
  440. * The list of servers that did not respond with NT LM 0.12.
  441. * This list helps improve performance and eliminate the messages indicating
  442. * that we had a communications error talking to the server in this list.
  443. */
  444. GLOBAL_EXTERN struct servers_not_supported *NotSuppList; /*@z4a */
  445. /*
  446. * The following is a hash table of all the users we know about.
  447. */
  448. GLOBAL_EXTERN struct smbUidInfo *GlobalUidList[UID_HASH];
  449. GLOBAL_EXTERN struct list_head GlobalServerList; /* BB not implemented yet */
  450. GLOBAL_EXTERN struct list_head GlobalSMBSessionList;
  451. GLOBAL_EXTERN struct list_head GlobalTreeConnectionList;
  452. GLOBAL_EXTERN rwlock_t GlobalSMBSeslock; /* protects list inserts on 3 above */
  453. GLOBAL_EXTERN struct list_head GlobalOplock_Q;
  454. GLOBAL_EXTERN struct list_head GlobalDnotifyReqList; /* Outstanding dir notify requests */
  455. GLOBAL_EXTERN struct list_head GlobalDnotifyRsp_Q; /* Dir notify response queue */
  456. /*
  457. * Global transaction id (XID) information
  458. */
  459. GLOBAL_EXTERN unsigned int GlobalCurrentXid; /* protected by GlobalMid_Sem */
  460. GLOBAL_EXTERN unsigned int GlobalTotalActiveXid; /* prot by GlobalMid_Sem */
  461. GLOBAL_EXTERN unsigned int GlobalMaxActiveXid; /* prot by GlobalMid_Sem */
  462. GLOBAL_EXTERN spinlock_t GlobalMid_Lock; /* protects above and list operations */
  463. /* on midQ entries */
  464. GLOBAL_EXTERN char Local_System_Name[15];
  465. /*
  466. * Global counters, updated atomically
  467. */
  468. GLOBAL_EXTERN atomic_t sesInfoAllocCount;
  469. GLOBAL_EXTERN atomic_t tconInfoAllocCount;
  470. GLOBAL_EXTERN atomic_t tcpSesAllocCount;
  471. GLOBAL_EXTERN atomic_t tcpSesReconnectCount;
  472. GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
  473. /* Various Debug counters to remove someday (BB) */
  474. GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
  475. #ifdef CONFIG_CIFS_STATS2
  476. GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
  477. GLOBAL_EXTERN atomic_t totSmBufAllocCount;
  478. #endif
  479. GLOBAL_EXTERN atomic_t smBufAllocCount;
  480. GLOBAL_EXTERN atomic_t midCount;
  481. /* Misc globals */
  482. GLOBAL_EXTERN unsigned int multiuser_mount; /* if enabled allows new sessions
  483. to be established on existing mount if we
  484. have the uid/password or Kerberos credential
  485. or equivalent for current user */
  486. GLOBAL_EXTERN unsigned int oplockEnabled;
  487. GLOBAL_EXTERN unsigned int experimEnabled;
  488. GLOBAL_EXTERN unsigned int lookupCacheEnabled;
  489. GLOBAL_EXTERN unsigned int extended_security; /* if on, session setup sent
  490. with more secure ntlmssp2 challenge/resp */
  491. GLOBAL_EXTERN unsigned int ntlmv2_support; /* better optional password hash */
  492. GLOBAL_EXTERN unsigned int sign_CIFS_PDUs; /* enable smb packet signing */
  493. GLOBAL_EXTERN unsigned int linuxExtEnabled;/*enable Linux/Unix CIFS extensions*/
  494. GLOBAL_EXTERN unsigned int CIFSMaxBufSize; /* max size not including hdr */
  495. GLOBAL_EXTERN unsigned int cifs_min_rcv; /* min size of big ntwrk buf pool */
  496. GLOBAL_EXTERN unsigned int cifs_min_small; /* min size of small buf pool */
  497. GLOBAL_EXTERN unsigned int cifs_max_pending; /* MAX requests at once to server*/