summaryrefslogtreecommitdiffstats
path: root/super0.c
diff options
context:
space:
mode:
authorNeil Brown <neilb@suse.de>2006-12-14 17:32:57 +1100
committerNeil Brown <neilb@suse.de>2006-12-14 17:32:57 +1100
commitbeae1dfe2e5a3f11e6e52a93fbf617d644708415 (patch)
treeca12b130f76d63e7156e43ac89d76c11b2c140b8 /super0.c
parentab5303d695eb7249b9462f9ad4e973711622a9c5 (diff)
downloadmdadm-beae1dfe2e5a3f11e6e52a93fbf617d644708415.tar.gz
mdadm-beae1dfe2e5a3f11e6e52a93fbf617d644708415.tar.xz
mdadm-beae1dfe2e5a3f11e6e52a93fbf617d644708415.zip
Central calls to ioctl BLKGETSIZE
Instead of opencoding the same thing everywhere.
Diffstat (limited to 'super0.c')
-rw-r--r--super0.c60
1 files changed, 14 insertions, 46 deletions
diff --git a/super0.c b/super0.c
index 2408c25..770d96e 100644
--- a/super0.c
+++ b/super0.c
@@ -588,20 +588,12 @@ static void add_to_super0(void *sbv, mdu_disk_info_t *dinfo)
static int store_super0(struct supertype *st, int fd, void *sbv)
{
- unsigned long size;
unsigned long long dsize;
unsigned long long offset;
mdp_super_t *super = sbv;
-
-#ifdef BLKGETSIZE64
- if (ioctl(fd, BLKGETSIZE64, &dsize) != 0)
-#endif
- {
- if (ioctl(fd, BLKGETSIZE, &size))
- return 1;
- else
- dsize = ((unsigned long long)size)<<9;
- }
+
+ if (!get_dev_size(fd, NULL, &dsize))
+ return 1;
if (dsize < MD_RESERVED_SECTORS*2*512)
return 2;
@@ -708,20 +700,10 @@ static int load_super0(struct supertype *st, int fd, void **sbp, char *devname)
int uuid[4];
struct bitmap_super_s *bsb;
-#ifdef BLKGETSIZE64
- if (ioctl(fd, BLKGETSIZE64, &dsize) != 0)
-#endif
- {
- if (ioctl(fd, BLKGETSIZE, &size)) {
- if (devname)
- fprintf(stderr, Name ": cannot find device size for %s: %s\n",
- devname, strerror(errno));
- return 1;
- } else
- dsize = size << 9;
- }
+ if (!get_dev_size(fd, devname, &dsize))
+ return 1;
- if (dsize < MD_RESERVED_SECTORS*2) {
+ if (dsize < MD_RESERVED_SECTORS*512 * 2) {
if (devname)
fprintf(stderr, Name ": %s is too small for md: size is %ld sectors.\n",
devname, size);
@@ -877,19 +859,12 @@ static int add_internal_bitmap0(struct supertype *st, void *sbv, int *chunkp,
void locate_bitmap0(struct supertype *st, int fd, void *sbv)
{
unsigned long long dsize;
- unsigned long size;
unsigned long long offset;
-#ifdef BLKGETSIZE64
- if (ioctl(fd, BLKGETSIZE64, &dsize) != 0)
-#endif
- {
- if (ioctl(fd, BLKGETSIZE, &size))
- return;
- else
- dsize = ((unsigned long long)size)<<9;
- }
- if (dsize < MD_RESERVED_SECTORS*2)
+ if (!get_dev_size(fd, NULL, &dsize))
+ return;
+
+ if (dsize < MD_RESERVED_SECTORS*512 * 2)
return;
offset = MD_NEW_SIZE_SECTORS(dsize>>9);
@@ -903,7 +878,6 @@ void locate_bitmap0(struct supertype *st, int fd, void *sbv)
int write_bitmap0(struct supertype *st, int fd, void *sbv)
{
- unsigned long size;
unsigned long long dsize;
unsigned long long offset;
mdp_super_t *sb = sbv;
@@ -913,17 +887,11 @@ int write_bitmap0(struct supertype *st, int fd, void *sbv)
int towrite, n;
char buf[4096];
-#ifdef BLKGETSIZE64
- if (ioctl(fd, BLKGETSIZE64, &dsize) != 0)
-#endif
- {
- if (ioctl(fd, BLKGETSIZE, &size))
- return 1;
- else
- dsize = ((unsigned long long)size)<<9;
- }
+ if (!get_dev_size(fd, NULL, &dsize))
+ return 1;
+
- if (dsize < MD_RESERVED_SECTORS*2)
+ if (dsize < MD_RESERVED_SECTORS*512 * 2)
return -1;
offset = MD_NEW_SIZE_SECTORS(dsize>>9);