1995-04-29 03:55:25 +02:00
|
|
|
/*
|
1996-03-24 19:55:39 +01:00
|
|
|
* ----------------------------------------------------------------------------
|
|
|
|
* "THE BEER-WARE LICENSE" (Revision 42):
|
|
|
|
* <phk@login.dknet.dk> wrote this file. As long as you retain this notice you
|
|
|
|
* can do whatever you want with this stuff. If we meet some day, and you think
|
|
|
|
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
|
|
|
* ----------------------------------------------------------------------------
|
|
|
|
*
|
1996-04-29 08:45:33 +02:00
|
|
|
* $Id: libdisk.h,v 1.21 1996/03/24 18:55:39 joerg Exp $
|
1996-03-24 19:55:39 +01:00
|
|
|
*
|
|
|
|
*/
|
1995-04-29 01:57:04 +02:00
|
|
|
|
1995-04-29 06:50:39 +02:00
|
|
|
#define MAX_NO_DISKS 20
|
1996-03-24 19:55:39 +01:00
|
|
|
/* Max # of disks Disk_Names() will return */
|
1995-04-29 06:50:39 +02:00
|
|
|
|
1995-05-06 05:28:32 +02:00
|
|
|
typedef enum {
|
|
|
|
whole,
|
|
|
|
unknown,
|
|
|
|
fat,
|
|
|
|
freebsd,
|
|
|
|
extended,
|
|
|
|
part,
|
|
|
|
unused,
|
1996-03-24 19:55:39 +01:00
|
|
|
} chunk_e;
|
1995-04-29 01:57:04 +02:00
|
|
|
|
1996-03-24 19:55:39 +01:00
|
|
|
__BEGIN_DECLS
|
1995-04-29 01:57:04 +02:00
|
|
|
struct disk {
|
|
|
|
char *name;
|
|
|
|
u_long flags;
|
1995-04-29 03:55:25 +02:00
|
|
|
# define DISK_ON_TRACK 1
|
1995-06-11 21:33:05 +02:00
|
|
|
#if 0
|
1995-04-29 01:57:04 +02:00
|
|
|
u_long real_cyl;
|
|
|
|
u_long real_hd;
|
|
|
|
u_long real_sect;
|
1995-06-11 21:33:05 +02:00
|
|
|
#endif
|
1995-04-29 01:57:04 +02:00
|
|
|
u_long bios_cyl;
|
|
|
|
u_long bios_hd;
|
|
|
|
u_long bios_sect;
|
1995-04-29 06:50:39 +02:00
|
|
|
u_char *bootmgr;
|
|
|
|
u_char *boot1;
|
|
|
|
u_char *boot2;
|
1995-04-29 01:57:04 +02:00
|
|
|
struct chunk *chunks;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct chunk {
|
|
|
|
struct chunk *next;
|
|
|
|
struct chunk *part;
|
1995-05-25 08:14:49 +02:00
|
|
|
struct disk *disk;
|
1995-05-08 04:08:33 +02:00
|
|
|
long offset;
|
1995-04-29 01:57:04 +02:00
|
|
|
u_long size;
|
|
|
|
u_long end;
|
|
|
|
char *name;
|
1995-05-04 00:36:52 +02:00
|
|
|
char *oname;
|
1996-03-24 19:55:39 +01:00
|
|
|
/* Used during Fixup_Names() to avoid renaming more than
|
|
|
|
* absolutely needed.
|
|
|
|
*/
|
1995-04-29 01:57:04 +02:00
|
|
|
chunk_e type;
|
|
|
|
int subtype;
|
|
|
|
u_long flags;
|
1995-04-29 03:55:25 +02:00
|
|
|
# define CHUNK_PAST_1024 1
|
1996-03-24 19:55:39 +01:00
|
|
|
/* this chunk cannot be booted from because it
|
|
|
|
* extends past cylinder 1024
|
|
|
|
*/
|
1995-04-29 03:55:25 +02:00
|
|
|
# define CHUNK_BSD_COMPAT 2
|
1996-03-24 19:55:39 +01:00
|
|
|
/* this chunk is in the BSD-compatibility, and has a
|
|
|
|
* short name too, ie wd0s4f -> wd0f
|
|
|
|
*/
|
1995-04-29 03:55:25 +02:00
|
|
|
# define CHUNK_BAD144 4
|
1996-03-24 19:55:39 +01:00
|
|
|
/* this chunk has bad144 mapping */
|
1995-04-29 03:55:25 +02:00
|
|
|
# define CHUNK_ALIGN 8
|
1996-03-24 19:55:39 +01:00
|
|
|
/* This chunk should be aligned */
|
1995-05-03 08:30:59 +02:00
|
|
|
# define CHUNK_IS_ROOT 16
|
1996-03-24 19:55:39 +01:00
|
|
|
/* This 'part' is a rootfs, allocate 'a' */
|
1995-05-04 09:00:57 +02:00
|
|
|
# define CHUNK_ACTIVE 32
|
1996-03-24 19:55:39 +01:00
|
|
|
/* This is the active slice in the MBR */
|
1995-12-07 11:34:59 +01:00
|
|
|
# define CHUNK_FORCE_ALL 64
|
1996-03-24 19:55:39 +01:00
|
|
|
/* Force a dedicated disk for FreeBSD, bypassing
|
|
|
|
* all BIOS geometry considerations
|
|
|
|
*/
|
1995-05-04 00:36:52 +02:00
|
|
|
|
|
|
|
void (*private_free)(void*);
|
|
|
|
void *(*private_clone)(void*);
|
1996-03-24 19:55:39 +01:00
|
|
|
void *private_data;
|
|
|
|
/* For data private to the application, and the management
|
|
|
|
* thereof. If the functions are not provided, no storage
|
|
|
|
* management is done, Cloning will just copy the pointer
|
|
|
|
* and freeing will just forget it.
|
|
|
|
*/
|
1995-04-29 01:57:04 +02:00
|
|
|
};
|
|
|
|
|
1996-03-24 19:55:39 +01:00
|
|
|
extern const char *chunk_n[];
|
1996-04-29 08:45:33 +02:00
|
|
|
extern const u_char boot1[], boot2[];
|
1996-03-24 19:55:39 +01:00
|
|
|
|
1995-04-29 03:55:25 +02:00
|
|
|
struct disk *
|
1996-03-24 19:55:39 +01:00
|
|
|
Open_Disk(const char *devname);
|
|
|
|
/* Will open the named disk, and return populated tree.
|
|
|
|
*/
|
1995-04-29 03:55:25 +02:00
|
|
|
|
|
|
|
struct disk *
|
|
|
|
Clone_Disk(struct disk *disk);
|
1996-03-24 19:55:39 +01:00
|
|
|
/* Clone a copy of a tree. Useful for "Undo" functionality
|
|
|
|
*/
|
1995-04-29 03:55:25 +02:00
|
|
|
|
1995-05-30 10:29:07 +02:00
|
|
|
void
|
1995-04-29 03:55:25 +02:00
|
|
|
Free_Disk(struct disk *disk);
|
1996-03-24 19:55:39 +01:00
|
|
|
/* Free a tree made with Open_Disk() or Clone_Disk()
|
|
|
|
*/
|
1995-04-29 03:55:25 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
Debug_Disk(struct disk *disk);
|
1996-03-24 19:55:39 +01:00
|
|
|
/* Print the content of the tree to stdout
|
|
|
|
*/
|
1995-04-29 03:55:25 +02:00
|
|
|
|
1995-06-11 21:33:05 +02:00
|
|
|
#if 0
|
1995-04-29 03:55:25 +02:00
|
|
|
struct disk *
|
|
|
|
Set_Phys_Geom(struct disk *disk, u_long cyl, u_long heads, u_long sects);
|
1996-03-24 19:55:39 +01:00
|
|
|
/* Use a different physical geometry. Makes sense for ST506 disks only.
|
|
|
|
* The tree returned is read from the disk, using this geometry.
|
|
|
|
*/
|
1995-06-11 21:33:05 +02:00
|
|
|
#endif
|
1995-04-29 03:55:25 +02:00
|
|
|
|
1995-05-30 10:29:07 +02:00
|
|
|
void
|
1995-04-29 03:55:25 +02:00
|
|
|
Set_Bios_Geom(struct disk *disk, u_long cyl, u_long heads, u_long sects);
|
1996-03-24 19:55:39 +01:00
|
|
|
/* Set the geometry the bios uses.
|
|
|
|
*/
|
1995-04-29 03:55:25 +02:00
|
|
|
|
1995-05-30 10:29:07 +02:00
|
|
|
int
|
1995-04-29 03:55:25 +02:00
|
|
|
Delete_Chunk(struct disk *disk, struct chunk *);
|
1996-03-24 19:55:39 +01:00
|
|
|
/* Free a chunk of disk_space
|
|
|
|
*/
|
1995-04-29 01:57:04 +02:00
|
|
|
|
1995-04-29 03:55:25 +02:00
|
|
|
void
|
|
|
|
Collapse_Disk(struct disk *disk);
|
1996-03-24 19:55:39 +01:00
|
|
|
/* Experimental, do not use.
|
|
|
|
*/
|
1995-04-29 03:55:25 +02:00
|
|
|
int
|
|
|
|
Collapse_Chunk(struct disk *disk, struct chunk *chunk);
|
1996-03-24 19:55:39 +01:00
|
|
|
/* Experimental, do not use.
|
|
|
|
*/
|
1995-04-29 01:57:04 +02:00
|
|
|
|
1995-05-30 10:29:07 +02:00
|
|
|
int
|
1996-03-24 19:55:39 +01:00
|
|
|
Create_Chunk(struct disk *disk, u_long offset, u_long size, chunk_e type,
|
|
|
|
int subtype, u_long flags);
|
|
|
|
/* Create a chunk with the specified paramters
|
|
|
|
*/
|
1995-04-29 01:57:04 +02:00
|
|
|
|
1995-04-29 06:00:57 +02:00
|
|
|
void
|
1995-12-07 11:34:59 +01:00
|
|
|
All_FreeBSD(struct disk *d, int force_all);
|
1996-03-24 19:55:39 +01:00
|
|
|
/* Make one FreeBSD chunk covering the entire disk;
|
|
|
|
* if force_all is set, bypass all BIOS geometry
|
|
|
|
* considerations.
|
|
|
|
*/
|
1995-04-29 06:00:57 +02:00
|
|
|
|
1995-05-30 10:29:07 +02:00
|
|
|
char *
|
1995-04-29 03:55:25 +02:00
|
|
|
CheckRules(struct disk *);
|
1996-03-24 19:55:39 +01:00
|
|
|
/* Return char* to warnings about broken design rules in this disklayout
|
|
|
|
*/
|
1995-04-29 01:57:04 +02:00
|
|
|
|
1995-04-29 06:50:39 +02:00
|
|
|
char **
|
|
|
|
Disk_Names();
|
1996-03-24 19:55:39 +01:00
|
|
|
/* Return char** with all disk's names (wd0, wd1 ...). You must free
|
|
|
|
* each pointer, as well as the array by hand
|
|
|
|
*/
|
1995-04-29 06:50:39 +02:00
|
|
|
|
|
|
|
void
|
1996-03-24 19:55:39 +01:00
|
|
|
Set_Boot_Mgr(struct disk *d, const u_char *bootmgr);
|
|
|
|
/* Use this boot-manager on this disk. Gets written when Write_Disk()
|
|
|
|
* is called
|
|
|
|
*/
|
1995-04-29 06:50:39 +02:00
|
|
|
|
|
|
|
void
|
1996-03-24 19:55:39 +01:00
|
|
|
Set_Boot_Blocks(struct disk *d, const u_char *boot1, const u_char *boot2);
|
|
|
|
/* Use these boot-blocks on this disk. Gets written when Write_Disk()
|
|
|
|
* is called
|
|
|
|
*/
|
1995-04-29 06:50:39 +02:00
|
|
|
|
1995-04-29 09:21:14 +02:00
|
|
|
int
|
|
|
|
Write_Disk(struct disk *d);
|
1996-03-24 19:55:39 +01:00
|
|
|
/* Write all the MBRs, disklabels, bootblocks and boot managers
|
|
|
|
*/
|
1995-04-29 09:21:14 +02:00
|
|
|
|
1995-04-30 08:09:29 +02:00
|
|
|
int
|
|
|
|
Cyl_Aligned(struct disk *d, u_long offset);
|
1996-03-24 19:55:39 +01:00
|
|
|
/* Check if offset is aligned on a cylinder according to the
|
|
|
|
* bios geometry
|
|
|
|
*/
|
1995-04-30 08:09:29 +02:00
|
|
|
|
|
|
|
u_long
|
|
|
|
Next_Cyl_Aligned(struct disk *d, u_long offset);
|
1996-03-24 19:55:39 +01:00
|
|
|
/* Round offset up to next cylinder according to the bios-geometry
|
|
|
|
*/
|
1995-04-30 08:09:29 +02:00
|
|
|
|
|
|
|
u_long
|
|
|
|
Prev_Cyl_Aligned(struct disk *d, u_long offset);
|
1996-03-24 19:55:39 +01:00
|
|
|
/* Round offset down to previous cylinder according to the bios-
|
|
|
|
* geometry
|
|
|
|
*/
|
1995-04-30 08:09:29 +02:00
|
|
|
|
|
|
|
int
|
|
|
|
Track_Aligned(struct disk *d, u_long offset);
|
1996-03-24 19:55:39 +01:00
|
|
|
/* Check if offset is aligned on a track according to the
|
|
|
|
* bios geometry
|
|
|
|
*/
|
1995-04-30 08:09:29 +02:00
|
|
|
|
|
|
|
u_long
|
|
|
|
Next_Track_Aligned(struct disk *d, u_long offset);
|
1996-03-24 19:55:39 +01:00
|
|
|
/* Round offset up to next track according to the bios-geometry
|
|
|
|
*/
|
1995-04-30 08:09:29 +02:00
|
|
|
|
|
|
|
u_long
|
|
|
|
Prev_Track_Aligned(struct disk *d, u_long offset);
|
1996-03-24 19:55:39 +01:00
|
|
|
/* Check if offset is aligned on a track according to the
|
|
|
|
* bios geometry
|
|
|
|
*/
|
1995-04-30 08:09:29 +02:00
|
|
|
|
1995-05-10 07:57:04 +02:00
|
|
|
struct chunk *
|
1996-03-24 19:55:39 +01:00
|
|
|
Create_Chunk_DWIM(struct disk *d, struct chunk *parent , u_long size,
|
|
|
|
chunk_e type, int subtype, u_long flags);
|
|
|
|
/* This one creates a partition inside the given parent of the given
|
|
|
|
* size, and returns a pointer to it. The first unused chunk big
|
|
|
|
* enough is used.
|
|
|
|
*/
|
1995-05-10 07:57:04 +02:00
|
|
|
|
1995-12-07 11:34:59 +01:00
|
|
|
int
|
1996-03-24 19:55:39 +01:00
|
|
|
MakeDev(struct chunk *c, const char *path);
|
1995-12-07 11:34:59 +01:00
|
|
|
|
|
|
|
int
|
1996-03-24 19:55:39 +01:00
|
|
|
MakeDevDisk(struct disk *d, const char *path);
|
|
|
|
/* Make device nodes for all chunks on this disk */
|
1995-05-12 20:50:00 +02:00
|
|
|
|
1995-06-11 21:33:05 +02:00
|
|
|
char *
|
|
|
|
ShowChunkFlags(struct chunk *c);
|
1996-03-24 19:55:39 +01:00
|
|
|
/* Return string to show flags. */
|
1995-06-11 21:33:05 +02:00
|
|
|
|
|
|
|
char *
|
|
|
|
ChunkCanBeRoot(struct chunk *c);
|
1996-03-24 19:55:39 +01:00
|
|
|
/* Return NULL if chunk can be /, explanation otherwise */
|
1995-06-11 21:33:05 +02:00
|
|
|
|
1995-05-30 10:29:07 +02:00
|
|
|
/*
|
1995-04-29 03:55:25 +02:00
|
|
|
* Implementation details >>> DO NOT USE <<<
|
|
|
|
*/
|
1995-04-29 01:57:04 +02:00
|
|
|
|
|
|
|
void Debug_Chunk(struct chunk *);
|
|
|
|
void Free_Chunk(struct chunk *);
|
|
|
|
struct chunk * Clone_Chunk(struct chunk *);
|
1996-03-24 19:55:39 +01:00
|
|
|
int Add_Chunk(struct disk *, long, u_long, const char *, chunk_e, int, u_long);
|
1995-04-29 01:57:04 +02:00
|
|
|
void Bios_Limit_Chunk(struct chunk *, u_long);
|
1996-03-24 19:55:39 +01:00
|
|
|
void * read_block(int, daddr_t);
|
1995-04-30 08:09:29 +02:00
|
|
|
void write_block(int fd, daddr_t block, void *foo);
|
1995-04-29 01:57:04 +02:00
|
|
|
struct disklabel * read_disklabel(int, daddr_t);
|
|
|
|
u_short dkcksum(struct disklabel *);
|
1996-03-24 19:55:39 +01:00
|
|
|
struct chunk * Find_Mother_Chunk(struct chunk *, u_long, u_long, chunk_e);
|
|
|
|
struct disk * Int_Open_Disk(const char *name, u_long size);
|
1995-04-30 13:04:16 +02:00
|
|
|
void Fixup_Names(struct disk *);
|
1996-03-24 19:55:39 +01:00
|
|
|
__END_DECLS
|
1995-04-29 01:57:04 +02:00
|
|
|
|
|
|
|
#define dprintf printf
|
1995-04-29 06:50:39 +02:00
|
|
|
|
|
|
|
/* TODO
|
|
|
|
*
|
|
|
|
* Need a error string mechanism from the functions instead of warn()
|
1995-05-30 10:29:07 +02:00
|
|
|
*
|
1995-04-29 06:50:39 +02:00
|
|
|
* Make sure only FreeBSD start at offset==0
|
1995-05-30 10:29:07 +02:00
|
|
|
*
|
1995-04-29 06:50:39 +02:00
|
|
|
* Collapse must align.
|
1995-05-30 10:29:07 +02:00
|
|
|
*
|
1995-04-29 06:50:39 +02:00
|
|
|
* Make Write_Disk(struct disk*)
|
1995-05-30 10:29:07 +02:00
|
|
|
*
|
1995-04-29 06:50:39 +02:00
|
|
|
* Consider booting from OnTrack'ed disks.
|
|
|
|
*
|
|
|
|
* Get Bios-geom, ST506 & OnTrack from driver (or otherwise)
|
|
|
|
*
|
|
|
|
* Make Create_DWIM().
|
|
|
|
*
|
1995-04-29 09:21:14 +02:00
|
|
|
* Make Is_Unchanged(struct disk *d1, struct chunk *c1)
|
1995-05-30 10:29:07 +02:00
|
|
|
*
|
1995-05-04 09:00:57 +02:00
|
|
|
* don't rename slices unless we have to
|
1995-04-29 06:50:39 +02:00
|
|
|
*
|
|
|
|
*Sample output from tst01:
|
|
|
|
*
|
|
|
|
* Debug_Disk(wd0) flags=0 real_geom=0/0/0 bios_geom=0/0/0
|
|
|
|
* >> 0x3d040 0 1411200 1411199 wd0 0 whole 0 0
|
|
|
|
* >>>> 0x3d080 0 960120 960119 wd0s1 3 freebsd 0 8
|
|
|
|
* >>>>>> 0x3d100 0 40960 40959 wd0s1a 5 part 0 0
|
|
|
|
* >>>>>> 0x3d180 40960 131072 172031 wd0s1b 5 part 0 0
|
|
|
|
* >>>>>> 0x3d1c0 172032 409600 581631 wd0s1e 5 part 0 0
|
|
|
|
* >>>>>> 0x3d200 581632 378488 960119 wd0s1f 5 part 0 0
|
|
|
|
* >>>> 0x3d140 960120 5670 965789 wd0s2 4 extended 0 8
|
1995-05-06 05:28:32 +02:00
|
|
|
* >>>>>> 0x3d2c0 960120 63 960182 - 6 unused 0 0
|
1995-04-29 06:50:39 +02:00
|
|
|
* >>>>>> 0x3d0c0 960183 5607 965789 wd0s5 2 fat 0 8
|
|
|
|
* >>>> 0x3d280 965790 1890 967679 wd0s3 1 foo -2 8
|
|
|
|
* >>>> 0x3d300 967680 443520 1411199 wd0s4 3 freebsd 0 8
|
|
|
|
* >>>>>> 0x3d340 967680 443520 1411199 wd0s4a 5 part 0 0
|
|
|
|
*
|
|
|
|
* ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
|
|
|
|
* level chunkptr start size end name type subtype flags
|
|
|
|
*
|
|
|
|
* Underlying data structure:
|
|
|
|
*
|
|
|
|
* Legend:
|
|
|
|
* <struct chunk> --> part
|
|
|
|
* |
|
|
|
|
* v next
|
|
|
|
*
|
|
|
|
* <wd0> --> <wd0s1> --> <wd0s1a>
|
|
|
|
* | |
|
|
|
|
* | v
|
|
|
|
* | <wd0s1b>
|
|
|
|
* | |
|
|
|
|
* | v
|
|
|
|
* | <wd0s1e>
|
|
|
|
* | |
|
|
|
|
* | v
|
|
|
|
* | <wd0s1f>
|
|
|
|
* |
|
|
|
|
* v
|
1995-05-06 05:28:32 +02:00
|
|
|
* <wd0s2> --> <unused>
|
1995-04-29 06:50:39 +02:00
|
|
|
* | |
|
|
|
|
* | v
|
|
|
|
* | <wd0s5>
|
|
|
|
* |
|
|
|
|
* v
|
1995-05-30 10:29:07 +02:00
|
|
|
* <wd0s3>
|
1995-04-29 06:50:39 +02:00
|
|
|
* |
|
|
|
|
* v
|
|
|
|
* <wd0s4> --> <wd0s4a>
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|