[SCM] Samba Shared Repository - branch v3-3-test updated - release-3-2-0pre2-5156-ga4badda

Volker Lendecke vlendec at samba.org
Sun Mar 22 11:28:02 GMT 2009


The branch, v3-3-test has been updated
       via  a4badda87bc10a820f3591a1232d840fa4262bf3 (commit)
       via  9ada8991505b43a81687076b35828f21598b5ca0 (commit)
       via  3bf35e844cc60d911b3b2eff19db0df6348a57b5 (commit)
      from  9bf3e129605d51483fd5ce47c90642f7e82ac102 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-3-test


- Log -----------------------------------------------------------------
commit a4badda87bc10a820f3591a1232d840fa4262bf3
Author: Volker Lendecke <vl at samba.org>
Date:   Sun Mar 22 11:39:32 2009 +0100

    Document the dirsort module

commit 9ada8991505b43a81687076b35828f21598b5ca0
Author: Volker Lendecke <vl at samba.org>
Date:   Sun Mar 22 11:39:10 2009 +0100

    Use StrCaseCmp in the dirsort module

commit 3bf35e844cc60d911b3b2eff19db0df6348a57b5
Author: Andy Kelk <andy at mopoke.co.uk>
Date:   Sun Mar 22 11:06:52 2009 +0100

    Add dirsort module

-----------------------------------------------------------------------

Summary of changes:
 .../{vfs_notify_fam.8.xml => vfs_dirsort.8.xml}    |   25 ++--
 source/Makefile.in                                 |    5 +
 source/configure.in                                |    3 +-
 source/modules/vfs_dirsort.c                       |  193 ++++++++++++++++++++
 4 files changed, 212 insertions(+), 14 deletions(-)
 copy docs-xml/manpages-3/{vfs_notify_fam.8.xml => vfs_dirsort.8.xml} (62%)
 create mode 100644 source/modules/vfs_dirsort.c


Changeset truncated at 500 lines:

diff --git a/docs-xml/manpages-3/vfs_notify_fam.8.xml b/docs-xml/manpages-3/vfs_dirsort.8.xml
similarity index 62%
copy from docs-xml/manpages-3/vfs_notify_fam.8.xml
copy to docs-xml/manpages-3/vfs_dirsort.8.xml
index 57f58c1..cec5f27 100644
--- a/docs-xml/manpages-3/vfs_notify_fam.8.xml
+++ b/docs-xml/manpages-3/vfs_dirsort.8.xml
@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="iso-8859-1"?>
 <!DOCTYPE refentry PUBLIC "-//Samba-Team//DTD DocBook V4.2-Based Variant V1.0//EN" "http://www.samba.org/samba/DTD/samba-doc">
-<refentry id="vfs_notify_fam.8">
+<refentry id="vfs_dirsort.8">
 
 <refmeta>
-	<refentrytitle>vfs_notify_fam</refentrytitle>
+	<refentrytitle>vfs_dirsort</refentrytitle>
 	<manvolnum>8</manvolnum>
 	<refmiscinfo class="source">Samba</refmiscinfo>
 	<refmiscinfo class="manual">System Administration tools</refmiscinfo>
@@ -12,13 +12,13 @@
 
 
 <refnamediv>
-	<refname>vfs_notify_fam</refname>
-	<refpurpose>FAM support for file change notifications</refpurpose>
+	<refname>vfs_dirsort</refname>
+	<refpurpose>Sort directory contents</refpurpose>
 </refnamediv>
 
 <refsynopsisdiv>
 	<cmdsynopsis>
-		<command>vfs objects = notify_fam</command>
+		<command>vfs objects = dirsort</command>
 	</cmdsynopsis>
 </refsynopsisdiv>
 
@@ -29,23 +29,22 @@
 	<citerefentry><refentrytitle>samba</refentrytitle>
 	<manvolnum>7</manvolnum></citerefentry> suite.</para>
 
-	<para>The <command>vfs_notify_fam</command> module makes use of
-	the system FAM (File Alteration Monitor) daemon to implement
-	file change notifications for Windows clients. FAM is generally
-	present only on IRIX and some BSD systems.</para>
+	<para>The <command>vfs_dirsort</command> module sorts directory
+	entries alphabetically before sending them to the client.</para>
 
