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 3 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, see <http://www.gnu.org/licenses/>.
23 #include "vfs_posix.h"
24 #include "librpc/gen_ndr/security.h"
30 NTSTATUS pvfs_write(struct ntvfs_module_context *ntvfs,
31 struct ntvfs_request *req, union smb_write *wr)
33 struct pvfs_state *pvfs = ntvfs->private_data;
38 if (wr->generic.level != RAW_WRITE_WRITEX) {
39 return ntvfs_map_write(ntvfs, req, wr);
42 f = pvfs_find_fd(pvfs, req, wr->writex.in.file.ntvfs);
44 return NT_STATUS_INVALID_HANDLE;
47 if (f->handle->fd == -1) {
48 return NT_STATUS_FILE_IS_A_DIRECTORY;
51 if (!(f->access_mask & (SEC_FILE_WRITE_DATA | SEC_FILE_APPEND_DATA))) {
52 return NT_STATUS_ACCESS_DENIED;
55 status = pvfs_check_lock(pvfs, f, req->smbpid,
59 NT_STATUS_NOT_OK_RETURN(status);
61 if (f->handle->name->stream_name) {
62 ret = pvfs_stream_write(pvfs,
66 wr->writex.in.offset);
69 /* possibly try an aio write */
70 if ((req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC) &&
71 (pvfs->flags & PVFS_FLAG_LINUX_AIO)) {
72 status = pvfs_aio_pwrite(req, wr, f);
73 if (NT_STATUS_IS_OK(status)) {
78 ret = pwrite(f->handle->fd,
81 wr->writex.in.offset);
85 return NT_STATUS_INVALID_PARAMETER;
87 return pvfs_map_errno(pvfs, errno);
90 f->handle->seek_offset = wr->writex.in.offset + ret;
92 wr->writex.out.nwritten = ret;
93 wr->writex.out.remaining = 0; /* should fill this in? */