2 common.h - Common data structures and functions.
4 Copyright 1992-1998 Werner Almesberger.
5 Copyright 1999-2005 John Coffman.
8 Licensed under the terms contained in the file 'COPYING' in the
19 #include <asm/types.h>
25 # define PAGE_SIZE 4096U
29 # define O_NOACCESS O_ACCMODE
31 /* open a file for "no access" */
35 /* special for LILO, bypass the actual open in dev_open( , ,-1) */
46 ;*/typedef struct { /*
48 ;*/ unsigned char sector,track; /* CX
51 ;*/ unsigned char device,head; /* DX
54 ;*/ unsigned char num_sect; /* AL
63 ;*/typedef struct { /*
65 ;*/ char name[MAX_IMAGE_NAME+1]; /* image name, NUL terminated
66 id_name: .blkb MAX_IMAGE_NAME_asm+1
67 ;*/ unsigned short password_crc[MAX_PW_CRC*(sizeof(INT4)/sizeof(short))]; /* 4 password CRC-32 values
68 id_password_crc:.blkb MAX_PW_CRC_asm*4
69 ;*/ unsigned short rd_size[2]; /* RAM disk size in sectors, 0 if none
70 id_rd_size: .blkb 4 ;don't change the order !!!
71 ;*/ SECTOR_ADDR initrd,start; /* start of initrd & kernel
72 id_initrd: .blkb sa_size ; **
73 id_start: .blkb sa_size ; **
74 ;*/ unsigned short flags,vga_mode; /* image flags & video mode
75 id_flags: .blkb 2 ; **
76 id_vga_mode: .blkb 2 ; **
83 ;*/typedef struct { /*
85 ;*/ unsigned char bytes_per_sector[2]; /*
86 bpb_bytes_per_sector: .blkb 2
87 ;*/ unsigned char sectors_per_cluster; /*
88 bpb_sectors_per_cluster:.blkb 1
89 ;*/ unsigned char reserved_sectors[2]; /*
91 ;*/ unsigned char number_of_FATs; /*
93 ;*/ unsigned char root_dir_entries[2]; /*
95 ;*/ unsigned char total_sectors[2]; /*
97 ;*/ unsigned char media_descriptor; /*
99 ;*/ unsigned char sectors_per_FAT[2]; /*
101 ;*/ unsigned char sectors_per_track[2]; /* DOS v.3
103 ;*/ unsigned char heads_per_cylinder[2]; /* DOS v.3
105 ;*/ unsigned char hidden_sectors[4]; /*
107 ;*/ unsigned char total_sectors_long[4]; /* if total_sectors==0
109 ;*/ unsigned char reserved[7]; /* pad to 32 bytes
111 ;*/} BIOS_PARAMETER_BLOCK; /*
117 ;*/typedef struct { /*
119 ;*/ unsigned char jump[3]; /* jump to boot code
121 ;*/ char system[8]; /* system ID
122 bpdos_system: .blkb 8
123 ;*/ BIOS_PARAMETER_BLOCK bpb; /* BIOS parameter block
124 bpdos_bpb: .blkb bpb_size
125 ;*/} BOOT_PARAMS_DOS; /* DOS fat header
131 ;*/typedef struct { /*
133 ;*/ unsigned char cli; /* clear interrupt flag instruction
135 ;*/ unsigned char jmp0, jmp1; /* short jump
137 ;*/ unsigned char stage; /*
139 ;*/ unsigned short code_length; /* length of the first stage code
140 par1_code_len: .blkb 2
141 ;*/ char signature[4]; /* "LILO"
142 par1_signature: .blkb 4
143 ;*/ unsigned short version; /*
144 par1_version: .blkb 2
145 ;*/ unsigned int map_stamp; /* timestamp for this installation (map creation)
146 par1_mapstamp: .blkb 4
147 ;*/ unsigned int raid_offset; /* raid partition/partition offset
148 par1_raid_offset: .blkb 4
149 ;*/ unsigned int timestamp; /* timestamp for restoration
150 par1_timestamp: .blkb 4
151 ;*/ unsigned int map_serial_no; /* volume serial no. / id containing the map file
152 par1_map_serial_no: .blkb 4
153 ;*/ unsigned short prompt; /* FLAG_PROMPT=always, FLAG_RAID install
155 ;*/ SECTOR_ADDR secondary; /* sectors of the second stage loader
156 par1_secondary: .blkb sa_size+1
157 ;*/} BOOT_PARAMS_1; /* first stage boot loader
164 ;*/typedef struct { /* second stage parameters
166 ;*/ char jump[6]; /* jump over the data
168 ;*/ char signature[4]; /* "LILO"
169 par2_signature: .blkb 4
170 ;*/ unsigned short version; /*
171 par2_version: .blkb 2
172 ;*/ unsigned int map_stamp; /* time of creation of the map file
173 par2_mapstamp: .blkb 4
174 ;*/ unsigned short stage; /*
176 ;*/ unsigned char port; /* COM port. 0 = none, 1 = COM1, etc. !!! keep these two serial bytes together !!!
177 ;*/ unsigned char ser_param; /* RS-232 parameters, must be 0 if unused
178 par2_port: .blkb 1 ; referenced together
179 par2_ser_param: .blkb 1 ; **
180 ;*/ unsigned short timeout; /* 54 msec delay until input time-out, 0xffff: never
181 par2_timeout: .blkb 2
182 ;*/ unsigned short delay; /* delay: wait that many 54 msec units.
184 ;*/ unsigned short msg_len; /* 0 if none
185 par2_msg_len: .blkb 2
186 ;*/ SECTOR_ADDR keytab; /* keyboard translation table
187 par2_keytab: .blkb sa_size
188 ;*/ unsigned char flag2; /* flags specific to the second stage loader
190 ;*/} BOOT_PARAMS_2; /* second stage boot loader
198 ;*/typedef struct { /*
200 ;*/ char jump[6]; /* jump over the data
202 ;*/ char signature[4]; /* "LILO"
203 parC_signature: .blkb 4
204 ;*/ unsigned short stage,version; /* stage is 0x10
206 parC_version: .blkb 2
207 ;*/ unsigned short offset; /* partition entry offset
209 ;*/ unsigned char drive; /* BIOS drive code
211 ;*/ unsigned char head; /* head; always 0
213 ;*/ unsigned short drvmap; /* offset of drive map
215 ;*/ unsigned char ptable[PARTITION_ENTRY*PARTITION_ENTRIES]; /* part. table
216 parC_ptable: .blkb 64
217 ;*/ unsigned short p_devmap[2]; /* pointer to device map filled in by second.S
219 ;*/} BOOT_PARAMS_C; /* chain loader
225 ;*/typedef struct { /*
227 ;*/ char menu_sig[4]; /* "MENU" or "BMP4" signature, or NULs if not present
229 ;*/ unsigned char at_text; /* attribute for normal menu text
231 ;*/ unsigned char at_highlight; /* attribute for highlighted text
232 mt_at_hilite: .blkb 1
233 ;*/ unsigned char at_border; /* attribute for borders
234 mt_at_border: .blkb 1
235 ;*/ unsigned char at_title; /* attribute for title
237 ;*/ unsigned char len_title; /* length of the title string
238 mt_len_title: .blkb 1
239 ;*/ char title[MAX_MENU_TITLE+2]; /* MENU title to override default
240 mt_title: .blkb MAX_MENU_TITLE_asm+2
241 ;*/ short row, col, ncol; /* BMP row, col, and ncols
245 ;*/ short maxcol, xpitch; /* BMP max per col, xpitch between cols
248 ;*/ short fg, bg, sh; /* BMP normal text fore, backgr, shadow
252 ;*/ short h_fg, h_bg, h_sh; /* highlight fg, bg, & shadow
256 ;*/ short t_fg, t_bg, t_sh; /* timer fg, bg, & shadow colors
260 ;*/ short t_row, t_col; /* timer position
263 ;*/ short mincol, reserved[3]; /* BMP min per col before spill to next, reserved spacer
267 ;*/ unsigned int serial_no[MAX_BIOS_DEVICES]; /* Known device serial nos. 0x80 .. 0x8F
268 mt_serial_no: .blkw MAX_BIOS_DEVICES_asm*2
269 ;*/ unsigned int raid_offset[MAX_RAID_DEVICES]; /* RAID offsets for flagged devices
270 mt_raid_offset: .blkw MAX_RAID_DEVICES_asm*2
271 ;*/ unsigned short raid_dev_mask; /* 16 bit raid device mask flagging items in serial_no
272 mt_raid_dev_mask: .blkw 1
273 ;*/ SECTOR_ADDR msg; /* initial greeting message
274 mt_msg: .blkb sa_size
275 ;*/ SECTOR_ADDR dflcmd; /* default command line
276 mt_dflcmd: .blkb sa_size
277 ;*/ SECTOR_ADDR mt_descr[MAX_DESCR_SECS]; /* descriptor disk addresses
278 mt_descr: .blkb sa_size*MAX_DESCR_SECS_asm
279 ;*/ char unused[150-MAX_BIOS_DEVICES*sizeof(int)-(MAX_RAID_DEVICES)*sizeof(int)-MAX_DESCR_SECS*sizeof(SECTOR_ADDR)]; /* spacer
280 mt_unused: .blkb 150-sa_size*MAX_DESCR_SECS_asm-4*MAX_BIOS_DEVICES_asm-4*MAX_RAID_DEVICES_asm
281 ;*/ short checksum[2]; /* checksum longword
283 ;*/ unsigned char mt_flag; /* contains the FLAG_NOBD only
285 ;*/ char unused2; /* spacer beyond checksum
287 ;*/} MENUTABLE; /* MENU and BITMAP parameters at KEYTABLE+256
296 unsigned char bootcode[MAX_BOOT_SIZE];
297 unsigned short mbz; /* must be zero */
299 unsigned short marker; /* may be zero */
300 unsigned char part[PART_TABLE_SIZE];
301 unsigned short boot_ind; /* 0xAA55 */
308 BOOT_PARAMS_DOS par_d;
310 unsigned char sector[SECTOR_SIZE];
315 IMAGE_DESCR descr[MAX_IMAGES]; /* boot file descriptors */
317 unsigned char sector[SECTOR_SIZE*MAX_DESCR_SECS];
319 unsigned int sector[SECTOR_SIZE/4*MAX_DESCR_SECS - 1];
320 unsigned int checksum;
326 unsigned char data[1];
333 unsigned char device, flags;
342 IMAGES_numerator = SECTOR_SIZE_asm*MAX_DESCR_SECS_asm - 4 - 1
343 IMAGES = IMAGES_numerator / id_size
347 unsigned short jump; /* 0: jump to startup code */
348 char signature[4]; /* 2: "HdrS" */
349 unsigned short version; /* 6: header version */
350 unsigned short x,y,z; /* 8: LOADLIN hacks */
351 unsigned short ver_offset; /* 14: kernel version string */
352 unsigned char loader; /* 16: loader type */
353 unsigned char flags; /* 17: loader flags */
354 unsigned short a; /* 18: more LOADLIN hacks */
355 unsigned int start; /* 20: kernel start, filled in by loader */
356 unsigned int ramdisk; /* 24: RAM disk start address */
357 unsigned int ramdisk_size; /* 28: RAM disk size */
358 unsigned short b,c; /* 32: bzImage hacks */
359 unsigned short heap_end_ptr;/* 36: 2.01 end of free area after setup code */
360 unsigned char d; /* 38: padding */
361 unsigned int cmd_line_ptr; /* 40: 2.02 address32 of command line */
362 unsigned int ramdisk_max; /* 44: 2.03 address32 of highest mem. for ramdisk */
365 #define alloc_t(t) ((t *) alloc(sizeof(t)))
367 typedef enum {X_NULL=0, X_NONE, X_AUTO, X_MBR_ONLY, X_MBR, X_SPEC} LILO_EXTRA;
368 typedef enum {AD_ANY=0, AD_GEOMETRIC, AD_LINEAR, AD_LBA32=4} ADDR_MODE;
369 typedef enum {DL_NOT_SET=0, DL_BAD=1, DL_UNKNOWN, DL_MAYBE, DL_GOOD} DL_BIOS;
371 extern LILO_EXTRA extra;
372 extern char *identify;
373 extern int verbose,test,compact,linear,nowarn,lba32,autoauto,passw,geometric;
374 extern int bios_boot, bios_map;
375 extern int ireloc, force_fs, force_raid, extended_pt, query;
376 extern int colormax, warnings;
377 extern DL_BIOS bios_passes_dl;
378 extern int boot_dev_nr,raid_index,raid_flags,do_md_install,ndisk,zflag,eflag;
379 extern unsigned short drv_map[DRVMAP_SIZE+1]; /* needed for fixup maps */
380 extern int curr_drv_map;
381 extern unsigned int prt_map[PRTMAP_SIZE+1];
382 extern int curr_prt_map, config_read;
383 extern unsigned int serial_no[MAX_BIOS_DEVICES];
384 extern char *config_file;
387 extern char *identify; /* in identify.c */
388 extern int dm_major_list[16];
389 extern int dm_major_nr;
391 #define crc(a,b) (~crc32((a),(b),CRC_POLY1))
393 { register unsigned short u1,u2; register unsigned int u=(x); u1=u; u2=u>>16; \
394 u1=(u1>>8)|(u1<<8); u2=(u2>>8)|(u2<<8); x=(unsigned int)u1<<16|u2; }
395 #define cc(x) crc(x.data,x.size)
396 #define comma (cc(First)|cc(Second)|cc(Third)|cc(Bitmap)|cc(Chain)|cc(Mbr)|cc(Mbr2))
399 /*volatile*/ void pdie(char *msg);
400 /* Do a perror and then exit. */
403 /*volatile*/ void die(char *fmt,...);
404 /* fprintf an error message and then exit. */
407 /*volatile*/ void warn(char *fmt,...);
408 /* issue a warning message if !nowarn */
411 void *alloc(int size);
412 /* Allocates the specified number of bytes. Dies on error. */
415 void *ralloc(void *old,int size);
416 /* Changes the size of an allocated memory area. Dies on error. */
419 char *stralloc(const char *str);
420 /* Like strdup, but dies on error. */
423 int to_number(char *num);
424 /* Converts a string to a number. Dies if the number is invalid. */
427 int timer_number(char *num);
428 /* Converts a string to a number. Allows suffix of 't', 's', 'm', 'h'
429 for Tenths, Seconds, Minutes, Hours. Dies if number is invalid for
430 "timeout" or "delay" */
433 void check_version(BOOT_SECTOR *sect, int stage);
434 /* Verify that a boot sector has the correct version number. */
437 int stat_equal(struct stat *a, struct stat *b);
438 /* Compares two stat structures. Returns a non-zero integer if they describe
439 the same file, zero if they don't. */
443 unsigned int crc32partial(unsigned char *cp, int nsize,
444 unsigned int polynomial, unsigned int *accum);
445 /* accumulate a partial CRC-32 */
449 unsigned int crc32 (unsigned char *cp, int nsize, unsigned int polynomial);
450 /* calculate a CRC-32 polynomial */
453 void show_link(char *name);
454 /* show what a link resolves to */