Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 25 Jan 2004 23:09:11 -0500
From:      slick <plan_b@videotron.ca>
To:        hackers@freebsd.org, freebsd-geom@freebsd.org
Subject:   code compatibility between normal and geom methods for accessingdisk devices
Message-ID:  <BDENIKJMJKOAJAMDFLDDCECICAAA.plan_b@videotron.ca>

next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.

--Boundary_(ID_ogyvznEVLFV5eupSOhg9Sg)
Content-type: text/plain; charset=iso-8859-1
Content-transfer-encoding: 7BIT

Hi,
	I wrote an fdisk program which uses several read(2) and write(2).
	My program should compile on any unix that uses sane libc.
	If compile it will work, except on systems that use geom methods.
	I read that geom is accessed via struct BIO.
	I can write a version of my program using struct BIO.
	I'm sure it will compile and work.
	Now should I maintain different version my program?
	Or should I write a set of function for each method, then some code to
detect whatever method the kernel is using and use the appropriate set of
functions.
	Also, I'm thinking, would it be a good idea to have another API to
interface every other devices API. Like:
		Parent	/dev		using Master Device API
		Child		/dev/disk	using GEOM API
		Child		/dev/net	using NET API
		.		.		.
		.		.		.
		.		.		.
	I'm a bit confussed...

	plan_b@videotron.ca
	thanks for reading

--Boundary_(ID_ogyvznEVLFV5eupSOhg9Sg)
Content-type: text/plain; name=fdisk.txt; CHARSET=US-ASCII
Content-transfer-encoding: 7BIT
Content-disposition: attachment; filename=fdisk.txt

#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <limits.h>
#include <sys/stat.h>
#include <sys/types.h>

int in;
int out;
int c = 0;
int bc_size = 446;
int pt_size = 66;
unsigned char buffer[512];

int bc_copy(char *source, char *destination);
int pt_copy(char *source, char *destination);
int bc_print(char *source);
int pt_print(char *source);
int p_activate(char *source, char *partition);
int p_type(char *source, char *partition, char *type);
int ptbe_edit(char *source, char *partition, char *bc, char *bh, char *bs, char *ec, char *eh, char *es);
int ptle_edit(char *source, char *partition, char *slba, char *lbas);
int pt_sign(char *source);
void pt_list();
void usage();

main(int argc, char **argv) {
	int opt;
	if (argc == 1) { usage(); return -1; }
	while ((opt = getopt(argc, argv, "a:c:C:e:E:hlp:P:S:t:u")) != -1) {
		switch (opt) {
			case 'a':
				if ((argc != 4)) {
					usage();
					return -1;
				}
				p_activate(argv[2], argv[3]);
				break;
			case 'c':
				if ((argc != 4)) {
					usage();
					return -1;
				}
				bc_copy(argv[2], argv[3]);
				break;
			case 'C':
				if ((argc != 4)) {
					usage();
					return -1;
				}
				pt_copy(argv[2], argv[3]);
				break;
			case 'e':
				if ((argc != 10)) {
					usage();
					return -1;
				}
				ptbe_edit(argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9]);
				break;
			case 'E':
				if ((argc != 6)) {
					usage();
					return -1;
				}
				ptle_edit(argv[2], argv[3], argv[4], argv[5]);
				break;
			case 'h':
				usage();
				break;
			case 'l':
				pt_list();
				break;
			case 'p':
				if ((argc != 3)) {
					usage();
					return -1;
				}
				bc_print(argv[2]);
				break;
			case 'P':
				if ((argc != 3)) {
					usage();
					return -1;
				}
				pt_print(argv[2]);
				break;
			case 'S':
				if ((argc != 3)) {
					usage();
					return -1;
				}
				pt_sign(argv[2]);
				break;
			case 't':
				if ((argc != 5)) {
					usage();
					return -1;
				}
				p_type(argv[2], argv[3], argv[4]);
				break;
			case 'u':
				usage();
				break;
			case '?':
				usage();
				break;
		}
		argc -= optind;
		argv += optind;
	}
}

