cifsglob.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. /*
  2. * fs/cifs/cifsglob.h
  3. *
  4. * Copyright (C) International Business Machines Corp., 2002,2005
  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. char server_Name[SERVER_NAME_LEN_WITH_NULL]; /* 15 chars + X'20'in 16th */
  98. char unicode_server_Name[SERVER_NAME_LEN_WITH_NULL * 2]; /* Unicode version of server_Name */
  99. struct socket *ssocket;
  100. union {
  101. struct sockaddr_in sockAddr;
  102. struct sockaddr_in6 sockAddr6;
  103. } addr;
  104. wait_queue_head_t response_q;
  105. wait_queue_head_t request_q; /* if more than maxmpx to srvr must block*/
  106. struct list_head pending_mid_q;
  107. void *Server_NlsInfo; /* BB - placeholder for future NLS info */
  108. unsigned short server_codepage; /* codepage for the server */
  109. unsigned long ip_address; /* IP addr for the server if known */
  110. enum protocolEnum protocolType;
  111. char versionMajor;
  112. char versionMinor;
  113. unsigned svlocal:1; /* local server or remote */
  114. atomic_t socketUseCount; /* number of open cifs sessions on socket */
  115. atomic_t inFlight; /* number of requests on the wire to server */
  116. enum statusEnum tcpStatus; /* what we think the status is */
  117. struct semaphore tcpSem;
  118. struct task_struct *tsk;
  119. char server_GUID[16];
  120. char secMode;
  121. enum securityEnum secType;
  122. unsigned int maxReq; /* Clients should submit no more */
  123. /* than maxReq distinct unanswered SMBs to the server when using */
  124. /* multiplexed reads or writes */
  125. unsigned int maxBuf; /* maxBuf specifies the maximum */
  126. /* message size the server can send or receive for non-raw SMBs */
  127. unsigned int maxRw; /* maxRw specifies the maximum */
  128. /* message size the server can send or receive for */
  129. /* SMB_COM_WRITE_RAW or SMB_COM_READ_RAW. */
  130. char sessid[4]; /* unique token id for this session */
  131. /* (returned on Negotiate */
  132. int capabilities; /* allow selective disabling of caps by smb sess */
  133. __u16 timeZone;
  134. char cryptKey[CIFS_CRYPTO_KEY_SIZE];
  135. char workstation_RFC1001_name[16]; /* 16th byte is always zero */
  136. __u32 sequence_number; /* needed for CIFS PDU signature */
  137. char mac_signing_key[CIFS_SESSION_KEY_SIZE + 16];
  138. };
  139. /*
  140. * The following is our shortcut to user information. We surface the uid,
  141. * and name. We always get the password on the fly in case it
  142. * has changed. We also hang a list of sessions owned by this user off here.
  143. */
  144. struct cifsUidInfo {
  145. struct list_head userList;
  146. struct list_head sessionList; /* SMB sessions for this user */
  147. uid_t linux_uid;
  148. char user[MAX_USERNAME_SIZE + 1]; /* ascii name of user */
  149. /* BB may need ptr or callback for PAM or WinBind info */
  150. };
  151. /*
  152. * Session structure. One of these for each uid session with a particular host
  153. */
  154. struct cifsSesInfo {
  155. struct list_head cifsSessionList;
  156. struct semaphore sesSem;
  157. struct cifsUidInfo *uidInfo; /* pointer to user info */
  158. struct TCP_Server_Info *server; /* pointer to server info */
  159. atomic_t inUse; /* # of mounts (tree connections) on this ses */
  160. enum statusEnum status;
  161. __u16 ipc_tid; /* special tid for connection to IPC share */
  162. __u16 flags;
  163. char *serverOS; /* name of operating system underlying server */
  164. char *serverNOS; /* name of network operating system of server */
  165. char *serverDomain; /* security realm of server */
  166. int Suid; /* remote smb uid */
  167. uid_t linux_uid; /* local Linux uid */
  168. int capabilities;
  169. char serverName[SERVER_NAME_LEN_WITH_NULL * 2]; /* BB make bigger for
  170. TCP names - will ipv6 and sctp addresses fit? */
  171. char userName[MAX_USERNAME_SIZE + 1];
  172. char domainName[MAX_USERNAME_SIZE + 1];
  173. char * password;
  174. };
  175. /* session flags */
  176. #define CIFS_SES_NT4 1
  177. /*
  178. * there is one of these for each connection to a resource on a particular
  179. * session
  180. */
  181. struct cifsTconInfo {
  182. struct list_head cifsConnectionList;
  183. struct list_head openFileList;
  184. struct semaphore tconSem;
  185. struct cifsSesInfo *ses; /* pointer to session associated with */
  186. char treeName[MAX_TREE_SIZE + 1]; /* UNC name of resource (in ASCII not UTF) */
  187. char *nativeFileSystem;
  188. __u16 tid; /* The 2 byte tree id */
  189. __u16 Flags; /* optional support bits */
  190. enum statusEnum tidStatus;
  191. atomic_t useCount; /* how many mounts (explicit or implicit) to this share */
  192. #ifdef CONFIG_CIFS_STATS
  193. atomic_t num_smbs_sent;
  194. atomic_t num_writes;
  195. atomic_t num_reads;
  196. atomic_t num_oplock_brks;
  197. atomic_t num_opens;
  198. atomic_t num_deletes;
  199. atomic_t num_mkdirs;
  200. atomic_t num_rmdirs;
  201. atomic_t num_renames;
  202. atomic_t num_t2renames;
  203. __u64 bytes_read;
  204. __u64 bytes_written;
  205. spinlock_t stat_lock;
  206. #endif
  207. FILE_SYSTEM_DEVICE_INFO fsDevInfo;
  208. FILE_SYSTEM_ATTRIBUTE_INFO fsAttrInfo; /* ok if file system name truncated */
  209. FILE_SYSTEM_UNIX_INFO fsUnixInfo;
  210. unsigned retry:1;
  211. /* BB add field for back pointer to sb struct? */
  212. };
  213. /*
  214. * This info hangs off the cifsFileInfo structure. This is used to track
  215. * byte stream locks on the file
  216. */
  217. struct cifsLockInfo {
  218. struct cifsLockInfo *next;
  219. int start;
  220. int length;
  221. int type;
  222. };
  223. /*
  224. * One of these for each open instance of a file
  225. */
  226. struct cifs_search_info {
  227. loff_t index_of_last_entry;
  228. __u16 entries_in_buffer;
  229. __u16 info_level;
  230. __u32 resume_key;
  231. char * ntwrk_buf_start;
  232. char * srch_entries_start;
  233. char * presume_name;
  234. unsigned int resume_name_len;
  235. unsigned endOfSearch:1;
  236. unsigned emptyDir:1;
  237. unsigned unicode:1;
  238. };
  239. struct cifsFileInfo {
  240. struct list_head tlist; /* pointer to next fid owned by tcon */
  241. struct list_head flist; /* next fid (file instance) for this inode */
  242. unsigned int uid; /* allows finding which FileInfo structure */
  243. __u32 pid; /* process id who opened file */
  244. __u16 netfid; /* file id from remote */
  245. /* BB add lock scope info here if needed */ ;
  246. /* lock scope id (0 if none) */
  247. struct file * pfile; /* needed for writepage */
  248. struct inode * pInode; /* needed for oplock break */
  249. unsigned closePend:1; /* file is marked to close */
  250. unsigned invalidHandle:1; /* file closed via session abend */
  251. struct semaphore fh_sem; /* prevents reopen race after dead ses*/
  252. char * search_resume_name; /* BB removeme BB */
  253. unsigned int resume_name_length; /* BB removeme - field renamed and moved BB */
  254. struct cifs_search_info srch_inf;
  255. };
  256. /*
  257. * One of these for each file inode
  258. */
  259. struct cifsInodeInfo {
  260. struct list_head lockList;
  261. /* BB add in lists for dirty pages - i.e. write caching info for oplock */
  262. struct list_head openFileList;
  263. int write_behind_rc;
  264. __u32 cifsAttrs; /* e.g. DOS archive bit, sparse, compressed, system */
  265. atomic_t inUse; /* num concurrent users (local openers cifs) of file*/
  266. unsigned long time; /* jiffies of last update/check of inode */
  267. unsigned clientCanCacheRead:1; /* read oplock */
  268. unsigned clientCanCacheAll:1; /* read and writebehind oplock */
  269. unsigned oplockPending:1;
  270. struct inode vfs_inode;
  271. };
  272. static inline struct cifsInodeInfo *
  273. CIFS_I(struct inode *inode)
  274. {
  275. return container_of(inode, struct cifsInodeInfo, vfs_inode);
  276. }
  277. static inline struct cifs_sb_info *
  278. CIFS_SB(struct super_block *sb)
  279. {
  280. return sb->s_fs_info;
  281. }
  282. /* one of these for every pending CIFS request to the server */
  283. struct mid_q_entry {
  284. struct list_head qhead; /* mids waiting on reply from this server */
  285. __u16 mid; /* multiplex id */
  286. __u16 pid; /* process id */
  287. __u32 sequence_number; /* for CIFS signing */
  288. struct timeval when_sent; /* time when smb sent */
  289. struct cifsSesInfo *ses; /* smb was sent to this server */
  290. struct task_struct *tsk; /* task waiting for response */
  291. struct smb_hdr *resp_buf; /* response buffer */
  292. int midState; /* wish this were enum but can not pass to wait_event */
  293. __u8 command; /* smb command code */
  294. unsigned multiPart:1; /* multiple responses to one SMB request */
  295. unsigned largeBuf:1; /* if valid response, is pointer to large buf */
  296. unsigned multiResp:1; /* multiple trans2 responses for one request */
  297. };
  298. struct oplock_q_entry {
  299. struct list_head qhead;
  300. struct inode * pinode;
  301. struct cifsTconInfo * tcon;
  302. __u16 netfid;
  303. };
  304. #define MID_FREE 0
  305. #define MID_REQUEST_ALLOCATED 1
  306. #define MID_REQUEST_SUBMITTED 2
  307. #define MID_RESPONSE_RECEIVED 4
  308. #define MID_RETRY_NEEDED 8 /* session closed while this request out */
  309. #define MID_NO_RESP_NEEDED 0x10
  310. #define MID_SMALL_BUFFER 0x20 /* 112 byte response buffer instead of 4K */
  311. /*
  312. *****************************************************************
  313. * All constants go here
  314. *****************************************************************
  315. */
  316. #define UID_HASH (16)
  317. /*
  318. * Note that ONE module should define _DECLARE_GLOBALS_HERE to cause the
  319. * following to be declared.
  320. */
  321. /****************************************************************************
  322. * Locking notes. All updates to global variables and lists should be
  323. * protected by spinlocks or semaphores.
  324. *
  325. * Spinlocks
  326. * ---------
  327. * GlobalMid_Lock protects:
  328. * list operations on pending_mid_q and oplockQ
  329. * updates to XID counters, multiplex id and SMB sequence numbers
  330. * GlobalSMBSesLock protects:
  331. * list operations on tcp and SMB session lists and tCon lists
  332. * f_owner.lock protects certain per file struct operations
  333. * mapping->page_lock protects certain per page operations
  334. *
  335. * Semaphores
  336. * ----------
  337. * sesSem operations on smb session
  338. * tconSem operations on tree connection
  339. * fh_sem file handle reconnection operations
  340. *
  341. ****************************************************************************/
  342. #ifdef DECLARE_GLOBALS_HERE
  343. #define GLOBAL_EXTERN
  344. #else
  345. #define GLOBAL_EXTERN extern
  346. #endif
  347. /*
  348. * The list of servers that did not respond with NT LM 0.12.
  349. * This list helps improve performance and eliminate the messages indicating
  350. * that we had a communications error talking to the server in this list.
  351. */
  352. GLOBAL_EXTERN struct servers_not_supported *NotSuppList; /*@z4a */
  353. /*
  354. * The following is a hash table of all the users we know about.
  355. */
  356. GLOBAL_EXTERN struct smbUidInfo *GlobalUidList[UID_HASH];
  357. GLOBAL_EXTERN struct list_head GlobalServerList; /* BB not implemented yet */
  358. GLOBAL_EXTERN struct list_head GlobalSMBSessionList;
  359. GLOBAL_EXTERN struct list_head GlobalTreeConnectionList;
  360. GLOBAL_EXTERN rwlock_t GlobalSMBSeslock; /* protects list inserts on 3 above */
  361. GLOBAL_EXTERN struct list_head GlobalOplock_Q;
  362. /*
  363. * Global transaction id (XID) information
  364. */
  365. GLOBAL_EXTERN unsigned int GlobalCurrentXid; /* protected by GlobalMid_Sem */
  366. GLOBAL_EXTERN unsigned int GlobalTotalActiveXid; /* prot by GlobalMid_Sem */
  367. GLOBAL_EXTERN unsigned int GlobalMaxActiveXid; /* prot by GlobalMid_Sem */
  368. GLOBAL_EXTERN spinlock_t GlobalMid_Lock; /* protects above and list operations */
  369. /* on midQ entries */
  370. GLOBAL_EXTERN char Local_System_Name[15];
  371. /*
  372. * Global counters, updated atomically
  373. */
  374. GLOBAL_EXTERN atomic_t sesInfoAllocCount;
  375. GLOBAL_EXTERN atomic_t tconInfoAllocCount;
  376. GLOBAL_EXTERN atomic_t tcpSesAllocCount;
  377. GLOBAL_EXTERN atomic_t tcpSesReconnectCount;
  378. GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
  379. /* Various Debug counters to remove someday (BB) */
  380. GLOBAL_EXTERN atomic_t bufAllocCount;
  381. GLOBAL_EXTERN atomic_t smBufAllocCount;
  382. GLOBAL_EXTERN atomic_t midCount;
  383. /* Misc globals */
  384. GLOBAL_EXTERN unsigned int multiuser_mount; /* if enabled allows new sessions
  385. to be established on existing mount if we
  386. have the uid/password or Kerberos credential
  387. or equivalent for current user */
  388. GLOBAL_EXTERN unsigned int oplockEnabled;
  389. GLOBAL_EXTERN unsigned int experimEnabled;
  390. GLOBAL_EXTERN unsigned int lookupCacheEnabled;
  391. GLOBAL_EXTERN unsigned int extended_security; /* if on, session setup sent
  392. with more secure ntlmssp2 challenge/resp */
  393. GLOBAL_EXTERN unsigned int ntlmv2_support; /* better optional password hash */
  394. GLOBAL_EXTERN unsigned int sign_CIFS_PDUs; /* enable smb packet signing */
  395. GLOBAL_EXTERN unsigned int linuxExtEnabled;/*enable Linux/Unix CIFS extensions*/
  396. GLOBAL_EXTERN unsigned int CIFSMaxBufSize; /* max size not including hdr */
  397. GLOBAL_EXTERN unsigned int cifs_min_rcv; /* min size of big ntwrk buf pool */
  398. GLOBAL_EXTERN unsigned int cifs_min_small; /* min size of small buf pool */
  399. GLOBAL_EXTERN unsigned int cifs_max_pending; /* MAX requests at once to server*/