/* Twrite - write to a file. */ Npfcall* diod_write (Npfid *fid, u64 offset, u32 count, u8 *data, Npreq *req) { Fid *f = fid->aux; Npfcall *ret; ssize_t n; if (!f->ioctx) { msg ("diod_write: fid is not open"); np_uerror (EBADF); goto error; } if ((f->flags & DIOD_FID_FLAGS_ROFS)) { np_uerror (EROFS); goto error_quiet; } if ((n = ioctx_pwrite (f->ioctx, data, count, offset)) < 0) { np_uerror (errno); goto error_quiet; } if (!(ret = np_create_rwrite (n))) { np_uerror (ENOMEM); goto error; } return ret; error: errn (np_rerror (), "diod_write %s@%s:%s", fid->user->uname, np_conn_get_client_id (fid->conn), path_s (f->path)); error_quiet: return NULL; }
/* Twrite - write to a file. */ Npfcall* diod_write (Npfid *fid, u64 offset, u32 count, u8 *data, Npreq *req) { Fid *f = fid->aux; Npfcall *ret; ssize_t n; if ((f->xflags & XFLAGS_RO)) { np_uerror (EROFS); goto error_quiet; } if ((n = pwrite (f->fd, data, count, offset)) < 0) { np_uerror (errno); goto error_quiet; } if (!(ret = np_create_rwrite (n))) { np_uerror (ENOMEM); goto error; } return ret; error: errn (np_rerror (), "diod_write %s@%s:%s", fid->user->uname, np_conn_get_client_id (fid->conn), f->path); error_quiet: return NULL; }
Npfcall * np_write(Npreq *req, Npfcall *tc) { int n; Npconn *conn = req->conn; Npfid *fid = req->fid; Npfcall *rc = NULL; if (!fid) { np_uerror (EIO); goto done; } if (fid->type & P9_QTAUTH) { if (conn->srv->auth) { n = conn->srv->auth->write(fid, tc->u.twrite.offset, tc->u.twrite.count, tc->u.twrite.data); if (n >= 0) if (!(rc = np_create_rwrite(n))) np_uerror(ENOMEM); goto done; } else { np_uerror(EIO); goto done; } } if ((fid->type & P9_QTDIR)) { np_uerror(EPERM); goto done; } if (tc->u.twrite.count + P9_IOHDRSZ > conn->msize) { np_uerror(EIO); goto done; } if (fid->type & P9_QTTMP) { rc = np_ctl_write(fid, tc->u.twrite.offset, tc->u.twrite.count, tc->u.twrite.data, req); } else { if (np_setfsid (req, fid->user, -1) < 0) goto done; if (!conn->srv->write) { np_uerror (ENOSYS); goto done; } rc = (*conn->srv->write)(fid, tc->u.twrite.offset, tc->u.twrite.count, tc->u.twrite.data, req); } done: return rc; }
static void test_rwrite (void) { Npfcall *fc, *fc2; if (!(fc = np_create_rwrite (1))) msg_exit ("out of memory in %s", __FUNCTION__); fc2 = _rcv_buf (fc, P9_RWRITE, __FUNCTION__); assert (fc->u.rwrite.count == fc2->u.rwrite.count); free (fc); free (fc2); }
/* Write from remote client */ static Npfcall* openssl_remote_write(Npfid *afid, u64 offset, u32 count, u8 *data) { struct openssl_session_auth_context* ctx; int res; ctx = (struct openssl_session_auth_context*)afid->aux; if ( ctx == NULL ) return np_create_rerror("No session context",EINVAL,1); /* We do not support offsets in our protocol */ if ( offset != 0 ) return np_create_rerror("No offset supported",EINVAL,1); res = write_to_buffer(&ctx->input_buffer, data, count); if ( res != count ) return np_create_rerror("Invalid count written",EINVAL,1); return np_create_rwrite(res); }