r2916: longhorn client doesn't bother setting the directory bit in ntcreatex
[samba.git] / source / ntvfs / posix / pvfs_write.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    POSIX NTVFS backend - write
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   write to a file
29 */
30 NTSTATUS pvfs_write(struct ntvfs_module_context *ntvfs,
31                     struct smbsrv_request *req, union smb_write *wr)
32 {
33         struct pvfs_state *pvfs = ntvfs->private_data;
34         ssize_t ret;
35         struct pvfs_file *f;
36
37         switch (wr->generic.level) {
38         case RAW_WRITE_WRITEX:
39                 f = pvfs_find_fd(pvfs, req, wr->writex.in.fnum);
40                 if (!f) {
41                         return NT_STATUS_INVALID_HANDLE;
42                 }
43                 ret = pwrite(f->fd, 
44                              wr->writex.in.data, 
45                              wr->writex.in.count,
46                              wr->writex.in.offset);
47                 if (ret == -1) {
48                         return map_nt_error_from_unix(errno);
49                 }
50                 
51                 wr->writex.out.nwritten = ret;
52                 wr->writex.out.remaining = 0; /* should fill this in? */
53
54                 return NT_STATUS_OK;
55
56         case RAW_WRITE_WRITE:
57                 f = pvfs_find_fd(pvfs, req, wr->write.in.fnum);
58                 if (!f) {
59                         return NT_STATUS_INVALID_HANDLE;
60                 }
61                 if (wr->write.in.count == 0) {
62                         /* a truncate! */
63                         ret = ftruncate(f->fd, wr->write.in.offset);
64                 } else {
65                         ret = pwrite(f->fd,
66                                      wr->write.in.data, 
67                                      wr->write.in.count,
68                                      wr->write.in.offset);
69                 }
70                 if (ret == -1) {
71                         return pvfs_map_errno(pvfs, errno);
72                 }
73                 
74                 wr->write.out.nwritten = ret;
75
76                 return NT_STATUS_OK;
77         }
78
79         return NT_STATUS_NOT_SUPPORTED;
80 }