r24120: add a file_id_create() hook into the VFS layer
authorStefan Metzmacher <metze@samba.org>
Thu, 2 Aug 2007 08:53:24 +0000 (08:53 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:29:08 +0000 (12:29 -0500)
it's needed for some cluster filesystems to
overload this function.

metze

source/include/vfs.h
source/include/vfs_macros.h
source/lib/file_id.c
source/modules/vfs_default.c
source/printing/printfsp.c
source/smbd/close.c
source/smbd/filename.c
source/smbd/open.c
source/smbd/reply.c
source/smbd/trans2.c

index b136750e7c4d9761f65fe84c1c626ef1819ed8b6..768c9fbcabb0b4af6c9bce4d5f22ab6b194fb626 100644 (file)
@@ -71,6 +71,7 @@
 /* Changed to version21 to add chflags operation -- jpeach */
 /* Changed to version22 to add lchown operation -- jra */
 /* Leave at 22 - not yet released. But change set_nt_acl to return an NTSTATUS. jra. */
+/* Leave at 22 - not yet released. Add file_id_create operation. --metze */
 #define SMB_VFS_INTERFACE_VERSION 22
 
 
@@ -162,6 +163,7 @@ typedef enum _vfs_op_type {
        SMB_VFS_OP_REALPATH,
        SMB_VFS_OP_NOTIFY_WATCH,
        SMB_VFS_OP_CHFLAGS,
+       SMB_VFS_OP_FILE_ID_CREATE,
 
        /* NT ACL operations. */
 
@@ -295,7 +297,8 @@ struct vfs_ops {
                                                          struct notify_event *ev),
                                         void *private_data, void *handle_p);
                int (*chflags)(struct vfs_handle_struct *handle, const char *path, uint flags);
-               
+               struct file_id (*file_id_create)(struct vfs_handle_struct *handle, SMB_DEV_T dev, SMB_INO_T inode);
+
                /* NT ACL operations. */
                
                size_t (*fget_nt_acl)(struct vfs_handle_struct *handle, struct files_struct *fsp, int fd,  uint32 security_info, struct security_descriptor **ppdesc);
@@ -414,6 +417,7 @@ struct vfs_ops {
                struct vfs_handle_struct *realpath;
                struct vfs_handle_struct *notify_watch;
                struct vfs_handle_struct *chflags;
+               struct vfs_handle_struct *file_id_create;
 
                /* NT ACL operations. */
 
index 9957b585de607e66718c20bd6c7f09aaa3caa28d..ac22ff5204886cedb4292d4f248417d17c4b106a 100644 (file)
@@ -80,6 +80,7 @@
 #define SMB_VFS_REALPATH(conn, path, resolved_path) ((conn)->vfs.ops.realpath((conn)->vfs.handles.realpath, (path), (resolved_path)))
 #define SMB_VFS_NOTIFY_WATCH(conn, ctx, e, callback, private_data, handle_p) ((conn)->vfs.ops.notify_watch((conn)->vfs.handles.notify_watch, (ctx), (e), (callback), (private_data), (handle_p)))
 #define SMB_VFS_CHFLAGS(conn, path, flags) ((conn)->vfs.ops.chflags((conn)->vfs.handles.chflags, (path), (flags)))
+#define SMB_VFS_FILE_ID_CREATE(conn, dev, inode) ((conn)->vfs.ops.file_id_create((conn)->vfs.handles.file_id_create, (dev), (inode)))
 
 /* NT ACL operations. */
 #define SMB_VFS_FGET_NT_ACL(fsp, fd, security_info, ppdesc) ((fsp)->conn->vfs.ops.fget_nt_acl((fsp)->conn->vfs.handles.fget_nt_acl, (fsp), (fd), (security_info), (ppdesc)))
 #define SMB_VFS_OPAQUE_REALPATH(conn, path, resolved_path) ((conn)->vfs_opaque.ops.realpath((conn)->vfs_opaque.handles.realpath, (path), (resolved_path)))
 #define SMB_VFS_OPAQUE_NOTIFY_WATCH(conn, ctx, e, callback, private_data, handle_p) ((conn)->vfs_opaque.ops.notify_watch((conn)->vfs_opaque.handles.notify_watch, (ctx), (e), (callback), (private_data), (handle_p)))
 #define SMB_VFS_OPAQUE_CHFLAGS(conn, path, flags) ((conn)->vfs_opaque.ops.chflags((conn)->vfs_opaque.handles.chflags, (path), (flags)))
+#define SMB_VFS_OPAQUE_FILE_ID_CREATE(conn, dev, inode) ((conn)->vfs.ops_opaque.file_id_create((conn)->vfs_opaque.handles.file_id_create, (dev), (inode)))
 
 /* NT ACL operations. */
 #define SMB_VFS_OPAQUE_FGET_NT_ACL(fsp, fd, security_info, ppdesc) ((fsp)->conn->vfs_opaque.ops.fget_nt_acl((fsp)->conn->vfs_opaque.handles.fget_nt_acl, (fsp), (fd), (security_info), (ppdesc)))
 #define SMB_VFS_NEXT_REALPATH(handle, path, resolved_path) ((handle)->vfs_next.ops.realpath((handle)->vfs_next.handles.realpath, (path), (resolved_path)))
 #define SMB_VFS_NEXT_NOTIFY_WATCH(conn, ctx, e, callback, private_data, handle_p) ((conn)->vfs_next.ops.notify_watch((conn)->vfs_next.handles.notify_watch, (ctx), (e), (callback), (private_data), (handle_p)))
 #define SMB_VFS_NEXT_CHFLAGS(handle, path, flags) ((handle)->vfs_next.ops.chflags((handle)->vfs_next.handles.chflags, (path), (flags)))
+#define SMB_VFS_NEXT_FILE_ID_CREATE(handle, dev, inode) ((handle)->vfs_next.ops.file_id_create((handle)->vfs_next.handles.file_id_create, (dev), (inode)))
 
 /* NT ACL operations. */
 #define SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, fd, security_info, ppdesc) ((handle)->vfs_next.ops.fget_nt_acl((handle)->vfs_next.handles.fget_nt_acl, (fsp), (fd), (security_info), (ppdesc)))
index 11263af08939be78105870f500f4158cd61142fe..a92cca08fa5f06da5d9d51c292bf9d528d35dab9 100644 (file)
@@ -25,7 +25,7 @@
   return a file_id which gives a unique ID for a file given the device and
   inode numbers
  */
-struct file_id file_id_create(SMB_DEV_T dev, SMB_INO_T inode)
+struct file_id file_id_create_dev(SMB_DEV_T dev, SMB_INO_T inode)
 {
        struct file_id key;
        /* the ZERO_STRUCT ensures padding doesn't break using the key as a
@@ -39,12 +39,11 @@ struct file_id file_id_create(SMB_DEV_T dev, SMB_INO_T inode)
 /*
   generate a file_id from a stat structure
  */
-struct file_id file_id_sbuf(const SMB_STRUCT_STAT *sbuf)
+struct file_id vfs_file_id_from_sbuf(connection_struct *conn, const SMB_STRUCT_STAT *sbuf)
 {
-       return file_id_create(sbuf->st_dev, sbuf->st_ino);
+       return SMB_VFS_FILE_ID_CREATE(conn, sbuf->st_dev, sbuf->st_ino);
 }
 
-
 /*
   return True if two file_id structures are equal
  */
index 6d14e475f1c10d060837806ad5bd4f3b60207605..76a03e9ffb5d5d7659b4a68a0f8d5115eae2aa27 100644 (file)
@@ -927,6 +927,11 @@ static int vfswrap_chflags(vfs_handle_struct *handle, const char *path, int flag
 #endif
 }
 
+static struct file_id vfswrap_file_id_create(struct vfs_handle_struct *handle, SMB_DEV_T dev, SMB_INO_T inode)
+{
+       return file_id_create_dev(dev, inode);
+}
+
 static size_t vfswrap_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp, int fd, uint32 security_info, SEC_DESC **ppdesc)
 {
        size_t result;
@@ -1314,6 +1319,8 @@ static vfs_op_tuple vfs_default_ops[] = {
         SMB_VFS_LAYER_OPAQUE},
        {SMB_VFS_OP(vfswrap_chflags),   SMB_VFS_OP_CHFLAGS,
         SMB_VFS_LAYER_OPAQUE},
+       {SMB_VFS_OP(vfswrap_file_id_create),    SMB_VFS_OP_FILE_ID_CREATE,
+        SMB_VFS_LAYER_OPAQUE},
 
        /* NT ACL operations. */
 
index 821f46041d25483d88e1b752d8a4354c9fb04f35..ab628e29fc8819e17119eadd2e7929e49ed9905c 100644 (file)
@@ -86,7 +86,7 @@ NTSTATUS print_fsp_open(connection_struct *conn, const char *fname,
        fsp->wcp = NULL; 
        SMB_VFS_FSTAT(fsp,fsp->fh->fd, &sbuf);
        fsp->mode = sbuf.st_mode;
-       fsp->file_id = file_id_sbuf(&sbuf);
+       fsp->file_id = vfs_file_id_from_sbuf(conn, &sbuf);
 
        conn->num_files_open++;
 
index 7c3e1eef2830cb17ff398b2913d058c359bbc619..9718fef4ea2052171c210ccd0d147e7628478b6e 100644 (file)
@@ -265,7 +265,7 @@ static NTSTATUS close_remove_share_mode(files_struct *fsp,
                goto done;
        }
 
-       id = file_id_sbuf(&sbuf);
+       id = vfs_file_id_from_sbuf(conn, &sbuf);
 
        if (!file_id_equal(&fsp->file_id, &id)) {
                DEBUG(5,("close_remove_share_mode: file %s. Delete on close "
index a1b56736a09393ef13b7b55071b3877bc7973d65..d5c22e81c368454b4b9a6a17f34ae419eee279ec 100644 (file)
@@ -540,7 +540,8 @@ NTSTATUS unix_convert(connection_struct *conn,
                } /* end else */
 
 #ifdef DEVELOPER
-               if (VALID_STAT(st) && get_delete_on_close_flag(file_id_sbuf(&st))) {
+               if (VALID_STAT(st) &&
+                   get_delete_on_close_flag(vfs_file_id_from_sbuf(conn, &st))) {
                        result = NT_STATUS_DELETE_PENDING;
                        goto fail;
                }
index 432f6b808a58b9403251c53022c46015edd4ea69..bff445bf61d54af3742b05707b0b32dcf66f858b 100644 (file)
@@ -357,7 +357,7 @@ static NTSTATUS open_file(files_struct *fsp,
        }
 
        fsp->mode = psbuf->st_mode;
-       fsp->file_id = file_id_sbuf(psbuf);
+       fsp->file_id = vfs_file_id_from_sbuf(conn, psbuf);
        fsp->vuid = req ? req->vuid : UID_FIELD_INVALID;
        fsp->file_pid = req ? req->smbpid : 0;
        fsp->can_lock = True;
@@ -1416,7 +1416,7 @@ NTSTATUS open_file_ntcreate(connection_struct *conn,
                return status;
        }
 
-       fsp->file_id = file_id_sbuf(psbuf);
+       fsp->file_id = vfs_file_id_from_sbuf(conn, psbuf);
        fsp->share_access = share_access;
        fsp->fh->private_options = create_options;
        fsp->access_mask = open_access_mask; /* We change this to the
@@ -1432,7 +1432,7 @@ NTSTATUS open_file_ntcreate(connection_struct *conn,
        }
 
        if (file_existed) {
-               id = file_id_sbuf(psbuf);
+               id = vfs_file_id_from_sbuf(conn, psbuf);
 
                lck = get_share_mode_lock(NULL, id,
                                          conn->connectpath,
@@ -2160,7 +2160,7 @@ NTSTATUS open_directory(connection_struct *conn,
         */
        
        fsp->mode = psbuf->st_mode;
-       fsp->file_id = file_id_sbuf(psbuf);
+       fsp->file_id = vfs_file_id_from_sbuf(conn, psbuf);
        fsp->vuid = req ? req->vuid : UID_FIELD_INVALID;
        fsp->file_pid = req ? req->smbpid : 0;
        fsp->can_lock = False;
@@ -2288,7 +2288,7 @@ NTSTATUS open_file_stat(connection_struct *conn, struct smb_request *req,
         */
        
        fsp->mode = psbuf->st_mode;
-       fsp->file_id = file_id_sbuf(psbuf);
+       fsp->file_id = vfs_file_id_from_sbuf(conn, psbuf);
        fsp->vuid = req ? req->vuid : UID_FIELD_INVALID;
        fsp->file_pid = req ? req->smbpid : 0;
        fsp->can_lock = False;
index ec27450593ea9d73105afb1aed8c9b85233ac1c2..cebb905a9e7556565e2a36694520b7cdcd9c329b 100644 (file)
@@ -4563,7 +4563,8 @@ NTSTATUS rename_internals_fsp(connection_struct *conn, files_struct *fsp, pstrin
        }
 
        if (dst_exists) {
-               files_struct *dst_fsp = file_find_di_first(file_id_sbuf(&sbuf1));
+               struct file_id fileid = vfs_file_id_from_sbuf(conn, &sbuf1);
+               files_struct *dst_fsp = file_find_di_first(fileid);
                if (dst_fsp) {
                        DEBUG(3, ("rename_internals_fsp: Target file open\n"));
                        return NT_STATUS_ACCESS_DENIED;
index 77a13ad18623e6a3b1d7426ff5d5991f52ddb9ca..2b0925d195b521894e97b4ed45f04080a7c8aa1f 100644 (file)
@@ -3312,6 +3312,7 @@ static int call_trans2qfilepathinfo(connection_struct *conn, char *inbuf, char *
        time_t create_time, mtime, atime;
        struct timespec create_time_ts, mtime_ts, atime_ts;
        files_struct *fsp = NULL;
+       struct file_id fileid;
        TALLOC_CTX *data_ctx = NULL;
        struct ea_list *ea_list = NULL;
        uint32 access_mask = 0x12019F; /* Default - GENERIC_EXECUTE mapping from Windows */
@@ -3378,7 +3379,8 @@ static int call_trans2qfilepathinfo(connection_struct *conn, char *inbuf, char *
                                return UNIXERROR(ERRDOS,ERRbadpath);
                        }
 
-                       delete_pending = get_delete_on_close_flag(file_id_sbuf(&sbuf));
+                       fileid = vfs_file_id_from_sbuf(conn, &sbuf);
+                       delete_pending = get_delete_on_close_flag(fileid);
                } else {
                        /*
                         * Original code - this is an open file.
@@ -3391,7 +3393,8 @@ static int call_trans2qfilepathinfo(connection_struct *conn, char *inbuf, char *
                                return(UNIXERROR(ERRDOS,ERRbadfid));
                        }
                        pos = fsp->fh->position_information;
-                       delete_pending = get_delete_on_close_flag(file_id_sbuf(&sbuf));
+                       fileid = vfs_file_id_from_sbuf(conn, &sbuf);
+                       delete_pending = get_delete_on_close_flag(fileid);
                        access_mask = fsp->access_mask;
                }
        } else {
@@ -3446,7 +3449,8 @@ static int call_trans2qfilepathinfo(connection_struct *conn, char *inbuf, char *
                        return UNIXERROR(ERRDOS,ERRbadpath);
                }
 
-               delete_pending = get_delete_on_close_flag(file_id_sbuf(&sbuf));
+               fileid = vfs_file_id_from_sbuf(conn, &sbuf);
+               delete_pending = get_delete_on_close_flag(fileid);
                if (delete_pending) {
                        return ERROR_NT(NT_STATUS_DELETE_PENDING);
                }
@@ -3572,8 +3576,10 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                        mtime_ts = fsp->pending_modtime;
                }
        } else {
+               files_struct *fsp1;
                /* Do we have this path open ? */
-               files_struct *fsp1 = file_find_di_first(file_id_sbuf(&sbuf));
+               fileid = vfs_file_id_from_sbuf(conn, &sbuf);
+               fsp1 = file_find_di_first(fileid);
                if (fsp1 && !null_timespec(fsp1->pending_modtime)) {
                        /* the pending modtime overrides the current modtime */
                        mtime_ts = fsp1->pending_modtime;