int p_activate(char *source, char *partition) {
	out = open(source, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR);
	while (c != 4) {
		lseek(out, bc_size, SEEK_SET);
		write(out, buffer, 1);
		bc_size = bc_size + 16;
		c++;
	}
	if ((strtoul(partition, NULL, 10) < 1) || (strtoul(partition, NULL, 10)) > 4) { printf("Partition Range: 1-4\n"); return -1; }
	bc_size = 430 + 16 * strtoul(partition, NULL, 10);
	buffer[0] = 128;
	lseek(out, bc_size, SEEK_SET);
	write(out, buffer, 1);
}

int bc_copy(char *source, char *destination) {
	in = open(source, O_RDONLY);
	out = open(destination, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR);
	read(in, buffer, bc_size);
	write(out, buffer, bc_size);
	printf("Boot Code has been transfered from %s to %s\n", source, destination);
}

int pt_copy(char *source, char *destination) {
	in = open(source, O_RDONLY);
	out = open(destination, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR);
	lseek(in, bc_size, SEEK_SET);
	read(in, buffer, pt_size);
	lseek(out, bc_size, SEEK_SET);
	write(out, buffer, pt_size);
	printf("Partition Table has been transfered from %s to %s\n", source, destination);
}

int ptbe_edit(char *source, char *partition, char *bc, char *bh, char *bs, char *ec, char *eh, char *es) {
	if ((strtoul(bc, NULL, 10) > 1024) || (strtoul(ec, NULL, 10) > 1024)) {
		printf("Maximum Cylinder value: 1024\n");
		return -1;
	}
	if ((strtoul(bh, NULL, 10) > 255) || (strtoul(eh, NULL, 10) > 255)) {
		printf("Maximum Head value: 255\n");
		return -1;
	}
	if ((strtoul(bs, NULL, 10) > 63) || (strtoul(es, NULL, 10) > 63)) {
		printf("Maximum Sector value: 63\n");
		return -1;
	}
	if ((strtoul(partition, NULL, 10) < 1) || (strtoul(partition, NULL, 10) > 4)) { printf("Partition Range: 1-4\n"); return -1; }
	bc_size = 430 + 16 * strtoul(partition, NULL, 10);
	in = open(source, O_RDONLY);
	lseek(in, bc_size, SEEK_SET);
	read(in, buffer, 8);
	buffer[1] =  strtoul(bh, NULL, 10);
	buffer[2] = (strtoul(bs, NULL, 10) + ((strtoul(bc, NULL, 10) & 768) >> 2));
	buffer[3] = (strtoul(bc, NULL, 10) & 255);
	buffer[5] =  strtoul(eh, NULL, 10);
	buffer[6] = (strtoul(es, NULL, 10) + ((strtoul(ec, NULL, 10) & 768) >> 2));
	buffer[7] = (strtoul(ec, NULL, 10) & 255);
	out = open(source, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR);
	lseek(out, bc_size, SEEK_SET);
	write(out, buffer, 8);
}

int ptle_edit(char *source, char *partition, char *slba, char *lbas) {
	if (strtoul(slba, NULL, 10) > 2000000000) {
		printf("Maximum Starting LBA value: 2000000000\n");
		return -1;
	}
	if (strtoul(lbas, NULL, 10) > 2000000000) {
		printf("Maximum LBA Size value: 2000000000\n");
		return -1;
	}
	if ((strtoul(partition, NULL, 10) < 1) || (strtoul(partition, NULL, 10) > 4)) { printf("Partition Range: 1-4\n"); return -1; }
	bc_size = 438 + 16 * strtoul(partition, NULL, 10);
	buffer[0] =  (strtoul(slba, NULL, 10) & 255);
	buffer[1] = ((strtoul(slba, NULL, 10) & 65280) >> 8);
	buffer[2] = ((strtoul(slba, NULL, 10) & 16711680) >> 16);
	buffer[3] =  (strtoul(slba, NULL, 10) >> 24);
	buffer[4] =  (strtoul(lbas, NULL, 10) & 255);
	buffer[5] = ((strtoul(lbas, NULL, 10) & 65280) >> 8);
	buffer[6] = ((strtoul(lbas, NULL, 10) & 16711680) >> 16);
	buffer[7] =  (strtoul(lbas, NULL, 10) >> 24);
	out = open(source, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR);
	lseek(out, bc_size, SEEK_SET);
	write(out, buffer, 8);
}

