From 69a3ffa32337471dbc9d89477de4c27a643394a1 Mon Sep 17 00:00:00 2001 From: Simon Wilkinson Date: Thu, 30 Sep 2010 20:24:49 +0100 Subject: [PATCH] usd: Move to using real 64bit quantities Move the usd library over to using afs_int64, rather than afs_hyper_t now that everything in userspace is assumed to be 64bit capable. Change-Id: I9ffc0996e1696d016dae96c0a2245cf5121c49a1 Reviewed-on: http://gerrit.openafs.org/4768 Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear --- src/butc/read_tape.c | 4 ++-- src/butm/file_tm.c | 40 ++++++++++++++-------------------------- src/usd/test/usd_test.c | 16 ++++++++-------- src/usd/usd.h | 10 +++++----- src/usd/usd_file.c | 40 +++++++++++++--------------------------- src/usd/usd_nt.c | 35 +++++++++++++++++------------------ src/volser/vos.c | 18 +++++++----------- 7 files changed, 66 insertions(+), 97 deletions(-) diff --git a/src/butc/read_tape.c b/src/butc/read_tape.c index c8818a3de..fe36a5778 100644 --- a/src/butc/read_tape.c +++ b/src/butc/read_tape.c @@ -194,7 +194,7 @@ openOutFile(struct volumeHeader *headerPtr) int rc; int oflag; int skip, first; - afs_hyper_t size; + afs_int64 size; /* If we were asked to skip this volume, then skip it */ if (nskip) { @@ -260,7 +260,7 @@ openOutFile(struct volumeHeader *headerPtr) return 0; } if (headerPtr->contd != TC_VOLCONTD) { - hzero(size); + size = 0; rc = USD_IOCTL(ofd, USD_IOCTL_SETSIZE, &size); if (rc != 0) { fprintf(stderr, "Unable to open file %s. Skipping. Code = %d\n", diff --git a/src/butm/file_tm.c b/src/butm/file_tm.c index 68a8f2045..21119a2c1 100644 --- a/src/butm/file_tm.c +++ b/src/butm/file_tm.c @@ -573,10 +573,9 @@ static int Rewind(usd_handle_t fid) { if (isafile) { - afs_hyper_t startOff, stopOff; - hzero(startOff); + afs_int64 stopOff; - return (USD_SEEK(fid, startOff, SEEK_SET, &stopOff)); + return (USD_SEEK(fid, 0, SEEK_SET, &stopOff)); } else { return (ForkIoctl(fid, USDTAPE_REW, 0)); } @@ -654,8 +653,9 @@ incPosition(struct butm_tapeInfo *info, usd_handle_t fid, afs_uint32 dataSize) info->posCount = 0; #if (defined(AFS_SUN_ENV) || defined(AFS_LINUX24_ENV)) if (!isafile) { - afs_hyper_t off; - hset64(off, 0, 0); + afs_int64 off; + + off = 0; USD_IOCTL(fid, USD_IOCTL_SETSIZE, &off); } #endif @@ -1126,7 +1126,7 @@ file_WriteLabel(struct butm_tapeInfo *info, struct butm_tapeLabel *label, afs_int32 fcode; struct tapeLabel *tlabel; struct progress *p; - afs_hyper_t off; /* offset */ + afs_int64 off; /* offset */ if (info->debug) printf("butm: Write tape label\n"); @@ -1149,7 +1149,7 @@ file_WriteLabel(struct butm_tapeInfo *info, struct butm_tapeLabel *label, if (isafile) { p = (struct progress *)info->tmRock; - hset64(off, 0, 0); + off = 0; code = USD_IOCTL(p->fid, USD_IOCTL_SETSIZE, &off); if (code) ERROR_EXIT(BUTM_POSITION); @@ -1555,9 +1555,8 @@ file_Seek(struct butm_tapeInfo *info, afs_int32 position) afs_int32 code = 0; afs_int32 w; osi_lloff_t posit; - afs_uint32 c, d; struct progress *p; - afs_hyper_t startOff, stopOff; /* for normal file(non-tape) seeks */ + afs_int64 stopOff; /* for normal file(non-tape) seeks */ if (info->debug) printf("butm: Seek to the tape position %d\n", position); @@ -1572,20 +1571,10 @@ file_Seek(struct butm_tapeInfo *info, afs_int32 position) p = (struct progress *)info->tmRock; posit = (osi_lloff_t) position *(osi_lloff_t) BUTM_BLOCKSIZE; - /* Not really necessary to do it this way, should be fixed */ -#ifdef O_LARGEFILE - c = (posit >> 32); - d = (posit & 0xffffffff); -#else - c = 0; - d = posit; -#endif - hset64(startOff, c, d); - - w = USD_SEEK(p->fid, startOff, SEEK_SET, &stopOff); + w = USD_SEEK(p->fid, posit, SEEK_SET, &stopOff); if (w) info->error = w; - if (hcmp(startOff, stopOff) != 0) + if (posit != stopOff) ERROR_EXIT(BUTM_POSITION); p->reading = p->writing = 0; @@ -1616,7 +1605,7 @@ file_SeekEODump(struct butm_tapeInfo *info, afs_int32 position) afs_int32 blockType; afs_int32 w; struct progress *p; - afs_hyper_t startOff, stopOff; /* file seek offsets */ + afs_int64 stopOff; /* file seek offsets */ if (info->debug) printf("butm: Seek to end-of-dump\n"); @@ -1630,16 +1619,15 @@ file_SeekEODump(struct butm_tapeInfo *info, afs_int32 position) if (isafile) { p = (struct progress *)info->tmRock; - hset64(startOff, 0, 0); - w = USD_SEEK(p->fid, startOff, SEEK_END, &stopOff); + w = USD_SEEK(p->fid, 0, SEEK_END, &stopOff); if (w) { info->error = w; ERROR_EXIT(BUTM_POSITION); } - if (hgetlo(stopOff) % BUTM_BLOCKSIZE) + if (stopOff % BUTM_BLOCKSIZE) ERROR_EXIT(BUTM_POSITION); - info->position = (hgetlo(stopOff) / BUTM_BLOCKSIZE); + info->position = (stopOff / BUTM_BLOCKSIZE); } else { /* Seek to the desired position */ code = SeekFile(info, (position - info->position) + 1); diff --git a/src/usd/test/usd_test.c b/src/usd/test/usd_test.c index ccf35602b..920c9cf63 100644 --- a/src/usd/test/usd_test.c +++ b/src/usd/test/usd_test.c @@ -36,7 +36,7 @@ static int ForwardSpace(usd_handle_t hTape, int cnt); static int BackSpace(usd_handle_t hTape, int cnt); static int PrepTape(usd_handle_t hTape); static int ShutdownTape(usd_handle_t hTape); -static int PrintTapePos(usd_handle_t hTape); +static afs_int64 PrintTapePos(usd_handle_t hTape); int main(int argc, char **argv) @@ -271,7 +271,7 @@ ShutdownTape(usd_handle_t hTape) } #ifdef AFS_NT40_ENV -static int +static afs_int64 PrintTapePos(usd_handle_t hTape) { DWORD rcode; @@ -289,21 +289,21 @@ PrintTapePos(usd_handle_t hTape) return (offLow); } #else -static int +static afs_int64 PrintTapePos(usd_handle_t hTape) { - afs_hyper_t startOff, stopOff; + afs_int64 startOff, stopOff; int rcode; - hset64(startOff, 0, 0); - hset64(stopOff, 0, 0); + startOff = 0; + stopOff = 0; rcode = USD_SEEK(hTape, startOff, SEEK_CUR, &stopOff); err_exit("Seek", "Tape Seek Test Failed", rcode); if (USDTEST_DEBUG) - printf("%s: Cur Tape Pos : %d bytes\n", whoami, stopOff.low); + printf("%s: Cur Tape Pos : %"AFS_INT64_FMT" bytes\n", whoami, stopOff); - return (stopOff.low); + return stopOff; } #endif diff --git a/src/usd/usd.h b/src/usd/usd.h index 485f4a871..af767693c 100644 --- a/src/usd/usd.h +++ b/src/usd/usd.h @@ -38,7 +38,7 @@ * * As a consequence of this method of reporting errors, output values are * returned in reference parameters instead of being encoded in the return - * value. Also, offsets and lengths use the afs_hyper_t type. */ + * value. Also, offsets and lengths use the afs_int64 type. */ /* NOTE -- this module is preempt safe. It assume it is being called from a * preemptive environment. Treat all calls as if they had an "_r" @@ -51,8 +51,8 @@ struct usd_handle { afs_uint32 * xferdP); int (*write) (usd_handle_t usd, char *buf, afs_uint32 nbyte, afs_uint32 * xferdP); - int (*seek) (usd_handle_t usd, afs_hyper_t inOff, int whence, - afs_hyper_t * outOffP); + int (*seek) (usd_handle_t usd, afs_int64 inOff, int whence, + afs_int64 * outOffP); int (*ioctl) (usd_handle_t usd, int req, void *arg); int (*close) (usd_handle_t usd); @@ -118,12 +118,12 @@ extern int usd_StandardOutput(usd_handle_t * usdP); #define USD_IOCTL_GETDEV 3 -/* GetSize(afs_hyper_t *sizeP) -- returns the size of the file. Doesn't work +/* GetSize(afs_int64 *sizeP) -- returns the size of the file. Doesn't work * on BLK or CHR devices. */ #define USD_IOCTL_GETSIZE 6 -/* SetSize(afs_hyper_t *sizeP) -- sets the size of the file. Doesn't work +/* SetSize(afs_int64 *sizeP) -- sets the size of the file. Doesn't work * on BLK or CHR devices. */ #define USD_IOCTL_SETSIZE 7 diff --git a/src/usd/usd_file.c b/src/usd/usd_file.c index 8b71e305e..cc00dc31d 100644 --- a/src/usd/usd_file.c +++ b/src/usd/usd_file.c @@ -49,19 +49,8 @@ typedef off_t osi_lloff_t; * conversion occur. A good compiler in a 64 bit environment will * elide the entire statement if the offset type is 64 bits wide. */ -#define osi_hFitsInOff(ahyper, noff) \ - ((sizeof(noff) == 4) ? hfitsin32(ahyper) : 1) - -#define osi_h2off(ahyper, noff) \ - ((sizeof(noff) == 4) \ - ? ((noff) = (osi_lloff_t)hgetlo(ahyper))\ - : ((noff) = ((osi_lloff_t)hgethi(ahyper)<<32) | (osi_lloff_t)hgetlo(ahyper))) - -#define osi_off2h(noff, ahyper) \ - ((sizeof(noff) == 4) \ - ? (hset32(ahyper, (int)noff)) \ - : (hset64(ahyper, (int)((noff>>32)&0xffffffff), ((int)noff&0xffffffff)))) - +#define osi_hFitsInOff(val) \ + ((sizeof(osi_lloff_t) == 4) ? (((val) & 0xffffffff00000000LL) == 0) : 1) /************ End of osi wrappers ***********************************/ @@ -106,21 +95,20 @@ usd_FileWrite(usd_handle_t usd, char *buf, afs_uint32 nbytes, extern osi_lloff_t osi_llseek(int, osi_lloff_t, int); static int -usd_FileSeek(usd_handle_t usd, afs_hyper_t reqOff, int whence, - afs_hyper_t * curOffP) +usd_FileSeek(usd_handle_t usd, afs_int64 reqOff, int whence, + afs_int64 * curOffP) { int fd = (intptr_t)(usd->handle); osi_lloff_t lloff; - if (!osi_hFitsInOff(reqOff, lloff)) + if (!osi_hFitsInOff(reqOff)) return EINVAL; - osi_h2off(reqOff, lloff); - lloff = osi_llseek(fd, lloff, whence); + lloff = osi_llseek(fd, reqOff, whence); if (lloff == (((osi_lloff_t) 0) - 1)) return errno; if (curOffP) - osi_off2h(lloff, *curOffP); + *curOffP = lloff; return 0; } @@ -137,8 +125,7 @@ usd_FileIoctl(usd_handle_t usd, int req, void *arg) #ifdef AFS_AIX_ENV struct statfs fsinfo; /* AIX stat structure doesn't have st_blksize */ #endif /* AFS_AIX_ENV */ - afs_hyper_t size; - osi_lloff_t off; + afs_int64 size; int code = 0; switch (req) { @@ -176,7 +163,7 @@ usd_FileIoctl(usd_handle_t usd, int req, void *arg) case USD_IOCTL_GETSIZE: if (S_ISCHR(info.st_mode) || S_ISBLK(info.st_mode)) return ENOTTY; /* shouldn't be a device */ - osi_off2h(info.st_size, *(afs_hyper_t *) arg); + *(afs_int64 *)arg = info.st_size; break; case USD_IOCTL_GETFULLNAME: *(char **)arg = usd->fullPathName; @@ -190,14 +177,13 @@ usd_FileIoctl(usd_handle_t usd, int req, void *arg) /* However, I'm pretty sure this doesn't work on Ultrix so I am * unsure about OSF/1 and HP/UX. 931118 */ - size = *(afs_hyper_t *) arg; - if (!osi_hFitsInOff(size, off)) + size = *(afs_int64 *) arg; + if (!osi_hFitsInOff(size)) return EFBIG; - osi_h2off(size, off); #ifdef O_LARGEFILE - code = ftruncate64(fd, off); + code = ftruncate64(fd, size); #else /* O_LARGEFILE */ - code = ftruncate(fd, off); + code = ftruncate(fd, size); #endif /* O_LARGEFILE */ if (code == -1) code = errno; diff --git a/src/usd/usd_nt.c b/src/usd/usd_nt.c index 506eda832..b2e09e6d6 100644 --- a/src/usd/usd_nt.c +++ b/src/usd/usd_nt.c @@ -100,13 +100,13 @@ usd_DeviceWrite(usd_handle_t usd, char *buf, afs_uint32 nbytes, * Add a check of the offset against the disk size to fix this problem. */ static int -usd_DeviceSeek(usd_handle_t usd, afs_hyper_t reqOff, int whence, - afs_hyper_t * curOffP) +usd_DeviceSeek(usd_handle_t usd, afs_int64 reqOff, int whence, + afs_int64 * curOffP) { HANDLE fd = usd->handle; DWORD method, result; DWORD error; - long loOffset, hiOffset; + LARGE_INTEGER offset, retOffset; /* determine move method based on value of whence */ @@ -124,28 +124,25 @@ usd_DeviceSeek(usd_handle_t usd, afs_hyper_t reqOff, int whence, /* attempt seek */ - loOffset = hgetlo(reqOff); - hiOffset = hgethi(reqOff); - if (usd->privateData) { /* For disk devices that know their size, check the offset against the * limit provided by DeviceIoControl(). */ - DWORDLONG offset = - ((DWORDLONG) hgethi(reqOff) << 32 | (DWORDLONG) hgetlo(reqOff)); - - DWORDLONG k = (DWORDLONG) ((afs_uint32) usd->privateData); + afs_int64 k = ((afs_uint32) usd->privateData); - if (offset >= (k << 10)) + if (reqOff >= (k << 10)) return EINVAL; } - result = SetFilePointer(fd, loOffset, &hiOffset, method); - if (result == 0xffffffff && (error = GetLastError()) != NO_ERROR) + offset.QuadPart = reqOff; + + result = SetFilePointerEx(fd, offset, &retOffset, method); + if (result == 0 && (error = GetLastError()) != NO_ERROR) return nterr_nt2unix(error, EIO); + if (curOffP) - hset64(*curOffP, hiOffset, result); + *curOffP = retOffset.QuadPart; return 0; } @@ -154,6 +151,7 @@ static int usd_DeviceIoctl(usd_handle_t usd, int req, void *arg) { HANDLE fd = usd->handle; + LARGE_INTEGER size; DWORD result; DWORD hiPart; int code = 0; @@ -231,14 +229,15 @@ usd_DeviceIoctl(usd_handle_t usd, int req, void *arg) break; case USD_IOCTL_GETSIZE: - result = GetFileSize(fd, &hiPart); - if (result == 0xffffffff && (code = GetLastError()) != NO_ERROR) + if (!GetFileSizeEx(fd, &size) && (code = GetLastError()) != NO_ERROR) return nterr_nt2unix(code, EIO); - hset64(*(afs_hyper_t *) arg, hiPart, result); + + *(afs_int64 *) arg = size.QuadPart; + return 0; case USD_IOCTL_SETSIZE: - code = usd_DeviceSeek(usd, *(afs_hyper_t *) arg, SEEK_SET, NULL); + code = usd_DeviceSeek(usd, *(afs_int64 *) arg, SEEK_SET, NULL); if (!code) { if (!SetEndOfFile(fd)) code = nterr_nt2unix(GetLastError(), EIO); diff --git a/src/volser/vos.c b/src/volser/vos.c index 95bf87ecc..4a931d0f7 100644 --- a/src/volser/vos.c +++ b/src/volser/vos.c @@ -134,7 +134,7 @@ FileExists(char *filename) { usd_handle_t ufd; int code; - afs_hyper_t size; + afs_int64 size; code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd); if (code) { @@ -331,7 +331,7 @@ WriteData(struct rx_call *call, void *rock) long blksize; afs_int32 error, code; int ufdIsOpen = 0; - afs_hyper_t filesize, currOffset; + afs_int64 currOffset; afs_uint32 buffer; afs_uint32 got; @@ -354,19 +354,15 @@ WriteData(struct rx_call *call, void *rock) goto wfail; } /* test if we have a valid dump */ - hset64(filesize, 0, 0); - USD_SEEK(ufd, filesize, SEEK_END, &currOffset); - hset64(filesize, hgethi(currOffset), hgetlo(currOffset)-sizeof(afs_uint32)); - USD_SEEK(ufd, filesize, SEEK_SET, &currOffset); + USD_SEEK(ufd, 0, SEEK_END, &currOffset); + USD_SEEK(ufd, currOffset - sizeof(afs_uint32), SEEK_SET, &currOffset); USD_READ(ufd, (char *)&buffer, sizeof(afs_uint32), &got); if ((got != sizeof(afs_uint32)) || (ntohl(buffer) != DUMPENDMAGIC)) { fprintf(STDERR, "Signature missing from end of file '%s'\n", filename); error = VOLSERBADOP; goto wfail; } - /* rewind, we are done */ - hset64(filesize, 0, 0); - USD_SEEK(ufd, filesize, SEEK_SET, &currOffset); + USD_SEEK(ufd, 0, SEEK_SET, &currOffset); } code = SendFile(ufd, call, blksize); if (code) { @@ -438,7 +434,7 @@ DumpFunction(struct rx_call *call, void *rock) char *filename = (char *)rock; usd_handle_t ufd; /* default is to stdout */ afs_int32 error = 0, code; - afs_hyper_t size; + afs_int64 size; long blksize; int ufdIsOpen = 0; @@ -452,7 +448,7 @@ DumpFunction(struct rx_call *call, void *rock) usd_Open(filename, USD_OPEN_CREATE | USD_OPEN_RDWR, 0666, &ufd); if (code == 0) { ufdIsOpen = 1; - hzero(size); + size = 0; code = USD_IOCTL(ufd, USD_IOCTL_SETSIZE, &size); } if (code == 0) { -- 2.39.5