2 preplink.c - description
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your opinion) any later version.
14 #include <sys/types.h>
19 volatile int bswap(int num
)
21 int ret
= (((num
& 0x000000ff) << 24) |
22 ((num
& 0x0000ff00) << 8 ) |
23 ((num
& 0x00ff0000) >> 8 ) |
24 ((num
& 0xff000000) >> 24));
28 struct partition_entry
{
29 unsigned char boot_indicator
;
30 unsigned char starting_head
;
31 unsigned char starting_sector
;
32 unsigned char starting_cylinder
;
34 unsigned char system_indicator
;
35 unsigned char ending_head
;
36 unsigned char ending_sector
;
37 unsigned char ending_cylinder
;
39 unsigned long beginning_sector
;
40 unsigned long number_of_sectors
;
43 int main(int argc
, char *argv
[])
45 unsigned char buff
[512]={0,};
46 struct partition_entry
*pe
= (struct partition_entry
*)&buff
[0x1be];
47 unsigned long *entry
= (unsigned long*)&buff
[0];
48 unsigned long *length
= (unsigned long*)&buff
[sizeof(long)];
54 if (!strcmp(argv
[1],"-"))
58 else if ((in
=open(argv
[1], 0)) < 0)
63 if (!strcmp(argv
[2],"-"))
67 else if ((out
=creat(argv
[2], 0755)) < 0)
72 if (fstat(in
, &info
) < 0)
74 fprintf(stderr
, "info failed\n");
80 *length
= info
.st_size
+ 0x400;
81 pe
->number_of_sectors
= 2*18*80;
83 *entry
= bswap(0x400);
84 *length
= bswap(info
.st_size
+ 0x400);
85 pe
->number_of_sectors
= bswap(2*18*80);
91 pe
->boot_indicator
= 0x80;
92 pe
->system_indicator
= 0x41;
95 pe
->starting_head
= 0;
96 pe
->starting_sector
= 2;
97 pe
->starting_cylinder
= 2;
99 pe
->ending_sector
= 18;
100 pe
->ending_cylinder
= 79;
102 pe
->beginning_sector
= 0;
104 write(out
, buff
, sizeof(buff
));
105 write(out
, entry
, sizeof(*entry
));
106 write(out
, length
, sizeof(*length
));
107 lseek(out
, 0x400, SEEK_SET
);
109 while ((n
=read(in
, buff
, sizeof(buff
))) > 0)