2 Unix SMB/CIFS implementation.
4 POSIX NTVFS backend - setfileinfo
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.
23 #include "include/includes.h"
24 #include "vfs_posix.h"
27 set info on a open file
29 NTSTATUS pvfs_setfileinfo(struct ntvfs_module_context *ntvfs,
30 struct smbsrv_request *req,
31 union smb_setfileinfo *info)
33 struct pvfs_state *pvfs = ntvfs->private_data;
34 struct utimbuf unix_times;
36 uint32_t create_options;
38 f = pvfs_find_fd(pvfs, req, info->generic.file.fnum);
40 return NT_STATUS_INVALID_HANDLE;
43 switch (info->generic.level) {
44 case RAW_SFILEINFO_END_OF_FILE_INFO:
45 case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
47 info->end_of_file_info.in.size) == -1) {
48 return pvfs_map_errno(pvfs, errno);
52 case RAW_SFILEINFO_SETATTRE:
53 unix_times.actime = info->setattre.in.access_time;
54 unix_times.modtime = info->setattre.in.write_time;
56 if (unix_times.actime == 0 && unix_times.modtime == 0) {
60 /* set modify time = to access time if modify time was 0 */
61 if (unix_times.actime != 0 && unix_times.modtime == 0) {
62 unix_times.modtime = unix_times.actime;
65 /* Set the date on this file */
66 if (utime(f->name->full_name, &unix_times) == -1) {
67 return pvfs_map_errno(pvfs, errno);
71 case RAW_SFILEINFO_DISPOSITION_INFO:
72 case RAW_SFILEINFO_DISPOSITION_INFORMATION:
73 if (!(f->access_mask & STD_RIGHT_DELETE_ACCESS)) {
74 return NT_STATUS_ACCESS_DENIED;
76 create_options = f->create_options;
77 if (info->disposition_info.in.delete_on_close) {
78 create_options |= NTCREATEX_OPTIONS_DELETE_ON_CLOSE;
80 create_options &= ~NTCREATEX_OPTIONS_DELETE_ON_CLOSE;
82 return pvfs_change_create_options(pvfs, req, f, create_options);
84 case RAW_SFILEINFO_POSITION_INFORMATION:
85 f->position = info->position_information.in.position;
94 set info on a pathname
96 NTSTATUS pvfs_setpathinfo(struct ntvfs_module_context *ntvfs,
97 struct smbsrv_request *req, union smb_setfileinfo *info)
99 struct pvfs_state *pvfs = ntvfs->private_data;
100 struct pvfs_filename *name;
102 struct utimbuf unix_times;
104 /* resolve the cifs name to a posix name */
105 status = pvfs_resolve_name(pvfs, req, info->generic.file.fname,
106 PVFS_RESOLVE_NO_WILDCARD, &name);
107 if (!NT_STATUS_IS_OK(status)) {
112 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
115 switch (info->generic.level) {
116 case RAW_SFILEINFO_END_OF_FILE_INFO:
117 case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
118 if (truncate(name->full_name,
119 info->end_of_file_info.in.size) == -1) {
120 return pvfs_map_errno(pvfs, errno);
124 case RAW_SFILEINFO_SETATTRE:
125 unix_times.actime = info->setattre.in.access_time;
126 unix_times.modtime = info->setattre.in.write_time;
128 if (unix_times.actime == 0 && unix_times.modtime == 0) {
132 /* set modify time = to access time if modify time was 0 */
133 if (unix_times.actime != 0 && unix_times.modtime == 0) {
134 unix_times.modtime = unix_times.actime;
137 /* Set the date on this file */
138 if (utime(name->full_name, &unix_times) == -1) {
139 return NT_STATUS_ACCESS_DENIED;
143 case RAW_SFILEINFO_DISPOSITION_INFO:
144 case RAW_SFILEINFO_DISPOSITION_INFORMATION:
145 return NT_STATUS_INVALID_PARAMETER;
147 case RAW_SFILEINFO_POSITION_INFORMATION:
151 return NT_STATUS_INVALID_LEVEL;