Skip to contentSkip to conversation

kexec: determine size of block device

PATCH Superseded Andreas Fenkart 1 participant 1 message Oct 26, 2015

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 kexec: determine size of block device

starting 'kexec -l /dev/mmcblk0p1' fails since the size of a block device can not be determined with stat

---
 kexec/kexec.c | 9 +++++++++
 1 file changed, 9 insertions(+)
kexec/kexec.c +9 -0
index b9f1816..99f743b 100644
@@ -26,6 +26,8 @@
 #include <stdlib.h>
 #include <errno.h>
 #include <limits.h>
+#include <sys/ioctl.h>
+#include <sys/mount.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/reboot.h>
@@ -552,6 +554,13 @@ char *slurp_file(const char *filename, off_t *r_size)
 		if (err < 0)
 			die("Can not seek to the begin of file %s: %s\n",
 					filename, strerror(errno));
+	} else if (S_ISBLK(stats.st_mode)) {
+		unsigned long long llu = -1;
+		err = ioctl(fd, BLKGETSIZE64, &llu);
+		if (err < 0)
+			die("Can't retrieve size of block device %s: %s\n",
+				filename, strerror(errno));
+		size = llu;
 	} else {
 		size = stats.st_size;
 	}
Signature · 7 lines
2.6.1


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec