From: Nathan Scott Date: Fri, 6 Jun 2003 02:52:27 +0000 (+0000) Subject: xfsprogs fixup - no longer issue ioctls to filesystems on regular files X-Git-Tag: v2.5.0~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f02037ce283f5166dca8a4c4e035b823e4fbe15d;p=thirdparty%2Fxfsprogs-dev.git xfsprogs fixup - no longer issue ioctls to filesystems on regular files --- diff --git a/libxfs/darwin.c b/libxfs/darwin.c index 6d6ac2d8b..b8138a0ac 100644 --- a/libxfs/darwin.c +++ b/libxfs/darwin.c @@ -70,48 +70,34 @@ platform_set_blocksize(int fd, char *path, int blocksize) { } -int -platform_get_blocksize(int fd, char *path) -{ - return BBSIZE; -} - void platform_flush_device(int fd) { ioctl(fd, DKIOCSYNCHRONIZECACHE, NULL); } -__int64_t -platform_findsize(char *path) +void +platform_findsizes(char *path, int fd, long long *sz, int *bsz) { - __int64_t ssize; __uint64_t size; struct stat64 st; - int fd; - if (stat64(path, &st) < 0) { + if (fstat64(fd, &st) < 0) { fprintf(stderr, _("%s: cannot stat the device file \"%s\": %s\n"), progname, path, strerror(errno)); exit(1); } - if ((st.st_mode & S_IFMT) == S_IFREG) - return (__int64_t)(st.st_size >> 9); - - if ((fd = open(path, O_RDONLY, 0)) < 0) { - fprintf(stderr, _("%s: " - "error opening the device special file \"%s\": %s\n"), - progname, path, strerror(errno)); - exit(1); + if ((st.st_mode & S_IFMT) == S_IFREG) { + *sz = (long long)(st.st_size >> 9); + *bsz = BBSIZE; + return; } - if (ioctl(fd, DKIOCGETBLOCKCOUNT, &size) < 0) { fprintf(stderr, _("%s: can't determine device size: %s\n"), progname, strerror(errno)); exit(1); } - close(fd); - ssize = (__int64_t)size; - return ssize; + *sz = (long long)size; + *bsz = BBSIZE; } diff --git a/libxfs/freebsd.c b/libxfs/freebsd.c index d1a9d747d..e04cd31a7 100644 --- a/libxfs/freebsd.c +++ b/libxfs/freebsd.c @@ -64,8 +64,7 @@ platform_check_ismounted(char *name, char *block, struct stat64 *s, int verbose) int platform_check_iswritable(char *name, char *block, struct stat64 *s, int fatal) { - int sts = 0; - return sts; + return 0; } void @@ -73,12 +72,6 @@ platform_set_blocksize(int fd, char *path, int blocksize) { } -int -platform_get_blocksize(int fd, char *path) -{ - return BBSIZE; -} - void platform_flush_device(int fd) { @@ -166,36 +159,24 @@ getdisksize(int fd, const char *fname) return size; } -__int64_t -platform_findsize(char *path) +void +platform_findsizes(char *path, int fd, long long *sz, int *bsz) { - int fd; - struct stat st; - __int64_t size; + struct stat st; + __int64_t size; - /* Test to see if we are dealing with a regular file rather than a - * block device, if we are just use the size returned by stat64 - */ - if (stat(path, &st) < 0) { + if (fstat(fd, &st) < 0) { fprintf(stderr, _("%s: " - "cannot stat the device special file \"%s\": %s\n"), + "cannot stat the device file \"%s\": %s\n"), progname, path, strerror(errno)); exit(1); } if ((st.st_mode & S_IFMT) == S_IFREG) { - return (__int64_t)(st.st_size >> 9); + *sz = (long long)(st.st_size >> 9); + *bsz = BBSIZE; + return; } - if ((fd = open(path, 0)) < 0) { - fprintf(stderr, _("%s: " - "error opening the device special file \"%s\": %s\n"), - progname, path, strerror(errno)); - exit(1); - } - - size = getdisksize(fd, path); - - close(fd); - - return size; + *sz = (long long) getdisksize(fd, path); + *bsz = BBSIZE; } diff --git a/libxfs/init.c b/libxfs/init.c index d94a7c901..e6f5ba108 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -329,13 +329,13 @@ voldone: a->setblksize); a->dfd = libxfs_device_to_fd(a->ddev); } else { - if(!check_open(dname,flags,&rawfile,&blockfile)) + if (!check_open(dname, flags, &rawfile, &blockfile)) goto done; a->ddev = libxfs_device_open(rawfile, a->dcreat, readonly, a->setblksize); a->dfd = libxfs_device_to_fd(a->ddev); - a->dsize = platform_findsize(rawfile); - a->dbsize = platform_get_blocksize(a->dfd, rawfile); + platform_findsizes(rawfile, a->dfd, + &a->dsize, &a->dbsize); } needcd = 1; } else @@ -348,13 +348,13 @@ voldone: a->lcreat, readonly, a->setblksize); a->logfd = libxfs_device_to_fd(a->logdev); } else { - if(!check_open(logname,flags,&rawfile,&blockfile)) + if (!check_open(logname, flags, &rawfile, &blockfile)) goto done; a->logdev = libxfs_device_open(rawfile, a->lcreat, readonly, a->setblksize); a->logfd = libxfs_device_to_fd(a->logdev); - a->logBBsize = platform_findsize(rawfile); - a->lbsize = platform_get_blocksize(a->logfd, rawfile); + platform_findsizes(rawfile, a->logfd, + &a->logBBsize, &a->lbsize); } needcd = 1; } else @@ -367,13 +367,13 @@ voldone: a->rcreat, readonly, a->setblksize); a->rtfd = libxfs_device_to_fd(a->rtdev); } else { - if(!check_open(rtname,flags,&rawfile,&blockfile)) + if (!check_open(rtname, flags, &rawfile, &blockfile)) goto done; a->rtdev = libxfs_device_open(rawfile, a->rcreat, readonly, a->setblksize); a->rtfd = libxfs_device_to_fd(a->rtdev); - a->rtsize = platform_findsize(rawfile); - a->rtbsize = platform_get_blocksize(a->rtfd, rawfile); + platform_findsizes(rawfile, a->rtfd, + &a->rtsize, &a->rtbsize); } needcd = 1; } else diff --git a/libxfs/init.h b/libxfs/init.h index 363d8c339..1c11df41f 100644 --- a/libxfs/init.h +++ b/libxfs/init.h @@ -38,9 +38,8 @@ extern int platform_check_ismounted (char *path, char *block, struct stat64 *sptr, int verbose); extern int platform_check_iswritable (char *path, char *block, struct stat64 *sptr, int fatal); -extern __int64_t platform_findsize (char *path); +extern void platform_findsizes (char *path, int fd, long long *sz, int *bsz); extern void platform_set_blocksize (int fd, char *path, int blocksize); -extern int platform_get_blocksize (int fd, char *path); extern void platform_flush_device (int fd); #endif /* LIBXFS_INIT_H */ diff --git a/libxfs/irix.c b/libxfs/irix.c index f32be60b8..622f1ca62 100644 --- a/libxfs/irix.c +++ b/libxfs/irix.c @@ -65,19 +65,21 @@ platform_flush_device(int fd) return; } -__int64_t -platform_findsize(char *path) +void +platform_findsizes(char *path, int fd, long long *sz, int *bsz) { struct stat64 st; - if (stat64(path, &st) < 0) { + if (fstat64(fd, &st) < 0) { fprintf(stderr, _("%s: cannot stat the device file \"%s\": %s\n"), progname, path, strerror(errno)); exit(1); } - if ((st.st_mode & S_IFMT) == S_IFREG) - return (__int64_t)(st.st_size >> 9); - - return findsize(path); + if ((st.st_mode & S_IFMT) == S_IFREG) { + *sz = (long long)(st.st_size >> 9); + } else { + *sz = findsize(path); + } + *bsz = BBSIZE; } diff --git a/libxfs/linux.c b/libxfs/linux.c index 068ec268e..d030457ec 100644 --- a/libxfs/linux.c +++ b/libxfs/linux.c @@ -120,67 +120,52 @@ platform_set_blocksize(int fd, char *path, int blocksize) } } -int -platform_get_blocksize(int fd, char *path) -{ - int blocksize; - - if (ioctl(fd, BLKSSZGET, &blocksize) < 0) { - fprintf(stderr, _("%s: warning - cannot get sector size " - "from block device %s: %s\n"), - progname, path, strerror(errno)); - blocksize = BBSIZE; - } - return blocksize; -} - void platform_flush_device(int fd) { ioctl(fd, BLKFLSBUF, 0); } -__int64_t -platform_findsize(char *path) +void +platform_findsizes(char *path, int fd, long long *sz, int *bsz) { - int fd; - int error; - __int64_t ssize; - __uint64_t size; struct stat64 st; + __uint64_t size; + int error; - if (stat64(path, &st) < 0) { + if (fstat64(fd, &st) < 0) { fprintf(stderr, _("%s: " "cannot stat the device file \"%s\": %s\n"), progname, path, strerror(errno)); exit(1); } - if ((st.st_mode & S_IFMT) == S_IFREG) - return (__int64_t)(st.st_size >> 9); - - if ((fd = open(path, O_RDONLY, 0)) < 0) { - fprintf(stderr, _("%s: " - "error opening the device special file \"%s\": %s\n"), - progname, path, strerror(errno)); - exit(1); + if ((st.st_mode & S_IFMT) == S_IFREG) { + *sz = (long long)(st.st_size >> 9); + *bsz = BBSIZE; + return; } error = ioctl(fd, BLKGETSIZE64, &size); if (error >= 0) { /* BLKGETSIZE64 returns size in bytes not 512-byte blocks */ - ssize = size >> 9; + *sz = (long long)(size >> 9); } else { /* If BLKGETSIZE64 fails, try BLKGETSIZE */ unsigned long tmpsize; + error = ioctl(fd, BLKGETSIZE, &tmpsize); if (error < 0) { fprintf(stderr, _("%s: can't determine device size\n"), progname); exit(1); } - ssize = (__int64_t)tmpsize; + *sz = (long long)tmpsize; } - close(fd); - return ssize; + if (ioctl(fd, BLKSSZGET, bsz) < 0) { + fprintf(stderr, _("%s: warning - cannot get sector size " + "from block device %s: %s\n"), + progname, path, strerror(errno)); + *bsz = BBSIZE; + } }