[edk2] [efibootmgr PATCH 1/7] disk_info_from_fd(): get major/minor from buf.st_rdev

Subject: [edk2] [efibootmgr PATCH 1/7] disk_info_from_fd(): get major/minor from buf.st_rdev

From: Laszlo Ersek <lersek@redhat.com>

To: "Jordan Hargrave" <Jordan_Hargrave@dell.com>, edk2-devel@lists.sourceforge.net, "Peter Jones" <pjones@redhat.com>, "Matthew Garrett" <mjg59@srcf.ucam.org>

Date: 2013-08-27 09:04:49

  • 2013-08-27 09:04:49  Laszlo Ersek   [edk2] [efibootmgr PATCH 1/7] disk_info_from_fd(): get major/minor from buf.st_rdev
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_stat.h.html :

  The  header shall define the structure of the data returned
  by the fstat(), lstat(), and stat() functions.

  The  header shall define the stat structure, which shall
  include at least the following members:

  [...]
  dev_t st_dev    Device ID of device containing file.
  [...]
  dev_t st_rdev   Device ID (if file is character or block special).
  [...]

In disk_info_from_fd(), we don't care about the device containing the
special file -- we care about the device the special file identifies.

Signed-off-by: Laszlo Ersek 
---
 src/lib/disk.c |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/lib/disk.c b/src/lib/disk.c
index 8ad590b..6c710f2 100644
--- a/src/lib/disk.c
+++ b/src/lib/disk.c
@@ -50,12 +50,18 @@ disk_info_from_fd(int fd,
 		perror("stat");
 		return 1;
 	}
-	if (!(S_ISBLK(buf.st_mode) || S_ISREG(buf.st_mode))) {
+	if (S_ISBLK(buf.st_mode)) {
+		major = buf.st_rdev >> 8;
+		minor = buf.st_rdev & 0xFF;
+	}
+	else if (S_ISREG(buf.st_mode)) {
+		major = buf.st_dev >> 8;
+		minor = buf.st_dev & 0xFF;
+	}
+	else {
 		printf("Cannot stat non-block or non-regular file\n");
 		return 1;
 	}
-	major = buf.st_dev >> 8;
-	minor = buf.st_dev & 0xFF;
 
 	/* IDE disks can have up to 64 partitions, or 6 bits worth,
 	 * and have one bit for the disk number.
-- 
1.7.1



------------------------------------------------------------------------------
Introducing Performance Central, a new site from SourceForge and 
AppDynamics. Performance Central is your source for news, insights, 
analysis and resources for efficient Application Performance Management. 
Visit us today!
http://pubads.g.doubleclick.net/gampad/clk?id=48897511&iu=/4140/ostg.clktrk
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel