thermal: ti-soc-thermal: Set the bandgap mask counter delay value
[deliverable/linux.git] / fs / cifs / smb2inode.c
CommitLineData
be4cb9e3
PS
1/*
2 * fs/cifs/smb2inode.c
3 *
4 * Copyright (C) International Business Machines Corp., 2002, 2011
5 * Etersoft, 2012
6 * Author(s): Pavel Shilovsky (pshilovsky@samba.org),
7 * Steve French (sfrench@us.ibm.com)
8 *
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.
13 *
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.
18 *
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
22 */
23#include <linux/fs.h>
24#include <linux/stat.h>
25#include <linux/slab.h>
26#include <linux/pagemap.h>
27#include <asm/div64.h>
28#include "cifsfs.h"
29#include "cifspdu.h"
30#include "cifsglob.h"
31#include "cifsproto.h"
32#include "cifs_debug.h"
33#include "cifs_fs_sb.h"
34#include "cifs_unicode.h"
35#include "fscache.h"
36#include "smb2glob.h"
37#include "smb2pdu.h"
38#include "smb2proto.h"
39
40static int
41smb2_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,
ca81983f 44 __u32 create_options, void *data, int command)
be4cb9e3
PS
45{
46 int rc, tmprc = 0;
be4cb9e3 47 __le16 *utf16_path;
2e44b288 48 __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
064f6047
PS
49 struct cifs_open_parms oparms;
50 struct cifs_fid fid;
be4cb9e3
PS
51
52 utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
53 if (!utf16_path)
54 return -ENOMEM;
55
064f6047
PS
56 oparms.tcon = tcon;
57 oparms.desired_access = desired_access;
58 oparms.disposition = create_disposition;
59 oparms.create_options = create_options;
60 oparms.fid = &fid;
9cbc0b73 61 oparms.reconnect = false;
064f6047
PS
62
63 rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL);
be4cb9e3
PS
64 if (rc) {
65 kfree(utf16_path);
66 return rc;
67 }
68
69 switch (command) {
70 case SMB2_OP_DELETE:
71 break;
72 case SMB2_OP_QUERY_INFO:
064f6047
PS
73 tmprc = SMB2_query_info(xid, tcon, fid.persistent_fid,
74 fid.volatile_fid,
be4cb9e3
PS
75 (struct smb2_file_all_info *)data);
76 break;
77 case SMB2_OP_MKDIR:
78 /*
79 * Directories are created through parameters in the
80 * SMB2_open() call.
81 */
82 break;
35143eb5 83 case SMB2_OP_RENAME:
064f6047
PS
84 tmprc = SMB2_rename(xid, tcon, fid.persistent_fid,
85 fid.volatile_fid, (__le16 *)data);
35143eb5 86 break;
568798cc 87 case SMB2_OP_HARDLINK:
064f6047
PS
88 tmprc = SMB2_set_hardlink(xid, tcon, fid.persistent_fid,
89 fid.volatile_fid, (__le16 *)data);
568798cc 90 break;
c839ff24 91 case SMB2_OP_SET_EOF:
064f6047
PS
92 tmprc = SMB2_set_eof(xid, tcon, fid.persistent_fid,
93 fid.volatile_fid, current->tgid,
94 (__le64 *)data);
c839ff24 95 break;
1feeaac7 96 case SMB2_OP_SET_INFO:
064f6047
PS
97 tmprc = SMB2_set_info(xid, tcon, fid.persistent_fid,
98 fid.volatile_fid,
1feeaac7
PS
99 (FILE_BASIC_INFO *)data);
100 break;
be4cb9e3 101 default:
f96637be 102 cifs_dbg(VFS, "Invalid command\n");
be4cb9e3
PS
103 break;
104 }
105
064f6047 106 rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
be4cb9e3
PS
107 if (tmprc)
108 rc = tmprc;
109 kfree(utf16_path);
110 return rc;
111}
112
f0df737e 113void
be4cb9e3
PS
114move_smb2_info_to_cifs(FILE_ALL_INFO *dst, struct smb2_file_all_info *src)
115{
116 memcpy(dst, src, (size_t)(&src->CurrentByteOffset) - (size_t)src);
117 dst->CurrentByteOffset = src->CurrentByteOffset;
118 dst->Mode = src->Mode;
119 dst->AlignmentRequirement = src->AlignmentRequirement;
120 dst->IndexNumber1 = 0; /* we don't use it */
121}
122
123int
124smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,
125 struct cifs_sb_info *cifs_sb, const char *full_path,
126 FILE_ALL_INFO *data, bool *adjust_tz)
127{
128 int rc;
129 struct smb2_file_all_info *smb2_data;
130
131 *adjust_tz = false;
132
133 smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + MAX_NAME * 2,
134 GFP_KERNEL);
135 if (smb2_data == NULL)
136 return -ENOMEM;
137
138 rc = smb2_open_op_close(xid, tcon, cifs_sb, full_path,
ca81983f
PS
139 FILE_READ_ATTRIBUTES, FILE_OPEN, 0, smb2_data,
140 SMB2_OP_QUERY_INFO);
be4cb9e3
PS
141 if (rc)
142 goto out;
143
144 move_smb2_info_to_cifs(data, smb2_data);
145out:
146 kfree(smb2_data);
147 return rc;
148}
a0e73183
PS
149
150int
151smb2_mkdir(const unsigned int xid, struct cifs_tcon *tcon, const char *name,
152 struct cifs_sb_info *cifs_sb)
153{
154 return smb2_open_op_close(xid, tcon, cifs_sb, name,
ca81983f 155 FILE_WRITE_ATTRIBUTES, FILE_CREATE,
a0e73183
PS
156 CREATE_NOT_FILE, NULL, SMB2_OP_MKDIR);
157}
158
159void
160smb2_mkdir_setinfo(struct inode *inode, const char *name,
161 struct cifs_sb_info *cifs_sb, struct cifs_tcon *tcon,
162 const unsigned int xid)
163{
164 FILE_BASIC_INFO data;
165 struct cifsInodeInfo *cifs_i;
166 u32 dosattrs;
167 int tmprc;
168
169 memset(&data, 0, sizeof(data));
170 cifs_i = CIFS_I(inode);
171 dosattrs = cifs_i->cifsAttrs | ATTR_READONLY;
172 data.Attributes = cpu_to_le32(dosattrs);
173 tmprc = smb2_open_op_close(xid, tcon, cifs_sb, name,
ca81983f 174 FILE_WRITE_ATTRIBUTES, FILE_CREATE,
a0e73183
PS
175 CREATE_NOT_FILE, &data, SMB2_OP_SET_INFO);
176 if (tmprc == 0)
177 cifs_i->cifsAttrs = dosattrs;
178}
1a500f01
PS
179
180int
181smb2_rmdir(const unsigned int xid, struct cifs_tcon *tcon, const char *name,
182 struct cifs_sb_info *cifs_sb)
183{
184 return smb2_open_op_close(xid, tcon, cifs_sb, name, DELETE, FILE_OPEN,
ca81983f 185 CREATE_NOT_FILE | CREATE_DELETE_ON_CLOSE,
1a500f01
PS
186 NULL, SMB2_OP_DELETE);
187}
cbe6f439
PS
188
189int
190smb2_unlink(const unsigned int xid, struct cifs_tcon *tcon, const char *name,
191 struct cifs_sb_info *cifs_sb)
192{
193 return smb2_open_op_close(xid, tcon, cifs_sb, name, DELETE, FILE_OPEN,
ca81983f 194 CREATE_DELETE_ON_CLOSE, NULL,
cbe6f439
PS
195 SMB2_OP_DELETE);
196}
35143eb5 197
568798cc
PS
198static int
199smb2_set_path_attr(const unsigned int xid, struct cifs_tcon *tcon,
200 const char *from_name, const char *to_name,
201 struct cifs_sb_info *cifs_sb, __u32 access, int command)
35143eb5
PS
202{
203 __le16 *smb2_to_name = NULL;
204 int rc;
205
206 smb2_to_name = cifs_convert_path_to_utf16(to_name, cifs_sb);
207 if (smb2_to_name == NULL) {
208 rc = -ENOMEM;
209 goto smb2_rename_path;
210 }
211
568798cc 212 rc = smb2_open_op_close(xid, tcon, cifs_sb, from_name, access,
ca81983f 213 FILE_OPEN, 0, smb2_to_name, command);
35143eb5
PS
214smb2_rename_path:
215 kfree(smb2_to_name);
216 return rc;
217}
568798cc
PS
218
219int
220smb2_rename_path(const unsigned int xid, struct cifs_tcon *tcon,
221 const char *from_name, const char *to_name,
222 struct cifs_sb_info *cifs_sb)
223{
224 return smb2_set_path_attr(xid, tcon, from_name, to_name, cifs_sb,
225 DELETE, SMB2_OP_RENAME);
226}
227
228int
229smb2_create_hardlink(const unsigned int xid, struct cifs_tcon *tcon,
230 const char *from_name, const char *to_name,
231 struct cifs_sb_info *cifs_sb)
232{
233 return smb2_set_path_attr(xid, tcon, from_name, to_name, cifs_sb,
234 FILE_READ_ATTRIBUTES, SMB2_OP_HARDLINK);
235}
c839ff24
PS
236
237int
238smb2_set_path_size(const unsigned int xid, struct cifs_tcon *tcon,
239 const char *full_path, __u64 size,
240 struct cifs_sb_info *cifs_sb, bool set_alloc)
241{
242 __le64 eof = cpu_to_le64(size);
243 return smb2_open_op_close(xid, tcon, cifs_sb, full_path,
ca81983f 244 FILE_WRITE_DATA, FILE_OPEN, 0, &eof,
c839ff24
PS
245 SMB2_OP_SET_EOF);
246}
1feeaac7
PS
247
248int
249smb2_set_file_info(struct inode *inode, const char *full_path,
250 FILE_BASIC_INFO *buf, const unsigned int xid)
251{
252 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
253 struct tcon_link *tlink;
254 int rc;
255
256 tlink = cifs_sb_tlink(cifs_sb);
257 if (IS_ERR(tlink))
258 return PTR_ERR(tlink);
259 rc = smb2_open_op_close(xid, tlink_tcon(tlink), cifs_sb, full_path,
ca81983f 260 FILE_WRITE_ATTRIBUTES, FILE_OPEN, 0, buf,
1feeaac7
PS
261 SMB2_OP_SET_INFO);
262 cifs_put_tlink(tlink);
263 return rc;
264}
This page took 0.083061 seconds and 5 git commands to generate.