Whamcloud - gitweb
libext2fs: precompute FS UUID checksum seed
[tools/e2fsprogs.git] / lib / ext2fs / getsize.c
index 79fba59..0a7053e 100644 (file)
@@ -7,14 +7,15 @@
  * Windows version of ext2fs_get_device_size by Chris Li, VMware.
  *
  * %Begin-Header%
- * This file may be redistributed under the terms of the GNU Public
- * License.
+ * This file may be redistributed under the terms of the GNU Library
+ * General Public License, version 2.
  * %End-Header%
  */
 
 #define _LARGEFILE_SOURCE
 #define _LARGEFILE64_SOURCE
 
+#include "config.h"
 #include <stdio.h>
 #if HAVE_UNISTD_H
 #include <unistd.h>
@@ -159,11 +160,7 @@ errcode_t ext2fs_get_device_size2(const char *file, int blocksize,
        char ch;
 #endif /* HAVE_SYS_DISKLABEL_H */
 
-#ifdef HAVE_OPEN64
-       fd = open64(file, O_RDONLY);
-#else
-       fd = open(file, O_RDONLY);
-#endif
+       fd = ext2fs_open_file(file, O_RDONLY, 0);
        if (fd < 0)
                return errno;
 
@@ -186,7 +183,7 @@ errcode_t ext2fs_get_device_size2(const char *file, int blocksize,
                *retblocks = size64 / blocksize;
                goto out;
        }
-#endif
+#endif /* BLKGETSIZE64 */
 
 #ifdef BLKGETSIZE
        if (ioctl(fd, BLKGETSIZE, &size) >= 0) {
@@ -235,13 +232,9 @@ errcode_t ext2fs_get_device_size2(const char *file, int blocksize,
 #endif /* HAVE_SYS_DISKLABEL_H */
 
        {
-#ifdef HAVE_FSTAT64
-               struct stat64   st;
-               if (fstat64(fd, &st) == 0)
-#else
-               struct stat     st;
-               if (fstat(fd, &st) == 0)
-#endif
+               ext2fs_struct_stat st;
+
+               if (ext2fs_fstat(fd, &st) == 0)
                        if (S_ISREG(st.st_mode)) {
                                *retblocks = st.st_size / blocksize;
                                goto out;
@@ -278,13 +271,14 @@ errcode_t ext2fs_get_device_size(const char *file, int blocksize,
 {
        errcode_t retval;
        blk64_t blocks;
-       retval = ext2fs_get_device_size2(file, blocksize, &blocks);
 
-       if (!retval && blocks < (1ULL << 32)) {
-               *retblocks = (blk_t) blocks;
+       retval = ext2fs_get_device_size2(file, blocksize, &blocks);
+       if (retval)
                return retval;
-       }
-       return EFBIG;
+       if (blocks >= (1ULL << 32))
+               return EFBIG;
+       *retblocks = (blk_t) blocks;
+       return 0;
 }
 
 #endif /* WIN32 */