shadow_copy2: add comment block explaining shadow_copy2_insert_string()
[mat/samba.git] / source3 / modules / vfs_shadow_copy2.c
index 1cf8e37ba4ab188b84fad8c37514e89421543847..06e5115f356e1088b27b7066a5371a4bc051922f 100644 (file)
 #include <ccan/hash/hash.h>
 #include "util_tdb.h"
 
-#define GMT_NAME_LEN 24 /* length of a @GMT- name */
-#define GMT_FORMAT "@GMT-%Y.%m.%d-%H.%M.%S"
-
 static bool shadow_copy2_find_slashes(TALLOC_CTX *mem_ctx, const char *str,
                                      size_t **poffsets,
                                      unsigned *pnum_offsets)
@@ -144,6 +141,11 @@ static bool shadow_copy2_find_slashes(TALLOC_CTX *mem_ctx, const char *str,
        return true;
 }
 
+/**
+ * Given a timstamp, build the string to insert into a path
+ * as a path component for creating the local path to the
+ * snapshot at the given timestamp of the input path.
+ */
 static char *shadow_copy2_insert_string(TALLOC_CTX *mem_ctx,
                                        struct vfs_handle_struct *handle,
                                        time_t snapshot)
@@ -189,6 +191,11 @@ static char *shadow_copy2_insert_string(TALLOC_CTX *mem_ctx,
                               snaptime_string);
 }
 
+/**
+ * Strip a snapshot component from an filename as
+ * handed in via the smb layer.
+ * Returns the parsed timestamp and the stripped filename.
+ */
 static bool shadow_copy2_strip_snapshot(TALLOC_CTX *mem_ctx,
                                        struct vfs_handle_struct *handle,
                                        const char *name,
@@ -710,7 +717,6 @@ static int shadow_copy2_unlink(vfs_handle_struct *handle,
        char *stripped;
        int ret, saved_errno;
        struct smb_filename *conv;
-       NTSTATUS status;
 
        if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
                                         smb_fname->base_name,
@@ -720,8 +726,8 @@ static int shadow_copy2_unlink(vfs_handle_struct *handle,
        if (timestamp == 0) {
                return SMB_VFS_NEXT_UNLINK(handle, smb_fname);
        }
-       status = copy_smb_filename(talloc_tos(), smb_fname, &conv);
-       if (!NT_STATUS_IS_OK(status)) {
+       conv = cp_smb_filename(talloc_tos(), smb_fname);
+       if (conv == NULL) {
                errno = ENOMEM;
                return -1;
        }
@@ -827,7 +833,6 @@ static int shadow_copy2_ntimes(vfs_handle_struct *handle,
        char *stripped;
        int ret, saved_errno;
        struct smb_filename *conv;
-       NTSTATUS status;
 
        if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
                                         smb_fname->base_name,
@@ -837,8 +842,8 @@ static int shadow_copy2_ntimes(vfs_handle_struct *handle,
        if (timestamp == 0) {
                return SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
        }
-       status = copy_smb_filename(talloc_tos(), smb_fname, &conv);
-       if (!NT_STATUS_IS_OK(status)) {
+       conv = cp_smb_filename(talloc_tos(), smb_fname);
+       if (conv == NULL) {
                errno = ENOMEM;
                return -1;
        }
@@ -963,6 +968,12 @@ done:
        return result;
 }
 
+/**
+ * Check whether a given directory contains a
+ * snapshot directory as direct subdirectory.
+ * If yes, return the path of the snapshot-subdir,
+ * otherwise return NULL.
+ */
 static char *have_snapdir(struct vfs_handle_struct *handle,
                          const char *path)
 {
@@ -986,6 +997,10 @@ static char *have_snapdir(struct vfs_handle_struct *handle,
        return NULL;
 }
 
+/**
+ * Find the snapshot directory (if any) for the given
+ * filename (which is relative to the share).
+ */
 static char *shadow_copy2_find_snapdir(TALLOC_CTX *mem_ctx,
                                       struct vfs_handle_struct *handle,
                                       struct smb_filename *smb_fname)
@@ -1035,7 +1050,8 @@ static bool shadow_copy2_snapshot_to_gmt(vfs_handle_struct *handle,
        ZERO_STRUCT(timestamp);
        if (lp_parm_bool(SNUM(handle->conn), "shadow", "sscanf", false)) {
                if (sscanf(name, fmt, &timestamp_long) != 1) {
-                       DEBUG(10, ("shadow_copy2_snapshot_to_gmt: no sscanf match %s: %s\n",
+                       DEBUG(10, ("shadow_copy2_snapshot_to_gmt: "
+                                  "no sscanf match %s: %s\n",
                                   fmt, name));
                        return false;
                }
@@ -1043,11 +1059,13 @@ static bool shadow_copy2_snapshot_to_gmt(vfs_handle_struct *handle,
                gmtime_r(&timestamp_t, &timestamp);
        } else {
                if (strptime(name, fmt, &timestamp) == NULL) {
-                       DEBUG(10, ("shadow_copy2_snapshot_to_gmt: no match %s: %s\n",
+                       DEBUG(10, ("shadow_copy2_snapshot_to_gmt: "
+                                  "no match %s: %s\n",
                                   fmt, name));
                        return false;
                }
-               DEBUG(10, ("shadow_copy2_snapshot_to_gmt: match %s: %s\n", fmt, name));
+               DEBUG(10, ("shadow_copy2_snapshot_to_gmt: match %s: %s\n",
+                          fmt, name));
                
                if (lp_parm_bool(SNUM(handle->conn), "shadow", "localtime", false)) {
                        timestamp.tm_isdst = -1;