r2751: this is a new ntvfs design which tries to solve:
[ira/wip.git] / source4 / ntvfs / posix / pvfs_qfileinfo.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    POSIX NTVFS backend - read
5
6    Copyright (C) Andrew Tridgell 2004
7
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.
12    
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.
17    
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.
21 */
22
23 #include "include/includes.h"
24 #include "vfs_posix.h"
25
26
27 /*
28   approximately map a struct pvfs_filename to a generic fileinfo struct
29 */
30 static NTSTATUS pvfs_map_fileinfo(struct pvfs_state *pvfs, TALLOC_CTX *mem_ctx,
31                                   struct pvfs_filename *name, union smb_fileinfo *info)
32 {
33         info->generic.out.create_time = name->dos.create_time;
34         info->generic.out.access_time = name->dos.access_time;
35         info->generic.out.write_time = name->dos.write_time;
36         info->generic.out.change_time = name->dos.change_time;
37
38         info->generic.out.alloc_size = name->dos.alloc_size;
39         info->generic.out.size = name->st.st_size;
40         info->generic.out.attrib = name->dos.attrib;
41         info->generic.out.nlink = name->dos.nlink;
42         info->generic.out.directory = (name->dos.attrib&FILE_ATTRIBUTE_DIRECTORY)?1:0;
43         info->generic.out.file_id = name->dos.file_id;
44
45         /* REWRITE: TODO stuff in here */
46         info->generic.out.delete_pending = 0;
47         info->generic.out.ea_size = 0;
48         info->generic.out.num_eas = 0;
49         info->generic.out.fname.s = name->original_name;
50         info->generic.out.alt_fname.s = pvfs_short_name(pvfs, name);
51         info->generic.out.compressed_size = name->st.st_size;
52         info->generic.out.format = 0;
53         info->generic.out.unit_shift = 0;
54         info->generic.out.chunk_shift = 0;
55         info->generic.out.cluster_shift = 0;
56         
57         info->generic.out.access_flags = 0;
58         info->generic.out.position = 0;
59         info->generic.out.mode = 0;
60         info->generic.out.alignment_requirement = 0;
61         info->generic.out.reparse_tag = 0;
62
63         /* setup a single data stream */
64         info->generic.out.num_streams = 1;
65         info->generic.out.streams = talloc_array_p(mem_ctx, 
66                                                    struct stream_struct,
67                                                    info->generic.out.num_streams);
68         if (!info->generic.out.streams) {
69                 return NT_STATUS_NO_MEMORY;
70         }
71         info->generic.out.streams[0].size = name->st.st_size;
72         info->generic.out.streams[0].alloc_size = name->st.st_size;
73         info->generic.out.streams[0].stream_name.s = talloc_strdup(mem_ctx, "::$DATA");
74
75         return NT_STATUS_OK;
76 }
77
78 /*
79   return info on a pathname
80 */
81 NTSTATUS pvfs_qpathinfo(struct ntvfs_module_context *ntvfs,
82                         struct smbsrv_request *req, union smb_fileinfo *info)
83 {
84         struct pvfs_state *pvfs = ntvfs->private_data;
85         struct pvfs_filename *name;
86         NTSTATUS status;
87
88         if (info->generic.level != RAW_FILEINFO_GENERIC) {
89                 return ntvfs_map_qpathinfo(req, info, ntvfs);
90         }
91         
92         /* resolve the cifs name to a posix name */
93         status = pvfs_resolve_name(pvfs, req, info->generic.in.fname, PVFS_RESOLVE_NO_WILDCARD, &name);
94         if (!NT_STATUS_IS_OK(status)) {
95                 return status;
96         }
97
98         if (!name->exists) {
99                 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
100         }
101
102         return pvfs_map_fileinfo(pvfs, req, name, info);
103 }
104
105 /*
106   query info on a open file
107 */
108 NTSTATUS pvfs_qfileinfo(struct ntvfs_module_context *ntvfs,
109                         struct smbsrv_request *req, union smb_fileinfo *info)
110 {
111         struct pvfs_state *pvfs = ntvfs->private_data;
112         struct pvfs_file *f;
113         NTSTATUS status;
114
115         if (info->generic.level != RAW_FILEINFO_GENERIC) {
116                 return ntvfs_map_qfileinfo(req, info, ntvfs);
117         }
118
119         f = pvfs_find_fd(pvfs, req, info->generic.in.fnum);
120         if (!f) {
121                 return NT_STATUS_INVALID_HANDLE;
122         }
123
124         /* update the file information */
125         status = pvfs_resolve_name_fd(pvfs, f->fd, f->name);
126         if (!NT_STATUS_IS_OK(status)) {
127                 return status;
128         }
129         
130         return pvfs_map_fileinfo(pvfs, req, f->name, info);
131 }