]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Util: get device size from id
authorAnna Czarnowska <anna.czarnowska@intel.com>
Mon, 22 Nov 2010 09:58:06 +0000 (20:58 +1100)
committerNeilBrown <neilb@suse.de>
Mon, 22 Nov 2010 09:58:06 +0000 (20:58 +1100)
Signed-off-by: Anna Czarnowska <anna.czarnowska@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
mdadm.h
util.c

diff --git a/mdadm.h b/mdadm.h
index 6c6e352d58d27c7c74cfc1f79e42522a89275afe..6b54249f4fbb79c3fa42da6aad74f7ee3bb1c283 100644 (file)
--- 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 ac5d8b137822583569fa415f486497b5c874a88c..1ecce3b8fd73d598051955bd8c6343b65bf29a9b 100644 (file)
--- 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)
 {