From b89cbd67a4e187d4f157a496f358e8a3c6f64b85 Mon Sep 17 00:00:00 2001 From: pavel Date: Mon, 30 Sep 2002 18:12:10 +0000 Subject: [PATCH] r24: COPYONWRITE had horrible coding style. Cleanups still needed. --- nbd-server.c | 126 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 63 insertions(+), 63 deletions(-) diff --git a/nbd-server.c b/nbd-server.c index 93448ac..bae7f0c 100644 --- a/nbd-server.c +++ b/nbd-server.c @@ -318,15 +318,14 @@ void maybeseek(int handle, fsoffset_t a) void myseek(int handle,fsoffset_t a) { #if HAVE_LLSEEK && !defined(FS_32BIT) - if (llseek(handle, a, SEEK_SET) < 0) + if (llseek(handle, a, SEEK_SET) < 0) #else - if (lseek(handle, (long)a, SEEK_SET) < 0) + if (lseek(handle, (long)a, SEEK_SET) < 0) #endif - err("Can not seek locally!\n"); + err("Can not seek locally!\n"); } -char pagebuf[DIFFPAGESIZE] ; - +char pagebuf[DIFFPAGESIZE]; int rawexpread(fsoffset_t a, char *buf, int len) { @@ -339,29 +338,29 @@ int expread(fsoffset_t a, char *buf, int len) int rdlen, offset; fsoffset_t mapcnt, mapl, maph, pagestart; - if (flags & F_COPYONWRITE) { - DEBUG3("Asked to read %d bytes at %Lu.\n", len, (unsigned long long)a); - - mapl=a/DIFFPAGESIZE ; maph=(a+len-1)/DIFFPAGESIZE ; - - for (mapcnt=mapl;mapcnt<=maph;mapcnt++) { - pagestart=mapcnt*DIFFPAGESIZE ; - offset=a-pagestart ; - rdlen=(lenhunksize) - rdlen=hunksize-(pagestart%hunksize) ; - if (rawexpread(pagestart,pagebuf,rdlen)) return -1 ; - memcpy(pagebuf+offset,buf,wrlen) ; - if (write(difffile,pagebuf,DIFFPAGESIZE)!=DIFFPAGESIZE) return -1 ; - } - len-=wrlen ; a+=wrlen ; buf+=wrlen ; - } - } else return(rawexpwrite(a,buf,len)); - return 0 ; +{ + u32 mapcnt,mapl,maph ; int wrlen,rdlen ; + fsoffset_t pagestart ; int offset ; + + if (!(flags & F_COPYONWRITE)) + return(rawexpwrite(a,buf,len)); + DEBUG3("Asked to write %d bytes at %Lu.\n", len, (unsigned long long)a); + + mapl=a/DIFFPAGESIZE ; maph=(a+len-1)/DIFFPAGESIZE ; + + for (mapcnt=mapl;mapcnt<=maph;mapcnt++) { + pagestart=mapcnt*DIFFPAGESIZE ; + offset=a-pagestart ; + wrlen=(lenhunksize) + rdlen=hunksize-(pagestart%hunksize) ; + if (rawexpread(pagestart,pagebuf,rdlen)) return -1 ; + memcpy(pagebuf+offset,buf,wrlen) ; + if (write(difffile,pagebuf,DIFFPAGESIZE)!=DIFFPAGESIZE) return -1 ; + } + len-=wrlen ; a+=wrlen ; buf+=wrlen ; + } + return 0; } int mainloop(int net) -- 1.7.10.4