[PATCH] kexec: determine size of block device

Simon Horman horms at verge.net.au
Thu Oct 15 18:30:26 PDT 2015


Hi Andreas,

On Fri, Oct 09, 2015 at 03:27:18PM +0200, Andreas Fenkart wrote:
> starting 'kexec -l /dev/mmcblk0p1' fails since the size of
> a block device can not be determined with stat

Could you provide some motivation for kexec reading a kernel image
from a block device as per the example above?

> Signed-off-by: Andreas Fenkart <andreas.fenkart at dev.digitalstrom.org>
> ---
>  kexec/kexec.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/kexec/kexec.c b/kexec/kexec.c
> index ff024f3..8b8846e 100644
> --- a/kexec/kexec.c
> +++ b/kexec/kexec.c
> @@ -26,7 +26,9 @@
>  #include <stdlib.h>
>  #include <errno.h>
>  #include <limits.h>
> +#include <sys/ioctl.h>
>  #include <sys/mman.h>
> +#include <sys/mount.h>
>  #include <sys/types.h>
>  #include <sys/stat.h>
>  #include <sys/reboot.h>
> @@ -554,6 +556,14 @@ char *slurp_file(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)) {
> +		/* taken from blockdev */

Is "blockdev" Linux kernel code?

> +		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 = nread = stats.st_size;
>  		buf = mmap(NULL, size,
> -- 
> 2.5.1
> 
> 
> _______________________________________________
> kexec mailing list
> kexec at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/kexec
> 



More information about the kexec mailing list