2 Unix SMB/CIFS implementation.
4 POSIX NTVFS backend - write
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.
24 #include "vfs_posix.h"
25 #include "librpc/gen_ndr/security.h"
31 NTSTATUS pvfs_write(struct ntvfs_module_context *ntvfs,
32 struct ntvfs_request *req, union smb_write *wr)
34 struct pvfs_state *pvfs = ntvfs->private_data;
39 if (wr->generic.level != RAW_WRITE_WRITEX) {
40 return ntvfs_map_write(ntvfs, req, wr);
43 f = pvfs_find_fd(pvfs, req, wr->writex.in.file.fnum);
45 return NT_STATUS_INVALID_HANDLE;
48 if (f->handle->fd == -1) {
49 return NT_STATUS_FILE_IS_A_DIRECTORY;
52 if (!(f->access_mask & (SEC_FILE_WRITE_DATA | SEC_FILE_APPEND_DATA))) {
53 return NT_STATUS_ACCESS_VIOLATION;
56 status = pvfs_check_lock(pvfs, f, req->smbpid,
60 if (!NT_STATUS_IS_OK(status)) {
64 if (f->handle->name->stream_name) {
65 ret = pvfs_stream_write(pvfs,
69 wr->writex.in.offset);
71 ret = pwrite(f->handle->fd,
74 wr->writex.in.offset);
78 return NT_STATUS_INVALID_PARAMETER;
80 return pvfs_map_errno(pvfs, errno);
83 f->handle->seek_offset = wr->writex.in.offset + ret;
85 wr->writex.out.nwritten = ret;
86 wr->writex.out.remaining = 0; /* should fill this in? */