All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Detect endian in cpio fs
@ 2009-08-27  8:27 Bean
  2009-08-28 12:03 ` Vladimir 'phcoder' Serbinenko
  0 siblings, 1 reply; 4+ messages in thread
From: Bean @ 2009-08-27  8:27 UTC (permalink / raw)
  To: The development of GRUB 2

[-- Attachment #1: Type: text/plain, Size: 196 bytes --]

Hi,

This patch allows to access big/little endian cpio archive from
big/little endian machine.

-- 
Bean

gitgrub home: http://github.com/grub/grub/
my fork page: http://github.com/bean123/grub/

[-- Attachment #2: cpio.diff --]
[-- Type: text/x-diff, Size: 1202 bytes --]

diff --git a/fs/cpio.c b/fs/cpio.c
index 1ec4ebe..2affa2e 100644
--- a/fs/cpio.c
+++ b/fs/cpio.c
@@ -76,6 +76,22 @@ struct grub_cpio_data
 
 static grub_dl_t my_mod;
 
+#ifndef MODE_USTAR
+
+static void
+grub_cpio_convert_header (struct head *head)
+{
+  if (head->magic != MAGIC_BCPIO)
+    {
+      head->magic = grub_swap_bytes16 (head->magic);
+      head->namesize = grub_swap_bytes16 (head->namesize);
+      head->filesize_1 = grub_swap_bytes16 (head->filesize_1);
+      head->filesize_2 = grub_swap_bytes16 (head->filesize_2);
+    }
+}
+
+#endif
+
 static grub_err_t
 grub_cpio_find_file (struct grub_cpio_data *data, char **name,
 		     grub_uint32_t * ofs)
@@ -86,6 +102,7 @@ grub_cpio_find_file (struct grub_cpio_data *data, char **name,
       if (grub_disk_read
 	  (data->disk, 0, data->hofs, sizeof (hd), &hd))
 	return grub_errno;
+      grub_cpio_convert_header (&hd);
 
       if (hd.magic != MAGIC_BCPIO)
 	return grub_error (GRUB_ERR_BAD_FS, "Invalid cpio archive");
@@ -153,6 +170,7 @@ grub_cpio_mount (grub_disk_t disk)
     goto fail;
 
 #ifndef MODE_USTAR
+  grub_cpio_convert_header (&hd);  
   if (hd.magic != MAGIC_BCPIO)
 #else
   if (grub_memcmp (hd.magic, MAGIC_USTAR,

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

* Re: [PATCH] Detect endian in cpio fs
  2009-08-27  8:27 [PATCH] Detect endian in cpio fs Bean
@ 2009-08-28 12:03 ` Vladimir 'phcoder' Serbinenko
  2009-08-28 12:20   ` Bean
  0 siblings, 1 reply; 4+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2009-08-28 12:03 UTC (permalink / raw)
  To: The development of GRUB 2

On Thu, Aug 27, 2009 at 10:27 AM, Bean<bean123ch@gmail.com> wrote:
> Hi,
>
> This patch allows to access big/little endian cpio archive from
> big/little endian machine.
Quick glance showed that you use swap_bytes. Could you use
grub_*_to_cpu* instead? This would simplify the future maintainability
if someone decides to port to a very special platform (e.g.
mixed-endian) since code would be uniform
>
> --
> Bean
>
> gitgrub home: http://github.com/grub/grub/
> my fork page: http://github.com/bean123/grub/
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>
>



-- 
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git



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

* Re: [PATCH] Detect endian in cpio fs
  2009-08-28 12:03 ` Vladimir 'phcoder' Serbinenko
@ 2009-08-28 12:20   ` Bean
  2009-08-28 12:27     ` Vladimir 'phcoder' Serbinenko
  0 siblings, 1 reply; 4+ messages in thread
From: Bean @ 2009-08-28 12:20 UTC (permalink / raw)
  To: The development of GRUB 2

On Fri, Aug 28, 2009 at 8:03 PM, Vladimir 'phcoder'
Serbinenko<phcoder@gmail.com> wrote:
> On Thu, Aug 27, 2009 at 10:27 AM, Bean<bean123ch@gmail.com> wrote:
>> Hi,
>>
>> This patch allows to access big/little endian cpio archive from
>> big/little endian machine.
> Quick glance showed that you use swap_bytes. Could you use
> grub_*_to_cpu* instead? This would simplify the future maintainability
> if someone decides to port to a very special platform (e.g.
> mixed-endian) since code would be uniform

Hi,

Actually it's not correct to use grub_*_to_cpu*. The code works by
first assuming cpio uses the same endian of host cpu, if not, swap it
and try the other endian. This method works for big/little endian cpio
on big/little endian machine. It's possible to achieve the same result
with a combination of #ifdef and grub_*_to_cpu*'s, but it's not as
simple as this and generate more code than necessary.

-- 
Bean

gitgrub home: http://github.com/grub/grub/
my fork page: http://github.com/bean123/grub/



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

* Re: [PATCH] Detect endian in cpio fs
  2009-08-28 12:20   ` Bean
@ 2009-08-28 12:27     ` Vladimir 'phcoder' Serbinenko
  0 siblings, 0 replies; 4+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2009-08-28 12:27 UTC (permalink / raw)
  To: The development of GRUB 2

On Fri, Aug 28, 2009 at 2:20 PM, Bean<bean123ch@gmail.com> wrote:
> On Fri, Aug 28, 2009 at 8:03 PM, Vladimir 'phcoder'
> Serbinenko<phcoder@gmail.com> wrote:
>> On Thu, Aug 27, 2009 at 10:27 AM, Bean<bean123ch@gmail.com> wrote:
>>> Hi,
>>>
>>> This patch allows to access big/little endian cpio archive from
>>> big/little endian machine.
>> Quick glance showed that you use swap_bytes. Could you use
>> grub_*_to_cpu* instead? This would simplify the future maintainability
>> if someone decides to port to a very special platform (e.g.
>> mixed-endian) since code would be uniform
>
> Hi,
>
> Actually it's not correct to use grub_*_to_cpu*. The code works by
> first assuming cpio uses the same endian of host cpu, if not, swap it
> and try the other endian. This method works for big/little endian cpio
> on big/little endian machine. It's possible to achieve the same result
> with a combination of #ifdef and grub_*_to_cpu*'s, but it's not as
> simple as this and generate more code than necessary.
>
Why is it more expensive than first try le and then be? What about
having 2 modules cpio_le and cpio_be?
> --
> Bean
>
> gitgrub home: http://github.com/grub/grub/
> my fork page: http://github.com/bean123/grub/
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>



-- 
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git



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

end of thread, other threads:[~2009-08-28 12:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-27  8:27 [PATCH] Detect endian in cpio fs Bean
2009-08-28 12:03 ` Vladimir 'phcoder' Serbinenko
2009-08-28 12:20   ` Bean
2009-08-28 12:27     ` Vladimir 'phcoder' Serbinenko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.