r23792: convert Samba4 to GPLv3
[kai/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 3 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, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include "includes.h"
23 #include "vfs_posix.h"
24 #include "system/time.h"
25 #include "librpc/gen_ndr/xattr.h"
26
27
28 /*
29   determine what access bits are needed for a call
30 */
31 static uint32_t pvfs_setfileinfo_access(union smb_setfileinfo *info)
32 {
33         uint32_t needed;
34
35         switch (info->generic.level) {
36         case RAW_SFILEINFO_EA_SET:
37                 needed = SEC_FILE_WRITE_EA;
38                 break;
39
40         case RAW_SFILEINFO_DISPOSITION_INFO:
41         case RAW_SFILEINFO_DISPOSITION_INFORMATION:
42                 needed = SEC_STD_DELETE;
43                 break;
44
45         case RAW_SFILEINFO_END_OF_FILE_INFO:
46                 needed = SEC_FILE_WRITE_DATA;
47                 break;
48
49         case RAW_SFILEINFO_POSITION_INFORMATION:
50                 needed = 0;
51                 break;
52
53         case RAW_SFILEINFO_SEC_DESC:
54                 needed = 0;
55                 if (info->set_secdesc.in.secinfo_flags & (SECINFO_OWNER|SECINFO_GROUP)) {
56                         needed |= SEC_STD_WRITE_OWNER;
57                 }
58                 if (info->set_secdesc.in.secinfo_flags & SECINFO_DACL) {
59                         needed |= SEC_STD_WRITE_DAC;
60                 }
61                 if (info->set_secdesc.in.secinfo_flags & SECINFO_SACL) {
62                         needed |= SEC_FLAG_SYSTEM_SECURITY;
63                 }
64                 break;
65
66         default:
67                 needed = SEC_FILE_WRITE_ATTRIBUTE;
68                 break;
69         }
70
71         return needed;
72 }
73
74 /*
75   rename_information level
76 */
77 static NTSTATUS pvfs_setfileinfo_rename(struct pvfs_state *pvfs, 
78                                         struct ntvfs_request *req, 
79                                         struct pvfs_filename *name,
80                                         union smb_setfileinfo *info)
81 {
82         NTSTATUS status;
83         struct pvfs_filename *name2;
84         char *new_name, *p;
85
86         /* renames are only allowed within a directory */
87         if (strchr_m(info->rename_information.in.new_name, '\\')) {
88                 return NT_STATUS_NOT_SUPPORTED;
89         }
90
91         if (name->dos.attrib & FILE_ATTRIBUTE_DIRECTORY) {
92                 /* don't allow this for now */
93                 return NT_STATUS_FILE_IS_A_DIRECTORY;
94         }
95
96         /* don't allow stream renames for now */
97         if (name->stream_name) {
98                 return NT_STATUS_INVALID_PARAMETER;
99         }
100
101         /* w2k3 does not appear to allow relative rename */
102         if (info->rename_information.in.root_fid != 0) {
103                 return NT_STATUS_INVALID_PARAMETER;
104         }
105
106         /* construct the fully qualified windows name for the new file name */
107         new_name = talloc_strdup(req, name->original_name);
108         if (new_name == NULL) {
109                 return NT_STATUS_NO_MEMORY;
110         }
111         p = strrchr_m(new_name, '\\');
112         if (p == NULL) {
113                 return NT_STATUS_OBJECT_NAME_INVALID;
114         }
115         *p = 0;
116
117         new_name = talloc_asprintf(req, "%s\\%s", new_name,
118                                    info->rename_information.in.new_name);
119         if (new_name == NULL) {
120                 return NT_STATUS_NO_MEMORY;
121         }
122
123         /* resolve the new name */
124         status = pvfs_resolve_name(pvfs, name, new_name, 0, &name2);
125         if (!NT_STATUS_IS_OK(status)) {
126                 return status;
127         }
128
129         /* if the destination exists, then check the rename is allowed */
130         if (name2->exists) {
131                 struct odb_lock *lck;
132
133                 if (strcmp(name2->full_name, name->full_name) == 0) {
134                         /* rename to same name is null-op */
135                         return NT_STATUS_OK;
136                 }
137
138                 if (!info->rename_information.in.overwrite) {
139                         return NT_STATUS_OBJECT_NAME_COLLISION;
140                 }
141
142                 status = pvfs_can_delete(pvfs, req, name2, &lck);
143                 if (NT_STATUS_EQUAL(status, NT_STATUS_SHARING_VIOLATION)) {
144                         return NT_STATUS_ACCESS_DENIED;
145                 }
146                 if (!NT_STATUS_IS_OK(status)) {
147                         return status;
148                 }
149         }
150
151         status = pvfs_access_check_parent(pvfs, req, name2, SEC_DIR_ADD_FILE);
152         if (!NT_STATUS_IS_OK(status)) {
153                 return status;
154         }
155
156         status = pvfs_do_rename(pvfs, name, name2->full_name);
157         if (NT_STATUS_IS_OK(status)) {
158                 name->full_name = talloc_steal(name, name2->full_name);
159                 name->original_name = talloc_steal(name, name2->original_name);
160         }
161
162         return NT_STATUS_OK;
163 }
164
165 /*
166   add a single DOS EA
167 */
168 NTSTATUS pvfs_setfileinfo_ea_set(struct pvfs_state *pvfs, 
169                                  struct pvfs_filename *name,
170                                  int fd, uint16_t num_eas,
171                                  struct ea_struct *eas)
172 {
173         struct xattr_DosEAs *ealist;
174         int i, j;
175         NTSTATUS status;
176
177         if (num_eas == 0) {
178                 return NT_STATUS_OK;
179         }
180
181         if (!(pvfs->flags & PVFS_FLAG_XATTR_ENABLE)) {
182                 return NT_STATUS_NOT_SUPPORTED;
183         }
184
185         ealist = talloc(name, struct xattr_DosEAs);
186
187         /* load the current list */
188         status = pvfs_doseas_load(pvfs, name, fd, ealist);
189         if (!NT_STATUS_IS_OK(status)) {
190                 return status;
191         }
192
193         for (j=0;j<num_eas;j++) {
194                 struct ea_struct *ea = &eas[j];
195                 /* see if its already there */
196                 for (i=0;i<ealist->num_eas;i++) {
197                         if (strcasecmp_m(ealist->eas[i].name, ea->name.s) == 0) {
198                                 ealist->eas[i].value = ea->value;
199                                 break;
200                         }
201                 }
202
203                 if (i==ealist->num_eas) {
204                         /* add it */
205                         ealist->eas = talloc_realloc(ealist, ealist->eas, 
206                                                        struct xattr_EA, 
207                                                        ealist->num_eas+1);
208                         if (ealist->eas == NULL) {
209                                 return NT_STATUS_NO_MEMORY;
210                         }
211                         ealist->eas[i].name = ea->name.s;
212                         ealist->eas[i].value = ea->value;
213                         ealist->num_eas++;
214                 }
215         }
216         
217         /* pull out any null EAs */
218         for (i=0;i<ealist->num_eas;i++) {
219                 if (ealist->eas[i].value.length == 0) {
220                         memmove(&ealist->eas[i],
221                                 &ealist->eas[i+1],
222                                 (ealist->num_eas-(i+1)) * sizeof(ealist->eas[i]));
223                         ealist->num_eas--;
224                         i--;
225                 }
226         }
227
228         status = pvfs_doseas_save(pvfs, name, fd, ealist);
229         if (!NT_STATUS_IS_OK(status)) {
230                 return status;
231         }
232
233         notify_trigger(pvfs->notify_context, 
234                        NOTIFY_ACTION_MODIFIED, 
235                        FILE_NOTIFY_CHANGE_EA,
236                        name->full_name);
237
238         name->dos.ea_size = 4;
239         for (i=0;i<ealist->num_eas;i++) {
240                 name->dos.ea_size += 4 + strlen(ealist->eas[i].name)+1 + 
241                         ealist->eas[i].value.length;
242         }
243
244         /* update the ea_size attrib */
245         return pvfs_dosattrib_save(pvfs, name, fd);
246 }
247
248 /*
249   set info on a open file
250 */
251 NTSTATUS pvfs_setfileinfo(struct ntvfs_module_context *ntvfs,
252                           struct ntvfs_request *req, 
253                           union smb_setfileinfo *info)
254 {
255         struct pvfs_state *pvfs = ntvfs->private_data;
256         struct utimbuf unix_times;
257         struct pvfs_file *f;
258         struct pvfs_file_handle *h;
259         struct pvfs_filename newstats;
260         NTSTATUS status;
261         uint32_t access_needed;
262         uint32_t change_mask = 0;
263
264         f = pvfs_find_fd(pvfs, req, info->generic.in.file.ntvfs);
265         if (!f) {
266                 return NT_STATUS_INVALID_HANDLE;
267         }
268
269         h = f->handle;
270
271         access_needed = pvfs_setfileinfo_access(info);
272         if ((f->access_mask & access_needed) != access_needed) {
273                 return NT_STATUS_ACCESS_DENIED;
274         }
275
276         /* update the file information */
277         status = pvfs_resolve_name_fd(pvfs, h->fd, h->name);
278         if (!NT_STATUS_IS_OK(status)) {
279                 return status;
280         }
281
282         /* we take a copy of the current file stats, then update
283            newstats in each of the elements below. At the end we
284            compare, and make any changes needed */
285         newstats = *h->name;
286
287         switch (info->generic.level) {
288         case RAW_SFILEINFO_SETATTR:
289                 if (!null_time(info->setattr.in.write_time)) {
290                         unix_to_nt_time(&newstats.dos.write_time, info->setattr.in.write_time);
291                 }
292                 if (info->setattr.in.attrib != FILE_ATTRIBUTE_NORMAL) {
293                         newstats.dos.attrib = info->setattr.in.attrib;
294                 }
295                 break;
296
297         case RAW_SFILEINFO_SETATTRE:
298         case RAW_SFILEINFO_STANDARD:
299                 if (!null_time(info->setattre.in.create_time)) {
300                         unix_to_nt_time(&newstats.dos.create_time, info->setattre.in.create_time);
301                 }
302                 if (!null_time(info->setattre.in.access_time)) {
303                         unix_to_nt_time(&newstats.dos.access_time, info->setattre.in.access_time);
304                 }
305                 if (!null_time(info->setattre.in.write_time)) {
306                         unix_to_nt_time(&newstats.dos.write_time, info->setattre.in.write_time);
307                 }
308                 break;
309
310         case RAW_SFILEINFO_EA_SET:
311                 return pvfs_setfileinfo_ea_set(pvfs, h->name, h->fd, 
312                                                info->ea_set.in.num_eas,
313                                                info->ea_set.in.eas);
314
315         case RAW_SFILEINFO_BASIC_INFO:
316         case RAW_SFILEINFO_BASIC_INFORMATION:
317                 if (!null_nttime(info->basic_info.in.create_time)) {
318                         newstats.dos.create_time = info->basic_info.in.create_time;
319                 }
320                 if (!null_nttime(info->basic_info.in.access_time)) {
321                         newstats.dos.access_time = info->basic_info.in.access_time;
322                 }
323                 if (!null_nttime(info->basic_info.in.write_time)) {
324                         newstats.dos.write_time = info->basic_info.in.write_time;
325                         newstats.dos.flags |= XATTR_ATTRIB_FLAG_STICKY_WRITE_TIME;
326                         h->sticky_write_time = True;
327                 }
328                 if (!null_nttime(info->basic_info.in.change_time)) {
329                         newstats.dos.change_time = info->basic_info.in.change_time;
330                 }
331                 if (info->basic_info.in.attrib != 0) {
332                         newstats.dos.attrib = info->basic_info.in.attrib;
333                 }
334                 break;
335
336         case RAW_SFILEINFO_DISPOSITION_INFO:
337         case RAW_SFILEINFO_DISPOSITION_INFORMATION:
338                 return pvfs_set_delete_on_close(pvfs, req, f, 
339                                                 info->disposition_info.in.delete_on_close);
340
341         case RAW_SFILEINFO_ALLOCATION_INFO:
342         case RAW_SFILEINFO_ALLOCATION_INFORMATION:
343                 newstats.dos.alloc_size = info->allocation_info.in.alloc_size;
344                 if (newstats.dos.alloc_size < newstats.st.st_size) {
345                         newstats.st.st_size = newstats.dos.alloc_size;
346                 }
347                 newstats.dos.alloc_size = pvfs_round_alloc_size(pvfs, 
348                                                                 newstats.dos.alloc_size);
349                 break;
350
351         case RAW_SFILEINFO_END_OF_FILE_INFO:
352         case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
353                 newstats.st.st_size = info->end_of_file_info.in.size;
354                 break;
355
356         case RAW_SFILEINFO_POSITION_INFORMATION:
357                 h->position = info->position_information.in.position;
358                 break;
359
360         case RAW_SFILEINFO_MODE_INFORMATION:
361                 /* this one is a puzzle */
362                 if (info->mode_information.in.mode != 0 &&
363                     info->mode_information.in.mode != 2 &&
364                     info->mode_information.in.mode != 4 &&
365                     info->mode_information.in.mode != 6) {
366                         return NT_STATUS_INVALID_PARAMETER;
367                 }
368                 h->mode = info->mode_information.in.mode;
369                 break;
370
371         case RAW_SFILEINFO_RENAME_INFORMATION:
372                 return pvfs_setfileinfo_rename(pvfs, req, h->name, 
373                                                info);
374
375         case RAW_SFILEINFO_SEC_DESC:
376                 notify_trigger(pvfs->notify_context, 
377                                NOTIFY_ACTION_MODIFIED, 
378                                FILE_NOTIFY_CHANGE_SECURITY,
379                                h->name->full_name);
380                 return pvfs_acl_set(pvfs, req, h->name, h->fd, f->access_mask, info);
381
382         default:
383                 return NT_STATUS_INVALID_LEVEL;
384         }
385
386         /* possibly change the file size */
387         if (newstats.st.st_size != h->name->st.st_size) {
388                 if (h->name->dos.attrib & FILE_ATTRIBUTE_DIRECTORY) {
389                         return NT_STATUS_FILE_IS_A_DIRECTORY;
390                 }
391                 if (h->name->stream_name) {
392                         status = pvfs_stream_truncate(pvfs, h->name, h->fd, newstats.st.st_size);
393                         if (!NT_STATUS_IS_OK(status)) {
394                                 return status;
395                         }
396                         
397                         change_mask |= FILE_NOTIFY_CHANGE_STREAM_SIZE;
398                 } else {
399                         int ret;
400                         if (f->access_mask & 
401                             (SEC_FILE_WRITE_DATA|SEC_FILE_APPEND_DATA)) {
402                                 ret = ftruncate(h->fd, newstats.st.st_size);
403                         } else {
404                                 ret = truncate(h->name->full_name, newstats.st.st_size);
405                         }
406                         if (ret == -1) {
407                                 return pvfs_map_errno(pvfs, errno);
408                         }
409                         change_mask |= FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_ATTRIBUTES;
410                 }
411         }
412
413         /* possibly change the file timestamps */
414         ZERO_STRUCT(unix_times);
415         if (newstats.dos.create_time != h->name->dos.create_time) {
416                 change_mask |= FILE_NOTIFY_CHANGE_CREATION;
417         }
418         if (newstats.dos.access_time != h->name->dos.access_time) {
419                 unix_times.actime = nt_time_to_unix(newstats.dos.access_time);
420                 change_mask |= FILE_NOTIFY_CHANGE_LAST_ACCESS;
421         }
422         if (newstats.dos.write_time != h->name->dos.write_time) {
423                 unix_times.modtime = nt_time_to_unix(newstats.dos.write_time);
424                 change_mask |= FILE_NOTIFY_CHANGE_LAST_WRITE;
425         }
426         if (unix_times.actime != 0 || unix_times.modtime != 0) {
427                 if (utime(h->name->full_name, &unix_times) == -1) {
428                         return pvfs_map_errno(pvfs, errno);
429                 }
430         }
431
432         /* possibly change the attribute */
433         if (newstats.dos.attrib != h->name->dos.attrib) {
434                 mode_t mode = pvfs_fileperms(pvfs, newstats.dos.attrib);
435                 if (!(h->name->dos.attrib & FILE_ATTRIBUTE_DIRECTORY)) {
436                         if (fchmod(h->fd, mode) == -1) {
437                                 return pvfs_map_errno(pvfs, errno);
438                         }
439                 }
440                 change_mask |= FILE_NOTIFY_CHANGE_ATTRIBUTES;
441         }
442
443         *h->name = newstats;
444
445         notify_trigger(pvfs->notify_context, 
446                        NOTIFY_ACTION_MODIFIED, 
447                        change_mask,
448                        h->name->full_name);
449
450         return pvfs_dosattrib_save(pvfs, h->name, h->fd);
451 }
452
453
454 /*
455   set info on a pathname
456 */
457 NTSTATUS pvfs_setpathinfo(struct ntvfs_module_context *ntvfs,
458                           struct ntvfs_request *req, union smb_setfileinfo *info)
459 {
460         struct pvfs_state *pvfs = ntvfs->private_data;
461         struct pvfs_filename *name;
462         struct pvfs_filename newstats;
463         NTSTATUS status;
464         struct utimbuf unix_times;
465         uint32_t access_needed;
466         uint32_t change_mask = 0;
467
468         /* resolve the cifs name to a posix name */
469         status = pvfs_resolve_name(pvfs, req, info->generic.in.file.path, 
470                                    PVFS_RESOLVE_STREAMS, &name);
471         if (!NT_STATUS_IS_OK(status)) {
472                 return status;
473         }
474
475         if (!name->exists) {
476                 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
477         }
478
479         access_needed = pvfs_setfileinfo_access(info);
480         status = pvfs_access_check_simple(pvfs, req, name, access_needed);
481         if (!NT_STATUS_IS_OK(status)) {
482                 return status;
483         }
484
485         /* we take a copy of the current file stats, then update
486            newstats in each of the elements below. At the end we
487            compare, and make any changes needed */
488         newstats = *name;
489
490         switch (info->generic.level) {
491         case RAW_SFILEINFO_SETATTR:
492                 if (!null_time(info->setattr.in.write_time)) {
493                         unix_to_nt_time(&newstats.dos.write_time, info->setattr.in.write_time);
494                 }
495                 if (info->setattr.in.attrib == 0) {
496                         newstats.dos.attrib = FILE_ATTRIBUTE_NORMAL;
497                 } else if (info->setattr.in.attrib != FILE_ATTRIBUTE_NORMAL) {
498                         newstats.dos.attrib = info->setattr.in.attrib;
499                 }
500                 break;
501
502         case RAW_SFILEINFO_SETATTRE:
503         case RAW_SFILEINFO_STANDARD:
504                 if (!null_time(info->setattre.in.create_time)) {
505                         unix_to_nt_time(&newstats.dos.create_time, info->setattre.in.create_time);
506                 }
507                 if (!null_time(info->setattre.in.access_time)) {
508                         unix_to_nt_time(&newstats.dos.access_time, info->setattre.in.access_time);
509                 }
510                 if (!null_time(info->setattre.in.write_time)) {
511                         unix_to_nt_time(&newstats.dos.write_time, info->setattre.in.write_time);
512                 }
513                 break;
514
515         case RAW_SFILEINFO_EA_SET:
516                 return pvfs_setfileinfo_ea_set(pvfs, name, -1, 
517                                                info->ea_set.in.num_eas,
518                                                info->ea_set.in.eas);
519
520         case RAW_SFILEINFO_BASIC_INFO:
521         case RAW_SFILEINFO_BASIC_INFORMATION:
522                 if (!null_nttime(info->basic_info.in.create_time)) {
523                         newstats.dos.create_time = info->basic_info.in.create_time;
524                 }
525                 if (!null_nttime(info->basic_info.in.access_time)) {
526                         newstats.dos.access_time = info->basic_info.in.access_time;
527                 }
528                 if (!null_nttime(info->basic_info.in.write_time)) {
529                         newstats.dos.write_time = info->basic_info.in.write_time;
530                 }
531                 if (!null_nttime(info->basic_info.in.change_time)) {
532                         newstats.dos.change_time = info->basic_info.in.change_time;
533                 }
534                 if (info->basic_info.in.attrib != 0) {
535                         newstats.dos.attrib = info->basic_info.in.attrib;
536                 }
537                 break;
538
539         case RAW_SFILEINFO_ALLOCATION_INFO:
540         case RAW_SFILEINFO_ALLOCATION_INFORMATION:
541                 if (info->allocation_info.in.alloc_size > newstats.dos.alloc_size) {
542                         /* strange. Increasing the allocation size via setpathinfo 
543                            should be silently ignored */
544                         break;
545                 }
546                 newstats.dos.alloc_size = info->allocation_info.in.alloc_size;
547                 if (newstats.dos.alloc_size < newstats.st.st_size) {
548                         newstats.st.st_size = newstats.dos.alloc_size;
549                 }
550                 newstats.dos.alloc_size = pvfs_round_alloc_size(pvfs, 
551                                                                 newstats.dos.alloc_size);
552                 break;
553
554         case RAW_SFILEINFO_END_OF_FILE_INFO:
555         case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
556                 newstats.st.st_size = info->end_of_file_info.in.size;
557                 break;
558
559         case RAW_SFILEINFO_MODE_INFORMATION:
560                 if (info->mode_information.in.mode != 0 &&
561                     info->mode_information.in.mode != 2 &&
562                     info->mode_information.in.mode != 4 &&
563                     info->mode_information.in.mode != 6) {
564                         return NT_STATUS_INVALID_PARAMETER;
565                 }
566                 return NT_STATUS_OK;
567
568         case RAW_SFILEINFO_RENAME_INFORMATION:
569                 return pvfs_setfileinfo_rename(pvfs, req, name, 
570                                                info);
571
572         case RAW_SFILEINFO_DISPOSITION_INFO:
573         case RAW_SFILEINFO_DISPOSITION_INFORMATION:
574         case RAW_SFILEINFO_POSITION_INFORMATION:
575                 return NT_STATUS_OK;
576
577         default:
578                 return NT_STATUS_INVALID_LEVEL;
579         }
580
581         /* possibly change the file size */
582         if (newstats.st.st_size != name->st.st_size) {
583                 if (name->stream_name) {
584                         status = pvfs_stream_truncate(pvfs, name, -1, newstats.st.st_size);
585                         if (!NT_STATUS_IS_OK(status)) {
586                                 return status;
587                         }
588                 } else if (truncate(name->full_name, newstats.st.st_size) == -1) {
589                         return pvfs_map_errno(pvfs, errno);
590                 }
591                 change_mask |= FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_ATTRIBUTES;
592         }
593
594         /* possibly change the file timestamps */
595         ZERO_STRUCT(unix_times);
596         if (newstats.dos.create_time != name->dos.create_time) {
597                 change_mask |= FILE_NOTIFY_CHANGE_CREATION;
598         }
599         if (newstats.dos.access_time != name->dos.access_time) {
600                 unix_times.actime = nt_time_to_unix(newstats.dos.access_time);
601                 change_mask |= FILE_NOTIFY_CHANGE_LAST_ACCESS;
602         }
603         if (newstats.dos.write_time != name->dos.write_time) {
604                 unix_times.modtime = nt_time_to_unix(newstats.dos.write_time);
605                 change_mask |= FILE_NOTIFY_CHANGE_LAST_WRITE;
606         }
607         if (unix_times.actime != 0 || unix_times.modtime != 0) {
608                 if (utime(name->full_name, &unix_times) == -1) {
609                         return pvfs_map_errno(pvfs, errno);
610                 }
611         }
612
613         /* possibly change the attribute */
614         newstats.dos.attrib |= (name->dos.attrib & FILE_ATTRIBUTE_DIRECTORY);
615         if (newstats.dos.attrib != name->dos.attrib) {
616                 mode_t mode = pvfs_fileperms(pvfs, newstats.dos.attrib);
617                 if (chmod(name->full_name, mode) == -1) {
618                         return pvfs_map_errno(pvfs, errno);
619                 }
620                 change_mask |= FILE_NOTIFY_CHANGE_ATTRIBUTES;
621         }
622
623         *name = newstats;
624
625         if (change_mask != 0) {
626                 notify_trigger(pvfs->notify_context, 
627                                NOTIFY_ACTION_MODIFIED, 
628                                change_mask,
629                                name->full_name);
630         }
631
632         return pvfs_dosattrib_save(pvfs, name, -1);
633 }
634