Date: Wed, 02 Oct 2013 13:13:47 -0700 From: Sean Bruno <sean_bruno@yahoo.com> To: sbruno@freebsd.org Cc: freebsd-fs@freebsd.org Subject: [SOLVED?] Re: Endian issues, LE write to BE partitions Message-ID: <1380744827.6516.16.camel@localhost> In-Reply-To: <1380730546.1619.47.camel@localhost> References: <1380730546.1619.47.camel@localhost>
next in thread | previous in thread | raw e-mail | index | archive | help
[-- Attachment #1 --]
On Wed, 2013-10-02 at 09:15 -0700, Sean Bruno wrote:
> Using makefs from an amd64 host to build a f/s in a VTOC8 partition will
> destroy the entire partition table. I simplified the test to simple dd
> to an existing partition and got the same result, exonerating mkfs
>
> I suspect a lack of endian knowledge in geom itself, not
> geom_part_vtoc8.
>
> test case:
> using amd64 host (10.0 current) create monolothic image
> truncate -s+5G /var/tmp/myfile.img
> mdconfig -f /var/tmp/myfile.img
> build and load geom_part_vtoc8 kernel module
> use gpart to create VTOC8 part table
> add partition to part table to yeild the following:
>
> => 0 10442250 md0 VTOC8 (5.0G)
> 0 10442250 1 freebsd-ufs (5G)
>
> dd to md0a from dev zero for just a bit
> dd if=/dev/zero of=/dev/md0a bs=64k count=100
>
> destroy md0 via mdconfig -d -u 0
> recreate it with mdconfig -f /var/tmp/myfile.img
>
> gpart displays no partions for the image any more:
> gpart: No such geom: md0.
>
> bcc freebsd-geom
Nathan brought me some knowledge. newfs(8) knows that the first 16
sectors for the first partition are special and not to touch it.
makefs(8) does not.
So, as a proof of concept, I modified makefs to read() the first 16
sectors from the "image" (in my case, /dev/md0a) and throw it away.
(lseek() failed on the partition, so read() was used)
This got me to a bootable SPARC64 image in qemu-system-sparc64, and will
probably allow further booting in other BE architectures.
Is this patch going to break non "device" makefs calls? e.g. if I want
to create an image file and not use a loopback device?
Index: ffs.c
===================================================================
--- ffs.c (revision 255871)
+++ ffs.c (working copy)
@@ -470,6 +470,7 @@
char *buf;
int i, bufsize;
off_t bufrem;
+ char temp_buf[16*512];
assert (image != NULL);
assert (fsopts != NULL);
@@ -480,6 +481,7 @@
warn("Can't open `%s' for writing", image);
return (-1);
}
+ read(fsopts->fd, temp_buf, 16*512);
/* zero image */
#if HAVE_STRUCT_STATVFS_F_IOSIZE && HAVE_FSTATVFS
bcc - nwhitehorn, freebsd-geom
[-- Attachment #2 --]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.14 (FreeBSD)
iQEcBAABAgAGBQJSTH57AAoJEBkJRdwI6BaHgJsH/jwJnObv/zaBDTXRnwuusSV4
Cj1MSaJOVgEyrguD75FMOCD3IcvXMThzehapdrc8OoWvdFXdufeXskUfS+FTWU8w
BTMir0SVaX1FGN518pXy+PHQpwEi8tfm8VTnspzUqrQwxK6qB/snwdPfO0wd88eS
vy1hXcnKwSugoIrFK5RYMjyXNMIuuFKxDRbxVDOEmpN6JgNeBxwl/RYnrsxQJPme
0y+ZFDZ3Qx7gEs3NjWM80uS2iu8TXst0yoM5mgQqkHkxdQsCximIUq4zQaBtEI5/
Tx7ZoxM3SrP0o9hQBNFEn2EYbfg94NY9uTR/Z9IkEcbd2/ZMcquwFxpKq+23Vcc=
=z2iu
-----END PGP SIGNATURE-----
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1380744827.6516.16.camel>
