added support for 64 bit file offsets under Solaris 2.6. Not tested
authorAndrew Tridgell <tridge@samba.org>
Wed, 6 May 1998 05:43:36 +0000 (05:43 +0000)
committerAndrew Tridgell <tridge@samba.org>
Wed, 6 May 1998 05:43:36 +0000 (05:43 +0000)
yet.

checksum.c
configure.in
flist.c
hlink.c
main.c
match.c
rsync.c
rsync.h
syscall.c
util.c

index 32299f0..6186aae 100644 (file)
@@ -93,13 +93,13 @@ void get_checksum2(char *buf,int len,char *sum)
 }
 
 
-void file_checksum(char *fname,char *sum,off_t size)
+void file_checksum(char *fname,char *sum,OFF_T size)
 {
-  off_t i;
+  OFF_T i;
   MDstruct MD;
   struct map_struct *buf;
   int fd;
-  off_t len = size;
+  OFF_T len = size;
   char tmpchunk[CSUM_CHUNK];
 
   bzero(sum,csum_length);
index 9d8b482..6ffd78e 100644 (file)
@@ -56,6 +56,13 @@ main() { long long x = 1000000; char b[20]; x *= x; sprintf(b,"%lld", x); exit(s
 echo yes;AC_DEFINE(HAVE_LONGLONG), 
 echo no)
 
+echo $ac_n "checking for off64_t ... $ac_c"
+AC_TRY_RUN([#include <stdio.h>
+#include <sys/stat.h>
+main() { struct stat64 st; off64_t s; exit((lstat64("/dev/null", &st)==0)?0:1); }],
+echo yes;AC_DEFINE(HAVE_LONGLONG), 
+echo no)
+
 echo $ac_n "checking for utimbuf ... $ac_c"
 AC_TRY_COMPILE([#include <sys/types.h>
 #include <utime.h>],
diff --git a/flist.c b/flist.c
index 86646bb..80754e9 100644 (file)
--- a/flist.c
+++ b/flist.c
@@ -48,16 +48,16 @@ extern int io_error;
 
 static char **local_exclude_list;
 
-int link_stat(const char *Path, struct stat *Buffer) 
+int link_stat(const char *Path, STRUCT_STAT *Buffer) 
 {
 #if SUPPORT_LINKS
     if (copy_links) {
-       return stat(Path, Buffer);
+       return do_stat(Path, Buffer);
     } else {
-       return lstat(Path, Buffer);
+       return do_lstat(Path, Buffer);
     }
 #else
-    return stat(Path, Buffer);
+    return do_stat(Path, Buffer);
 #endif
 }
 
@@ -65,7 +65,7 @@ int link_stat(const char *Path, struct stat *Buffer)
   This function is used to check if a file should be included/excluded
   from the list of files based on its name and type etc
  */
-static int match_file_name(char *fname,struct stat *st)
+static int match_file_name(char *fname,STRUCT_STAT *st)
 {
   if (check_exclude(fname,local_exclude_list)) {
     if (verbose > 2)
@@ -80,7 +80,7 @@ static dev_t filesystem_dev;
 
 static void set_filesystem(char *fname)
 {
-  struct stat st;
+  STRUCT_STAT st;
   if (link_stat(fname,&st) != 0) return;
   filesystem_dev = st.st_dev;
 }
@@ -322,9 +322,9 @@ static void receive_file_entry(struct file_struct **fptr,
 /* determine if a file in a different filesstem should be skipped
    when one_file_system is set. We bascally only want to include
    the mount points - but they can be hard to find! */
-static int skip_filesystem(char *fname, struct stat *st)
+static int skip_filesystem(char *fname, STRUCT_STAT *st)
 {
-       struct stat st2;
+       STRUCT_STAT st2;
        char *p = strrchr(fname, '/');
 
        /* skip all but directories */
@@ -346,7 +346,7 @@ static int skip_filesystem(char *fname, struct stat *st)
 static struct file_struct *make_file(char *fname)
 {
        struct file_struct *file;
-       struct stat st;
+       STRUCT_STAT st;
        char sum[SUM_LENGTH];
        char *p;
        char cleaned_name[MAXPATHLEN];
@@ -553,7 +553,7 @@ static void send_directory(int f,struct file_list *flist,char *dir)
 struct file_list *send_file_list(int f,int argc,char *argv[])
 {
        int i,l;
-       struct stat st;
+       STRUCT_STAT st;
        char *p,*dir;
        char dbuf[MAXPATHLEN];
        char lastpath[MAXPATHLEN]="";
diff --git a/hlink.c b/hlink.c
index 31c19cd..6b2c060 100644 (file)
--- a/hlink.c
+++ b/hlink.c
@@ -106,7 +106,7 @@ int check_hard_link(struct file_struct *file)
 #if SUPPORT_HARD_LINKS
 static void hard_link_one(int i)
 {
-       struct stat st1,st2;
+       STRUCT_STAT st1,st2;
 
        if (link_stat(f_name(&hlink_list[i-1]),&st1) != 0) return;
 
diff --git a/main.c b/main.c
index cbda40e..c0e15d6 100644 (file)
--- a/main.c
+++ b/main.c
@@ -273,9 +273,9 @@ oom:
 
 static char *get_local_name(struct file_list *flist,char *name)
 {
-  struct stat st;
+  STRUCT_STAT st;
 
-  if (stat(name,&st) == 0) {
+  if (do_stat(name,&st) == 0) {
     if (S_ISDIR(st.st_mode)) {
       if (chdir(name) != 0) {
        fprintf(FERROR,"chdir %s : %s (1)\n",name,strerror(errno));
diff --git a/match.c b/match.c
index 7f6e708..dda156f 100644 (file)
--- a/match.c
+++ b/match.c
@@ -87,13 +87,13 @@ static void build_hash_table(struct sum_struct *s)
 }
 
 
-static off_t last_match;
+static OFF_T last_match;
 
 
 static void matched(int f,struct sum_struct *s,struct map_struct *buf,
-                   off_t offset,int i)
+                   OFF_T offset,int i)
 {
-       off_t n = offset - last_match;
+       OFF_T n = offset - last_match;
        int j;
 
        if (verbose > 2 && i >= 0)
@@ -123,9 +123,9 @@ static void matched(int f,struct sum_struct *s,struct map_struct *buf,
 
 
 static void hash_search(int f,struct sum_struct *s,
-                       struct map_struct *buf,off_t len)
+                       struct map_struct *buf,OFF_T len)
 {
-       off_t offset;
+       OFF_T offset;
        int j,k;
        int end;
        char sum2[SUM_LENGTH];
@@ -220,7 +220,7 @@ static void hash_search(int f,struct sum_struct *s,
 }
 
 
-void match_sums(int f,struct sum_struct *s,struct map_struct *buf,off_t len)
+void match_sums(int f,struct sum_struct *s,struct map_struct *buf,OFF_T len)
 {
        char file_sum[MD4_SUM_LENGTH];
 
diff --git a/rsync.c b/rsync.c
index 5f0cef6..463d428 100644 (file)
--- a/rsync.c
+++ b/rsync.c
@@ -72,15 +72,15 @@ static int delete_file(char *fname)
        struct dirent *di;
        char buf[MAXPATHLEN];
        extern int force_delete;
-       struct stat st;
+       STRUCT_STAT st;
        int ret;
 
        if (do_unlink(fname) == 0 || errno == ENOENT) return 0;
 
 #if SUPPORT_LINKS
-       ret = lstat(fname, &st);
+       ret = do_lstat(fname, &st);
 #else
-       ret = stat(fname, &st);
+       ret = do_stat(fname, &st);
 #endif
        if (ret) {
                fprintf(FERROR,"stat(%s) : %s\n", fname, strerror(errno));
@@ -158,14 +158,14 @@ static void send_sums(struct sum_struct *s,int f_out)
 
   generate approximately one checksum every n bytes
   */
-static struct sum_struct *generate_sums(struct map_struct *buf,off_t len,int n)
+static struct sum_struct *generate_sums(struct map_struct *buf,OFF_T len,int n)
 {
   int i;
   struct sum_struct *s;
   int count;
   int block_len = n;
   int remainder = (len%block_len);
-  off_t offset = 0;
+  OFF_T offset = 0;
 
   count = (len+(block_len-1))/block_len;
 
@@ -219,7 +219,7 @@ static struct sum_struct *receive_sums(int f)
 {
   struct sum_struct *s;
   int i;
-  off_t offset = 0;
+  OFF_T offset = 0;
 
   s = (struct sum_struct *)malloc(sizeof(*s));
   if (!s) out_of_memory("receive_sums");
@@ -264,11 +264,11 @@ static struct sum_struct *receive_sums(int f)
 }
 
 
-static int set_perms(char *fname,struct file_struct *file,struct stat *st,
+static int set_perms(char *fname,struct file_struct *file,STRUCT_STAT *st,
                     int report)
 {
   int updated = 0;
-  struct stat st2;
+  STRUCT_STAT st2;
 
   if (dry_run) return 0;
 
@@ -329,7 +329,7 @@ static int set_perms(char *fname,struct file_struct *file,struct stat *st,
 
 /* choose whether to skip a particular file */
 static int skip_file(char *fname,
-                    struct file_struct *file, struct stat *st)
+                    struct file_struct *file, STRUCT_STAT *st)
 {
        if (st->st_size != file->length) {
                return 0;
@@ -364,7 +364,7 @@ int adapt_block_size(struct file_struct *file, int bsize)
 void recv_generator(char *fname,struct file_list *flist,int i,int f_out)
 {  
   int fd;
-  struct stat st;
+  STRUCT_STAT st;
   struct map_struct *buf;
   struct sum_struct *s;
   int statret;
@@ -541,8 +541,8 @@ void recv_generator(char *fname,struct file_list *flist,int i,int f_out)
 static int receive_data(int f_in,struct map_struct *buf,int fd,char *fname)
 {
   int i,n,remainder,len,count;
-  off_t offset = 0;
-  off_t offset2;
+  OFF_T offset = 0;
+  OFF_T offset2;
   char *data;
   static char file_sum1[MD4_SUM_LENGTH];
   static char file_sum2[MD4_SUM_LENGTH];
@@ -661,7 +661,7 @@ static void add_delete_entry(struct file_struct *file)
 static int delete_already_done(struct file_list *flist,int j)
 {
        int i;
-       struct stat st;
+       STRUCT_STAT st;
 
        if (link_stat(f_name(flist->files[j]), &st)) return 1;
 
@@ -743,7 +743,7 @@ void sig_int(void)
 int recv_files(int f_in,struct file_list *flist,char *local_name,int f_gen)
 {  
   int fd1,fd2;
-  struct stat st;
+  STRUCT_STAT st;
   char *fname;
   char fnametmp[MAXPATHLEN];
   struct map_struct *buf;
@@ -794,7 +794,7 @@ int recv_files(int f_in,struct file_list *flist,char *local_name,int f_gen)
       /* open the file */  
       fd1 = open(fname,O_RDONLY);
 
-      if (fd1 != -1 && fstat(fd1,&st) != 0) {
+      if (fd1 != -1 && do_fstat(fd1,&st) != 0) {
        fprintf(FERROR,"fstat %s : %s\n",fname,strerror(errno));
        receive_data(f_in,NULL,-1,NULL);
        close(fd1);
@@ -944,7 +944,7 @@ void send_files(struct file_list *flist,int f_out,int f_in)
   int fd;
   struct sum_struct *s;
   struct map_struct *buf;
-  struct stat st;
+  STRUCT_STAT st;
   char fname[MAXPATHLEN];  
   int i;
   struct file_struct *file;
@@ -1015,7 +1015,7 @@ void send_files(struct file_list *flist,int f_out,int f_in)
          }
          
          /* map the local file */
-         if (fstat(fd,&st) != 0) {
+         if (do_fstat(fd,&st) != 0) {
                  io_error = 1;
                  fprintf(FERROR,"fstat failed : %s\n",strerror(errno));
                  free_sums(s);
diff --git a/rsync.h b/rsync.h
index 6034952..34eeb57 100644 (file)
--- a/rsync.h
+++ b/rsync.h
 #define uint32 unsigned int32
 #endif
 
-#if (SIZEOF_LONG == 8) 
+#if HAVE_OFF64_T
+#define OFF_T off64_t
+#define STRUCT_STAT struct stat64
+#else
+#define OFF_T off_t
+#define STRUCT_STAT struct stat
+#endif
+
+#if HAVE_OFF64_T
+#define int64 off64_t
+#elif (SIZEOF_LONG == 8) 
 #define int64 long
 #elif (SIZEOF_INT == 8) 
 #define int64 int
 struct file_struct {
        unsigned flags;
        time_t modtime;
-       off_t length;
+       OFF_T length;
        mode_t mode;
        ino_t inode;
        dev_t dev;
@@ -244,7 +254,7 @@ struct file_list {
 };
 
 struct sum_buf {
-  off_t offset;                        /* offset in file of this chunk */
+  OFF_T offset;                        /* offset in file of this chunk */
   int len;                     /* length of chunk of file */
   int i;                       /* index of this chunk */
   uint32 sum1;                 /* simple checksum */
@@ -252,7 +262,7 @@ struct sum_buf {
 };
 
 struct sum_struct {
-  off_t flength;               /* total file length */
+  OFF_T flength;               /* total file length */
   int count;                   /* how many chunks */
   int remainder;               /* flength % block_length */
   int n;                       /* block_length */
@@ -262,7 +272,7 @@ struct sum_struct {
 struct map_struct {
        char *map,*p;
        int fd,p_size,p_len;
-       off_t size, p_offset;
+       OFF_T size, p_offset;
 };
 
 /* we need this function because of the silly way in which duplicate
index 3152859..103c002 100644 (file)
--- a/syscall.c
+++ b/syscall.c
@@ -95,3 +95,30 @@ char *do_mktemp(char *template)
        if (dry_run) return NULL;
        return mktemp(template);
 }
+
+int do_stat(const char *fname, STRUCT_STAT *st)
+{
+#if HAVE_OFF64_T
+       return stat64(fname, st);
+#else
+       return stat(fname, st);
+#endif
+}
+
+int do_lstat(const char *fname, STRUCT_STAT *st)
+{
+#if HAVE_OFF64_T
+       return lstat64(fname, st);
+#else
+       return lstat(fname, st);
+#endif
+}
+
+int do_fstat(int fd, STRUCT_STAT *st)
+{
+#if HAVE_OFF64_T
+       return fstat64(fd, st);
+#else
+       return fstat(fd, st);
+#endif
+}
diff --git a/util.c b/util.c
index f61e91d..e39f3cc 100644 (file)
--- a/util.c
+++ b/util.c
@@ -32,7 +32,7 @@ int num_waiting(int fd)
 }
 
 
-struct map_struct *map_file(int fd,off_t len)
+struct map_struct *map_file(int fd,OFF_T len)
 {
   struct map_struct *ret;
   ret = (struct map_struct *)malloc(sizeof(*ret));
@@ -54,7 +54,7 @@ struct map_struct *map_file(int fd,off_t len)
 }
 
 
-char *map_ptr(struct map_struct *map,off_t offset,int len)
+char *map_ptr(struct map_struct *map,OFF_T offset,int len)
 {
   int nread = -2;