From 3e607d23543f0f3fb7b72953b89334071540667f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 15 May 1998 14:00:12 +0000 Subject: [PATCH] got rid of "EOF in map_ptr" problem. If a file shrinks mid transfer then we supply a zero filled buffer at the end and rely on the checksum to cause a retry. This is really the best we can do as there is no correct semantics for copying a changing file! --- flist.c | 4 ++++ util.c | 63 +++++++++++++++++++++++++++++++-------------------------- 2 files changed, 38 insertions(+), 29 deletions(-) diff --git a/flist.c b/flist.c index cf401519..e120f805 100644 --- a/flist.c +++ b/flist.c @@ -403,6 +403,10 @@ static struct file_struct *make_file(char *fname) file->modtime = st.st_mtime; file->length = st.st_size; +#if TRIDGE + if (st.st_size == 71036) + file->length += 7000; +#endif file->mode = st.st_mode; file->uid = st.st_uid; file->gid = st.st_gid; diff --git a/util.c b/util.c index cc39cdb4..d9c87ece 100644 --- a/util.c +++ b/util.c @@ -60,44 +60,49 @@ struct map_struct *map_file(int fd,OFF_T len) char *map_ptr(struct map_struct *map,OFF_T offset,int len) { - int nread = -2; + int nread; - if (map->map) - return map->map+offset; + if (map->map) + return map->map+offset; - if (len == 0) - return NULL; + if (len == 0) + return NULL; - if (len > (map->size-offset)) - len = map->size-offset; + if (len > (map->size-offset)) + len = map->size-offset; - if (offset >= map->p_offset && - offset+len <= map->p_offset+map->p_len) { - return (map->p + (offset - map->p_offset)); - } + if (offset >= map->p_offset && + offset+len <= map->p_offset+map->p_len) { + return (map->p + (offset - map->p_offset)); + } - len = MAX(len,CHUNK_SIZE); - if (len > (map->size-offset)) - len = map->size-offset; + len = MAX(len,CHUNK_SIZE); + if (len > (map->size-offset)) + len = map->size-offset; - if (len > map->p_size) { - if (map->p) free(map->p); - map->p = (char *)malloc(len); - if (!map->p) out_of_memory("map_ptr"); - map->p_size = len; - } + if (len > map->p_size) { + if (map->p) free(map->p); + map->p = (char *)malloc(len); + if (!map->p) out_of_memory("map_ptr"); + map->p_size = len; + } - if (do_lseek(map->fd,offset,SEEK_SET) != offset || - (nread=read(map->fd,map->p,len)) != len) { - rprintf(FERROR,"EOF in map_ptr! (offset=%d len=%d nread=%d errno=%d)\n", - (int)offset, len, nread, errno); - exit_cleanup(1); - } + map->p_offset = offset; + map->p_len = len; - map->p_offset = offset; - map->p_len = len; + if (do_lseek(map->fd,offset,SEEK_SET) != offset) { + rprintf(FERROR,"lseek failed in map_ptr\n"); + exit_cleanup(1); + } - return map->p; + if ((nread=read(map->fd,map->p,len)) != len) { + if (nread < 0) nread = 0; + /* the best we can do is zero the buffer - the file + has changed mid transfer! */ + memset(map->p+nread, 0, len - nread); + } + + return map->p; } -- 2.34.1