mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] sandbox: add_image: mmap block devices
@ 2019-10-24 16:02 Robert Karszniewicz
  2019-10-24 16:07 ` Ahmad Fatoum
  0 siblings, 1 reply; 5+ messages in thread
From: Robert Karszniewicz @ 2019-10-24 16:02 UTC (permalink / raw)
  To: barebox

This makes it possible to mount block devices from the host machine,
which have been passed as arguments to --image

Signed-off-by: Robert Karszniewicz <r.karszniewicz@phytec.de>
---
 arch/sandbox/os/common.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/arch/sandbox/os/common.c b/arch/sandbox/os/common.c
index 86118822a..805ac8eef 100644
--- a/arch/sandbox/os/common.c
+++ b/arch/sandbox/os/common.c
@@ -39,6 +39,8 @@
 #include <signal.h>
 #include <sys/select.h>
 #include <sys/wait.h>
+#include <sys/ioctl.h>
+#include <linux/fs.h>
 /*
  * ...except the ones needed to connect with barebox
  */
@@ -260,6 +262,12 @@ static int add_image(char *str, char *devname_template, int *devname_number)
 	hf->size = s.st_size;
 	hf->devname = strdup(devname);
 
+	if (S_ISBLK(s.st_mode)) {
+		if (-1 == ioctl(fd, BLKGETSIZE64, &hf->size)) {
+			perror("ioctl");
+			goto err_out;
+		}
+	}
 	hf->base = (unsigned long)mmap(NULL, hf->size,
 			PROT_READ | (readonly ? 0 : PROT_WRITE),
 			MAP_SHARED, fd, 0);
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] sandbox: add_image: mmap block devices
  2019-10-24 16:02 [PATCH] sandbox: add_image: mmap block devices Robert Karszniewicz
@ 2019-10-24 16:07 ` Ahmad Fatoum
  2019-10-25 11:08   ` Robert Karszniewicz
  2019-10-25 11:19   ` [PATCH v2] " Robert Karszniewicz
  0 siblings, 2 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2019-10-24 16:07 UTC (permalink / raw)
  To: Robert Karszniewicz, barebox

