Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * getsize.c --- get the size of a partition. |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 3 | * |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 4 | * Copyright (C) 1995, 1995 Theodore Ts'o. |
Theodore Ts'o | c692840 | 2003-04-17 22:06:46 -0400 | [diff] [blame] | 5 | * Copyright (C) 2003 VMware, Inc. |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 6 | * |
Theodore Ts'o | c692840 | 2003-04-17 22:06:46 -0400 | [diff] [blame] | 7 | * Windows version of ext2fs_get_device_size by Chris Li, VMware. |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 8 | * |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 9 | * %Begin-Header% |
Theodore Ts'o | 543547a | 2010-05-17 21:31:56 -0400 | [diff] [blame] | 10 | * This file may be redistributed under the terms of the GNU Library |
| 11 | * General Public License, version 2. |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 12 | * %End-Header% |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 13 | */ |
| 14 | |
Theodore Ts'o | dc5f68c | 2000-05-25 23:31:54 +0000 | [diff] [blame] | 15 | #define _LARGEFILE_SOURCE |
| 16 | #define _LARGEFILE64_SOURCE |
| 17 | |
Theodore Ts'o | d1154eb | 2011-09-18 17:34:37 -0400 | [diff] [blame] | 18 | #include "config.h" |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 19 | #include <stdio.h> |
| 20 | #if HAVE_UNISTD_H |
| 21 | #include <unistd.h> |
| 22 | #endif |
Theodore Ts'o | c4e749a | 1998-02-20 05:33:14 +0000 | [diff] [blame] | 23 | #if HAVE_ERRNO_H |
| 24 | #include <errno.h> |
| 25 | #endif |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 26 | #include <fcntl.h> |
Theodore Ts'o | 9845cf5 | 2004-09-17 19:07:03 -0400 | [diff] [blame] | 27 | #ifdef HAVE_SYS_IOCTL_H |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 28 | #include <sys/ioctl.h> |
Theodore Ts'o | 9845cf5 | 2004-09-17 19:07:03 -0400 | [diff] [blame] | 29 | #endif |
| 30 | #ifdef HAVE_LINUX_FD_H |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 31 | #include <linux/fd.h> |
| 32 | #endif |
| 33 | #ifdef HAVE_SYS_DISKLABEL_H |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 34 | #include <sys/disklabel.h> |
Theodore Ts'o | 9845cf5 | 2004-09-17 19:07:03 -0400 | [diff] [blame] | 35 | #endif |
Matthias Andree | b34cbdd | 2003-12-28 18:21:26 +0100 | [diff] [blame] | 36 | #ifdef HAVE_SYS_DISK_H |
Theodore Ts'o | 9845cf5 | 2004-09-17 19:07:03 -0400 | [diff] [blame] | 37 | #ifdef HAVE_SYS_QUEUE_H |
Matthias Andree | b34cbdd | 2003-12-28 18:21:26 +0100 | [diff] [blame] | 38 | #include <sys/queue.h> /* for LIST_HEAD */ |
Theodore Ts'o | 9845cf5 | 2004-09-17 19:07:03 -0400 | [diff] [blame] | 39 | #endif |
Matthias Andree | b34cbdd | 2003-12-28 18:21:26 +0100 | [diff] [blame] | 40 | #include <sys/disk.h> |
Theodore Ts'o | 9845cf5 | 2004-09-17 19:07:03 -0400 | [diff] [blame] | 41 | #endif |
Theodore Ts'o | 2c5cfbc | 2004-03-08 14:12:09 -0500 | [diff] [blame] | 42 | #ifdef __linux__ |
| 43 | #include <sys/utsname.h> |
| 44 | #endif |
Andreas Dilger | 9b7d811 | 2005-07-09 22:06:59 -0500 | [diff] [blame] | 45 | #if HAVE_SYS_STAT_H |
| 46 | #include <sys/stat.h> |
| 47 | #endif |
Matthias Andree | df3e159 | 2006-05-30 16:28:42 +0200 | [diff] [blame] | 48 | #include <ctype.h> |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 49 | |
Theodore Ts'o | 7fd86d3 | 2000-05-25 23:42:22 +0000 | [diff] [blame] | 50 | #if defined(__linux__) && defined(_IO) && !defined(BLKGETSIZE) |
| 51 | #define BLKGETSIZE _IO(0x12,96) /* return device size */ |
| 52 | #endif |
| 53 | |
Theodore Ts'o | 85b8700 | 2004-03-02 10:11:11 -0500 | [diff] [blame] | 54 | #if defined(__linux__) && defined(_IOR) && !defined(BLKGETSIZE64) |
| 55 | #define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size in bytes (u64 *arg) */ |
| 56 | #endif |
| 57 | |
Theodore Ts'o | e71d873 | 2003-03-14 02:13:48 -0500 | [diff] [blame] | 58 | #ifdef APPLE_DARWIN |
Theodore Ts'o | e71d873 | 2003-03-14 02:13:48 -0500 | [diff] [blame] | 59 | #define BLKGETSIZE DKIOCGETBLOCKCOUNT32 |
| 60 | #endif /* APPLE_DARWIN */ |
| 61 | |
Theodore Ts'o | b5abe6f | 1998-01-19 14:47:53 +0000 | [diff] [blame] | 62 | #include "ext2_fs.h" |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 63 | #include "ext2fs.h" |
| 64 | |
Theodore Ts'o | c692840 | 2003-04-17 22:06:46 -0400 | [diff] [blame] | 65 | #if defined(__CYGWIN__) || defined (WIN32) |
| 66 | #include "windows.h" |
| 67 | #include "winioctl.h" |
| 68 | |
Theodore Ts'o | 1a9c8c3 | 2004-10-08 12:45:24 -0400 | [diff] [blame] | 69 | #if (_WIN32_WINNT >= 0x0500) |
| 70 | #define HAVE_GET_FILE_SIZE_EX 1 |
| 71 | #endif |
| 72 | |
Theodore Ts'o | c692840 | 2003-04-17 22:06:46 -0400 | [diff] [blame] | 73 | errcode_t ext2fs_get_device_size(const char *file, int blocksize, |
| 74 | blk_t *retblocks) |
| 75 | { |
| 76 | HANDLE dev; |
| 77 | PARTITION_INFORMATION pi; |
| 78 | DISK_GEOMETRY gi; |
| 79 | DWORD retbytes; |
Theodore Ts'o | 1a9c8c3 | 2004-10-08 12:45:24 -0400 | [diff] [blame] | 80 | #ifdef HAVE_GET_FILE_SIZE_EX |
Theodore Ts'o | 05a27b1 | 2003-04-29 21:10:15 -0400 | [diff] [blame] | 81 | LARGE_INTEGER filesize; |
Theodore Ts'o | 1a9c8c3 | 2004-10-08 12:45:24 -0400 | [diff] [blame] | 82 | #else |
| 83 | DWORD filesize; |
| 84 | #endif /* HAVE_GET_FILE_SIZE_EX */ |
Theodore Ts'o | c692840 | 2003-04-17 22:06:46 -0400 | [diff] [blame] | 85 | |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 86 | dev = CreateFile(file, GENERIC_READ, |
Theodore Ts'o | c692840 | 2003-04-17 22:06:46 -0400 | [diff] [blame] | 87 | FILE_SHARE_READ | FILE_SHARE_WRITE , |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 88 | NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); |
| 89 | |
Theodore Ts'o | c692840 | 2003-04-17 22:06:46 -0400 | [diff] [blame] | 90 | if (dev == INVALID_HANDLE_VALUE) |
| 91 | return EBADF; |
| 92 | if (DeviceIoControl(dev, IOCTL_DISK_GET_PARTITION_INFO, |
| 93 | &pi, sizeof(PARTITION_INFORMATION), |
| 94 | &pi, sizeof(PARTITION_INFORMATION), |
| 95 | &retbytes, NULL)) { |
| 96 | |
| 97 | *retblocks = pi.PartitionLength.QuadPart / blocksize; |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 98 | |
Theodore Ts'o | c692840 | 2003-04-17 22:06:46 -0400 | [diff] [blame] | 99 | } else if (DeviceIoControl(dev, IOCTL_DISK_GET_DRIVE_GEOMETRY, |
| 100 | &gi, sizeof(DISK_GEOMETRY), |
| 101 | &gi, sizeof(DISK_GEOMETRY), |
| 102 | &retbytes, NULL)) { |
| 103 | |
| 104 | *retblocks = gi.BytesPerSector * |
| 105 | gi.SectorsPerTrack * |
| 106 | gi.TracksPerCylinder * |
| 107 | gi.Cylinders.QuadPart / blocksize; |
Theodore Ts'o | 05a27b1 | 2003-04-29 21:10:15 -0400 | [diff] [blame] | 108 | |
Theodore Ts'o | 1a9c8c3 | 2004-10-08 12:45:24 -0400 | [diff] [blame] | 109 | #ifdef HAVE_GET_FILE_SIZE_EX |
Theodore Ts'o | 05a27b1 | 2003-04-29 21:10:15 -0400 | [diff] [blame] | 110 | } else if (GetFileSizeEx(dev, &filesize)) { |
| 111 | *retblocks = filesize.QuadPart / blocksize; |
Theodore Ts'o | c692840 | 2003-04-17 22:06:46 -0400 | [diff] [blame] | 112 | } |
Theodore Ts'o | 1a9c8c3 | 2004-10-08 12:45:24 -0400 | [diff] [blame] | 113 | #else |
| 114 | } else { |
| 115 | filesize = GetFileSize(dev, NULL); |
| 116 | if (INVALID_FILE_SIZE != filesize) { |
| 117 | *retblocks = filesize / blocksize; |
| 118 | } |
| 119 | } |
| 120 | #endif /* HAVE_GET_FILE_SIZE_EX */ |
Theodore Ts'o | c692840 | 2003-04-17 22:06:46 -0400 | [diff] [blame] | 121 | |
| 122 | CloseHandle(dev); |
| 123 | return 0; |
| 124 | } |
| 125 | |
| 126 | #else |
| 127 | |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 128 | static int valid_offset (int fd, ext2_loff_t offset) |
| 129 | { |
| 130 | char ch; |
| 131 | |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 132 | if (ext2fs_llseek (fd, offset, 0) < 0) |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 133 | return 0; |
| 134 | if (read (fd, &ch, 1) < 1) |
| 135 | return 0; |
| 136 | return 1; |
| 137 | } |
| 138 | |
| 139 | /* |
| 140 | * Returns the number of blocks in a partition |
| 141 | */ |
Jose R. Santos | beab8de | 2008-08-20 12:34:07 -0500 | [diff] [blame] | 142 | errcode_t ext2fs_get_device_size2(const char *file, int blocksize, |
Andreas Dilger | 3e554cc | 2012-11-22 16:17:19 -0700 | [diff] [blame] | 143 | blk64_t *retblocks) |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 144 | { |
Andreas Dilger | 9b7d811 | 2005-07-09 22:06:59 -0500 | [diff] [blame] | 145 | int fd, rc = 0; |
Theodore Ts'o | 85b8700 | 2004-03-02 10:11:11 -0500 | [diff] [blame] | 146 | unsigned long long size64; |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 147 | ext2_loff_t high, low; |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 148 | |
Theodore Ts'o | c4012e5 | 2011-10-06 13:28:07 -0400 | [diff] [blame] | 149 | fd = ext2fs_open_file(file, O_RDONLY, 0); |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 150 | if (fd < 0) |
| 151 | return errno; |
| 152 | |
Theodore Ts'o | 85b8700 | 2004-03-02 10:11:11 -0500 | [diff] [blame] | 153 | #ifdef DKIOCGETBLOCKCOUNT /* For Apple Darwin */ |
Theodore Ts'o | 2c5cfbc | 2004-03-08 14:12:09 -0500 | [diff] [blame] | 154 | if (ioctl(fd, DKIOCGETBLOCKCOUNT, &size64) >= 0) { |
Theodore Ts'o | 85b8700 | 2004-03-02 10:11:11 -0500 | [diff] [blame] | 155 | *retblocks = size64 / (blocksize / 512); |
Andreas Dilger | 9b7d811 | 2005-07-09 22:06:59 -0500 | [diff] [blame] | 156 | goto out; |
Theodore Ts'o | 85b8700 | 2004-03-02 10:11:11 -0500 | [diff] [blame] | 157 | } |
| 158 | #endif |
| 159 | |
| 160 | #ifdef BLKGETSIZE64 |
Andreas Dilger | 3e554cc | 2012-11-22 16:17:19 -0700 | [diff] [blame] | 161 | { |
| 162 | int valid_blkgetsize64 = 1; |
Theodore Ts'o | 2c5cfbc | 2004-03-08 14:12:09 -0500 | [diff] [blame] | 163 | #ifdef __linux__ |
Andreas Dilger | 3e554cc | 2012-11-22 16:17:19 -0700 | [diff] [blame] | 164 | struct utsname ut; |
| 165 | |
| 166 | if ((uname(&ut) == 0) && |
| 167 | ((ut.release[0] == '2') && (ut.release[1] == '.') && |
| 168 | (ut.release[2] < '6') && (ut.release[3] == '.'))) |
| 169 | valid_blkgetsize64 = 0; |
Theodore Ts'o | 2c5cfbc | 2004-03-08 14:12:09 -0500 | [diff] [blame] | 170 | #endif |
Andreas Dilger | 3e554cc | 2012-11-22 16:17:19 -0700 | [diff] [blame] | 171 | if (valid_blkgetsize64 && |
| 172 | ioctl(fd, BLKGETSIZE64, &size64) >= 0) { |
| 173 | *retblocks = size64 / blocksize; |
| 174 | goto out; |
| 175 | } |
Theodore Ts'o | 85b8700 | 2004-03-02 10:11:11 -0500 | [diff] [blame] | 176 | } |
Andreas Dilger | 7270fbe | 2012-02-24 00:48:57 -0700 | [diff] [blame] | 177 | #endif /* BLKGETSIZE64 */ |
Theodore Ts'o | 85b8700 | 2004-03-02 10:11:11 -0500 | [diff] [blame] | 178 | |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 179 | #ifdef BLKGETSIZE |
Andreas Dilger | 3e554cc | 2012-11-22 16:17:19 -0700 | [diff] [blame] | 180 | { |
| 181 | unsigned long size; |
| 182 | |
| 183 | if (ioctl(fd, BLKGETSIZE, &size) >= 0) { |
| 184 | *retblocks = size / (blocksize / 512); |
| 185 | goto out; |
| 186 | } |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 187 | } |
| 188 | #endif |
Theodore Ts'o | 85b8700 | 2004-03-02 10:11:11 -0500 | [diff] [blame] | 189 | |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 190 | #ifdef FDGETPRM |
Andreas Dilger | 3e554cc | 2012-11-22 16:17:19 -0700 | [diff] [blame] | 191 | { |
| 192 | struct floppy_struct this_floppy; |
| 193 | |
| 194 | if (ioctl(fd, FDGETPRM, &this_floppy) >= 0) { |
| 195 | *retblocks = this_floppy.size / (blocksize / 512); |
| 196 | goto out; |
| 197 | } |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 198 | } |
| 199 | #endif |
Matthias Andree | 289e055 | 2004-03-30 03:57:41 +0200 | [diff] [blame] | 200 | |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 201 | #ifdef HAVE_SYS_DISKLABEL_H |
Matthias Andree | 289e055 | 2004-03-30 03:57:41 +0200 | [diff] [blame] | 202 | { |
Andreas Dilger | 3e554cc | 2012-11-22 16:17:19 -0700 | [diff] [blame] | 203 | int part; |
| 204 | struct disklabel lab; |
| 205 | struct partition *pp; |
| 206 | char ch; |
| 207 | |
| 208 | #if defined(DIOCGMEDIASIZE) |
| 209 | { |
| 210 | off_t ms; |
| 211 | u_int bs; |
| 212 | if (ioctl(fd, DIOCGMEDIASIZE, &ms) >= 0) { |
| 213 | *retblocks = ms / blocksize; |
| 214 | goto out; |
| 215 | } |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 216 | } |
Andreas Dilger | 3e554cc | 2012-11-22 16:17:19 -0700 | [diff] [blame] | 217 | #elif defined(DIOCGDINFO) |
| 218 | /* old disklabel interface */ |
| 219 | part = strlen(file) - 1; |
| 220 | if (part >= 0) { |
| 221 | ch = file[part]; |
| 222 | if (isdigit(ch)) |
| 223 | part = 0; |
| 224 | else if (ch >= 'a' && ch <= 'h') |
| 225 | part = ch - 'a'; |
| 226 | else |
| 227 | part = -1; |
| 228 | } |
| 229 | if (part >= 0 && (ioctl(fd, DIOCGDINFO, (char *)&lab) >= 0)) { |
| 230 | pp = &lab.d_partitions[part]; |
| 231 | if (pp->p_size) { |
| 232 | *retblocks = pp->p_size / (blocksize / 512); |
| 233 | goto out; |
| 234 | } |
| 235 | } |
Matthias Andree | 289e055 | 2004-03-30 03:57:41 +0200 | [diff] [blame] | 236 | #endif /* defined(DIOCG*) */ |
Andreas Dilger | 3e554cc | 2012-11-22 16:17:19 -0700 | [diff] [blame] | 237 | } |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 238 | #endif /* HAVE_SYS_DISKLABEL_H */ |
| 239 | |
Andreas Dilger | 9b7d811 | 2005-07-09 22:06:59 -0500 | [diff] [blame] | 240 | { |
Andreas Dilger | 6b56f3d | 2011-09-24 12:59:31 -0400 | [diff] [blame] | 241 | ext2fs_struct_stat st; |
| 242 | |
| 243 | if (ext2fs_fstat(fd, &st) == 0) |
Andreas Dilger | 9b7d811 | 2005-07-09 22:06:59 -0500 | [diff] [blame] | 244 | if (S_ISREG(st.st_mode)) { |
| 245 | *retblocks = st.st_size / blocksize; |
| 246 | goto out; |
| 247 | } |
| 248 | } |
| 249 | |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 250 | /* |
| 251 | * OK, we couldn't figure it out by using a specialized ioctl, |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 252 | * which is generally the best way. So do binary search to |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 253 | * find the size of the partition. |
| 254 | */ |
| 255 | low = 0; |
Andreas Dilger | 3e554cc | 2012-11-22 16:17:19 -0700 | [diff] [blame] | 256 | for (high = 1024; valid_offset(fd, high); high *= 2) |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 257 | low = high; |
Andreas Dilger | 3e554cc | 2012-11-22 16:17:19 -0700 | [diff] [blame] | 258 | while (low < high - 1) { |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 259 | const ext2_loff_t mid = (low + high) / 2; |
| 260 | |
| 261 | if (valid_offset (fd, mid)) |
| 262 | low = mid; |
| 263 | else |
| 264 | high = mid; |
| 265 | } |
Andreas Dilger | 3e554cc | 2012-11-22 16:17:19 -0700 | [diff] [blame] | 266 | valid_offset(fd, 0); |
Theodore Ts'o | 283df83 | 2005-03-18 20:11:59 -0500 | [diff] [blame] | 267 | size64 = low + 1; |
Theodore Ts'o | 283df83 | 2005-03-18 20:11:59 -0500 | [diff] [blame] | 268 | *retblocks = size64 / blocksize; |
Andreas Dilger | 9b7d811 | 2005-07-09 22:06:59 -0500 | [diff] [blame] | 269 | out: |
| 270 | close(fd); |
| 271 | return rc; |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 272 | } |
Theodore Ts'o | abf7d38 | 2000-06-10 19:27:17 +0000 | [diff] [blame] | 273 | |
Jose R. Santos | beab8de | 2008-08-20 12:34:07 -0500 | [diff] [blame] | 274 | errcode_t ext2fs_get_device_size(const char *file, int blocksize, |
| 275 | blk_t *retblocks) |
| 276 | { |
| 277 | errcode_t retval; |
| 278 | blk64_t blocks; |
Jose R. Santos | beab8de | 2008-08-20 12:34:07 -0500 | [diff] [blame] | 279 | |
Theodore Ts'o | 9f7a1fc | 2009-01-20 13:37:47 -0500 | [diff] [blame] | 280 | retval = ext2fs_get_device_size2(file, blocksize, &blocks); |
| 281 | if (retval) |
Jose R. Santos | beab8de | 2008-08-20 12:34:07 -0500 | [diff] [blame] | 282 | return retval; |
Theodore Ts'o | 9f7a1fc | 2009-01-20 13:37:47 -0500 | [diff] [blame] | 283 | if (blocks >= (1ULL << 32)) |
| 284 | return EFBIG; |
| 285 | *retblocks = (blk_t) blocks; |
| 286 | return 0; |
Jose R. Santos | beab8de | 2008-08-20 12:34:07 -0500 | [diff] [blame] | 287 | } |
| 288 | |
Theodore Ts'o | c692840 | 2003-04-17 22:06:46 -0400 | [diff] [blame] | 289 | #endif /* WIN32 */ |
| 290 | |
Theodore Ts'o | abf7d38 | 2000-06-10 19:27:17 +0000 | [diff] [blame] | 291 | #ifdef DEBUG |
| 292 | int main(int argc, char **argv) |
| 293 | { |
| 294 | blk_t blocks; |
| 295 | int retval; |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 296 | |
Theodore Ts'o | abf7d38 | 2000-06-10 19:27:17 +0000 | [diff] [blame] | 297 | if (argc < 2) { |
| 298 | fprintf(stderr, "Usage: %s device\n", argv[0]); |
| 299 | exit(1); |
| 300 | } |
| 301 | |
| 302 | retval = ext2fs_get_device_size(argv[1], 1024, &blocks); |
| 303 | if (retval) { |
| 304 | com_err(argv[0], retval, |
| 305 | "while calling ext2fs_get_device_size"); |
| 306 | exit(1); |
| 307 | } |
Eric Sandeen | d0ff90d | 2006-09-12 14:56:15 -0400 | [diff] [blame] | 308 | printf("Device %s has %u 1k blocks.\n", argv[1], blocks); |
Theodore Ts'o | abf7d38 | 2000-06-10 19:27:17 +0000 | [diff] [blame] | 309 | exit(0); |
| 310 | } |
| 311 | #endif |