Remove the use of dirfd inside the vfs_dirsort.c.
authorJeremy Allison <jra@samba.org>
Tue, 9 Apr 2013 17:50:55 +0000 (10:50 -0700)
committerKarolin Seeger <kseeger@samba.org>
Wed, 19 Jun 2013 08:55:34 +0000 (10:55 +0200)
Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
source3/modules/vfs_dirsort.c

index ea65e63f0c369e67f4aed80c23075917dcff70ca..9b772ccbe5842d298f49dba329bf96f2582b3826 100644 (file)
@@ -33,7 +33,8 @@ struct dirsort_privates {
        unsigned int number_of_entries;
        struct timespec mtime;
        SMB_STRUCT_DIR *source_directory;
-       int fd;
+       files_struct *fsp; /* If open via FDOPENDIR. */
+       struct smb_filename *smb_fname; /* If open via OPENDIR */
 };
 
 static void free_dirsort_privates(void **datap) {
@@ -45,16 +46,21 @@ static bool get_sorted_dir_mtime(vfs_handle_struct *handle,
                                struct timespec *ret_mtime)
 {
        int ret;
-       struct stat dir_stat;
+       struct timespec mtime;
 
-       ret = fstat(data->fd, &dir_stat);
+       if (data->fsp) {
+               ret = fsp_stat(data->fsp);
+               mtime = data->fsp->fsp_name->st.st_ex_mtime;
+       } else {
+               ret = SMB_VFS_STAT(handle->conn, data->smb_fname);
+               mtime = data->smb_fname->st.st_ex_mtime;
+       }
 
        if (ret == -1) {
                return false;
        }
 
-       ret_mtime->tv_sec = dir_stat.st_mtime;
-       ret_mtime->tv_nsec = 0;
+       *ret_mtime = mtime;
 
        return true;
 }
@@ -113,6 +119,7 @@ static SMB_STRUCT_DIR *dirsort_opendir(vfs_handle_struct *handle,
                                       const char *fname, const char *mask,
                                       uint32 attr)
 {
+       NTSTATUS status;
        struct dirsort_privates *data = NULL;
 
        /* set up our private data about this directory */
@@ -124,6 +131,16 @@ static SMB_STRUCT_DIR *dirsort_opendir(vfs_handle_struct *handle,
        data->directory_list = NULL;
        data->pos = 0;
 
+       status = create_synthetic_smb_fname(data,
+                                       fname,
+                                       NULL,
+                                       NULL,
+                                       &data->smb_fname);
+       if (!NT_STATUS_IS_OK(status)) {
+               TALLOC_FREE(data);
+               return NULL;
+       }
+
        /* Open the underlying directory and count the number of entries */
        data->source_directory = SMB_VFS_NEXT_OPENDIR(handle, fname, mask,
                                                      attr);
@@ -133,8 +150,6 @@ static SMB_STRUCT_DIR *dirsort_opendir(vfs_handle_struct *handle,
                return NULL;
        }
 
-       data->fd = dirfd(data->source_directory);
-
        if (!open_and_sort_dir(handle, data)) {
                SMB_VFS_NEXT_CLOSEDIR(handle,data->source_directory);
                TALLOC_FREE(data);
@@ -162,6 +177,7 @@ static SMB_STRUCT_DIR *dirsort_fdopendir(vfs_handle_struct *handle,
 
        data->directory_list = NULL;
        data->pos = 0;
+       data->fsp = fsp;
 
        /* Open the underlying directory and count the number of entries */
        data->source_directory = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask,
@@ -172,8 +188,6 @@ static SMB_STRUCT_DIR *dirsort_fdopendir(vfs_handle_struct *handle,
                return NULL;
        }
 
-       data->fd = dirfd(data->source_directory);
-
        if (!open_and_sort_dir(handle, data)) {
                SMB_VFS_NEXT_CLOSEDIR(handle,data->source_directory);
                TALLOC_FREE(data);