On 10/24/19 6:02 PM, Robert Karszniewicz wrote:
> This makes it possible to mount block devices from the host machine,
> which have been passed as arguments to --image
> 
> Signed-off-by: Robert Karszniewicz <r.karszniewicz@phytec.de>
> ---
>  arch/sandbox/os/common.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/arch/sandbox/os/common.c b/arch/sandbox/os/common.c
> index 86118822a..805ac8eef 100644
> --- a/arch/sandbox/os/common.c
> +++ b/arch/sandbox/os/common.c
> @@ -39,6 +39,8 @@
>  #include <signal.h>
>  #include <sys/select.h>
>  #include <sys/wait.h>
> +#include <sys/ioctl.h>
> +#include <linux/fs.h>
>  /*
>   * ...except the ones needed to connect with barebox
>   */
> @@ -260,6 +262,12 @@ static int add_image(char *str, char *devname_template, int *devname_number)
>  	hf->size = s.st_size;
>  	hf->devname = strdup(devname);
>  
> +	if (S_ISBLK(s.st_mode)) {
> +		if (-1 == ioctl(fd, BLKGETSIZE64, &hf->size)) {

This looks out of place for barebox, the -1 should be on the right side.

> +			perror("ioctl");
> +			goto err_out;
> +		}
> +	}
>  	hf->base = (unsigned long)mmap(NULL, hf->size,
>  			PROT_READ | (readonly ? 0 : PROT_WRITE),
>  			MAP_SHARED, fd, 0);
> 


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] sandbox: add_image: mmap block devices
  2019-10-24 16:07 ` Ahmad Fatoum
@ 2019-10-25 11:08   ` Robert Karszniewicz
  2019-10-25 11:19   ` [PATCH v2] " Robert Karszniewicz
  1 sibling, 0 replies; 5+ messages in thread
From: Robert Karszniewicz @ 2019-10-25 11:08 UTC (permalink / raw)
  To: barebox

On 10/24/19 6:07 PM, Ahmad Fatoum wrote:
> On 10/24/19 6:02 PM, Robert Karszniewicz wrote:
>> This makes it possible to mount block devices from the host machine,
>> which have been passed as arguments to --image
>>
>> Signed-off-by: Robert Karszniewicz <r.karszniewicz@phytec.de>
>> ---
>>   arch/sandbox/os/common.c | 8 ++++++++
>>   1 file changed, 8 insertions(+)
>>
>> diff --git a/arch/sandbox/os/common.c b/arch/sandbox/os/common.c
>> index 86118822a..805ac8eef 100644
>> --- a/arch/sandbox/os/common.c
>> +++ b/arch/sandbox/os/common.c
>> @@ -39,6 +39,8 @@
>>   #include <signal.h>
>>   #include <sys/select.h>
>>   #include <sys/wait.h>
>> +#include <sys/ioctl.h>
>> +#include <linux/fs.h>
>>   /*
>>    * ...except the ones needed to connect with barebox
>>    */
>> @@ -260,6 +262,12 @@ static int add_image(char *str, char *devname_template, int *devname_number)
>>   	hf->size = s.st_size;
>>   	hf->devname = strdup(devname);
>>   
>> +	if (S_ISBLK(s.st_mode)) {
>> +		if (-1 == ioctl(fd, BLKGETSIZE64, &hf->size)) {
> 
> This looks out of place for barebox, the -1 should be on the right side.

Oh, right, sorry! I have a habit to put trivial- and constant-sized 
symbols to the left, to not hide them behind those long function calls, etc.

> 
>> +			perror("ioctl");
>> +			goto err_out;
>> +		}
>> +	}
>>   	hf->base = (unsigned long)mmap(NULL, hf->size,
>>   			PROT_READ | (readonly ? 0 : PROT_WRITE),
>>   			MAP_SHARED, fd, 0);
>>
> 
> 


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH v2] sandbox: add_image: mmap block devices
  2019-10-24 16:07 ` Ahmad Fatoum
  2019-10-25 11:08   ` Robert Karszniewicz
@ 2019-10-25 11:19   ` Robert Karszniewicz
  2019-10-28 11:44     ` Sascha Hauer
  1 sibling, 1 reply; 5+ messages in thread
From: Robert Karszniewicz @ 2019-10-25 11:19 UTC (permalink / raw)
  To: barebox

This makes it possible to mount block devices from the host machine,
which have been passed as arguments to --image

Signed-off-by: Robert Karszniewicz <r.karszniewicz@phytec.de>
---
Changes from v1:
- move -1 to the right side of the comparison

 arch/sandbox/os/common.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/arch/sandbox/os/common.c b/arch/sandbox/os/common.c
index 86118822a..e826c9cb3 100644
--- a/arch/sandbox/os/common.c
+++ b/arch/sandbox/os/common.c
@@ -39,6 +39,8 @@
 #include <signal.h>
 #include <sys/select.h>
 #include <sys/wait.h>
+#include <sys/ioctl.h>
+#include <linux/fs.h>
 /*
  * ...except the ones needed to connect with barebox
  */
@@ -260,6 +262,12 @@ static int add_image(char *str, char *devname_template, int *devname_number)
 	hf->size = s.st_size;
 	hf->devname = strdup(devname);
 
+	if (S_ISBLK(s.st_mode)) {
+		if (ioctl(fd, BLKGETSIZE64, &hf->size) == -1) {
+			perror("ioctl");
+			goto err_out;
+		}
+	}
 	hf->base = (unsigned long)mmap(NULL, hf->size,
 			PROT_READ | (readonly ? 0 : PROT_WRITE),
 			MAP_SHARED, fd, 0);
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH v2] sandbox: add_image: mmap block devices
  2019-10-25 11:19   ` [PATCH v2] " Robert Karszniewicz
@ 2019-10-28 11:44     ` Sascha Hauer
  0 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2019-10-28 11:44 UTC (permalink / raw)
  To: Robert Karszniewicz; +Cc: barebox

On Fri, Oct 25, 2019 at 01:19:12PM +0200, Robert Karszniewicz wrote:
> This makes it possible to mount block devices from the host machine,
> which have been passed as arguments to --image
> 
> Signed-off-by: Robert Karszniewicz <r.karszniewicz@phytec.de>
> ---
> Changes from v1:
> - move -1 to the right side of the comparison
> 
>  arch/sandbox/os/common.c | 8 ++++++++
>  1 file changed, 8 insertions(+)

Applied, thanks

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2019-10-28 11:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-24 16:02 [PATCH] sandbox: add_image: mmap block devices Robert Karszniewicz
2019-10-24 16:07 ` Ahmad Fatoum
2019-10-25 11:08   ` Robert Karszniewicz
2019-10-25 11:19   ` [PATCH v2] " Robert Karszniewicz
2019-10-28 11:44     ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox