4 * Copyright (C) International Business Machines Corp., 2002, 2011
6 * Author(s): Pavel Shilovsky (pshilovsky@samba.org),
7 * Steve French (sfrench@us.ibm.com)
9 * This library is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as published
11 * by the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
17 * the GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <linux/stat.h>
25 #include <linux/slab.h>
26 #include <linux/pagemap.h>
27 #include <asm/div64.h>
31 #include "cifsproto.h"
32 #include "cifs_debug.h"
33 #include "cifs_fs_sb.h"
34 #include "cifs_unicode.h"
38 #include "smb2proto.h"
41 smb2_open_op_close(const unsigned int xid, struct cifs_tcon *tcon,
42 struct cifs_sb_info *cifs_sb, const char *full_path,
43 __u32 desired_access, __u32 create_disposition,
44 __u32 file_attributes, __u32 create_options,
45 void *data, int command)
48 u64 persistent_fid, volatile_fid;
51 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
55 rc = SMB2_open(xid, tcon, utf16_path, &persistent_fid, &volatile_fid,
56 desired_access, create_disposition, file_attributes,
57 create_options, NULL);
66 case SMB2_OP_QUERY_INFO:
67 tmprc = SMB2_query_info(xid, tcon, persistent_fid,
69 (struct smb2_file_all_info *)data);
73 * Directories are created through parameters in the
78 tmprc = SMB2_rename(xid, tcon, persistent_fid, volatile_fid,
82 cERROR(1, "Invalid command");
86 rc = SMB2_close(xid, tcon, persistent_fid, volatile_fid);
94 move_smb2_info_to_cifs(FILE_ALL_INFO *dst, struct smb2_file_all_info *src)
96 memcpy(dst, src, (size_t)(&src->CurrentByteOffset) - (size_t)src);
97 dst->CurrentByteOffset = src->CurrentByteOffset;
98 dst->Mode = src->Mode;
99 dst->AlignmentRequirement = src->AlignmentRequirement;
100 dst->IndexNumber1 = 0; /* we don't use it */
104 smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,
105 struct cifs_sb_info *cifs_sb, const char *full_path,
106 FILE_ALL_INFO *data, bool *adjust_tz)
109 struct smb2_file_all_info *smb2_data;
113 smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + MAX_NAME * 2,
115 if (smb2_data == NULL)
118 rc = smb2_open_op_close(xid, tcon, cifs_sb, full_path,
119 FILE_READ_ATTRIBUTES, FILE_OPEN, 0, 0,
120 smb2_data, SMB2_OP_QUERY_INFO);
124 move_smb2_info_to_cifs(data, smb2_data);
131 smb2_mkdir(const unsigned int xid, struct cifs_tcon *tcon, const char *name,
132 struct cifs_sb_info *cifs_sb)
134 return smb2_open_op_close(xid, tcon, cifs_sb, name,
135 FILE_WRITE_ATTRIBUTES, FILE_CREATE, 0,
136 CREATE_NOT_FILE, NULL, SMB2_OP_MKDIR);
140 smb2_mkdir_setinfo(struct inode *inode, const char *name,
141 struct cifs_sb_info *cifs_sb, struct cifs_tcon *tcon,
142 const unsigned int xid)
144 FILE_BASIC_INFO data;
145 struct cifsInodeInfo *cifs_i;
149 memset(&data, 0, sizeof(data));
150 cifs_i = CIFS_I(inode);
151 dosattrs = cifs_i->cifsAttrs | ATTR_READONLY;
152 data.Attributes = cpu_to_le32(dosattrs);
153 tmprc = smb2_open_op_close(xid, tcon, cifs_sb, name,
154 FILE_WRITE_ATTRIBUTES, FILE_CREATE, 0,
155 CREATE_NOT_FILE, &data, SMB2_OP_SET_INFO);
157 cifs_i->cifsAttrs = dosattrs;
161 smb2_rmdir(const unsigned int xid, struct cifs_tcon *tcon, const char *name,
162 struct cifs_sb_info *cifs_sb)
164 return smb2_open_op_close(xid, tcon, cifs_sb, name, DELETE, FILE_OPEN,
165 0, CREATE_NOT_FILE | CREATE_DELETE_ON_CLOSE,
166 NULL, SMB2_OP_DELETE);
170 smb2_unlink(const unsigned int xid, struct cifs_tcon *tcon, const char *name,
171 struct cifs_sb_info *cifs_sb)
173 return smb2_open_op_close(xid, tcon, cifs_sb, name, DELETE, FILE_OPEN,
174 0, CREATE_DELETE_ON_CLOSE, NULL,
179 smb2_rename_path(const unsigned int xid, struct cifs_tcon *tcon,
180 const char *from_name, const char *to_name,
181 struct cifs_sb_info *cifs_sb)
183 __le16 *smb2_to_name = NULL;
186 smb2_to_name = cifs_convert_path_to_utf16(to_name, cifs_sb);
187 if (smb2_to_name == NULL) {
189 goto smb2_rename_path;
192 rc = smb2_open_op_close(xid, tcon, cifs_sb, from_name, DELETE,
193 FILE_OPEN, 0, 0, smb2_to_name, SMB2_OP_RENAME);