]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfsprogs fixup - no longer issue ioctls to filesystems on regular files
authorNathan Scott <nathans@sgi.com>
Fri, 6 Jun 2003 02:52:27 +0000 (02:52 +0000)
committerNathan Scott <nathans@sgi.com>
Fri, 6 Jun 2003 02:52:27 +0000 (02:52 +0000)
libxfs/darwin.c
libxfs/freebsd.c
libxfs/init.c
libxfs/init.h
libxfs/irix.c
libxfs/linux.c

index 6d6ac2d8b81f20e2245316615144daf5bf7685fb..b8138a0aca57544882cf6afaed4bebec2d2b3276 100644 (file)
@@ -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;
 }
index d1a9d747d4a21d92da62e35f23b3953b5210fce6..e04cd31a73d0f5ae3381a1cece53635659e48722 100644 (file)
@@ -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;
 }
index d94a7c9016a1146276a567e411aecca20d96c254..e6f5ba1087aa564e0b987a9fc51f0aac320274cf 100644 (file)
@@ -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
index 363d8c3398cf8595c68e988d72f81b591e5180f5..1c11df41fbac584025adda9cb1c649c3923f995c 100644 (file)
@@ -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 */
index f32be60b831c075b4be19565a7fb0c0f89bca13a..622f1ca62bc8288488f7869163f377d2110e7aa2 100644 (file)
@@ -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;
 }
index 068ec268e78cd39a5802b15378d48fffa81fa9b1..d030457ecceda85595b39e95a586e5045e2e1f8f 100644 (file)
@@ -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;
+       }
 }