-	<para>This module is not stackable.</para>
+	<para>Please be aware that adding this module might have negative
+	performance implications for large directories.</para>
 
 </refsect1>
 
 <refsect1>
 	<title>EXAMPLES</title>
 
-	<para>Support FAM notifications globally:</para>
+	<para>Sort directories for all shares:</para>
 
 <programlisting>
         <smbconfsection name="[global]"/>
-	<smbconfoption name="vfs objects">notify_fam</smbconfoption>
+	<smbconfoption name="vfs objects">dirsort</smbconfoption>
 </programlisting>
 
 </refsect1>
@@ -53,7 +52,7 @@
 <refsect1>
 	<title>VERSION</title>
 
-	<para>This man page is correct for version 3.0.25 of the Samba suite.
+	<para>This man page is correct for version 3.3 of the Samba suite.
 	</para>
 </refsect1>
 
diff --git a/source/Makefile.in b/source/Makefile.in
index 988ca2c..ee22703 100644
--- a/source/Makefile.in
+++ b/source/Makefile.in
@@ -635,6 +635,7 @@ VFS_SYNCOPS_OBJ = modules/vfs_syncops.o
 VFS_ACL_XATTR_OBJ = modules/vfs_acl_xattr.o
 VFS_ACL_TDB_OBJ = modules/vfs_acl_tdb.o
 VFS_SMB_TRAFFIC_ANALYZER_OBJ = modules/vfs_smb_traffic_analyzer.o
+VFS_DIRSORT_OBJ = modules/vfs_dirsort.o
 
 PLAINTEXT_AUTH_OBJ = auth/pampass.o auth/pass_check.o
 
@@ -2462,6 +2463,10 @@ bin/security. at SHLIBEXT@: $(BINARY_PREREQS) libgpo/gpext/security.o
 	@echo "Building plugin $@"
 	@$(SHLD_MODULE) libgpo/gpext/security.o
 
+bin/dirsort. at SHLIBEXT@: $(BINARY_PREREQS) $(VFS_DIRSORT_OBJ)
+	@echo "Building plugin $@"
+	@$(SHLD_MODULE) $(VFS_DIRSORT_OBJ)
+
 #########################################################
 ## IdMap NSS plugins
 
diff --git a/source/configure.in b/source/configure.in
index 6d8a387..b5319bb 100644
--- a/source/configure.in
+++ b/source/configure.in
@@ -409,7 +409,7 @@ dnl These have to be built static:
 default_static_modules="pdb_smbpasswd pdb_tdbsam rpc_lsarpc rpc_samr rpc_winreg rpc_initshutdown rpc_dssetup rpc_wkssvc rpc_svcctl2 rpc_ntsvcs2 rpc_netlogon rpc_netdfs rpc_srvsvc rpc_spoolss rpc_eventlog2 auth_sam auth_unix auth_winbind auth_server auth_domain auth_builtin vfs_default nss_info_template"
 
 dnl These are preferably build shared, and static if dlopen() is not available
-default_shared_modules="vfs_recycle vfs_audit vfs_extd_audit vfs_full_audit vfs_netatalk vfs_fake_perms vfs_default_quota vfs_readonly vfs_cap vfs_expand_msdfs vfs_shadow_copy vfs_shadow_copy2 charset_CP850 charset_CP437 auth_script vfs_readahead vfs_xattr_tdb vfs_streams_xattr vfs_streams_depot vfs_acl_xattr vfs_acl_tdb vfs_smb_traffic_analyzer vfs_preopen"
+default_shared_modules="vfs_recycle vfs_audit vfs_extd_audit vfs_full_audit vfs_netatalk vfs_fake_perms vfs_default_quota vfs_readonly vfs_cap vfs_expand_msdfs vfs_shadow_copy vfs_shadow_copy2 charset_CP850 charset_CP437 auth_script vfs_readahead vfs_xattr_tdb vfs_streams_xattr vfs_streams_depot vfs_acl_xattr vfs_acl_tdb vfs_smb_traffic_analyzer vfs_preopen vfs_dirsort"
 
 if test "x$developer" = xyes; then
    default_static_modules="$default_static_modules rpc_rpcecho"
