Blame kpartx/unixware.c

Packit Service 0af388
#include "kpartx.h"
Packit Service 0af388
#include <stdio.h>
Packit Service 0af388
Packit Service 0af388
#define UNIXWARE_FS_UNUSED     0
Packit Service 0af388
#define UNIXWARE_NUMSLICE      16
Packit Service 0af388
#define UNIXWARE_DISKMAGIC     (0xCA5E600D)
Packit Service 0af388
#define UNIXWARE_DISKMAGIC2    (0x600DDEEE)
Packit Service 0af388
Packit Service 0af388
struct unixware_slice {
Packit Service 0af388
	unsigned short s_label;		/* label */
Packit Service 0af388
	unsigned short s_flags;		/* permission flags */
Packit Service 0af388
	unsigned int   start_sect;	/* starting sector */
Packit Service 0af388
	unsigned int   nr_sects;	/* number of sectors in slice */
Packit Service 0af388
};
Packit Service 0af388
Packit Service 0af388
struct unixware_disklabel {
Packit Service 0af388
	unsigned int   d_type;		/* drive type */
Packit Service 0af388
	unsigned char  d_magic[4];	/* the magic number */
Packit Service 0af388
	unsigned int   d_version;	/* version number */
Packit Service 0af388
	char    d_serial[12];		/* serial number of the device */
Packit Service 0af388
	unsigned int   d_ncylinders;	/* # of data cylinders per device */
Packit Service 0af388
	unsigned int   d_ntracks;	/* # of tracks per cylinder */
Packit Service 0af388
	unsigned int   d_nsectors;	/* # of data sectors per track */
Packit Service 0af388
	unsigned int   d_secsize;	/* # of bytes per sector */
Packit Service 0af388
	unsigned int   d_part_start;	/* # of first sector of this partition */
Packit Service 0af388
	unsigned int   d_unknown1[12];	/* ? */
Packit Service 0af388
	unsigned int   d_alt_tbl;	/* byte offset of alternate table */
Packit Service 0af388
	unsigned int   d_alt_len;	/* byte length of alternate table */
Packit Service 0af388
	unsigned int   d_phys_cyl;	/* # of physical cylinders per device */
Packit Service 0af388
	unsigned int   d_phys_trk;	/* # of physical tracks per cylinder */
Packit Service 0af388
	unsigned int   d_phys_sec;	/* # of physical sectors per track */
Packit Service 0af388
	unsigned int   d_phys_bytes;	/* # of physical bytes per sector */
Packit Service 0af388
	unsigned int   d_unknown2;	/* ? */
Packit Service 0af388
	unsigned int   d_unknown3;	/* ? */
Packit Service 0af388
	unsigned int   d_pad[8];	/* pad */
Packit Service 0af388
Packit Service 0af388
	struct unixware_vtoc {
Packit Service 0af388
		unsigned char   v_magic[4];	/* the magic number */
Packit Service 0af388
		unsigned int    v_version;	/* version number */
Packit Service 0af388
		char    v_name[8];		/* volume name */
Packit Service 0af388
		unsigned short  v_nslices;	/* # of slices */
Packit Service 0af388
		unsigned short  v_unknown1;	/* ? */
Packit Service 0af388
		unsigned int    v_reserved[10];	/* reserved */
Packit Service 0af388
		struct unixware_slice
Packit Service 0af388
		    v_slice[UNIXWARE_NUMSLICE]; /* slice headers */
Packit Service 0af388
	} vtoc;
Packit Service 0af388
Packit Service 0af388
};  /* 408 */
Packit Service 0af388
Packit Service 0af388
int
Packit Service 0af388
read_unixware_pt(int fd, struct slice all, struct slice *sp, unsigned int ns) {
Packit Service 0af388
	struct unixware_disklabel *l;
Packit Service 0af388
	struct unixware_slice *p;
Packit Service 0af388
	unsigned int offset = all.start;
Packit Service 0af388
	char *bp;
Packit Service 0af388
	unsigned int n = 0;
Packit Service 0af388
Packit Service 0af388
	bp = getblock(fd, offset+29);	/* 1 sector suffices */
Packit Service 0af388
	if (bp == NULL)
Packit Service 0af388
		return -1;
Packit Service 0af388
Packit Service 0af388
	l = (struct unixware_disklabel *) bp;
Packit Service 0af388
	if (four2int(l->d_magic) != UNIXWARE_DISKMAGIC ||
Packit Service 0af388
	    four2int(l->vtoc.v_magic) != UNIXWARE_DISKMAGIC2)
Packit Service 0af388
		return -1;
Packit Service 0af388
Packit Service 0af388
	p = &l->vtoc.v_slice[1];	/* slice 0 is the whole disk. */
Packit Service 0af388
	while (p - &l->vtoc.v_slice[0] < UNIXWARE_NUMSLICE) {
Packit Service 0af388
		if (p->s_label == UNIXWARE_FS_UNUSED)
Packit Service 0af388
			/* nothing */;
Packit Service 0af388
		else if (n < ns) {
Packit Service 0af388
			sp[n].start = p->start_sect;
Packit Service 0af388
			sp[n].size = p->nr_sects;
Packit Service 0af388
			n++;
Packit Service 0af388
		} else {
Packit Service 0af388
			fprintf(stderr,
Packit Service 0af388
				"unixware_partition: too many slices\n");
Packit Service 0af388
			break;
Packit Service 0af388
		}
Packit Service 0af388
		p++;
Packit Service 0af388
	}
Packit Service 0af388
	return n;
Packit Service 0af388
}