smb2file.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * fs/cifs/smb2file.c
  3. *
  4. * Copyright (C) International Business Machines Corp., 2002, 2011
  5. * Author(s): Steve French (sfrench@us.ibm.com),
  6. * Pavel Shilovsky ((pshilovsky@samba.org) 2012
  7. *
  8. * This library is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU Lesser General Public License as published
  10. * by the Free Software Foundation; either version 2.1 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  16. * the GNU Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public License
  19. * along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #include <linux/fs.h>
  23. #include <linux/stat.h>
  24. #include <linux/slab.h>
  25. #include <linux/pagemap.h>
  26. #include <asm/div64.h>
  27. #include "cifsfs.h"
  28. #include "cifspdu.h"
  29. #include "cifsglob.h"
  30. #include "cifsproto.h"
  31. #include "cifs_debug.h"
  32. #include "cifs_fs_sb.h"
  33. #include "cifs_unicode.h"
  34. #include "fscache.h"
  35. #include "smb2proto.h"
  36. int
  37. smb2_open_file(const unsigned int xid, struct cifs_tcon *tcon, const char *path,
  38. int disposition, int desired_access, int create_options,
  39. struct cifs_fid *fid, __u32 *oplock, FILE_ALL_INFO *buf,
  40. struct cifs_sb_info *cifs_sb)
  41. {
  42. int rc;
  43. __le16 *smb2_path;
  44. struct smb2_file_all_info *smb2_data = NULL;
  45. smb2_path = cifs_convert_path_to_utf16(path, cifs_sb);
  46. if (smb2_path == NULL) {
  47. rc = -ENOMEM;
  48. goto out;
  49. }
  50. smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + MAX_NAME * 2,
  51. GFP_KERNEL);
  52. if (smb2_data == NULL) {
  53. rc = -ENOMEM;
  54. goto out;
  55. }
  56. desired_access |= FILE_READ_ATTRIBUTES;
  57. rc = SMB2_open(xid, tcon, smb2_path, &fid->persistent_fid,
  58. &fid->volatile_fid, desired_access, disposition,
  59. 0, 0, smb2_data);
  60. if (rc)
  61. goto out;
  62. if (buf) {
  63. /* open response does not have IndexNumber field - get it */
  64. rc = SMB2_get_srv_num(xid, tcon, fid->persistent_fid,
  65. fid->volatile_fid,
  66. &smb2_data->IndexNumber);
  67. if (rc) {
  68. /* let get_inode_info disable server inode numbers */
  69. smb2_data->IndexNumber = 0;
  70. rc = 0;
  71. }
  72. move_smb2_info_to_cifs(buf, smb2_data);
  73. }
  74. out:
  75. *oplock = 0;
  76. kfree(smb2_data);
  77. kfree(smb2_path);
  78. return rc;
  79. }