@@ -6401,6 +6401,7 @@ SMB_MODULE(vfs_notify_fam, \$(VFS_NOTIFY_FAM_OBJ), "bin/notify_fam.$SHLIBEXT", V
 SMB_MODULE(vfs_acl_xattr, \$(VFS_ACL_XATTR_OBJ), "bin/acl_xattr.$SHLIBEXT", VFS)
 SMB_MODULE(vfs_acl_tdb, \$(VFS_ACL_TDB_OBJ), "bin/acl_tdb.$SHLIBEXT", VFS)
 SMB_MODULE(vfs_smb_traffic_analyzer, \$(VFS_SMB_TRAFFIC_ANALYZER_OBJ), "bin/smb_traffic_analyzer.$SHLIBEXT", VFS)
+SMB_MODULE(vfs_dirsort, \$(VFS_DIRSORT_OBJ), "bin/dirsort.$SHLIBEXT", VFS)
 
 
 SMB_SUBSYSTEM(VFS,smbd/vfs.o)
diff --git a/source/modules/vfs_dirsort.c b/source/modules/vfs_dirsort.c
new file mode 100644
index 0000000..d7f2b03
--- /dev/null
+++ b/source/modules/vfs_dirsort.c
@@ -0,0 +1,193 @@
+/*
+ * VFS module to provide a sorted directory list.
+ *
+ * Copyright (C) Andy Kelk (andy at mopoke.co.uk), 2009
+ *
+ *
+ * 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "includes.h"
+
+static int compare_dirent (const void *a, const void *b) {
+	const SMB_STRUCT_DIRENT *da = (const SMB_STRUCT_DIRENT *) a;
+	const SMB_STRUCT_DIRENT *db = (const SMB_STRUCT_DIRENT *) b;
+	return StrCaseCmp(da->d_name, db->d_name);
+}
+
+struct dirsort_privates {
+	long pos;
+	SMB_STRUCT_DIRENT *directory_list;
+	long number_of_entries;
+	time_t mtime;
+	SMB_STRUCT_DIR *source_directory;
+	int fd;
+};
+
+static void free_dirsort_privates(void **datap) {
+	struct dirsort_privates *data = (struct dirsort_privates *) *datap;
+	SAFE_FREE(data->directory_list);
+	SAFE_FREE(data);
+	*datap = NULL;
+
+	return;
+}
+
+static void open_and_sort_dir (vfs_handle_struct *handle)
+{
+	SMB_STRUCT_DIRENT *dp;
+	struct stat dir_stat;
+	long current_pos;
+	struct dirsort_privates *data = NULL;
+
+	SMB_VFS_HANDLE_GET_DATA(handle, data, struct dirsort_privates, return);
+
+	data->number_of_entries = 0;
+
+	if (fstat(data->fd, &dir_stat) == 0) {
+		data->mtime = dir_stat.st_mtime;
+	}
+
+	while (SMB_VFS_NEXT_READDIR(handle, data->source_directory) != NULL) {
+		data->number_of_entries++;
+	}
+
+	/* Open the underlying directory and count the number of entries
+	   Skip back to the beginning as we'll read it again */
+	SMB_VFS_NEXT_REWINDDIR(handle, data->source_directory);
+
+	/* Set up an array and read the directory entries into it */
+	SAFE_FREE(data->directory_list); /* destroy previous cache if needed */
+	data->directory_list = (SMB_STRUCT_DIRENT *)SMB_MALLOC(
+		data->number_of_entries * sizeof(SMB_STRUCT_DIRENT));
+	current_pos = data->pos;
+	data->pos = 0;
+	while ((dp = SMB_VFS_NEXT_READDIR(handle, data->source_directory))
+	       != NULL) {
+		data->directory_list[data->pos++] = *dp;
+	}
+
+	/* Sort the directory entries by name */
+	data->pos = current_pos;
+	qsort(data->directory_list, data->number_of_entries,
+	      sizeof(SMB_STRUCT_DIRENT), compare_dirent);
+}
+
+static SMB_STRUCT_DIR *dirsort_opendir(vfs_handle_struct *handle,
+				       const char *fname, const char *mask,
+				       uint32 attr)
+{
+	struct dirsort_privates *data = NULL;
+
+	/* set up our private data about this directory */
+	data = (struct dirsort_privates *)SMB_MALLOC(
+		sizeof(struct dirsort_privates));
+
+	data->directory_list = NULL;
+	data->pos = 0;
+
+	/* Open the underlying directory and count the number of entries */
+	data->source_directory = SMB_VFS_NEXT_OPENDIR(handle, fname, mask,
+						      attr);
+
+	data->fd = dirfd(data->source_directory);
+
+	SMB_VFS_HANDLE_SET_DATA(handle, data, free_dirsort_privates,
+				struct dirsort_privates, return NULL);
+
+	open_and_sort_dir(handle);
+
+	return data->source_directory;
+}
+
+static SMB_STRUCT_DIRENT *dirsort_readdir(vfs_handle_struct *handle,
+					  SMB_STRUCT_DIR *dirp)
+{
+	struct dirsort_privates *data = NULL;
+	time_t current_mtime;
+	struct stat dir_stat;
+
+	SMB_VFS_HANDLE_GET_DATA(handle, data, struct dirsort_privates,
+				return NULL);
+
+	if (fstat(data->fd, &dir_stat) == -1) {
+		return NULL;
+	}
+
+	current_mtime = dir_stat.st_mtime;
+
+	/* throw away cache and re-read the directory if we've changed */
+	if (current_mtime > data->mtime) {
+		open_and_sort_dir(handle);
+	}
+
+	if (data->pos >= data->number_of_entries) {
+		return NULL;
+	}
+
+	return &data->directory_list[data->pos++];
+}
+
+static void dirsort_seekdir(vfs_handle_struct *handle, SMB_STRUCT_DIR *dirp,
+			    long offset)
+{
+	struct dirsort_privates *data = NULL;
+	SMB_VFS_HANDLE_GET_DATA(handle, data, struct dirsort_privates, return);
+
+	data->pos = offset;
+}
+
+static long dirsort_telldir(vfs_handle_struct *handle, SMB_STRUCT_DIR *dirp)
+{
+	struct dirsort_privates *data = NULL;
+	SMB_VFS_HANDLE_GET_DATA(handle, data, struct dirsort_privates,
+				return -1);
+
+	return data->pos;
+}
+
+static void dirsort_rewinddir(vfs_handle_struct *handle, SMB_STRUCT_DIR *dirp)
+{
+	struct dirsort_privates *data = NULL;
+	SMB_VFS_HANDLE_GET_DATA(handle, data, struct dirsort_privates, return);
+
+	data->pos = 0;
+}
+
+/* VFS operations structure */
+
+static vfs_op_tuple dirsort_op_tuples[] = {
+
+    /* Directory operations */
+
+    {SMB_VFS_OP(dirsort_opendir),	     SMB_VFS_OP_OPENDIR,
+     SMB_VFS_LAYER_TRANSPARENT},
+    {SMB_VFS_OP(dirsort_readdir),	     SMB_VFS_OP_READDIR,
+     SMB_VFS_LAYER_TRANSPARENT},
+    {SMB_VFS_OP(dirsort_seekdir),	     SMB_VFS_OP_SEEKDIR,
+     SMB_VFS_LAYER_TRANSPARENT},
+    {SMB_VFS_OP(dirsort_telldir),	     SMB_VFS_OP_TELLDIR,
+     SMB_VFS_LAYER_TRANSPARENT},
+    {SMB_VFS_OP(dirsort_rewinddir),	     SMB_VFS_OP_REWINDDIR,
+     SMB_VFS_LAYER_TRANSPARENT},
+
+    {NULL,				     SMB_VFS_OP_NOOP,
+     SMB_VFS_LAYER_NOOP}
+};
+
+NTSTATUS vfs_dirsort_init(void)
+{
+	return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "dirsort",
+				dirsort_op_tuples);
+}


-- 
Samba Shared Repository


More information about the samba-cvs mailing list