Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame^] | 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 | |
| 37 | int |
| 38 | smb2_open_file(const unsigned int xid, struct cifs_tcon *tcon, const char *path, |
| 39 | int disposition, int desired_access, int create_options, |
| 40 | struct cifs_fid *fid, __u32 *oplock, FILE_ALL_INFO *buf, |
| 41 | struct cifs_sb_info *cifs_sb) |
| 42 | { |
| 43 | int rc; |
| 44 | __le16 *smb2_path; |
| 45 | struct smb2_file_all_info *smb2_data = NULL; |
| 46 | |
| 47 | smb2_path = cifs_convert_path_to_utf16(path, cifs_sb); |
| 48 | if (smb2_path == NULL) { |
| 49 | rc = -ENOMEM; |
| 50 | goto out; |
| 51 | } |
| 52 | |
| 53 | smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + MAX_NAME * 2, |
| 54 | GFP_KERNEL); |
| 55 | if (smb2_data == NULL) { |
| 56 | rc = -ENOMEM; |
| 57 | goto out; |
| 58 | } |
| 59 | |
| 60 | desired_access |= FILE_READ_ATTRIBUTES; |
| 61 | |
| 62 | rc = SMB2_open(xid, tcon, smb2_path, &fid->persistent_fid, |
| 63 | &fid->volatile_fid, desired_access, disposition, |
| 64 | 0, 0, smb2_data); |
| 65 | if (rc) |
| 66 | goto out; |
| 67 | |
| 68 | if (buf) { |
| 69 | /* open response does not have IndexNumber field - get it */ |
| 70 | rc = SMB2_get_srv_num(xid, tcon, fid->persistent_fid, |
| 71 | fid->volatile_fid, |
| 72 | &smb2_data->IndexNumber); |
| 73 | if (rc) { |
| 74 | /* let get_inode_info disable server inode numbers */ |
| 75 | smb2_data->IndexNumber = 0; |
| 76 | rc = 0; |
| 77 | } |
| 78 | move_smb2_info_to_cifs(buf, smb2_data); |
| 79 | } |
| 80 | |
| 81 | out: |
| 82 | *oplock = 0; |
| 83 | kfree(smb2_data); |
| 84 | kfree(smb2_path); |
| 85 | return rc; |
| 86 | } |