Example #1
0
static ssize_t real_write_file(files_struct *fsp,const char *data, SMB_OFF_T pos, size_t n)
{
    ssize_t ret;

    if (pos == -1) {
        ret = vfs_write_data(fsp, data, n);
    } else {
        fsp->fh->pos = pos;
        if (pos && lp_strict_allocate(SNUM(fsp->conn))) {
            if (vfs_fill_sparse(fsp, pos) == -1) {
                return -1;
            }
        }
        ret = vfs_pwrite_data(fsp, data, n, pos);
    }

    DEBUG(10,("real_write_file (%s): pos = %.0f, size = %lu, returned %ld\n",
              fsp->fsp_name, (double)pos, (unsigned long)n, (long)ret ));

    if (ret != -1) {
        fsp->fh->pos += ret;

        /*
         * It turns out that setting the last write time from a Windows
         * client stops any subsequent writes from updating the write time.
         * Doing this after the write gives a race condition here where
         * a stat may see the changed write time before we reset it here,
         * but it's cheaper than having to store the write time in shared
         * memory and look it up using dev/inode across all running smbd's.
         * The 99% solution will hopefully be good enough in this case. JRA.
         */

        if (fsp->pending_modtime) {
            set_filetime(fsp->conn, fsp->fsp_name, fsp->pending_modtime);

            /* If we didn't get the "set modtime" call ourselves, we must
               store the last write time to restore on close. JRA. */
            if (!fsp->pending_modtime_owner) {
                fsp->last_write_time = time(NULL);
            }
        }

        /* Yes - this is correct - writes don't update this. JRA. */
        /* Found by Samba4 tests. */
#if 0
        fsp->position_information = fsp->pos;
#endif
    }

    return ret;
}
Example #2
0
ssize_t write_file(files_struct * fsp, char *data, SMB_OFF_T pos, size_t n)
{
	if (!fsp->can_write)
	{
		errno = EPERM;
		return (0);
	}

	if (!fsp->modified)
	{
		fsp->modified = True;
	}

	if ((pos != -1) && (seek_file(fsp, pos) == -1))
		return -1;

	return vfs_write_data(fsp, data, n);
}
Example #3
0
static ssize_t real_write_file(struct smb_request *req,
				files_struct *fsp,
				const char *data,
				SMB_OFF_T pos,
				size_t n)
{
	ssize_t ret;

        if (pos == -1) {
                ret = vfs_write_data(req, fsp, data, n);
        } else {
		fsp->fh->pos = pos;
		if (pos && lp_strict_allocate(SNUM(fsp->conn) &&
				!fsp->is_sparse)) {
			if (vfs_fill_sparse(fsp, pos) == -1) {
				return -1;
			}
		}
                ret = vfs_pwrite_data(req, fsp, data, n, pos);
	}

	DEBUG(10,("real_write_file (%s): pos = %.0f, size = %lu, returned %ld\n",
		  fsp_str_dbg(fsp), (double)pos, (unsigned long)n, (long)ret));

	if (ret != -1) {
		fsp->fh->pos += ret;

/* Yes - this is correct - writes don't update this. JRA. */
/* Found by Samba4 tests. */
#if 0
		fsp->position_information = fsp->pos;
#endif
	}

	return ret;
}