linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 05/17] Util: get device size from id
@ 2010-10-29 14:19 Czarnowska, Anna
  2010-11-05  5:42 ` Dan Williams
  0 siblings, 1 reply; 2+ messages in thread
From: Czarnowska, Anna @ 2010-10-29 14:19 UTC (permalink / raw)
  To: Neil Brown
  Cc: linux-raid@vger.kernel.org, Neubauer, Wojciech, Williams, Dan J,
	Ciechanowski, Ed, Labun, Marcin,
	Hawrylewicz Czarnowski, Przemyslaw, Czarnowska, Anna

From c0bbe01f5f73d123af899338e838d45df1a4abee Mon Sep 17 00:00:00 2001
From: Anna Czarnowska <anna.czarnowska@intel.com>
Date: Fri, 22 Oct 2010 13:23:15 +0200
Subject: [PATCH 05/17] Util: get device size from id

Signed-off-by: Anna Czarnowska <anna.czarnowska@intel.com>
---
 mdadm.h |    1 +
 util.c  |   18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/mdadm.h b/mdadm.h
index 450fb11..66363fb 100644
--- a/mdadm.h
+++ b/mdadm.h
@@ -745,6 +745,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 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 bb85253..e340600 100644
--- a/util.c
+++ b/util.c
@@ -1160,6 +1160,24 @@ int get_dev_size(int fd, char *dname, unsigned long long *sizep)
 	return 1;
 }
 
+int dev_size_from_id(unsigned id, unsigned long long *size)
+{
+	char *dv;
+	int fd;
+
+	dv = map_dev(major(id), minor(id), 1);
+	if (!dv)
+		return 0;
+	fd = open(dv, O_RDONLY);
+	if (fd < 0)
+		return 0;
+	if (get_dev_size(fd, dv, size)) {
+		close(fd);
+		return 1;
+	}
+	close(fd);
+	return 0;
+}
 
 /* Sets endofpart parameter to the last block used by the last GPT partition on the device.
  * Returns: 1 if successful
-- 
1.6.4.2

---------------------------------------------------------------------
Intel Technology Poland sp. z o.o.
z siedziba w Gdansku
ul. Slowackiego 173
80-298 Gdansk

Sad Rejonowy Gdansk Polnoc w Gdansku, 
VII Wydzial Gospodarczy Krajowego Rejestru Sadowego, 
numer KRS 101882

NIP 957-07-52-316
Kapital zakladowy 200.000 zl

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-11-05  5:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-29 14:19 [PATCH 05/17] Util: get device size from id Czarnowska, Anna
2010-11-05  5:42 ` Dan Williams

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).