int bc_print(char *source) {
	int bc = 0;
	in = open(source, O_RDONLY);
	read(in, buffer, bc_size);
	for (c; c < bc_size; c++) {
		if (bc == 16) {
			bc = 0;
			printf("\n");
		}
		printf("%02x", buffer[c]);
		bc++;
	}
	printf("\n");
}

int pt_print(char *source) {
	in = open(source, O_RDONLY);
	printf("\n");
	while ( c != 4) {
		lseek(in, bc_size, SEEK_SET);
		read(in, buffer, 16);
		printf("Partition %2d is active %02x, type %02x, LBA start %d and LBA size %d\n", (c + 1), buffer[0], buffer[4], buffer[8] + (buffer[9] * 256) + (buffer[10] * 65536) + (buffer[11] * 16777216), buffer[12] + (buffer[13] * 256) + (buffer[14] * 65536) + (buffer[15] * 16777216));
		printf("Beginning: %4d cylinder, %3d head, %2d sector\n", (((buffer[2] & 0xc0) << 2) + buffer[3]), buffer[1], (buffer[2] & 0x3f));
		printf("Ending:    %4d cylinder, %3d head, %2d sector\n\n", (((buffer[6] & 0xc0) << 2) + buffer[7]), buffer[5], (buffer[6] & 0x3f));
		bc_size = bc_size + 16;
		c++;
	}
}

int p_type(char *source, char *partition, char *type) {
	if (strtoul(type, NULL, 10) > 255) { printf("Wrong Partition Type.\n"); pt_list(); return -1; }
	if ((strtoul(partition, NULL, 10) < 1) || (strtoul(partition, NULL, 10) > 4)) { printf("Partition Range: 1-4\n"); return -1; }
	bc_size = 434 + 16 * strtoul(partition, NULL, 10);
	buffer[0] = strtoul(type, NULL, 10);
	out = open(source, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR);
	lseek(out, bc_size, SEEK_SET);
	write(out, buffer, 1);
}

int pt_sign(char *source) {
	buffer[0] = 85;
	buffer[1] = 170;
	out = open(source, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR);
	lseek(out, 510, SEEK_SET);
	write(out, buffer, 2);
}

void pt_list() {
	printf("\n");
	printf("00 Empty\n");
	printf("01 12-bit FAT primary partition\n");
	printf("04 16-bit FAT primary partition\n");
	printf("05 Extended partition\n");
	printf("06 BIGDOS FAT primary partition\n");
	printf("07 NTFS primary partition\n");
	printf("63 Unix System V (SCO, ISC Unix, UnixWare, ...), Mach, GNU Hurd\n");
	printf("64 Novell Netware 286, 2.xx\n");
	printf("65 Novell Netware 386, 3.xx or 4.xx\n");
	printf("69 Novell Netware 5+, Novell Netware NSS Partition\n");
	printf("82 Linux swap\n");
	printf("83 Linux native partition\n");
	printf("84 Hibernation partition\n");
	printf("85 Linux extended partition\n");
	printf("86 NTFS volume set\n");
	printf("87 NTFS volume set\n");
	printf("8b Legacy Fault Tolerant FAT32 volume\n");
	printf("8c Legacy Fault Tolerant FAT32 volume using BIOS extended INT 13h\n");
	printf("a0 Laptop hibernation partition\n");
	printf("a5 NetBSD, FreeBSD, 386BSD\n");
	printf("a6 OpenBSD\n");
	printf("a9 NetBSD\n");
	printf("eb BeOS\n");
	printf("fb VMWare File System partition\n");
	printf("fc VMWare Swap partition\n");
	printf("\n");
}

