Detect endian in cpio fs
PATCH 1/1 Detect endian in cpio fs
Hi,
This patch allows to access big/little endian cpio archive from big/little endian machine.
Signature · 4 lines
Bean gitgrub home: http://github.com/grub/grub/ my fork page: http://github.com/bean123/grub/
fs/cpio.c +18 -0
@@ -76,6 +76,22 @@ struct grub_cpio_datastatic 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,
Quoted 4 lines · Bean
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
Quoted 13 lines
--
Beangitgrub home: http://github.com/grub/grub/
my fork page: http://github.com/bean123/grub/_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 4 lines
Regards Vladimir 'phcoder' Serbinenko Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
Quoted 9 lines · Vladimir 'phcoder' Serbinenko
Quoted 4 lines · Bean
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.
Signature · 4 lines
Bean gitgrub home: http://github.com/grub/grub/ my fork page: http://github.com/bean123/grub/
Quoted 12 lines · Bean
Quoted 9 lines · Vladimir 'phcoder' Serbinenko
Quoted 4 lines · Bean
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
Quoted 9 lines
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?
Quoted 12 lines
--
Beangitgrub home: http://github.com/grub/grub/
my fork page: http://github.com/bean123/grub/_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 4 lines
Regards Vladimir 'phcoder' Serbinenko Personal git repository: http://repo.or.cz/w/grub2/phcoder.git