s3: smbd: Now we've proved dst_dirfsp parameter is always NULL, remove the parameter...
[Samba.git] / source3 / smbd / fd_handle.c
blobeb7fa55e22a81b41c2c1730851412ef35757cd20
1 /*
2 Unix SMB/CIFS implementation.
3 fd_handle structure handling
4 Copyright (C) Ralph Boehme 2020
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "includes.h"
21 #include "fd_handle.h"
23 struct fd_handle {
24 size_t ref_count;
25 int fd;
26 uint64_t position_information;
27 off_t pos;
29 * NT Create options, but we only look at
30 * NTCREATEX_FLAG_DENY_DOS and
31 * NTCREATEX_FLAG_DENY_FCB.
33 uint32_t private_options;
34 uint64_t gen_id;
37 static int fd_handle_destructor(struct fd_handle *fh)
39 SMB_ASSERT((fh->fd == -1) || (fh->fd == AT_FDCWD));
40 return 0;
43 struct fd_handle *fd_handle_create(TALLOC_CTX *mem_ctx)
45 struct fd_handle *fh = NULL;
47 fh = talloc_zero(mem_ctx, struct fd_handle);
48 if (fh == NULL) {
49 return NULL;
51 fh->fd = -1;
53 talloc_set_destructor(fh, fd_handle_destructor);
55 return fh;
58 size_t fh_get_refcount(struct fd_handle *fh)
60 return fh->ref_count;
63 void fh_set_refcount(struct fd_handle *fh, size_t ref_count)
65 fh->ref_count = ref_count;
68 uint64_t fh_get_position_information(struct fd_handle *fh)
70 return fh->position_information;
73 void fh_set_position_information(struct fd_handle *fh, uint64_t posinfo)
75 fh->position_information = posinfo;
78 off_t fh_get_pos(struct fd_handle *fh)
80 return fh->pos;
83 void fh_set_pos(struct fd_handle *fh, off_t pos)
85 fh->pos = pos;
88 uint32_t fh_get_private_options(struct fd_handle *fh)
90 return fh->private_options;
93 void fh_set_private_options(struct fd_handle *fh, uint32_t private_options)
95 fh->private_options = private_options;
98 uint64_t fh_get_gen_id(struct fd_handle *fh)
100 return fh->gen_id;
103 void fh_set_gen_id(struct fd_handle *fh, uint64_t gen_id)
105 fh->gen_id = gen_id;
108 /****************************************************************************
109 Helper functions for working with fsp->fh->fd
110 ****************************************************************************/
112 int fsp_get_io_fd(const struct files_struct *fsp)
114 if (fsp->fsp_flags.is_pathref) {
115 DBG_ERR("fsp [%s] is a path referencing fsp\n",
116 fsp_str_dbg(fsp));
117 #ifdef DEVELOPER
118 smb_panic("fsp is a pathref");
119 #endif
120 return -1;
123 return fsp->fh->fd;
126 int fsp_get_pathref_fd(const struct files_struct *fsp)
128 return fsp->fh->fd;
131 void fsp_set_fd(struct files_struct *fsp, int fd)
134 * Deliberately allow setting an fd if the existing fd is the
135 * same. This happens if a VFS module assigns the fd to
136 * fsp->fh->fd in its openat VFS function. The canonical place
137 * where the assignment is done is in fd_open(), but some VFS
138 * modules do it anyway.
141 SMB_ASSERT(fsp->fh->fd == -1 ||
142 fsp->fh->fd == fd ||
143 fd == -1 ||
144 fd == AT_FDCWD);
146 fsp->fh->fd = fd;