void usage() {
	printf("\n");
	printf("fdisk - Partition Manager\n");
	printf("\n");
	printf("SYNOPSYS\n");
	printf("     fdisk [-a:c:C:e:E:hlp:P:t:] [source] [destination] [partition] [type] [CHS start, CHS end] [LBA start, LBA size]\n");
	printf("\n");
	printf("	-a	Activate [partition] on [source].\n");
	printf("        -c      Copy Boot Code from [source] to [destination].\n");
	printf("        -C      Copy Partition Table from [source] to [destination].\n");
	printf("	-e	Edit [partition] CHS parameters on [source].\n");
	printf("	-E	Edit [partition] LBA parameters on [source].\n");
	printf("        -h      Print help.\n");
	printf("        -l      Print Partition Type list.\n");
	printf("        -p      Print Boot Code from [source].\n");
	printf("        -P      Print Partition Table from [source].\n");
	printf("	-S	Sign the Partition Table.\n");
	printf("	-t	Change [partition] [type] on [source].\n");
	printf("	-u	Print help.\n");
	printf("\n");
}

--Boundary_(ID_ogyvznEVLFV5eupSOhg9Sg)
Content-type: application/octet-stream; name=fdisk.c
Content-transfer-encoding: quoted-printable
Content-disposition: attachment; filename=fdisk.c

