preallocate.diff   [plain text]


--- src/extract.c~before~preallocate	2006-03-29 12:03:07.000000000 -0800
+++ src/extract.c	2006-03-29 12:04:17.000000000 -0800
@@ -48,6 +48,10 @@ struct copyfile_list_entry_t {
 extern LIST_HEAD(copyfile_list_t, copyfile_list_entry_t) copyfile_list;
 #endif
 
+#ifdef __APPLE__
+#include <sys/mount.h>
+#endif /* __APPLE__ */
+
 bool we_are_root;		/* true if our effective uid == 0 */
 static mode_t newdir_umask;	/* umask when creating new directories */
 static mode_t current_umask;	/* current umask (which is set to 0 if -p) */
@@ -747,6 +751,10 @@ extract_archive (void)
 	{
 	  static int conttype_diagnosed;
 
+#ifdef __APPLE__
+	  /* XXX Would be nice to suppress this warning if we pre-allocate. */
+#endif /* __APPLE__ */
+
 	  if (!conttype_diagnosed)
 	    {
 	      conttype_diagnosed = 1;
@@ -769,6 +777,29 @@ extract_archive (void)
 	  break;
 	}
 
+#ifdef __APPLE__
+    /* Pre-allocate blocks for the destination file if it resides
+       on Xsan.  */
+
+    if (! current_stat_info.is_sparse)
+      {
+	struct statfs sfs;
+
+	if (fstatfs (fd, &sfs) == 0
+	    && strcmp (sfs.f_fstypename, "acfs") == 0)
+	  {
+	    fstore_t fst;
+
+	    fst.fst_flags = 0;
+	    fst.fst_posmode = F_PEOFPOSMODE;
+	    fst.fst_offset = 0;
+	    fst.fst_length = current_stat_info.stat.st_size;
+
+	    (void) fcntl (fd, F_PREALLOCATE, &fst);
+	  }
+      }
+#endif /* __APPLE__ */
+
     extract_file:
       if (current_stat_info.is_sparse)
 	{