Mail Archives: cygwin/2011/01/13/19:33:05
--------------enig41D65490FA8457F8AB8883B1
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Hi All:
I've been doing lots of experimentation with calling grub-setup from Window=
s to prepare the bootsector of a FAT32 volume. I'm finding that for some r=
eason, the bootcode doesn't actually get written to the PBR even though gru=
b-setup thinks the write has succeeded.
To achieve this test i'm doing the following:
1) Create the FAT32 partition using diskpart
2) mkdir -p /boot/grub
3) Drop a boot.img and core.img in /boot/grub taken from a Linux build (the=
y're in ELF's then).
4) grub-setup.exe --verbose --force -d /cygdrive/e/boot/grub /dev/sdb1
If I dd the partition bootsector before starting and afterward to compare, =
it's not changing at all.
(dd if=3D/dev/sdb of=3Dbootsect bs=3D512 skip=3D128 count=3D1)
Now conversely if I use dd to try to place the contents of a 512 byte file =
in that place, it works fine.
(dd if=3Dbootsect of=3D/dev/sdb bs=3D512 seek=3D128 count=3D1)
I've tried to compare the code that dd and grub-setup both use, and even mo=
dified the open mode that grub-setup uses, but still get the same results.
If I run grub-setup under strace, a Windows error actually shows up, which =
makes me think this is actually a bug in cygwin1.dll. Here's the relevant =
output from strace on grub-setup as it's opening the drive, seeking and att=
empting to write it:
206 13511691 [main] grub-setup 2608 open: open (/dev/sdb, 0x10202)
52 13511743 [main] grub-setup 2608 normalize_posix_path: src /dev/sdb
52 13511795 [main] grub-setup 2608 normalize_posix_path: /dev/sdb =3D no=
rmalize_posix_path (/dev/sdb)
53 13511848 [main] grub-setup 2608 mount_info::conv_to_win32_path: conv_=
to_win32_path (/dev/sdb)
58 13511906 [main] grub-setup 2608 mount_info::conv_to_win32_path: src_p=
ath /dev/sdb, dst \Device\Harddisk1\Partition0, flags 0x2, rc 0
58 13511964 [main] grub-setup 2608 build_fh_pc: fh 0x612424E4
54 13512018 [main] grub-setup 2608 fhandler_base::open: (\Device\Harddis=
k1\Partition0, 0x10002)
76 13512094 [main] grub-setup 2608 fhandler_base::set_flags: flags 0x100=
02, supplied_bin 0x10000
58 13512152 [main] grub-setup 2608 fhandler_base::set_flags: O_TEXT/O_BI=
NARY set in flags 0x10000
52 13512204 [main] grub-setup 2608 fhandler_base::set_flags: filemode se=
t to binary
52 13512256 [main] grub-setup 2608 fhandler_base::open: 0 =3D NtCreateFi=
le (0x224, C0100000, \Device\Harddisk1\Partition0, io, NULL, 0, 7, 1, 4020,=
NULL, 0)
53 13512309 [main] grub-setup 2608 fhandler_base::open: 1 =3D fhandler_b=
ase::open (\Device\Harddisk1\Partition0, 0x10002)
193 13512502 [main] grub-setup 2608 fhandler_dev_floppy::get_drive_info: =
disk geometry: (780 cyl)*(64 trk)*(63 sec)*(512 bps)
58 13512560 [main] grub-setup 2608 fhandler_dev_floppy::get_drive_info: =
partition info: offset 0 length 1610612736
53 13512613 [main] grub-setup 2608 fhandler_dev_floppy::get_drive_info: =
drive size: 1610612736
52 13512665 [main] grub-setup 2608 open: 4 =3D open (/dev/sdb, 0x10202)
106 13512771 [main] grub-setup 2608 lseek64: 65536 =3D lseek (4, 65536, 0)
52 13512823 [main] grub-setup 2608 writev: writev (4, 0x22C784, 1)
52 13512875 [main] grub-setup 2608 fhandler_base::write: binary write
287 13513162 [main] grub-setup 2608 fhandler_dev_floppy::write_file: 1 (e=
rr 0) =3D WriteFile (548, 13541288, write 512, written 512, 0)
67 13513229 [main] grub-setup 2608 writev: 512 =3D write (4, 0x22C784, 1=
), errno 2
66 13513295 [main] grub-setup 2608 seterrno_from_win_error: /netrel/src/=
cygwin-snapshot-20101229-1/winsup/cygwin/fhandler.cc:1591 windows error 1
60 13513355 [main] grub-setup 2608 geterrno_from_win_error: windows erro=
r 1 =3D=3D errno 54
If I compare that to what DD is doing:
2131 391915 [main] dd 3400 open: 3 =3D open (/dev/sdb, 0x10202)
1183 393098 [main] dd 3400 dtable::dup3: dup3 (3, 1, 0x0)
1337 394435 [main] dd 3400 build_fh_pc: fh 0x61241884
1187 395622 [main] dd 3400 fhandler_base::dup: in fhandler_base dup
1174 396796 [main] dd 3400 dtable::dup_worker: duped '/dev/sdb' old 0x154=
, new 0x160
1342 398138 [main] dd 3400 dtable::dup3: newfh->io_handle 0x160, oldfh->i=
o_handle 0x154, new win32_name 0x61242214, old win32_name 0x6124225C
1682 399820 [main] dd 3400 close: close (1)
1271 401091 [main] dd 3400 fhandler_base::close: closing '' handle 0x258
1417 402508 [main] dd 3400 close: 0 =3D close (1)
1157 403665 [main] dd 3400 dtable::dup3: 1 =3D dup3 (3, 1, 0x0)
1073 404738 [main] dd 3400 close: close (3)
1475 406213 [main] dd 3400 fhandler_base::close: closing '/dev/sdb' handl=
e 0x154
1620 407833 [main] dd 3400 close: 0 =3D close (3)
1291 409124 [main] dd 3400 __set_errno: virtual int fhandler_base::ftrunc=
ate(_off64_t, bool):1558 val 22
2224 411348 [main] dd 3400 ftruncate64: -1 =3D ftruncate (1, 65536)
1379 412727 [main] dd 3400 fhandler_dev_raw::fstat: here
1214 413941 [main] dd 3400 fhandler_base::fstat: here
1162 415103 [main] dd 3400 time: 1294954129 =3D time (0)
945 416048 [main] dd 3400 fstat64: 0 =3D fstat (1, 0x22CC48)
673 416721 [main] dd 3400 lseek64: 65536 =3D lseek (1, 65536, 1)
944 417665 [main] dd 3400 readv: readv (0, 0x22CB94, 1) blocking, sigcat=
chers 2
1801 419466 [main] dd 3400 fhandler_base::read: returning 512, binary mode
1357 420823 [main] dd 3400 readv: 512 =3D readv (0, 0x22CB94, 1), errno 0
1535 422358 [main] dd 3400 fhandler_base::write: binary write
1468 423826 [main] dd 3400 fhandler_dev_floppy::write_file: 1 (err 0) =3D=
WriteFile (352, 9437184, write 512, written 512, 0)
I'm not sure why internally cygwin decided to use writev() for grub-setup a=
nd write() for writing the data out. In both cases, dd and grub-setup both=
use write() in their code.
I've already tried the latest snapshot of cygwin1.dll (2011-12-29 at this t=
ime), and i'm getting the same results as with the current stable version.
Any ideas?
--=20
*Mario Limonciello*
Linux Engineer
*Dell* | OS Engineering
--------------enig41D65490FA8457F8AB8883B1
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAk0vmbAACgkQ2CrZjkA73YvyZACfQYrPCv/NOsmRViLj/MyJaRA3
meMAoJsjNCXywM8r9h0xOEIsTDKeXgdy
=lN3r
-----END PGP SIGNATURE-----
--------------enig41D65490FA8457F8AB8883B1--
- Raw text -