Namespace improvements.
authorWayne Davison <wayned@samba.org>
Thu, 2 Nov 2006 17:31:08 +0000 (17:31 +0000)
committerWayne Davison <wayned@samba.org>
Thu, 2 Nov 2006 17:31:08 +0000 (17:31 +0000)
fake-super.diff
xattrs.diff

index e8a078a..57fc95f 100644 (file)
@@ -418,7 +418,7 @@ above:
  
  /* These are to make syscall.o shut up. */
  int dry_run = 0;
-+int am_root = 0; /* TODO: add option to set this to -1. */
++int am_root = 0;
  int read_only = 1;
  int list_only = 0;
  int preserve_perms = 0;
@@ -434,54 +434,44 @@ above:
  int preserve_perms = 0;
 --- old/xattr.c
 +++ new/xattr.c
-@@ -28,11 +28,14 @@
- extern int dry_run;
- extern int read_only;
- extern int list_only;
-+extern int am_root;
- extern unsigned int file_struct_len;
- #define RSYNC_XAL_INITIAL 5
- #define RSYNC_XAL_LIST_INITIAL 100
+@@ -39,6 +39,12 @@ extern unsigned int file_struct_len;
+ #define ROOT_PREFIX "root."
+ #define RPRE_LEN (sizeof ROOT_PREFIX - 1)
  
-+#define FAKE_XATTR "user.rsync%stat"
++#ifdef HAVE_LINUX_XATTRS
++#define FAKE_XATTR USER_PREFIX "rsync.%stat"
++#else
++#define FAKE_XATTR "rsync.%stat"
++#endif
 +
  typedef struct {
        char *name;
        char *datum;
-@@ -134,9 +137,15 @@ static int rsync_xal_get(const char *fna
-       if (name_size == 0)
-               return 0;
-       for (left = name_size, name = namebuf; left > 0 ; left -= len, name += len) {
--              rsync_xa *rxas = EXPAND_ITEM_LIST(xalp, rsync_xa, RSYNC_XAL_INITIAL);
-+              rsync_xa *rxas;
+@@ -144,6 +150,10 @@ static int rsync_xal_get(const char *fna
+                       continue;
+ #endif
  
-               len = strlen(name) + 1;
 +              if (am_root < 0 && len == sizeof FAKE_XATTR
-+               && name[10] == '%' && strcmp(name, FAKE_XATTR) == 0)
++               && name[11] == '%' && strcmp(name, FAKE_XATTR) == 0)
 +                      continue;
 +
-+              rxas = EXPAND_ITEM_LIST(xalp, rsync_xa, RSYNC_XAL_INITIAL);
-+
+               rxas = EXPAND_ITEM_LIST(xalp, rsync_xa, RSYNC_XAL_INITIAL);
                datum_size = sys_lgetxattr(fname, name, NULL, 0);
-               if (datum_size < 0) {
-                       if (errno == ENOTSUP)
-@@ -288,6 +297,14 @@ void receive_xattr(struct file_struct *f
-                               out_of_memory("receive_xattr");
-                       read_buf(f, ptr, name_len);
-                       read_buf(f, ptr + name_len, datum_len);
-+
+@@ -315,6 +325,12 @@ void receive_xattr(struct file_struct *f
+                               memmove(ptr, ptr + UPRE_LEN, rxa->name_len);
+                       }
+ #endif
 +                      if (am_root < 0 && name_len == sizeof FAKE_XATTR
-+                       && ptr[10] == '%' && strcmp(ptr, FAKE_XATTR) == 0) {
++                       && ptr[11] == '%' && strcmp(ptr, FAKE_XATTR) == 0) {
 +                              free(ptr);
 +                              temp_xattr.count--;
 +                              continue;
 +                      }
-+
-                       rxa->name_len = name_len;
-                       rxa->datum_len = datum_len;
-                       rxa->name = ptr;
-@@ -373,4 +390,146 @@ int set_xattr(const char *fname, const s
+               }
+               ndx = rsync_xal_l.count; /* pre-incremented count */
+               rsync_xal_store(&temp_xattr); /* adds item to rsync_xal_l */
+@@ -390,4 +406,146 @@ int set_xattr(const char *fname, const s
        return rsync_xal_set(fname, lst + ndx); /* TODO:  This needs to return 1 if no xattrs changed! */
  }
  
index d337e50..cbde400 100644 (file)
@@ -629,7 +629,7 @@ TODO:
  transfer.  The resulting value is treated as though it was the permissions
 --- old/xattr.c
 +++ new/xattr.c
-@@ -0,0 +1,376 @@
+@@ -0,0 +1,393 @@
 +/*
 + * Extended Attribute support for rsync.
 + * Written by Jay Fenlason, vaguely based on the ACLs patch.
@@ -658,6 +658,7 @@ TODO:
 +#ifdef SUPPORT_XATTRS
 +
 +extern int dry_run;
++extern int am_root;
 +extern int read_only;
 +extern int list_only;
 +extern unsigned int file_struct_len;
@@ -665,6 +666,11 @@ TODO:
 +#define RSYNC_XAL_INITIAL 5
 +#define RSYNC_XAL_LIST_INITIAL 100
 +
++#define USER_PREFIX "user."
++#define UPRE_LEN (sizeof USER_PREFIX - 1)
++#define ROOT_PREFIX "root."
++#define RPRE_LEN (sizeof ROOT_PREFIX - 1)
++
 +typedef struct {
 +      char *name;
 +      char *datum;
@@ -678,13 +684,6 @@ TODO:
 +static item_list empty_xattr = EMPTY_ITEM_LIST;
 +static item_list rsync_xal_l = EMPTY_ITEM_LIST;
 +
-+#ifndef HAVE_LINUX_XATTRS
-+/* Linux extended attributes keep the namespace in the key.
-+ * Let's do the same for all other platforms. */
-+#define USER_PREFIX "user."
-+#define UPRE_LEN (sizeof USER_PREFIX - 1)
-+#endif
-+
 +/* ------------------------------------------------------------------------- */
 +
 +static void rsync_xal_free(item_list *xalp)
@@ -766,9 +765,19 @@ TODO:
 +      if (name_size == 0)
 +              return 0;
 +      for (left = name_size, name = namebuf; left > 0 ; left -= len, name += len) {
-+              rsync_xa *rxas = EXPAND_ITEM_LIST(xalp, rsync_xa, RSYNC_XAL_INITIAL);
++              rsync_xa *rxas;
 +
 +              len = strlen(name) + 1;
++
++#ifdef HAVE_LINUX_XATTRS
++              /* We only send user and root namespaces. */
++              if (strncmp(name, USER_PREFIX, UPRE_LEN) != 0
++               && strncmp(name, ROOT_PREFIX, RPRE_LEN) != 0)
++                      continue;
++#endif
++
++              rxas = EXPAND_ITEM_LIST(xalp, rsync_xa, RSYNC_XAL_INITIAL);
++
 +              datum_size = sys_lgetxattr(fname, name, NULL, 0);
 +              if (datum_size < 0) {
 +                      if (errno == ENOTSUP)
@@ -876,17 +885,19 @@ TODO:
 +              write_byte(f, 'X');
 +              write_int(f, count);
 +              for (rxa = sxp->xattr->items; count--; rxa++) {
-+#ifdef HAVE_LINUX_XATTRS
-+                      /* Linux already puts the namespace in the key. */
-+                      write_int(f, rxa->name_len);
-+                      write_int(f, rxa->datum_len);
-+#else
-+                      /* Other platforms need the namespace added in,
-+                       * so use the "user." namespace for all keys. */
-+                      write_int(f, rxa->name_len + UPRE_LEN);
-+                      write_int(f, rxa->datum_len);
-+                      write_buf(f, USER_PREFIX, UPRE_LEN);
++#ifndef HAVE_LINUX_XATTRS
++                      /* This OS only sends the user namespace, so we may have
++                       * stored a root namespace from Linux in user space. */
++                      if (strncmp(ptr, ROOT_PREFIX, RPRE_LEN) != 0) {
++                              write_int(f, rxa->name_len + UPRE_LEN);
++                              write_int(f, rxa->datum_len);
++                              write_buf(f, USER_PREFIX, UPRE_LEN);
++                      } else
 +#endif
++                      {
++                              write_int(f, rxa->name_len);
++                              write_int(f, rxa->datum_len);
++                      }
 +                      write_buf(f, rxa->name, rxa->name_len);
 +                      write_buf(f, rxa->datum, rxa->datum_len);
 +              }
@@ -924,10 +935,16 @@ TODO:
 +                      rxa->datum_len = datum_len;
 +                      rxa->name = ptr;
 +                      rxa->datum = ptr + name_len;
-+#ifndef HAVE_LINUX_XATTRS
-+                      if (strncmp(rxa->name, USER_PREFIX, UPRE_LEN) == 0) {
++#ifdef HAVE_LINUX_XATTRS
++                      if (!am_root && strncmp(ptr, ROOT_PREFIX, RPRE_LEN) == 0) {
++                              temp_xattr.count--;
++                              free(ptr);
++                              continue;
++                      }
++#else
++                      if (strncmp(ptr, USER_PREFIX, UPRE_LEN) == 0) {
 +                              rxa->name_len -= UPRE_LEN;
-+                              memmove(rxa->name, rxa->name + UPRE_LEN, rxa->name_len);
++                              memmove(ptr, ptr + UPRE_LEN, rxa->name_len);
 +                      }
 +#endif
 +              }