Skip to contentSkip to conversation

Rewrite of grub-mkdevicemap

DISCUSSION Lubomir Kundrak 3 participants 5 messages Feb 2, 2006 – Feb 9, 2006

lore
Share & tools
lore
#0 lore raw

Hello.

I am currently working on BSD port of GRUB, so I first need the basic utilities to work. I decided to rewrite grub-mkdevicemap, because the old version was hard to modify, and actually didn't use all the information provided by the kernel.

Actually works with OpenBSD, NetBSD, FreeBSD 5, 6, DragonFly and Linux. Please note, that this won't actually build on non-glibc systems, unless standalone argp and patch for it from here
http://lists.gnu.org/archive/html/grub-devel/2005-11/msg00162.html
is included.

Changelog entry and uuencoded source file is bellow

2006-01-02 Lubomir Kundrak <[email protected]>

* util/i386/pc/grub-mkdevicemap.c: Complete rewrite

begin 644 util/i386/pc/grub-mkdevicemap.c M"B\J"BJ(&=R=6(M;6MD979I8V5M87@+2T@9V5N97)A=&4@0DE/4RUT;RUN M871I=F4@9&ES:R!M87*("H@0V]P>7)I9VAT("A#*2R,#`V("!,=6)O;6ER M($MU;F1R86L*("H*("H@5&AI<R!P<F]G<F%M(&ES(&9R964@<V]F='=A<F4[ M('EO=2!C86X@<F5D:7-T<FEB=71E(&ET(&%N9"]O<B!M;V1I9GD*("H@:70@ M=6YD97(@=&AE('1E<FUS(&]F('1H92!'3E4@1V5N97)A;"!0=6)L:6,@3&EC M96YS92!A<R!P=6)L:7-H960@8GD@"BJ('1H92!&<F5E(%-O9G1W87)E($9O M=6YD871I;VX[(&5I=&AE<B!V97)S:6]N(#(@;V8@=&AE($QI8V5N<V4L(&]R M"BJ("AA="!Y;W5R(&]P=&EO;BD@86YY(&QA=&5R('9E<G-I;VXN"BJ"BJ M(%1H:7,@<')O9W)A;2!I<R!D:7-T<FEB=71E9"!I;B!T:&4@:&]P92!T:&%T M(&ET('=I;&P@8F4@=7-E9G5L+"@"BJ(&)U="!7251(3U54($%.62!705)2 M04Y463L@=VET:&]U="!E=F5N('1H92!I;7!L:65D('=A<G)A;G1Y(&]F(H@ M*B!-15)#2$%.5$%"24Q)5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8VQU9&4@/&UA8VAI;F4O M8W!U+F@^"B,@:6YC;'5D92\9&ER96YT+F@^"B,@:6YC;'5D92\<WES+W-T M870N:#X*(R!I;F-L=61E(#QM86-H:6YE+V)I;W-V87(N:#X*(V5N9&EF("\J M(%]?3W!E;D)31%]?("HO"@HC9&5F:6YE($))3U-?1$E32U,),'AF9@HC9&5F M:6YE($))3U-?2$0)"3!X.#)+RH@3G5M8F5R(&]F(&9I<G-T(&AA<F0M9&ES M:R!D979I8V4N("J+PH*(V1E9FEN90E'4E5"7T1)4TM?5%E015].3TY%"3* M(V1E9FEN90E'4E5"7T1)4TM?5%E015](1DQ"B-D969I;F4)1U)50E]$25-+ M7U194$5?1D0),@H*+RH@5&AE(&1E=FEC92!M87N("J+PIS=')U8W0@9W)U M8E]D:7-K"GL*("!C:&%R(&9I;&5?;F%M95M-05A0051(3$5.73L*("!I;G0@ M;6%T8VAE<SL*("!I;G0@='EP93L)"2\J(%-E92!D969I;F5S(&%B;W9E+B@ M*B\*?2!G<G5B7V1E=FEC95]M87!;0DE/4U]$25-+4UT["@HO*B!#;VUM86YD M(&QI;F4@87)G=6UE;G1S+B@*B\*<W1R=6-T(&%R9W5M96YT<PI[(H@(&-H M87(@*F1E=FEC95]M87["GT["@IS=&%T:6,@<W1R=6-T(&%R9W!?;W!T:6]N M(&]P=&EO;G-;72]"B@>PH@("@>R)D979I8V4M;6%P(BP@)VTG+"B1DE, M12(L(#L"B@("@(D]U='!U="!D979I8V4@;6%P('1O($9)3$4@6V1E9F%U M;'0](B!$149!54Q47T1%5DE#15]-05@(ETB+"P?2P*("@('LB=F5R8F]S M92(L("@("=V)RP@,"P@("@("P+"B4')I;G0@=F5R8F]S92!M97-S86=E M<R(L(#!]+H@("@>RP+"P+"P+"P+"P+"P('T*("!].PH*8V]N<W0@ M8VAA<BJ87)G<%]P<F]G<F%M7W9E<G-I;VX@/2!04D]'3D%-10H)"0D)("@ M(BH(E!!0TM!1T5?3D%-12(I("(*"0D)"2@(%!!0TM!1T5?5D524TE/3CL* M8V]N<W0@8VAA<BJ87)G<%]P<F]G<F%M7V)U9U]A9&1R97-S(#T@4$%#2T%' M15]"54=215!/4E0["G-T871I8R!C:&%R(&1O8UM=(#T@(D=E;F5R871E(&$@ M9&5V:6-E(&UA<"!F:6QE(&%U=&]M871I8V%L;'DN(CL*"F-H87(@*G!R;V=N M86UE.PH*:6YT(&=R=6)?;&%S=%]H9"]($))3U-?2$0@+2Q.PH*+RH@3F]T M($]P96Y"4T0M<W!E8VEF:6,L(&)U="!U<V5D(&]N;'D@:6X@3W!E;D)31"!C M;V1E+B@*B\*(VEF(&1E9FEN960@*%]?3W!E;D)31%]?*0H*+RH@4V-A;G,@ M9&ER96-T;W)Y('-P96-I9FEE9"!B>2!R;V]T(')E8W5R<VEV96QY('5N=&EL M(&EN(&9I;F1S('1H92!F:6QE(&]F"B@(&)L;V-K(&1E=FEC92!D978N("!) M;B!C87-E(&1E=FEC92!I<R!F;W5N9"P@:71S(&YA;64@:7,@8V]P:65D('1O M(&9N86UE+H@("!O=&AE<G=I<V4@9FYA;64@:7,@=6YT;W5C:&5D+BJ+PH* M:6YT"F=E=%]D979?9FYA;64@*&-H87(@*F9N86UE+"!D979?="!D978L(&-H M87(@*G)O;W0I"GL*("!$25(@*F1I<CL*("!S=')U8W0@9&ER96YT("IE;G0[ M"@H@(&=R=6)?=71I;%]I;F9O("@B<V5A<F-H:6YG(&9O<B!D979I8V4@,'@E M,#1X(&EN("5S(BP@9&5V+"!R;V]T*3L*"B@9&ER(#T@;W!E;F1I<BH<F]O M="D["B@:68@*&1I<B]/2!.54Q,*0H@("@>PH@("@("!G<G5B7W5T:6Q? M:6YF;RH(G5N86)L92!T;R!O<&5N("5S.BE<R(L(')O;W0L('-T<F5R<F]R M("AE<G)N;RDI.PH@("@("!R971U<FX@+3$["B@("!]"@H@('=H:6QE("@H M96YT(#T@<F5A9&1I<BH9&ER*2DI"B@("!["B@("@('-T<G5C="!S=&%T M('-T.PH@("@("!C:&%R('!A=&A;34%84$%42$Q%3ET@/2B(CL*"B@("@ M('-T<FYC870@*'!A=&@L(')O;W0L($U!6%!!5$A,14XI.PH@("@("!S=')N M8V%T("AP871H+"B+R(L($U!6%!!5$A,14XI.PH@("@("!S=')N8V%T("AP M871H+"!E;G0M/F1?;F%M92P@34%84$%42$Q%3BD["@H@("@("!I9BH<W1A M="H<&%T:"P@)G-T*2^(#I"@E["@D@(&=R=6)?=71I;%]I;F9O("@B=6YA M8FQE('1O('-T870@)7,Z("5S(BP@<&%T:"P@<W1R97)R;W(@*&5R<FYO*2D[ M"@D@(&-O;G1I;G5E.PH)?0H*("@("@:68@*%-?25-$25(@*'-T+G-T7VUO M9&4I("8F(&5N="T^9%]N86UE6S!=("$]("<N)RD*"6=E=%]D979?9FYA;64@ M*&9N86UE+"!D978L('!A=&@I.PH*("@("@:68@*%-?25-"3$L@*'-T+G-T M7VUO9&4I("8F(&1E=B]/2!S="YS=%]R9&5V*0H)<W1R;F-P>2H9FYA;64L M('!A=&@L($U!6%!!5$A,14XI.PH*("@("@:68@*&9N86UE6S!=*0H)8G)E M86L["B@("!]"@H@("@8VQO<V5D:7(@*&1I<BD["B@("!R971U<FX@,#L* M("!]"@HC96YD:68@+RH@7U]/<&5N0E-$7U\@*B\*"B-I9B!D969I;F5D("A? M7VDS.#9?7RD*(R!I9B!D969I;F5D("A?7TYE=$)31%]?*2F)B!D969I;F5D M("A-05A?0DE/4T1)4TM3*0H*:6YT"F=E=')A=W!A<G1I=&EO;BH*2O*B!8 M6%@Z("UL=71I;"J+PI["B@<F5T=7)N(#,["GT*"B\J(%1H:7,@9G5N8W1I M;VX@<F5T<FEE=F5S(&EN9F]R;6%T:6]N(&9R;VT@=&AE($YE=$)31"]I,S@V M(&ME<FYE;"!T;PH@("!C;VYS=')U8W0@9&5V:6-E(&UA<"X@($ET(')E='5R M;G,@;G5M8F5R(&]F(&1I<VMS(&UA=&-H960N"B*("@5&AE($YE=$)31"]I M,S@V(&YA=&EV92!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E<RLK.PH*"2@:68@*"@A(&UA=&-H*2F)BH9W)U8E]D M979I8V5?;6%P6V)I7V1E=ETN9FEL95]N86UE6S!=(#T](#I*0H)("@('L* M"2@("@(&UA=&-H(#T@8FE?9&5V.PH)("@("@;F1I<VMS*RL["@D@("@ M("!S;G!R:6YT9BH9W)U8E]D979I8V5?;6%P6V)I7V1E=ETN9FEL95]N86UE M+"!-05A0051(3$5.+H)"2@("@("B+V1E=B\E<R5C(BP@=&AI<RT^;FE? M9&5V;F%M92P*"0D@("@("@9V5T<F%W<&%R=&ET:6]N("@I("L@)V$G*3L* M"2@("!]"@E]"@H@("@("!I9BH(2!M871C:"D*"7L*"2@+RH@4')O8F%B M;'D@:70G<R!R96UO=F%B;&4@55-"(&1R:79E(&]R('=H871E=F5R+B@*B\* M"2@9W)U8E]U=&EL7VEN9F\@*")U;F%B;&4@=&\@9W5E<W,@0DE/4R!D:7-K M(&YU;6)E<B!F;W(@9&5V:6-E("5S7&XB+H)"0D@('1H:7,M/FYI7V1E=FYA M;64I.PH)?0H@("@?0H*("!F<F5E("AD:7-K<RD["B@<F5T=7)N(&YD:7-K M<SL*?0H*(R!E;F1I9@DO*BA7U].971"4T1?7RJ+PH*(R!I9B!D969I;F5D M("A?7T]P96Y"4T1?7RD*"B\J($1O97,@=&AI;F=S('-I;6EL87(@=&\@=VAA M="!N971B<V1?9V5T7V1I<VMI;F9O*"D@9&]E<R!F;W(@3F5T0E-$"B@($%S M($]P96Y"4T0@:7,@:G5S="!O8G-O;&5T92!.971"4T0L(&ET(&ES(&QI='1L M92!L97-S(&5L96=A;G0@86YD"B@(&QI='1L92!L97-S(&%C8W5R871E(#HI M("H3F\@;V9F96YS92P@:G5S="!K:61D:6YG+B@4F5A;&QY(#IO*2J+R* M"FEN=IO<&5N8G-D7V=E=%]D:7-K:6YF;RH*0I["B@:6YT(&UI8ELT73L* M("!I;G0@;F1I<VMS(#T@,#L*("!I;G0@:3L*"B@;6EB6S!=(#T@0U1,7TU! M0TA$15["B@;6EB6S%=(#T@0U!57T))3U,["B@;6EB6S)=(#T@0DE/4U]$ M25-+24Y&3SL*"B@9F]R("AI(#T@,#L@:2\($))3U-?1$E32U,[(&DK*RD* M("@('L*("@("@8FEO<U]D:7-K:6YF;U]T(&1I<VL["B@("@('-I>F5? M="!S:7IE(#T@<VEZ96]F("AB:6]S7V1I<VMI;F9O7W0I.PH@("@("!C:&%R M('!A=&A;34%84$%42$Q%3ET@/2B(CL*("@("@9&5V7W0@<F1E=CL*"B@ M("@(&UI8ELS72](&D["@H@("@("!I9BH<WES8W1L("AM:6(L(#0L("9D M:7-K+"F<VEZ92P@3E5,3"P@,"D@/3T@+3$I"@EC;VYT:6YU93L*"B@("@ M("\J('-W:71C:"!M86IO<B]M:6YO<B!N=6UB97(@*B\*("@("@<F1E=B] M("AD:7-K+F)S9%]D978@)BP>#P9F8I(#P\(#@["B@("@(')D978@?#T@ M*&1I<VLN8G-D7V1E=BF(#!X9F8P,"D@/CX@.#L*"B@("@(&=E=%]D979? M9FYA;64@*'!A=&@L(')D978L("(O9&5V(BD["@H@("@("!I9BH<&%T:%LP M72D*"7L*"2@:6YT(&1E=FYO(#T@9&ES:RYB:6]S7VYU;6)E<CL*"@D@(&YD M:7-K<RLK.PH)("!G<G5B7V1E=FEC95]M87!;9&5V;F]=+FUA=&-H97,K*SL* M"2@<W1R;F-P>2H9W)U8E]D979I8V5?;6%P6V1E=FYO72YF:6QE7VYA;64L M('!A=&@L($U!6%!!5$A,14XI.PH)("!G<G5B7V1E=FEC95]M87!;9&5V;F]= M+G1Y<&4@/2!D979N;R\($))3U-?2$0*"0D)"0D_($=254)?1$E32U]465!% M7T9$"@D@(D)"2@("@("@.B!'4E5"7T1)4TM?5%E015](1#L*"7T*("@ M('T*"B@<F5T=7)N(#["GT*"B,@96YD:68)+RH@7U]/<&5N0E-$7U\@*B\* M(V5N9&EF"2\J(%]?:3,X-E]?("HO"@HC:68@9&5F:6YE9"H0E-$*0H*+RH@ M06QL($)31"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\*"FEN=IL:6YU>%]G971?9F1S("@I"GL*("!I;G0@;F1I<VMS(#T@ M,#L*("!&24Q%("ID979I8V5S.PH@(&-H87(@9&5V6TU!6%!!5$A,14Y=.PH* M("!D979I8V5S(#T@9F]P96X@*"(O<')O8R]D979I8V5S(BP@(G(B*3L*("!I M9BH9&5V:6-E<R]/2!.54Q,*0H@("@>PH@("@("!G<G5B7W5T:6Q?:6YF M;RH(B]P<F]C+V1E=FEC97,Z("5S(BP@<W1R97)R;W(@*&5R<FYO*2D["B@ M("@(')E='5R;BM,3L*("@('T*"B@=VAI;&4@*&9S8V%N9BH9&5V:6-E M<RP@(B5S)7-<;B(L(&1E=BP@9&5V*2A/2!%3T8I"B@("!["B@("@(&EF M("AS=')C;7@*&1E=BP@(F9D(BD@/3T@,"D*("@("@("!["B@("@("@ M("!G<G5B7V1E=FEC95]M87!;;F1I<VMS72YM871C:&5S*RL["B@("@("@ M("!G<G5B7V1E=FEC95]M87!;;F1I<VMS72YT>7!E(#T@1U)50E]$25-+7U19 M4$5?2$0["B@("@("@("!S;G!R:6YT9BH9W)U8E]D979I8V5?;6%P6VYD M:7-K<UTN9FEL95]N86UE+H@("@("@("@("@("@("@34%84$%42$Q% M3BP@(B]D978O9F0E:2(L(&YD:7-K<RD["B@("@("@("!N9&ES:W,K*SL* M("@("@("!]"B@("!]"@H@(&9C;&]S92H9&5V:6-E<RD["B@<F5T=7)N M(&YD:7-K<SL*?0H*(V5N9&EF"2\J(%]?;&EN=7A?7RJ+PH*+RH@0V%L;',@ M3U,O;6%C:&EN92!D97!E;F1E;G0@<F]U=&EN97,@=&\@8V]N<W1R=6-T('1H M92!M87L(&]R9&5R960@8GD*("@<F5S=6QT(&%C8W5R86-Y+BJ+PH*=F]I M9IG971?;6%P("@I"GL*"B-I9B!D969I;F5D("A"4T0I"B,@:68@9&5F:6YE M9"H7U].971"4T1?7RD*"B@:68@*&YE=&)S9%]G971?9&ES:VEN9F\@*"D@ M/BP*0H@("@"@D@("@34%84$%42$Q%3BP@>PH@("@("!C:&%R("ID:7-K M='EP97-;72]"@E["@D@(")F9"(L("\J(&9L;W!P>2J+PH)("P"@E].PH@ M("@("!B<V1?9V5T7V1I<VMN86UE<RH9&ES:W1Y<&5S*3L*("@('T*("!E M;'-E"B@("!["B@("@(&-H87(@*F1I<VMT>7!E<UM=(#T*"7L*"2@(F9D M(BP@+RH@9FQO<'!Y("HO"@D@(")W9"(L("\J($E$12J+PH)("B<V0B+"O M*B!30U-)("HO"@D@(#*"7T["B@("@(&)S9%]G971?9&ES:VYA;65S("AD M:7-K='EP97,I.PH@("@?0H*(R!E;&EF(&1E9FEN960@*%]?3W!E;D)31%]? M*0H*("!I9BH;W!E;F)S9%]G971?9&ES:VEN9F\@*"D@/3T@,"D*("@('L* M("@("@8VAA<BJ9&ES:W1Y<&5S6UT@/0H)>PH)("B9F0B+"O*B!F;&]P M<'D@*B\*"2@(G=D(BP@+RH@241%("HO"@D@(")S9"(L("\J(%-#4TD@*B\* M"2@,H)?3L*("@("@8G-D7V=E=%]D:7-K;F%M97,@*&1I<VMT>7!E<RD[ M"B@("!]"@HC(&5L<V4)+RH@(5]?3F5T0E-$7U\@)B8@(5]?3W!E;D)31%]? M("HO"@H@('L*("@(&-H87(@*F1I<VMT>7!E<UM=(#T*("@("@>PH)(F9D M(BP@+RH@9FQO<'!Y("HO"@DB860B+"O*B!)1$4@*B\*"2)D82(L("\J($E$ M12J+PH)(G-D(BP@+RH@4T-322J+PH),H@("@("!].PH@("@("!B<V1? M9V5T7V1I<VMN86UE<RH9&ES:W1Y<&5S*3L*("!]"@HC("!W87)N:6YG(")4 M:&ES($)31"!V87)I86YT(&ES(&YO="!S=7!P;W)T960@>65T(@HC(&5N9&EF M"B-E;&EF(&1E9FEN960@*%]?;&EN=7A?7RD*"B@;&EN=7A?9V5T7VAD<RH M*3L*("!L:6YU>%]G971?9F1S("@I.PH*(V5L<V4*(R!E<G)O<B`B5&AI<R!/ M4R!I<R!N;W0@<W5P<&]R=&5D(@HC96YD:68*"GT*"B\J($]U='!U=',@=&AE M(&UA<"!C;VYS=')U8W1E9"!B>2!G971?;6%P*"D@=&\@82!D979I8V4@;6%P M(&9I;&4N("HO"@IV;VED"F1U;7!?;6%P("AS=')U8W0@87)G=6UE;G1S("IA M<F=S*0I["B@1DE,12J;W5T<'5T.PH@(&EN="!I.PH*("!I9BH<W1R8VUP M("AA<F=S+3YD979I8V5?;6%P+"B+2(I(#T](#I"B@("!["B@("@(&]U M='!U="]('-T9&]U=#L*("@('T*("!E;'-E"B@("!["B@("@(&]U='!U M="](&9O<&5N("AA<F=S+3YD979I8V5?;6%P+"B=R(I.PH@("@("!I9BH M;W5T<'5T(#T]($Y53$PI"@E["@D@(&=R=6)?=71I;%]E<G)O<BH(G5N86)L M92!T;R!O<&5N("5S.BE<R(L"@D)"2@(&%R9W,M/F1E=FEC95]M87L('-T M<F5R<F]R("AE<G)N;RDI.PH)?0H@("@?0H*("!F;W(@*&D@/2P.R!I(#P@ M0DE/4U]$25-+4SL@:2LK*0H@("@>PH@("@("!I9BH9W)U8E]D979I8V5? M;6%P6VE=+G1Y<&4I"@E["@D@(&9P<FEN=&8@*&]U='!U="P@(B@E<R5I*5QT M)7-<;B(L"@D)("@9W)U8E]D979I8V5?;6%P6VE=+G1Y<&4@/3T@1U)50E]$ M25-+7U194$5?2$0@/RB:&0B(#H*"0D@("!G<G5B7V1E=FEC95]M87!;:5TN M='EP92]/2!'4E5"7T1)4TM?5%E015]&1"_(")F9"(@.@H)"2@("(_/S\B M+H)"2@(&D@/"!"24]37TA$(#\@:2Z(&D@+2!"24]37TA$+H)"2@(&=R M=6)?9&5V:6-E7VUA<%MI72YF:6QE7VYA;64I.PH)?0H@('T*?0H*<W1A=&EC M(&5R<F]R7W0*<&%R<V5?;W!T("AI;G0@:V5Y+"!C:&%R("IA<F<L('-T<G5C M="!A<F=P7W-T871E("IS=&%T92D*>R*("!S=')U8W0@87)G=6UE;G1S("IA M<F=S(#T@<W1A=&4M/FEN<'5T.PH@"B@<W=I=&-H("AK97DI"B@("!["B@ M("!C87-E("=M)SH*("@("@87)G<RT^9&5V:6-E7VUA<"](&%R9SL*("@ M("@8G)E86L["B@("!C87-E("=V)SH*("@("@=F5R8F]S:71Y*RL["B@ M("@(&)R96%K.PH@("@9&5F875L=#H*("@("@<F5T=7)N($%21U!?15)2 M7U5.2TY/5TX["B@("!]"B@<F5T=7)N(#["GT*(IS=&%T:6,@<W1R=6-T M(&%R9W@87)G<"]('MO<'1I;VYS+"!P87)S95]O<'0L($Y53$PL(&1O8RP@ M,"P@,"P@,'T["@II;G0*;6%I;BH:6YT(&%R9V,L(&-H87(@*F%R9W9;72D* M>PH@('-T<G5C="!A<F=U;65N=',@87)G<R]"B@("!["B@("@("YD979I M8V5?;6%P(#T@1$5&055,5%]$159)0T5?34%0+H@("@?3L*"B@<')O9VYA M;64@/2!04D]'3D%-13L*("!A<F=P7W!A<G-E("@F87)G<"P@87)G8RP@87)G M=BP@,"P@,"P@)F%R9W,I.PH*("!G971?;6%P("@I.PH@(&1U;7!?;6%P("@F 787)G<RD["@H@(')E='5R;BP.PI]"@I?
`
end

---------------------------------------------------------------------------
o Lubomir Kundrak
°O° <[email protected]>, http://skosi.org/~lkundrak/
(_) SKOSI -- Slovak OpenSource Initiative
---------------------------------------------------------------------------

#1 lore raw
Quoted 5 lines · Lubomir Kundrak

I am currently working on BSD port of GRUB, so I first need the basic utilities to work. I decided to rewrite grub-mkdevicemap, because the old version was hard to modify, and actually didn't use all the information provided by the kernel.

I don't know why you thought it is difficult to modify. grub-mkdevicemap.c is based on lib/device.c in GRUB Legacy, which works well with *BSD.

Quoted 1 line

Changelog entry and uuencoded source file is bellow

I could not record it correctly. Can you attach it as a plain text?

Thanks,
Okuji

#2 lore raw
Quoted 7 lines · Yoshinori K. Okuji
Quoted 5 lines · Lubomir Kundrak

I am currently working on BSD port of GRUB, so I first need the basic utilities to work. I decided to rewrite grub-mkdevicemap, because the old version was hard to modify, and actually didn't use all the information provided by the kernel.

Quoted 6 lines

I don't know why you thought it is difficult to modify. grub-mkdevicemap.c is based on lib/device.c in GRUB Legacy, which works well with *BSD.

Quoted 1 line

Changelog entry and uuencoded source file is bellow

I could not record it correctly. Can you attach it as a plain text?

Lubomir had problems with inline emails before, so I assume he can't. Here it is, copied from Lubomir's email.

--
Marco

2006-01-02 Lubomir Kundrak <[email protected]>

* util/i386/pc/grub-mkdevicemap.c: Complete rewrite

/*
* grub-mkdevicemap -- generate BIOS-to-native disk map
* Copyright (C) 2006 Lubomir Kundrak
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */

#define DEFAULT_DIRECTORY "/grub"
#define DEFAULT_DEVICE_MAP DEFAULT_DIRECTORY "/device.map"

#define PROGNAME "grub-mkdevicemap"

#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <argp.h>
#include <grub/util/misc.h>
#include <sys/param.h>

#if defined (BSD)

# include <sys/types.h>
# include <sys/sysctl.h>
#endif /* BSD */

#if defined (__NetBSD__)

# include <machine/cpu.h>
# include <util.h>
#endif /* __NetBSD__ */

#if defined (__OpenBSD__)

# include <machine/cpu.h>
# include <dirent.h>
# include <sys/stat.h>
# include <machine/biosvar.h>
#endif /* __OpenBSD__ */

#define BIOS_DISKS 0xff
#define BIOS_HD 0x80 /* Number of first hard-disk device. */

#define GRUB_DISK_TYPE_NONE 0
#define GRUB_DISK_TYPE_HD 1
#define GRUB_DISK_TYPE_FD 2

/* The device map. */
struct grub_disk
{
char file_name[MAXPATHLEN];
int matches;
int type; /* See defines above. */
} grub_device_map[BIOS_DISKS];

/* Command line arguments. */
struct arguments
{
char *device_map;
};

static struct argp_option options[] =

  {
    {"device-map", 'm', "FILE", 0,
     "Output device map to FILE [default=" DEFAULT_DEVICE_MAP "]", 0},
    {"verbose",    'v', 0,      0, "Print verbose messages", 0},
    { 0, 0, 0, 0, 0, 0 }

};

const char *argp_program_version = PROGNAME

				   " ("PACKAGE_NAME") "
				   PACKAGE_VERSION;

const char *argp_program_bug_address = PACKAGE_BUGREPORT; static char doc[] = "Generate a device map file automatically.";

char *progname;

int grub_last_hd = BIOS_HD - 1;

/* Not OpenBSD-specific, but used only in OpenBSD code. */ #if defined (__OpenBSD__)

/* Scans directory specified by root recursively until in finds the file of
block device dev. In case device is found, its name is copied to fname, otherwise fname is untouched. */

int
get_dev_fname (char *fname, dev_t dev, char *root) {
DIR *dir;
struct dirent *ent;

grub_util_info ("searching for device 0x%04x in %s", dev, root);

  dir = opendir (root);
  if (dir == NULL)
    {
      grub_util_info ("unable to open %s: %s", root, strerror (errno));
      return -1;
    }

  while ((ent = readdir (dir)))
    {
      struct stat st;
      char path[MAXPATHLEN] = "";
      strncat (path, root, MAXPATHLEN);
      strncat (path, "/", MAXPATHLEN);
      strncat (path, ent->d_name, MAXPATHLEN);

      if (stat (path, &st) > 0)
	{
	  grub_util_info ("unable to stat %s: %s", path, strerror (errno));
	  continue;
	}

      if (S_ISDIR (st.st_mode) && ent->d_name[0] != '.')
	get_dev_fname (fname, dev, path);

      if (S_ISBLK (st.st_mode) && dev == st.st_rdev)
	strncpy (fname, path, MAXPATHLEN);

      if (fname[0])
	break;
    }

    closedir (dir);
    return 0;

}

#endif /* __OpenBSD__ */

#if defined (__i386__)

# if defined (__NetBSD__) && defined (MAX_BIOSDISKS)

int
getrawpartition () /* XXX: -lutil */
{
return 3;
}

/* This function retrieves information from the NetBSD/i386 kernel to
construct device map. It returns number of disks matched.

The NetBSD/i386 native bootloader passes checksum of MBR of each BIOS disk and kernel tries to match it with its devices. It exports the results via "machdep.diskinfo" sysctl. See bottom of <sys/cpu.h> for more details.

Note 1:
GRUB doesn't (but imho should) pass anything like that, so when running kernel was booted by GRUB, this function always returns 0.

Note 2:
Diskinfo contains information only about hard disks. */

int
netbsd_get_diskinfo ()
{
struct disklist *disks;
size_t size;
int mib[2];
int ndisks = 0;
int i;

  mib[0] = CTL_MACHDEP;
  mib[1] = CPU_DISKINFO;

if (sysctl (mib, 2, NULL, &size, NULL, 0) == -1)

    return -1;

disks = (struct disklist *) malloc (size);
if (! disks)

    {
      grub_util_info ("can't allocate %i B of memory for diskinfo struct",
		      size); 
      return -1;
    }

if (sysctl (mib, 2, disks, &size, NULL, 0) == -1)

    return -1;

/* BIOS hard disk devices */

  for (i = 0; i < disks->dl_nbiosdisks; i++)
    {
      struct biosdisk_info *this = &disks->dl_biosdisks[i];
      grub_device_map[this->bi_dev].type = GRUB_DISK_TYPE_HD;
      if (this->bi_dev > grub_last_hd)
	grub_last_hd = this->bi_dev;
    }

/* Native hard disk devices */

  for (i = 0; i < disks->dl_nnativedisks; i++)
    {
      struct nativedisk_info *this = &disks->dl_nativedisks[i];
      int match = 0;
      int i;
      if (this->ni_nmatches > 1)
	{
	  grub_util_info ("%s corresponds to more than one BIOS disk.",
			  this->ni_devname);
	}

      for (i = 0; i < this->ni_nmatches; i++)
	{
	  int bi_dev = disks->dl_biosdisks[this->ni_biosmatches[i]].bi_dev;
 
	  grub_device_map[bi_dev].matches++;

	  if ((! match) && (grub_device_map[bi_dev].file_name[0] == 0))
	    {
	      match = bi_dev;
	      ndisks++;
	      snprintf (grub_device_map[bi_dev].file_name, MAXPATHLEN,
		       "/dev/%s%c", this->ni_devname,
		       getrawpartition () + 'a');
	    }
	}

      if (! match)
	{
	  /* Probably it's removable USB drive or whatever.  */
	  grub_util_info ("unable to guess BIOS disk number for device %s\n",
			  this->ni_devname);
	}
    }

free (disks);
return ndisks;
}

# endif /* !__NetBSD__ */

# if defined (__OpenBSD__)

/* Does things similar to what netbsd_get_diskinfo() does for NetBSD
As OpenBSD is just obsolete NetBSD, it is little less elegant and little less accurate :) (No offense, just kidding. Really :o) */

int
openbsd_get_diskinfo ()
{
int mib[4];
int ndisks = 0;
int i;

  mib[0] = CTL_MACHDEP;
  mib[1] = CPU_BIOS;
  mib[2] = BIOS_DISKINFO;

  for (i = 0; i < BIOS_DISKS; i++)
    {
      bios_diskinfo_t disk;
      size_t size = sizeof (bios_diskinfo_t);
      char path[MAXPATHLEN] = "";
      dev_t rdev;
      mib[3] = i;

      if (sysctl (mib, 4, &disk, &size, NULL, 0) == -1)
	continue;

      /* switch major/minor number */
      rdev = (disk.bsd_dev & 0x00ff) << 8;
      rdev |= (disk.bsd_dev & 0xff00) >> 8;

      get_dev_fname (path, rdev, "/dev");

      if (path[0])
	{
	  int devno = disk.bios_number;

	  ndisks++;
	  grub_device_map[devno].matches++;
	  strncpy (grub_device_map[devno].file_name, path, MAXPATHLEN);
	  grub_device_map[devno].type = devno < BIOS_HD
					? GRUB_DISK_TYPE_FD
	  			        : GRUB_DISK_TYPE_HD;
	}
    }

return 0;
}

# endif /* __OpenBSD__ */
#endif /* __i386__ */

#if defined (BSD)

/* All BSD variants provide list of disk devices they recognize. So they might be used
as alternative information source for device map construction.

FreeBSD/Dragonfly: kern.disks
NetBSD/OpenBSD: hw.disknames */

int
bsd_get_disknames (disktypes)
char *disktypes[];
{
char **p;
char *disknames;
size_t size;
int mib[2];

#if defined (__FreeBSD__) || defined (__DragonFly__)

/* XXX: any way for systems without sysctlnametomib()?
I failed to find constants for kern.disks in headers. Grrrr. I am very sorry about that. Anyways, do they change at all? */

  size = 2;
  if (sysctlnametomib("kern.disks", mib, &size) == -1)
    return -1;

#else /* !__FreeBSD__ && !__DragonFly__ */

  mib[0] = CTL_HW;
  mib[1] = HW_DISKNAMES;

#endif

if (sysctl (mib, 2, NULL, &size, NULL, 0) == -1)

    return -1;
  disknames = (char *) malloc (size);
  if (! disknames)
    {
      grub_util_info ("can't allocate %i B of memory for disk list", size); 
      return -1;
    }

if (sysctl (mib, 2, disknames, &size, NULL, 0) == -1)

    return -1;

for (p = &disktypes[0]; *p; p++)

    {
      char *disks = disknames;
	while ((disks = strstr (disks, *p)))
	  {
	    int disknum;

	    disknum = atoi (&disks[2]);
	    switch (*p[0])
	      {
	      case 'f':
		grub_device_map[disknum].matches++;
		grub_device_map[disknum].type = GRUB_DISK_TYPE_FD;
		snprintf (grub_device_map[disknum].file_name,
			 MAXPATHLEN, "/dev/fd%ia", disknum);
		break;
	      case 'w':
		grub_last_hd++;
		grub_device_map[grub_last_hd].matches++;
		grub_device_map[grub_last_hd].type = GRUB_DISK_TYPE_HD;
		snprintf (grub_device_map[grub_last_hd].file_name,
			 MAXPATHLEN, "/dev/hd%ia", disknum);
		break;
	      case 's':
		grub_last_hd++;
		grub_device_map[grub_last_hd].matches++;
		grub_device_map[grub_last_hd].type = GRUB_DISK_TYPE_HD;
		snprintf (grub_device_map[grub_last_hd].file_name,
			MAXPATHLEN, "/dev/sd%ia", disknum);
		break;
	      }
	    disks++;
	  }
    }

free (disknames);
return 0;
}

#endif /* BSD */

#if defined (__linux__)

/* Routine for getting information about disks from Linux's procfs

1.) Using /proc/ide and /proc/scsi would be a good idea if all
SCSI and SCSI-SATA drivers implemented /proc/scsi interface. So we don't use this.

2.) EDD bios support would be great. 2.6 Linux supports it.
Not yet implemented here.

3.) We can dig names of disks from /proc/partitions.
Everything that does not end with number is considered to be a disk. */

int
linux_get_hds ()
{
int ndisks = 0;
FILE *partitions;
char dev[MAXPATHLEN];

  partitions = fopen ("/proc/partitions", "r");
  if (partitions == NULL)
    {
      grub_util_info ("/proc/partitions: %s", strerror (errno));
      return -1;
    }

while (getc (partitions) != '\n'); /* skip header */
while (fscanf (partitions, "%s%s%s%s\n", dev, dev, dev, dev) != EOF)

    { 
      if (!isdigit (dev[strlen (dev)-1]))
	{
	  grub_last_hd++;
	  ndisks++;
	  grub_device_map[grub_last_hd].matches++;
	  grub_device_map[grub_last_hd].type = GRUB_DISK_TYPE_HD;
	  snprintf (grub_device_map[grub_last_hd].file_name,
		   MAXPATHLEN, "/dev/%s", dev);
	}
    }

fclose (partitions);
return ndisks;
}

/* 4.) Floppies don't have partitions.UGet number of floppies
from /proc/devices */

int
linux_get_fds ()
{
int ndisks = 0;
FILE *devices;
char dev[MAXPATHLEN];

  devices = fopen ("/proc/devices", "r");
  if (devices == NULL)
    {
      grub_util_info ("/proc/devices: %s", strerror (errno));
      return -1;
    }

  while (fscanf (devices, "%s%s\n", dev, dev) != EOF)
    {
      if (strcmp (dev, "fd") == 0)
        {
          grub_device_map[ndisks].matches++;
          grub_device_map[ndisks].type = GRUB_DISK_TYPE_HD;
          snprintf (grub_device_map[ndisks].file_name,
                   MAXPATHLEN, "/dev/fd%i", ndisks);
          ndisks++;
        }
    }

fclose (devices);
return ndisks;
}

#endif /* __linux__ */

/* Calls OS/machine dependent routines to construct the map, ordered by
result accuracy. */

void
get_map ()
{

#if defined (BSD)

# if defined (__NetBSD__)

if (netbsd_get_diskinfo () > 0)

	    MAXPATHLEN, {
      char *disktypes[] =
	{
	  "fd", /* floppy */
	  0
	};
      bsd_get_disknames (disktypes);
    }
  else
    {
      char *disktypes[] =
	{
	  "fd", /* floppy */
	  "wd", /* IDE */
	  "sd", /* SCSI */
	  0
	};
      bsd_get_disknames (disktypes);
    }
# elif defined (__OpenBSD__)

if (openbsd_get_diskinfo () == 0)

    {
      char *disktypes[] =
	{
	  "fd", /* floppy */
	  "wd", /* IDE */
	  "sd", /* SCSI */
	  0
	};
      bsd_get_disknames (disktypes);
    }

# else /* !__NetBSD__ && !__OpenBSD__ */

  {
    char *disktypes[] =
      {
	"fd", /* floppy */
	"ad", /* IDE */
	"da", /* IDE */
	"sd", /* SCSI */
	0
      };
      bsd_get_disknames (disktypes);

}

# warning "This BSD variant is not supported yet"

# endif
#elif defined (__linux__)
  linux_get_hds ();
  linux_get_fds ();

#else

# error "This OS is not supported"
#endif

}

/* Outputs the map constructed by get_map() to a device map file. */

void
dump_map (struct arguments *args)
{
FILE *output;
int i;

if (strcmp (args->device_map, "-") == 0)

    {
      output = stdout;
    }
  else
    {
      output = fopen (args->device_map, "w");
      if (output == NULL)
	{
	  grub_util_error ("unable to open %s: %s",
			   args->device_map, strerror (errno));
	}
    }

for (i = 0; i < BIOS_DISKS; i++)

    {
      if (grub_device_map[i].type)
	{
	  fprintf (output, "(%s%i)\t%s\n",
		   grub_device_map[i].type == GRUB_DISK_TYPE_HD ? "hd" :
		   grub_device_map[i].type == GRUB_DISK_TYPE_FD ? "fd" :
		   "???",
		   i < BIOS_HD ? i : i - BIOS_HD,
		   grub_device_map[i].file_name);
	}

}
}

static error_t
parse_opt (int key, char *arg, struct argp_state *state) {
struct arguments *args = state->input;

switch (key)

    {
    case 'm':
      args->device_map = arg;
      break;
    case 'v':
      verbosity++;
      break;
    default:
      return ARGP_ERR_UNKNOWN;
    }

return 0;
}

static struct argp argp = {options, parse_opt, NULL, doc, 0, 0, 0};

int
main (int argc, char *argv[])
{
struct arguments args =

    {
      .device_map = DEFAULT_DEVICE_MAP,
    };
  progname = PROGNAME;
  argp_parse (&argp, argc, argv, 0, 0, &args);

  get_map ();
  dump_map (&args);

return 0;
}

#3 lore raw
In reply to Yoshinori K. Okuji
Quoted 10 lines · Lubomir Kundrak
Quoted 5 lines

I am currently working on BSD port of GRUB, so I first need the basic utilities to work. I decided to rewrite grub-mkdevicemap, because the old version was hard to modify, and actually didn't use all the information provided by the kernel.

I don't know why you thought it is difficult to modify. grub-mkdevicemap.c is
based on lib/device.c in GRUB Legacy, which works well with *BSD.

Current version doesn't due to a subtle bug. But anyways, when we can get a list of disks, even with BIOS numbers in some cases, from kernel, why don't we? Current version doesn't try to do any guess, and open()s every disk to ensure that it exists, which is unnecessary, slow, and can even lead to crashes in case of faulty/strange hardware. (see the workaround for floppy).

Quoted 5 lines
Quoted 2 lines

Changelog entry and uuencoded source file is bellow

I could not record it correctly. Can you attach it as a plain text?

Mea culpa. I probably need lectures about sending mails :) You can either patch the faulty file resultng from attempt to uudecode the file with the patch below, or i attach the whole file with this message.

291c291,292
< grub_device_map[devnom_FD
---

Quoted 6 lines

grub_device_map[devno].type = devno < BIOS_HD
? GRUB_DISK_TYPE_FD

Thanks,
Okuji

Have a nice day!
Lubo

Quoted 6 lines

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

---------------------------------------------------------------------------
o Lubomir Kundrak
°O° <[email protected]>, http://skosi.org/~lkundrak/
(_) SKOSI -- Slovak OpenSource Initiative
---------------------------------------------------------------------------

#4 lore raw
Quoted 1 line · Lubomir Kundrak

Current version doesn't due to a subtle bug.

Then, please fix the subtle bug. Why can't we make incremental development? I don't like to rewrite everything every time someone finds a bug.

Quoted 3 lines

But anyways, when we can
get a list of disks, even with BIOS numbers in some cases, from kernel, why don't we?

Because it was not supported when GRUB Legacy was developed.

Quoted 4 lines

Current version doesn't try to do any guess, and open()s every disk to ensure that it exists, which is unnecessary, slow, and can even lead to crashes in case of faulty/strange hardware. (see the workaround for floppy).

I don't object to adding such support. But please keep it in mind that we should support old kernels as well.

Okuji