cifsglob.h 15 KB

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