2 Unix SMB/CIFS implementation.
4 POSIX NTVFS backend - read
6 Copyright (C) Andrew Tridgell 2004
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program 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 the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "vfs_posix.h"
25 #include "librpc/gen_ndr/ndr_xattr.h"
28 reply to a RAW_FILEINFO_EA_LIST call
30 NTSTATUS pvfs_query_ea_list(struct pvfs_state *pvfs, TALLOC_CTX *mem_ctx,
31 struct pvfs_filename *name, int fd,
33 struct ea_name *names,
34 struct smb_ea_list *eas)
38 struct xattr_DosEAs *ealist = talloc_p(mem_ctx, struct xattr_DosEAs);
41 status = pvfs_doseas_load(pvfs, name, fd, ealist);
42 if (!NT_STATUS_IS_OK(status)) {
45 eas->eas = talloc_array_p(mem_ctx, struct ea_struct, num_names);
46 if (eas->eas == NULL) {
47 return NT_STATUS_NO_MEMORY;
49 eas->num_eas = num_names;
50 for (i=0;i<num_names;i++) {
52 eas->eas[i].flags = 0;
53 eas->eas[i].name.s = names[i].name.s;
54 eas->eas[i].value = data_blob(NULL, 0);
55 for (j=0;j<ealist->num_eas;j++) {
56 if (StrCaseCmp(eas->eas[i].name.s,
57 ealist->eas[j].name) == 0) {
58 eas->eas[i].value = ealist->eas[j].value;
67 reply to a RAW_FILEINFO_ALL_EAS call
69 static NTSTATUS pvfs_query_all_eas(struct pvfs_state *pvfs, TALLOC_CTX *mem_ctx,
70 struct pvfs_filename *name, int fd,
71 struct smb_ea_list *eas)
75 struct xattr_DosEAs *ealist = talloc_p(mem_ctx, struct xattr_DosEAs);
78 status = pvfs_doseas_load(pvfs, name, fd, ealist);
79 if (!NT_STATUS_IS_OK(status)) {
82 eas->eas = talloc_array_p(mem_ctx, struct ea_struct, ealist->num_eas);
83 if (eas->eas == NULL) {
84 return NT_STATUS_NO_MEMORY;
87 for (i=0;i<ealist->num_eas;i++) {
88 eas->eas[eas->num_eas].flags = 0;
89 eas->eas[eas->num_eas].name.s = ealist->eas[i].name;
90 eas->eas[eas->num_eas].value = ealist->eas[i].value;
97 approximately map a struct pvfs_filename to a generic fileinfo struct
99 static NTSTATUS pvfs_map_fileinfo(struct pvfs_state *pvfs,
100 struct smbsrv_request *req,
101 struct pvfs_filename *name, union smb_fileinfo *info,
104 switch (info->generic.level) {
105 case RAW_FILEINFO_GENERIC:
106 return NT_STATUS_INVALID_LEVEL;
108 case RAW_FILEINFO_GETATTR:
109 info->getattr.out.attrib = name->dos.attrib;
110 info->getattr.out.size = name->st.st_size;
111 info->getattr.out.write_time = nt_time_to_unix(name->dos.write_time);
114 case RAW_FILEINFO_GETATTRE:
115 case RAW_FILEINFO_STANDARD:
116 info->standard.out.create_time = nt_time_to_unix(name->dos.create_time);
117 info->standard.out.access_time = nt_time_to_unix(name->dos.access_time);
118 info->standard.out.write_time = nt_time_to_unix(name->dos.write_time);
119 info->standard.out.size = name->st.st_size;
120 info->standard.out.alloc_size = name->dos.alloc_size;
121 info->standard.out.attrib = name->dos.attrib;
124 case RAW_FILEINFO_EA_SIZE:
125 info->ea_size.out.create_time = nt_time_to_unix(name->dos.create_time);
126 info->ea_size.out.access_time = nt_time_to_unix(name->dos.access_time);
127 info->ea_size.out.write_time = nt_time_to_unix(name->dos.write_time);
128 info->ea_size.out.size = name->st.st_size;
129 info->ea_size.out.alloc_size = name->dos.alloc_size;
130 info->ea_size.out.attrib = name->dos.attrib;
131 info->ea_size.out.ea_size = name->dos.ea_size;
134 case RAW_FILEINFO_EA_LIST:
135 return pvfs_query_ea_list(pvfs, req, name, fd,
136 info->ea_list.in.num_names,
137 info->ea_list.in.ea_names,
140 case RAW_FILEINFO_ALL_EAS:
141 return pvfs_query_all_eas(pvfs, req, name, fd, &info->all_eas.out);
143 case RAW_FILEINFO_IS_NAME_VALID:
146 case RAW_FILEINFO_BASIC_INFO:
147 case RAW_FILEINFO_BASIC_INFORMATION:
148 info->basic_info.out.create_time = name->dos.create_time;
149 info->basic_info.out.access_time = name->dos.access_time;
150 info->basic_info.out.write_time = name->dos.write_time;
151 info->basic_info.out.change_time = name->dos.change_time;
152 info->basic_info.out.attrib = name->dos.attrib;
155 case RAW_FILEINFO_STANDARD_INFO:
156 case RAW_FILEINFO_STANDARD_INFORMATION:
157 info->standard_info.out.alloc_size = name->dos.alloc_size;
158 info->standard_info.out.size = name->st.st_size;
159 info->standard_info.out.nlink = name->st.st_nlink;
160 info->standard_info.out.delete_pending = 0;
161 info->standard_info.out.directory =
162 (name->dos.attrib & FILE_ATTRIBUTE_DIRECTORY)? 1 : 0;
165 case RAW_FILEINFO_EA_INFO:
166 case RAW_FILEINFO_EA_INFORMATION:
167 info->ea_info.out.ea_size = name->dos.ea_size;
170 case RAW_FILEINFO_NAME_INFO:
171 case RAW_FILEINFO_NAME_INFORMATION:
172 info->name_info.out.fname.s = name->original_name;
175 case RAW_FILEINFO_ALL_INFO:
176 case RAW_FILEINFO_ALL_INFORMATION:
177 info->all_info.out.create_time = name->dos.create_time;
178 info->all_info.out.access_time = name->dos.access_time;
179 info->all_info.out.write_time = name->dos.write_time;
180 info->all_info.out.change_time = name->dos.change_time;
181 info->all_info.out.attrib = name->dos.attrib;
182 info->all_info.out.alloc_size = name->dos.alloc_size;
183 info->all_info.out.size = name->st.st_size;
184 info->all_info.out.nlink = name->st.st_nlink;
185 info->all_info.out.delete_pending = 0;
186 info->all_info.out.directory =
187 (name->dos.attrib & FILE_ATTRIBUTE_DIRECTORY)? 1 : 0;
188 info->all_info.out.ea_size = name->dos.ea_size;
189 info->all_info.out.fname.s = name->original_name;
192 case RAW_FILEINFO_ALT_NAME_INFO:
193 case RAW_FILEINFO_ALT_NAME_INFORMATION:
194 info->name_info.out.fname.s = pvfs_short_name(pvfs, name, name);
197 case RAW_FILEINFO_STREAM_INFO:
198 case RAW_FILEINFO_STREAM_INFORMATION:
199 return pvfs_stream_information(pvfs, req, name, fd, &info->stream_info.out);
201 case RAW_FILEINFO_COMPRESSION_INFO:
202 case RAW_FILEINFO_COMPRESSION_INFORMATION:
203 info->compression_info.out.compressed_size = name->st.st_size;
204 info->compression_info.out.format = 0;
205 info->compression_info.out.unit_shift = 0;
206 info->compression_info.out.chunk_shift = 0;
207 info->compression_info.out.cluster_shift = 0;
210 case RAW_FILEINFO_INTERNAL_INFORMATION:
211 info->internal_information.out.file_id = name->dos.file_id;
214 case RAW_FILEINFO_ACCESS_INFORMATION:
215 info->access_information.out.access_flags = 0;
218 case RAW_FILEINFO_POSITION_INFORMATION:
219 info->position_information.out.position = 0;
222 case RAW_FILEINFO_MODE_INFORMATION:
223 info->mode_information.out.mode = 0;
226 case RAW_FILEINFO_ALIGNMENT_INFORMATION:
227 info->alignment_information.out.alignment_requirement = 0;
230 case RAW_FILEINFO_NETWORK_OPEN_INFORMATION:
231 info->network_open_information.out.create_time = name->dos.create_time;
232 info->network_open_information.out.access_time = name->dos.access_time;
233 info->network_open_information.out.write_time = name->dos.write_time;
234 info->network_open_information.out.change_time = name->dos.change_time;
235 info->network_open_information.out.alloc_size = name->dos.alloc_size;
236 info->network_open_information.out.size = name->st.st_size;
237 info->network_open_information.out.attrib = name->dos.attrib;
240 case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION:
241 info->attribute_tag_information.out.attrib = name->dos.attrib;
242 info->attribute_tag_information.out.reparse_tag = 0;
245 case RAW_FILEINFO_SEC_DESC:
246 return pvfs_acl_query(pvfs, req, name, fd, info);
249 return NT_STATUS_INVALID_LEVEL;
253 return info on a pathname
255 NTSTATUS pvfs_qpathinfo(struct ntvfs_module_context *ntvfs,
256 struct smbsrv_request *req, union smb_fileinfo *info)
258 struct pvfs_state *pvfs = ntvfs->private_data;
259 struct pvfs_filename *name;
262 /* resolve the cifs name to a posix name */
263 status = pvfs_resolve_name(pvfs, req, info->generic.in.fname, PVFS_RESOLVE_STREAMS, &name);
264 if (!NT_STATUS_IS_OK(status)) {
268 if (!name->stream_exists) {
269 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
272 status = pvfs_map_fileinfo(pvfs, req, name, info, -1);
278 query info on a open file
280 NTSTATUS pvfs_qfileinfo(struct ntvfs_module_context *ntvfs,
281 struct smbsrv_request *req, union smb_fileinfo *info)
283 struct pvfs_state *pvfs = ntvfs->private_data;
285 struct pvfs_file_handle *h;
288 f = pvfs_find_fd(pvfs, req, info->generic.in.fnum);
290 return NT_STATUS_INVALID_HANDLE;
294 /* update the file information */
295 status = pvfs_resolve_name_fd(pvfs, h->fd, h->name);
296 if (!NT_STATUS_IS_OK(status)) {
300 status = pvfs_map_fileinfo(pvfs, req, h->name, info, h->fd);
302 /* a qfileinfo can fill in a bit more info than a qpathinfo -
303 now modify the levels that need to be fixed up */
304 switch (info->generic.level) {
305 case RAW_FILEINFO_STANDARD_INFO:
306 case RAW_FILEINFO_STANDARD_INFORMATION:
307 if (h->create_options & NTCREATEX_OPTIONS_DELETE_ON_CLOSE) {
308 info->standard_info.out.delete_pending = 1;
309 info->standard_info.out.nlink--;
313 case RAW_FILEINFO_ALL_INFO:
314 case RAW_FILEINFO_ALL_INFORMATION:
315 if (h->create_options & NTCREATEX_OPTIONS_DELETE_ON_CLOSE) {
316 info->all_info.out.delete_pending = 1;
317 info->all_info.out.nlink--;
321 case RAW_FILEINFO_POSITION_INFORMATION:
322 info->position_information.out.position = h->position;
325 case RAW_FILEINFO_ACCESS_INFORMATION:
326 info->access_information.out.access_flags = f->access_mask;
329 case RAW_FILEINFO_MODE_INFORMATION:
330 info->mode_information.out.mode = h->mode;