[PATCH] shadow copy sorting

Ed Plese ed at edplese.com
Tue Mar 7 20:15:56 GMT 2006


Hi,

Attached is a patch for Samba 3 that sorts the list of shadow copies in
the shadow copy VFS module.  The patch allows a "sort" parameter to be
specified for the shadow copy module to both enable sorting and specify
the sort order: "asc" for ascending and "desc" for descending.  If the
"sort" parameter is not specified for this module, the behavior is exactly
as it is without the patch.

Without sorting, the shadow copies appear in the Windows UI in the same
order that readdir() returns them to Samba, which is not always in order
by date.

Comments and feedback welcome.

Thanks,

Ed Plese
-------------- next part --------------
Index: vfs_shadow_copy.c
===================================================================
--- vfs_shadow_copy.c	(revision 13979)
+++ vfs_shadow_copy.c	(working copy)
@@ -62,6 +62,42 @@
 	SMB_STRUCT_DIRENT *dirs;
 } shadow_copy_Dir;
 
+static int shadow_copy_label_cmp_asc(const void *x, const void *y)
+{
+	return strncmp((char *)x, (char *)y, sizeof(SHADOW_COPY_LABEL));
+}
+
+static int shadow_copy_label_cmp_desc(const void *x, const void *y)
+{
+	return -strncmp((char *)x, (char *)y, sizeof(SHADOW_COPY_LABEL));
+}
+
+static void shadow_copy_sort_data(vfs_handle_struct *handle, SHADOW_COPY_DATA *shadow_copy_data)
+{
+	const char *tmp_str = NULL;
+
+	if (shadow_copy_data && shadow_copy_data->num_volumes > 0 &&
+		shadow_copy_data->labels) {
+
+		tmp_str = lp_parm_const_string(SNUM(handle->conn), "shadow_copy", "sort","");
+
+		if (strcmp(tmp_str, "asc") == 0) {
+			qsort(shadow_copy_data->labels,
+				shadow_copy_data->num_volumes,
+				sizeof(SHADOW_COPY_LABEL),
+				shadow_copy_label_cmp_asc);
+
+		} else if (strcmp(tmp_str, "desc") == 0) {
+			qsort(shadow_copy_data->labels,
+				shadow_copy_data->num_volumes,
+				sizeof(SHADOW_COPY_LABEL),
+				shadow_copy_label_cmp_desc);
+		}
+	}
+ 
+	return;
+}
+
 static BOOL shadow_copy_match_name(const char *name)
 {
 	if (strncmp(SHADOW_COPY_PREFIX,name, sizeof(SHADOW_COPY_PREFIX)-1)==0 &&
@@ -209,6 +245,8 @@
 		shadow_copy_data->labels = tlabels;
 	}
 
+	shadow_copy_sort_data(handle, shadow_copy_data);
+
 	SMB_VFS_NEXT_CLOSEDIR(handle,fsp->conn,p);
 	return 0;
 }


More information about the samba-technical mailing list