r2436: the second big lump of posix vfs code.
[bbaumbach/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 smbsrv_request *req, 
30                           union smb_setfileinfo *info)
31 {
32         struct pvfs_private *pvfs = req->tcon->ntvfs_private;
33         struct utimbuf unix_times;
34         struct pvfs_file *f;
35
36         f = pvfs_find_fd(pvfs, info->generic.file.fnum);
37         if (!f) {
38                 return NT_STATUS_INVALID_HANDLE;
39         }
40
41         switch (info->generic.level) {
42         case RAW_SFILEINFO_END_OF_FILE_INFO:
43         case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
44                 if (ftruncate(f->fd,
45                               info->end_of_file_info.in.size) != 0) {
46                         return pvfs_map_errno(pvfs, errno);
47                 }
48                 break;
49         case RAW_SFILEINFO_SETATTRE:
50                 unix_times.actime = info->setattre.in.access_time;
51                 unix_times.modtime = info->setattre.in.write_time;
52         
53                 if (unix_times.actime == 0 && unix_times.modtime == 0) {
54                         break;
55                 } 
56
57                 /* set modify time = to access time if modify time was 0 */
58                 if (unix_times.actime != 0 && unix_times.modtime == 0) {
59                         unix_times.modtime = unix_times.actime;
60                 }
61
62                 /* Set the date on this file */
63                 if (utime(f->name->full_name, &unix_times) == -1) {
64                         return NT_STATUS_ACCESS_DENIED;
65                 }
66                 break;
67         }
68         return NT_STATUS_OK;
69 }