#include <unistd.h>=0A=
#include <stdio.h>=0A=
#include <fcntl.h>=0A=
#include <stdlib.h>=0A=
#include <limits.h>=0A=
#include <sys/stat.h>=0A=
#include <sys/types.h>=0A=
=0A=
int in;=0A=
int out;=0A=
int c =3D 0;=0A=
int bc_size =3D 446;=0A=
int pt_size =3D 66;=0A=
unsigned char buffer[512];=0A=
=0A=
int bc_copy(char *source, char *destination);=0A=
int pt_copy(char *source, char *destination);=0A=
int bc_print(char *source);=0A=
int pt_print(char *source);=0A=
int p_activate(char *source, char *partition);=0A=
int p_type(char *source, char *partition, char *type);=0A=
int ptbe_edit(char *source, char *partition, char *bc, char *bh, char =
*bs, char *ec, char *eh, char *es);=0A=
int ptle_edit(char *source, char *partition, char *slba, char *lbas);=0A=
int pt_sign(char *source);=0A=
void pt_list();=0A=
void usage();=0A=
=0A=
main(int argc, char **argv) {=0A=
	int opt;=0A=
	if (argc =3D=3D 1) { usage(); return -1; }=0A=
	while ((opt =3D getopt(argc, argv, "a:c:C:e:E:hlp:P:S:t:u")) !=3D -1) {=0A=
		switch (opt) {=0A=
			case 'a':=0A=
				if ((argc !=3D 4)) {=0A=
					usage();=0A=
					return -1;=0A=
				}=0A=
				p_activate(argv[2], argv[3]);=0A=
				break;=0A=
			case 'c':=0A=
				if ((argc !=3D 4)) {=0A=
					usage();=0A=
					return -1;=0A=
				}=0A=
				bc_copy(argv[2], argv[3]);=0A=
				break;=0A=
			case 'C':=0A=
				if ((argc !=3D 4)) {=0A=
					usage();=0A=
					return -1;=0A=
				}=0A=
				pt_copy(argv[2], argv[3]);=0A=
				break;=0A=
			case 'e':=0A=
				if ((argc !=3D 10)) {=0A=
					usage();=0A=
					return -1;=0A=
				}=0A=
				ptbe_edit(argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], =
argv[8], argv[9]);=0A=
				break;=0A=
			case 'E':=0A=
				if ((argc !=3D 6)) {=0A=
					usage();=0A=
					return -1;=0A=
				}=0A=
				ptle_edit(argv[2], argv[3], argv[4], argv[5]);=0A=
				break;=0A=
			case 'h':=0A=
				usage();=0A=
				break;=0A=
			case 'l':=0A=
				pt_list();=0A=
				break;=0A=
			case 'p':=0A=
				if ((argc !=3D 3)) {=0A=
					usage();=0A=
					return -1;=0A=
				}=0A=
				bc_print(argv[2]);=0A=
				break;=0A=
			case 'P':=0A=
				if ((argc !=3D 3)) {=0A=
					usage();=0A=
					return -1;=0A=
				}=0A=
				pt_print(argv[2]);=0A=
				break;=0A=
			case 'S':=0A=
				if ((argc !=3D 3)) {=0A=
					usage();=0A=
					return -1;=0A=
				}=0A=
				pt_sign(argv[2]);=0A=
				break;=0A=
			case 't':=0A=
				if ((argc !=3D 5)) {=0A=
					usage();=0A=
					return -1;=0A=
				}=0A=
				p_type(argv[2], argv[3], argv[4]);=0A=
				break;=0A=
			case 'u':=0A=
				usage();=0A=
				break;=0A=
			case '?':=0A=
				usage();=0A=
				break;=0A=
		}=0A=
		argc -=3D optind;=0A=
		argv +=3D optind;=0A=
	}=0A=
}=0A=
=0A=
int p_activate(char *source, char *partition) {=0A=
	out =3D open(source, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR);=0A=
	while (c !=3D 4) {=0A=
		lseek(out, bc_size, SEEK_SET);=0A=
		write(out, buffer, 1);=0A=
		bc_size =3D bc_size + 16;=0A=
		c++;=0A=
	}=0A=
	if ((strtoul(partition, NULL, 10) < 1) || (strtoul(partition, NULL, =
10)) > 4) { printf("Partition Range: 1-4\n"); return -1; }=0A=
	bc_size =3D 430 + 16 * strtoul(partition, NULL, 10);=0A=
	buffer[0] =3D 128;=0A=
	lseek(out, bc_size, SEEK_SET);=0A=
	write(out, buffer, 1);=0A=
}=0A=
=0A=
int bc_copy(char *source, char *destination) {=0A=
	in =3D open(source, O_RDONLY);=0A=
	out =3D open(destination, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR);=0A=
	read(in, buffer, bc_size);=0A=
	write(out, buffer, bc_size);=0A=
	printf("Boot Code has been transfered from %s to %s\n", source, =
destination);=0A=
}=0A=
=0A=
int pt_copy(char *source, char *destination) {=0A=
	in =3D open(source, O_RDONLY);=0A=
	out =3D open(destination, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR);=0A=
	lseek(in, bc_size, SEEK_SET);=0A=
	read(in, buffer, pt_size);=0A=
	lseek(out, bc_size, SEEK_SET);=0A=
	write(out, buffer, pt_size);=0A=
	printf("Partition Table has been transfered from %s to %s\n", source, =
destination);=0A=
}=0A=
=0A=
int ptbe_edit(char *source, char *partition, char *bc, char *bh, char =
*bs, char *ec, char *eh, char *es) {=0A=
	if ((strtoul(bc, NULL, 10) > 1024) || (strtoul(ec, NULL, 10) > 1024)) {=0A=
		printf("Maximum Cylinder value: 1024\n");=0A=
		return -1;=0A=
	}=0A=
	if ((strtoul(bh, NULL, 10) > 255) || (strtoul(eh, NULL, 10) > 255)) {=0A=
		printf("Maximum Head value: 255\n");=0A=
		return -1;=0A=
	}=0A=
	if ((strtoul(bs, NULL, 10) > 63) || (strtoul(es, NULL, 10) > 63)) {=0A=
		printf("Maximum Sector value: 63\n");=0A=
		return -1;=0A=
	}=0A=
	if ((strtoul(partition, NULL, 10) < 1) || (strtoul(partition, NULL, 10) =
> 4)) { printf("Partition Range: 1-4\n"); return -1; }=0A=
	bc_size =3D 430 + 16 * strtoul(partition, NULL, 10);=0A=
	in =3D open(source, O_RDONLY);=0A=
	lseek(in, bc_size, SEEK_SET);=0A=
	read(in, buffer, 8);=0A=
	buffer[1] =3D  strtoul(bh, NULL, 10);=0A=
	buffer[2] =3D (strtoul(bs, NULL, 10) + ((strtoul(bc, NULL, 10) & 768) =
>> 2));=0A=
	buffer[3] =3D (strtoul(bc, NULL, 10) & 255);=0A=
	buffer[5] =3D  strtoul(eh, NULL, 10);=0A=
	buffer[6] =3D (strtoul(es, NULL, 10) + ((strtoul(ec, NULL, 10) & 768) =
>> 2));=0A=
	buffer[7] =3D (strtoul(ec, NULL, 10) & 255);=0A=
	out =3D open(source, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR);=0A=
	lseek(out, bc_size, SEEK_SET);=0A=
	write(out, buffer, 8);=0A=
}=0A=
=0A=
int ptle_edit(char *source, char *partition, char *slba, char *lbas) {=0A=
	if (strtoul(slba, NULL, 10) > 2000000000) {=0A=
		printf("Maximum Starting LBA value: 2000000000\n");=0A=
		return -1;=0A=
	}=0A=
	if (strtoul(lbas, NULL, 10) > 2000000000) {=0A=
		printf("Maximum LBA Size value: 2000000000\n");=0A=
		return -1;=0A=
	}=0A=
	if ((strtoul(partition, NULL, 10) < 1) || (strtoul(partition, NULL, 10) =
> 4)) { printf("Partition Range: 1-4\n"); return -1; }=0A=
	bc_size =3D 438 + 16 * strtoul(partition, NULL, 10);=0A=
	buffer[0] =3D  (strtoul(slba, NULL, 10) & 255);=0A=
	buffer[1] =3D ((strtoul(slba, NULL, 10) & 65280) >> 8);=0A=
	buffer[2] =3D ((strtoul(slba, NULL, 10) & 16711680) >> 16);=0A=
	buffer[3] =3D  (strtoul(slba, NULL, 10) >> 24);=0A=
	buffer[4] =3D  (strtoul(lbas, NULL, 10) & 255);=0A=
	buffer[5] =3D ((strtoul(lbas, NULL, 10) & 65280) >> 8);=0A=
	buffer[6] =3D ((strtoul(lbas, NULL, 10) & 16711680) >> 16);=0A=
	buffer[7] =3D  (strtoul(lbas, NULL, 10) >> 24);=0A=
	out =3D open(source, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR);=0A=
	lseek(out, bc_size, SEEK_SET);=0A=
	write(out, buffer, 8);=0A=
}=0A=
=0A=
int bc_print(char *source) {=0A=
	int bc =3D 0;=0A=
	in =3D open(source, O_RDONLY);=0A=
	read(in, buffer, bc_size);=0A=
	for (c; c < bc_size; c++) {=0A=
		if (bc =3D=3D 16) {=0A=
			bc =3D 0;=0A=
			printf("\n");=0A=
		}=0A=
		printf("%02x", buffer[c]);=0A=
		bc++;=0A=
	}=0A=
	printf("\n");=0A=
}=0A=
=0A=
int pt_print(char *source) {=0A=
	in =3D open(source, O_RDONLY);=0A=
	printf("\n");=0A=
	while ( c !=3D 4) {=0A=
		lseek(in, bc_size, SEEK_SET);=0A=
		read(in, buffer, 16);=0A=
		printf("Partition %2d is active %02x, type %02x, LBA start %d and LBA =
size %d\n", (c + 1), buffer[0], buffer[4], buffer[8] + (buffer[9] * 256) =
+ (buffer[10] * 65536) + (buffer[11] * 16777216), buffer[12] + =
(buffer[13] * 256) + (buffer[14] * 65536) + (buffer[15] * 16777216));=0A=
		printf("Beginning: %4d cylinder, %3d head, %2d sector\n", (((buffer[2] =
& 0xc0) << 2) + buffer[3]), buffer[1], (buffer[2] & 0x3f));=0A=
		printf("Ending:    %4d cylinder, %3d head, %2d sector\n\n", =
(((buffer[6] & 0xc0) << 2) + buffer[7]), buffer[5], (buffer[6] & 0x3f));=0A=
		bc_size =3D bc_size + 16;=0A=
		c++;=0A=
	}=0A=
}=0A=
=0A=
int p_type(char *source, char *partition, char *type) {=0A=
	if (strtoul(type, NULL, 10) > 255) { printf("Wrong Partition Type.\n"); =
pt_list(); return -1; }=0A=
	if ((strtoul(partition, NULL, 10) < 1) || (strtoul(partition, NULL, 10) =
> 4)) { printf("Partition Range: 1-4\n"); return -1; }=0A=
	bc_size =3D 434 + 16 * strtoul(partition, NULL, 10);=0A=
	buffer[0] =3D strtoul(type, NULL, 10);=0A=
	out =3D open(source, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR);=0A=
	lseek(out, bc_size, SEEK_SET);=0A=
	write(out, buffer, 1);=0A=
}=0A=
=0A=
int pt_sign(char *source) {=0A=
	buffer[0] =3D 85;=0A=
	buffer[1] =3D 170;=0A=
	out =3D open(source, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR);=0A=
	lseek(out, 510, SEEK_SET);=0A=
	write(out, buffer, 2);=0A=
}=0A=
=0A=
void pt_list() {=0A=
	printf("\n");=0A=
	printf("00 Empty\n");=0A=
	printf("01 12-bit FAT primary partition\n");=0A=
	printf("04 16-bit FAT primary partition\n");=0A=
	printf("05 Extended partition\n");=0A=
	printf("06 BIGDOS FAT primary partition\n");=0A=
	printf("07 NTFS primary partition\n");=0A=
	printf("63 Unix System V (SCO, ISC Unix, UnixWare, ...), Mach, GNU =
Hurd\n");=0A=
	printf("64 Novell Netware 286, 2.xx\n");=0A=
	printf("65 Novell Netware 386, 3.xx or 4.xx\n");=0A=
	printf("69 Novell Netware 5+, Novell Netware NSS Partition\n");=0A=
	printf("82 Linux swap\n");=0A=
	printf("83 Linux native partition\n");=0A=
	printf("84 Hibernation partition\n");=0A=
	printf("85 Linux extended partition\n");=0A=
	printf("86 NTFS volume set\n");=0A=
	printf("87 NTFS volume set\n");=0A=
	printf("8b Legacy Fault Tolerant FAT32 volume\n");=0A=
	printf("8c Legacy Fault Tolerant FAT32 volume using BIOS extended INT =
13h\n");=0A=
	printf("a0 Laptop hibernation partition\n");=0A=
	printf("a5 NetBSD, FreeBSD, 386BSD\n");=0A=
	printf("a6 OpenBSD\n");=0A=
	printf("a9 NetBSD\n");=0A=
	printf("eb BeOS\n");=0A=
	printf("fb VMWare File System partition\n");=0A=
	printf("fc VMWare Swap partition\n");=0A=
	printf("\n");=0A=
}=0A=
=0A=
void usage() {=0A=
	printf("\n");=0A=
	printf("fdisk - Partition Manager\n");=0A=
	printf("\n");=0A=
	printf("SYNOPSYS\n");=0A=
	printf("     fdisk [-a:c:C:e:E:hlp:P:t:] [source] [destination] =
[partition] [type] [CHS start, CHS end] [LBA start, LBA size]\n");=0A=
	printf("\n");=0A=
	printf("	-a	Activate [partition] on [source].\n");=0A=
	printf("        -c      Copy Boot Code from [source] to =
[destination].\n");=0A=
	printf("        -C      Copy Partition Table from [source] to =
[destination].\n");=0A=
	printf("	-e	Edit [partition] CHS parameters on [source].\n");=0A=
	printf("	-E	Edit [partition] LBA parameters on [source].\n");=0A=
	printf("        -h      Print help.\n");=0A=
	printf("        -l      Print Partition Type list.\n");=0A=
	printf("        -p      Print Boot Code from [source].\n");=0A=
	printf("        -P      Print Partition Table from [source].\n");=0A=
	printf("	-S	Sign the Partition Table.\n");=0A=
	printf("	-t	Change [partition] [type] on [source].\n");=0A=
	printf("	-u	Print help.\n");=0A=
	printf("\n");=0A=
}=0A=

--Boundary_(ID_ogyvznEVLFV5eupSOhg9Sg)--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?BDENIKJMJKOAJAMDFLDDCECICAAA.plan_b>