*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
+#include "system/filesys.h"
+#include "smbd/smbd.h"
/* Extent preallocation module.
*
#define MODULE "prealloc"
static int module_debug;
-static int preallocate_space(int fd, SMB_OFF_T size)
+static int preallocate_space(int fd, off_t size)
{
- lock_type fl = {0};
int err;
+ lock_type fl = {0};
if (size <= 0) {
return 0;
err = -1;
errno = ENOSYS;
#endif
-
if (err) {
DEBUG(module_debug,
("%s: preallocate failed on fd=%d size=%lld: %s\n",
const char * service,
const char * user)
{
- module_debug = lp_parm_int(SNUM(handle->conn),
+ int ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
+
+ if (ret < 0) {
+ return ret;
+ }
+
+ module_debug = lp_parm_int(SNUM(handle->conn),
MODULE, "debug", 100);
- return SMB_VFS_NEXT_CONNECT(handle, service, user);
+ return 0;
}
-static int prealloc_open(vfs_handle_struct* handle,
- const char * fname,
- files_struct * fsp,
- int flags,
- mode_t mode)
+static int prealloc_openat(struct vfs_handle_struct* handle,
+ const struct files_struct *dirfsp,
+ const struct smb_filename *smb_fname,
+ files_struct *fsp,
+ const struct vfs_open_how *how)
{
int fd;
- off64_t size = 0;
-
+ off_t size = 0;
const char * dot;
char fext[10];
- if (!(flags & (O_CREAT|O_TRUNC))) {
+ if (!(how->flags & (O_CREAT|O_TRUNC))) {
/* Caller is not intending to rewrite the file. Let's not mess
* with the allocation in this case.
*/
}
*fext = '\0';
- dot = strrchr(fname, '.');
+ dot = strrchr(smb_fname->base_name, '.');
if (dot && *++dot) {
if (strlen(dot) < sizeof(fext)) {
+ bool ok;
strncpy(fext, dot, sizeof(fext));
- strnorm(fext, CASE_LOWER);
+ ok = strlower_m(fext);
+ if (!ok);
+ goto normal_open;
+ }
}
}
goto normal_open;
}
- fd = SMB_VFS_NEXT_OPEN(handle, fname, fsp, flags, mode);
+ fd = SMB_VFS_NEXT_OPENAT(handle, dirfsp, smb_fname, fsp, how);
if (fd < 0) {
return fd;
}
- /* Prellocate only if the file is being created or replaced. Note that
+ /* Preallocate only if the file is being created or replaced. Note that
* Samba won't ever pass down O_TRUNC, which is why we have to handle
* truncate calls specially.
*/
- if ((flags & O_CREAT) || (flags & O_TRUNC)) {
- SMB_OFF_T * psize;
+ if ((how->flags & O_CREAT) || (how->flags & O_TRUNC)) {
+ off_t * psize;
- psize = VFS_ADD_FSP_EXTENSION(handle, fsp, SMB_OFF_T);
+ psize = VFS_ADD_FSP_EXTENSION(handle, fsp, off_t, NULL);
if (psize == NULL || *psize == -1) {
return fd;
}
DEBUG(module_debug,
("%s: preallocating %s (fd=%d) to %lld bytes\n",
- MODULE, fname, fd, (long long)size));
+ MODULE, smb_fname_str_dbg(smb_fname), fd,
+ (long long)size));
*psize = size;
if (preallocate_space(fd, *psize) < 0) {
* preallocation.
*/
DEBUG(module_debug, ("%s: skipping preallocation for %s\n",
- MODULE, fname));
- return SMB_VFS_NEXT_OPEN(handle, fname, fsp, flags, mode);
+ MODULE, smb_fname_str_dbg(smb_fname)));
+ return SMB_VFS_NEXT_OPENAT(handle, dirfsp, smb_fname, fsp, how);
}
static int prealloc_ftruncate(vfs_handle_struct * handle,
files_struct * fsp,
- int fd,
- SMB_OFF_T offset)
+ off_t offset)
{
- SMB_OFF_T *psize;
- int ret = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, fd, offset);
+ off_t *psize;
+ int ret = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, offset);
/* Maintain the allocated space even in the face of truncates. */
if ((psize = VFS_FETCH_FSP_EXTENSION(handle, fsp))) {
- preallocate_space(fd, *psize);
+ preallocate_space(fsp_get_io_fd(fsp), *psize);
}
return ret;
}
-static vfs_op_tuple prealloc_op_tuples[] = {
- {SMB_VFS_OP(prealloc_open), SMB_VFS_OP_OPEN, SMB_VFS_LAYER_TRANSPARENT},
- {SMB_VFS_OP(prealloc_ftruncate), SMB_VFS_OP_FTRUNCATE, SMB_VFS_LAYER_TRANSPARENT},
- {SMB_VFS_OP(prealloc_connect), SMB_VFS_OP_CONNECT, SMB_VFS_LAYER_TRANSPARENT},
- {NULL, SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP}
+static struct vfs_fn_pointers prealloc_fns = {
+ .openat_fn = prealloc_openat,
+ .ftruncate_fn = prealloc_ftruncate,
+ .connect_fn = prealloc_connect,
};
-NTSTATUS vfs_prealloc_init(void);
-NTSTATUS vfs_prealloc_init(void)
+static_decl_vfs;
+NTSTATUS vfs_prealloc_init(TALLOC_CTX *ctx)
{
return smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
- MODULE, prealloc_op_tuples);
+ MODULE, &prealloc_fns);
}
-