smbd: use fh_[get|set]_pos() and fh_[get|set]_position_information()
authorRalph Boehme <slow@samba.org>
Mon, 28 Sep 2020 08:32:29 +0000 (10:32 +0200)
committerRalph Boehme <slow@samba.org>
Wed, 16 Dec 2020 09:08:30 +0000 (09:08 +0000)
Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/modules/vfs_commit.c
source3/modules/vfs_default.c
source3/printing/nt_printing.c
source3/smbd/aio.c
source3/smbd/durable.c
source3/smbd/fake_file.c
source3/smbd/fileio.c
source3/smbd/reply.c
source3/smbd/trans2.c

index f5514bc607f399991477f305ca03a303a58932b7..a933a5982e50954fa5e3ffcd195b1ea0f4c9f93d 100644 (file)
@@ -327,7 +327,9 @@ static void commit_pwrite_written(struct tevent_req *subreq)
         * Ok, this is a sync fake. We should make the sync async as well, but
         * I'm too lazy for that right now -- vl
         */
-       commit_ret = commit(state->handle, state->fsp, state->fsp->fh->pos,
+       commit_ret = commit(state->handle,
+                           state->fsp,
+                           fh_get_pos(state->fsp->fh),
                            state->ret);
 
        if (commit_ret == -1) {
index a438ae3cca40237b50711c21bae5d3094f93863e..71b84dd5e07ff76d0310c8af772ea925c1d1be69 100644 (file)
@@ -762,7 +762,7 @@ static ssize_t vfswrap_pread(vfs_handle_struct *handle, files_struct *fsp, void
        if (result == -1 && errno == ESPIPE) {
                /* Maintain the fiction that pipes can be seeked (sought?) on. */
                result = sys_read(fsp_get_io_fd(fsp), data, n);
-               fsp->fh->pos = 0;
+               fh_set_pos(fsp->fh, 0);
        }
 
 #else /* HAVE_PREAD */
index 2e9205ec1b4d7162067ec7341b5cfb6307d41471..0e33c6a6876854e7cd05bef99ab895a7b02e20e5 100644 (file)
@@ -706,7 +706,7 @@ static int get_file_version(files_struct *fsp,
 {
        char    *buf = NULL;
        ssize_t byte_count;
-       off_t in_pos = fsp->fh->pos;
+       off_t in_pos = fh_get_pos(fsp->fh);
 
        buf=(char *)SMB_MALLOC(DOS_HEADER_SIZE);
        if (buf == NULL) {
index f141d67316740b9eecbd8f26b2a61991d6fb9e7b..038487ad4ba7eed7dc4356947641d550b4d7f1c1 100644 (file)
@@ -282,8 +282,9 @@ static void aio_pread_smb1_done(struct tevent_req *req)
        } else {
                outsize = setup_readX_header(outbuf, nread);
 
-               aio_ex->fsp->fh->pos = aio_ex->offset + nread;
-               aio_ex->fsp->fh->position_information = aio_ex->fsp->fh->pos;
+               fh_set_pos(aio_ex->fsp->fh, aio_ex->offset + nread);
+               fh_set_position_information(aio_ex->fsp->fh,
+                                           fh_get_pos(aio_ex->fsp->fh));
 
                DEBUG( 3, ("handle_aio_read_complete file %s max=%d "
                           "nread=%d\n", fsp_str_dbg(fsp),
@@ -609,7 +610,7 @@ static void aio_pwrite_smb1_done(struct tevent_req *req)
                DEBUG(3,("handle_aio_write: %s, num=%d wrote=%d\n",
                         fsp_fnum_dbg(fsp), (int)numtowrite, (int)nwritten));
 
-               aio_ex->fsp->fh->pos = aio_ex->offset + nwritten;
+               fh_set_pos(aio_ex->fsp->fh, aio_ex->offset + nwritten);
        }
 
        show_msg(outbuf);
@@ -783,8 +784,9 @@ static void aio_pread_smb2_done(struct tevent_req *req)
        status = smb2_read_complete(subreq, nread, vfs_aio_state.error);
 
        if (nread > 0) {
-               fsp->fh->pos = aio_ex->offset + nread;
-               fsp->fh->position_information = fsp->fh->pos;
+               fh_set_pos(fsp->fh, aio_ex->offset + nread);
+               fh_set_position_information(fsp->fh,
+                                               fh_get_pos(fsp->fh));
        }
 
        DEBUG(10, ("smb2: scheduled aio_read completed "
index 28bf850c37b61f6c98aada60df9797144f79d0eb..6aeaa202798d9375fd75e5beeee38288de6dd8d7 100644 (file)
@@ -101,7 +101,7 @@ NTSTATUS vfs_default_durable_cookie(struct files_struct *fsp,
        cookie.servicepath = conn->connectpath;
        cookie.base_name = fsp->fsp_name->base_name;
        cookie.initial_allocation_size = fsp->initial_allocation_size;
-       cookie.position_information = fsp->fh->position_information;
+       cookie.position_information = fh_get_position_information(fsp->fh);
        cookie.update_write_time_triggered =
                fsp->fsp_flags.update_write_time_triggered;
        cookie.update_write_time_on_close =
@@ -254,7 +254,7 @@ NTSTATUS vfs_default_durable_disconnect(struct files_struct *fsp,
        cookie.servicepath = conn->connectpath;
        cookie.base_name = fsp_str_dbg(fsp);
        cookie.initial_allocation_size = fsp->initial_allocation_size;
-       cookie.position_information = fsp->fh->position_information;
+       cookie.position_information = fh_get_position_information(fsp->fh);
        cookie.update_write_time_triggered =
                fsp->fsp_flags.update_write_time_triggered;
        cookie.update_write_time_on_close =
@@ -753,7 +753,7 @@ NTSTATUS vfs_default_durable_reconnect(struct connection_struct *conn,
        }
 
        fsp->initial_allocation_size = cookie.initial_allocation_size;
-       fsp->fh->position_information = cookie.position_information;
+       fh_set_position_information(fsp->fh, cookie.position_information);
        fsp->fsp_flags.update_write_time_triggered =
                cookie.update_write_time_triggered;
        fsp->fsp_flags.update_write_time_on_close =
index 705fe0c00ec811688b8f8c9a2df59ccd2a35ae4e..c4c81dd19f9a3f6477e978b6eb28f12f52adb869 100644 (file)
@@ -169,7 +169,7 @@ NTSTATUS open_fake_file(struct smb_request *req, connection_struct *conn,
        fsp->conn = conn;
        fsp_set_fd(fsp, -1);
        fsp->vuid = current_vuid;
-       fsp->fh->pos = -1;
+       fh_set_pos(fsp->fh, -1);
        fsp->fsp_flags.can_lock = false; /* Should this be true ? - No, JRA */
        fsp->access_mask = access_mask;
        status = fsp_set_smb_fname(fsp, smb_fname);
index b6244241ca8f394fe30c95909bb565a5a90fdd33..38f2ab90229601c9b982eb3ead7ef62bd0a2a386 100644 (file)
@@ -31,6 +31,7 @@
 
 ssize_t read_file(files_struct *fsp,char *data,off_t pos,size_t n)
 {
+       off_t new_pos;
        ssize_t ret = 0;
        bool ok;
 
@@ -46,7 +47,7 @@ ssize_t read_file(files_struct *fsp,char *data,off_t pos,size_t n)
                return -1;
        }
 
-       fsp->fh->pos = pos;
+       fh_set_pos(fsp->fh, pos);
 
        if (n > 0) {
                ret = SMB_VFS_PREAD(fsp,data,n,pos);
@@ -59,8 +60,9 @@ ssize_t read_file(files_struct *fsp,char *data,off_t pos,size_t n)
        DEBUG(10,("read_file (%s): pos = %.0f, size = %lu, returned %lu\n",
                  fsp_str_dbg(fsp), (double)pos, (unsigned long)n, (long)ret));
 
-       fsp->fh->pos += ret;
-       fsp->fh->position_information = fsp->fh->pos;
+       new_pos = fh_get_pos(fsp->fh) + ret;
+       fh_set_pos(fsp->fh, new_pos);
+       fh_set_position_information(fsp->fh, new_pos);
 
        return(ret);
 }
@@ -88,7 +90,7 @@ static ssize_t real_write_file(struct smb_request *req,
                return 0;
        }
 
-       fsp->fh->pos = pos;
+       fh_set_pos(fsp->fh, pos);
        if (pos &&
            lp_strict_allocate(SNUM(fsp->conn)) &&
            !fsp->fsp_flags.is_sparse)
@@ -103,7 +105,8 @@ static ssize_t real_write_file(struct smb_request *req,
                  fsp_str_dbg(fsp), (double)pos, (unsigned long)n, (long)ret));
 
        if (ret != -1) {
-               fsp->fh->pos += ret;
+               off_t new_pos = fh_get_pos(fsp->fh) + ret;
+               fh_set_pos(fsp->fh, new_pos);
 
 /* Yes - this is correct - writes don't update this. JRA. */
 /* Found by Samba4 tests. */
index a7bbccbd5b2b5a0ff315dbd5bacc6bbe4e375efc..ba49a792f3cdae23b2a87a3e6441f389d2e62478 100644 (file)
@@ -5612,7 +5612,7 @@ void reply_lseek(struct smb_request *req)
                        break;
                case 1:
                        umode = SEEK_CUR;
-                       res = fsp->fh->pos + startpos;
+                       res = fh_get_pos(fsp->fh) + startpos;
                        break;
                case 2:
                        umode = SEEK_END;
@@ -5648,7 +5648,7 @@ void reply_lseek(struct smb_request *req)
                }
        }
 
-       fsp->fh->pos = res;
+       fh_set_pos(fsp->fh, res);
 
        reply_outbuf(req, 2, 0);
        SIVAL(req->outbuf,smb_vwv0,res);
index fa2255a4d5aa0417d07862cd662923904d73d8d2..e51f2a3f430e0dcb8df8ffd620c9549f58b7fa31 100644 (file)
@@ -5312,7 +5312,7 @@ NTSTATUS smbd_do_qfilepathinfo(connection_struct *conn,
        }
 
        if (fsp) {
-               pos = fsp->fh->position_information;
+               pos = fh_get_position_information(fsp->fh);
        }
 
        if (fsp) {
@@ -6934,7 +6934,7 @@ static NTSTATUS smb_file_position_information(connection_struct *conn,
        DEBUG(10,("smb_file_position_information: Set file position "
                  "information for file %s to %.0f\n", fsp_str_dbg(fsp),
                  (double)position_information));
-       fsp->fh->position_information = position_information;
+       fh_set_position_information(fsp->fh, position_information);
        return NT_STATUS_OK;
 }