Skip to contentSkip to conversation

kexec: determine size of block device

PATCH Applied Andreas Fenkart 2 participants 2 messages Nov 9, 2015 – Nov 11, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 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 | 8 ++++++++
 1 file changed, 8 insertions(+)
kexec/kexec.c +8 -0
index ca1e81d..cf6e03d 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>
@@ -555,6 +557,12 @@ static char *slurp_file_generic(const char *filename, off_t *r_size,
 			die("Can not seek to the begin of file %s: %s\n",
 					filename, strerror(errno));
 		buf = slurp_fd(fd, filename, size, &nread);
+	} else if (S_ISBLK(stats.st_mode)) {
+		err = ioctl(fd, BLKGETSIZE64, &size);
+		if (err < 0)
+			die("Can't retrieve size of block device %s: %s\n",
+				filename, strerror(errno));
+		buf = slurp_fd(fd, filename, size, &nread);
 	} else {
 		size = stats.st_size;
 		if (use_mmap) {
Signature · 7 lines
2.6.1


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