smb1ops.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * SMB1 (CIFS) version specific operations
  3. *
  4. * Copyright (c) 2012, Jeff Layton <jlayton@redhat.com>
  5. *
  6. * This library is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License v2 as published
  8. * by the Free Software Foundation.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  13. * the GNU Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public License
  16. * along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #include "cifsglob.h"
  20. #include "cifsproto.h"
  21. #include "cifs_debug.h"
  22. #include "cifspdu.h"
  23. /*
  24. * An NT cancel request header looks just like the original request except:
  25. *
  26. * The Command is SMB_COM_NT_CANCEL
  27. * The WordCount is zeroed out
  28. * The ByteCount is zeroed out
  29. *
  30. * This function mangles an existing request buffer into a
  31. * SMB_COM_NT_CANCEL request and then sends it.
  32. */
  33. static int
  34. send_nt_cancel(struct TCP_Server_Info *server, void *buf,
  35. struct mid_q_entry *mid)
  36. {
  37. int rc = 0;
  38. struct smb_hdr *in_buf = (struct smb_hdr *)buf;
  39. /* -4 for RFC1001 length and +2 for BCC field */
  40. in_buf->smb_buf_length = cpu_to_be32(sizeof(struct smb_hdr) - 4 + 2);
  41. in_buf->Command = SMB_COM_NT_CANCEL;
  42. in_buf->WordCount = 0;
  43. put_bcc(0, in_buf);
  44. mutex_lock(&server->srv_mutex);
  45. rc = cifs_sign_smb(in_buf, server, &mid->sequence_number);
  46. if (rc) {
  47. mutex_unlock(&server->srv_mutex);
  48. return rc;
  49. }
  50. rc = smb_send(server, in_buf, be32_to_cpu(in_buf->smb_buf_length));
  51. mutex_unlock(&server->srv_mutex);
  52. cFYI(1, "issued NT_CANCEL for mid %u, rc = %d",
  53. in_buf->Mid, rc);
  54. return rc;
  55. }
  56. static bool
  57. cifs_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
  58. {
  59. return ob1->netfid == ob2->netfid;
  60. }
  61. static unsigned int
  62. cifs_read_data_offset(char *buf)
  63. {
  64. READ_RSP *rsp = (READ_RSP *)buf;
  65. return le16_to_cpu(rsp->DataOffset);
  66. }
  67. static unsigned int
  68. cifs_read_data_length(char *buf)
  69. {
  70. READ_RSP *rsp = (READ_RSP *)buf;
  71. return (le16_to_cpu(rsp->DataLengthHigh) << 16) +
  72. le16_to_cpu(rsp->DataLength);
  73. }
  74. static struct mid_q_entry *
  75. cifs_find_mid(struct TCP_Server_Info *server, char *buffer)
  76. {
  77. struct smb_hdr *buf = (struct smb_hdr *)buffer;
  78. struct mid_q_entry *mid;
  79. spin_lock(&GlobalMid_Lock);
  80. list_for_each_entry(mid, &server->pending_mid_q, qhead) {
  81. if (mid->mid == buf->Mid &&
  82. mid->mid_state == MID_REQUEST_SUBMITTED &&
  83. le16_to_cpu(mid->command) == buf->Command) {
  84. spin_unlock(&GlobalMid_Lock);
  85. return mid;
  86. }
  87. }
  88. spin_unlock(&GlobalMid_Lock);
  89. return NULL;
  90. }
  91. static void
  92. cifs_add_credits(struct TCP_Server_Info *server, const unsigned int add)
  93. {
  94. spin_lock(&server->req_lock);
  95. server->credits += add;
  96. server->in_flight--;
  97. spin_unlock(&server->req_lock);
  98. wake_up(&server->request_q);
  99. }
  100. static void
  101. cifs_set_credits(struct TCP_Server_Info *server, const int val)
  102. {
  103. spin_lock(&server->req_lock);
  104. server->credits = val;
  105. server->oplocks = val > 1 ? enable_oplocks : false;
  106. spin_unlock(&server->req_lock);
  107. }
  108. static int *
  109. cifs_get_credits_field(struct TCP_Server_Info *server)
  110. {
  111. return &server->credits;
  112. }
  113. struct smb_version_operations smb1_operations = {
  114. .send_cancel = send_nt_cancel,
  115. .compare_fids = cifs_compare_fids,
  116. .setup_request = cifs_setup_request,
  117. .check_receive = cifs_check_receive,
  118. .add_credits = cifs_add_credits,
  119. .set_credits = cifs_set_credits,
  120. .get_credits_field = cifs_get_credits_field,
  121. .read_data_offset = cifs_read_data_offset,
  122. .read_data_length = cifs_read_data_length,
  123. .map_error = map_smb_to_linux_error,
  124. .find_mid = cifs_find_mid,
  125. .check_message = checkSMB,
  126. .dump_detail = cifs_dump_detail,
  127. .is_oplock_break = is_valid_oplock_break,
  128. };
  129. struct smb_version_values smb1_values = {
  130. .version_string = SMB1_VERSION_STRING,
  131. .large_lock_type = LOCKING_ANDX_LARGE_FILES,
  132. .exclusive_lock_type = 0,
  133. .shared_lock_type = LOCKING_ANDX_SHARED_LOCK,
  134. .unlock_lock_type = 0,
  135. .header_size = sizeof(struct smb_hdr),
  136. .max_header_size = MAX_CIFS_HDR_SIZE,
  137. .read_rsp_size = sizeof(READ_RSP),
  138. };