From: Anna Czarnowska Date: Mon, 22 Nov 2010 09:58:06 +0000 (+1100) Subject: Util: get device size from id X-Git-Tag: mdadm-3.2~266 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=52d5d101a9d17b856aaa7884f7e290166f62d03c;p=thirdparty%2Fmdadm.git Util: get device size from id Signed-off-by: Anna Czarnowska Signed-off-by: NeilBrown --- diff --git a/mdadm.h b/mdadm.h index 6c6e352d..6b54249f 100644 --- a/mdadm.h +++ b/mdadm.h @@ -747,6 +747,7 @@ static inline struct supertype *guess_super(int fd) { extern struct supertype *dup_super(struct supertype *st); extern int get_dev_size(int fd, char *dname, unsigned long long *sizep); extern int must_be_container(int fd); +extern int dev_size_from_id(unsigned id, unsigned long long *size); extern void get_one_disk(int mdfd, mdu_array_info_t *ainf, mdu_disk_info_t *disk); void wait_for(char *dev, int fd); diff --git a/util.c b/util.c index ac5d8b13..1ecce3b8 100644 --- a/util.c +++ b/util.c @@ -1094,6 +1094,22 @@ struct supertype *super_by_fd(int fd, char **subarrayp) } #endif /* !defined(MDASSEMBLE) || defined(MDASSEMBLE) && defined(MDASSEMBLE_AUTO) */ +int dev_size_from_id(unsigned int id, unsigned long long *size) +{ + char buf[20]; + int fd; + + sprintf(buf, "%d:%d", major(id), minor(id)); + fd = dev_open(buf, O_RDONLY); + if (fd < 0) + return 0; + if (get_dev_size(fd, NULL, size)) { + close(fd); + return 1; + } + close(fd); + return 0; +} struct supertype *dup_super(struct supertype *orig) {