r2751: this is a new ntvfs design which tries to solve:
[gd/samba-autobuild/.git] / source4 / ntvfs / posix / pvfs_setfileinfo.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    POSIX NTVFS backend - setfileinfo
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   set info on a open file
28 */
29 NTSTATUS pvfs_setfileinfo(struct ntvfs_module_context *ntvfs,
30                           struct smbsrv_request *req, 
31                           union smb_setfileinfo *info)
32 {
33         struct pvfs_state *pvfs = ntvfs->private_data;
34         struct utimbuf unix_times;
35         struct pvfs_file *f;
36
37         f = pvfs_find_fd(pvfs, req, info->generic.file.fnum);
38         if (!f) {
39                 return NT_STATUS_INVALID_HANDLE;
40         }
41
42         switch (info->generic.level) {
43         case RAW_SFILEINFO_END_OF_FILE_INFO:
44         case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
45                 if (ftruncate(f->fd,
46                               info->end_of_file_info.in.size) != 0) {
47                         return pvfs_map_errno(pvfs, errno);
48                 }
49                 break;
50         case RAW_SFILEINFO_SETATTRE:
51                 unix_times.actime = info->setattre.in.access_time;
52                 unix_times.modtime = info->setattre.in.write_time;
53         
54                 if (unix_times.actime == 0 && unix_times.modtime == 0) {
55                         break;
56                 } 
57
58                 /* set modify time = to access time if modify time was 0 */
59                 if (unix_times.actime != 0 && unix_times.modtime == 0) {
60                         unix_times.modtime = unix_times.actime;
61                 }
62
63                 /* Set the date on this file */
64                 if (utime(f->name->full_name, &unix_times) == -1) {
65                         return NT_STATUS_ACCESS_DENIED;
66                 }
67                 break;
68         }
69         return NT_STATUS_OK;
70 }