X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=libsysio%2Ftests%2Ftest_copy.c;h=e1954ffc46e478976469ee88cc29f2ccbacd5008;hb=961b3c97b57354fc17017be8087509d1fbce875d;hp=9ac97b170ca6665781e477d98d6834f5732ec0e4;hpb=8692f4651696ff4324db3ad738d3fa62f68d7347;p=fs%2Flustre-release.git diff --git a/libsysio/tests/test_copy.c b/libsysio/tests/test_copy.c index 9ac97b1..e1954ff 100644 --- a/libsysio/tests/test_copy.c +++ b/libsysio/tests/test_copy.c @@ -41,8 +41,6 @@ * lee@sandia.gov */ -#define _BSD_SOURCE - #include #include #include @@ -52,7 +50,11 @@ #include #include #include +#include +#if defined(SYSIO_LABEL_NAMES) +#include "sysio.h" +#endif #include "xtio.h" #include "test.h" @@ -136,7 +138,7 @@ open_file(const char *path, int flags, mode_t mode) { int fd; - fd = open(path, flags, mode); + fd = SYSIO_INTERFACE_NAME(open)(path, flags, mode); if (fd < 0) perror(path); @@ -149,11 +151,14 @@ copy_file(const char *spath, const char *dpath) int sfd, dfd; int flags; int rtn; - static char buf[1024]; + struct stat stat; + char *buf; + size_t bufsiz; ssize_t cc, wcc; sfd = dfd = -1; rtn = -1; + buf = NULL; sfd = open_file(spath, O_RDONLY, 0); if (sfd < 0) @@ -165,8 +170,23 @@ copy_file(const char *spath, const char *dpath) if (dfd < 0) goto out; - while ((cc = read(sfd, buf, sizeof(buf))) > 0) - if ((wcc = write(dfd, buf, cc)) != cc) { + rtn = SYSIO_INTERFACE_NAME(fstat)(dfd, &stat); + if (rtn != 0) { + perror(dpath); + goto out; + } + bufsiz = stat.st_blksize; + if (bufsiz < (64 * 1024)) + bufsiz = + (((64 * 1024) / stat.st_blksize - 1) + 1) * (64 * 1024); + buf = malloc(bufsiz); + if (!buf) { + perror(dpath); + goto out; + } + + while ((cc = SYSIO_INTERFACE_NAME(read)(sfd, buf, bufsiz)) > 0) + if ((wcc = SYSIO_INTERFACE_NAME(write)(dfd, buf, cc)) != cc) { if (wcc < 0) { perror(dpath); break; @@ -178,14 +198,20 @@ copy_file(const char *spath, const char *dpath) (unsigned )cc); break; } - if (cc < 0) + if (cc < 0) { perror(spath); + rtn = -1; + } out: - if (sfd >= 0 && close(sfd) != 0) + if (buf) + free(buf); + if (sfd >= 0 && SYSIO_INTERFACE_NAME(close)(sfd) != 0) perror(spath); - if (dfd >= 0 && (fsync(dfd) != 0 || close(dfd) != 0)) + if (dfd >= 0 && + (SYSIO_INTERFACE_NAME(fsync)(dfd) != 0 || + SYSIO_INTERFACE_NAME(close)(dfd) != 0)) perror(dpath); - return 0; + return rtn; }