diff options
author | Jeremy Katz <katzj@redhat.com> | 2002-12-03 21:24:07 +0000 |
---|---|---|
committer | Jeremy Katz <katzj@redhat.com> | 2002-12-03 21:24:07 +0000 |
commit | 8345996b3b9f995c464789292c21e2496fe80189 (patch) | |
tree | 49149f75685d96ff9078343db4158911b1b34664 /balkan | |
parent | 093639f925df83f717caeb8a930b22968b9309c8 (diff) | |
download | anaconda-8345996b3b9f995c464789292c21e2496fe80189.tar.gz anaconda-8345996b3b9f995c464789292c21e2496fe80189.tar.xz anaconda-8345996b3b9f995c464789292c21e2496fe80189.zip |
die balkan die die die
Diffstat (limited to 'balkan')
-rw-r--r-- | balkan/.cvsignore | 1 | ||||
-rw-r--r-- | balkan/Makefile | 49 | ||||
-rw-r--r-- | balkan/_balkanmodule.c | 120 | ||||
-rw-r--r-- | balkan/balkan.h | 33 | ||||
-rw-r--r-- | balkan/bsdlabel.c | 141 | ||||
-rw-r--r-- | balkan/bsdlabel.h | 6 | ||||
-rw-r--r-- | balkan/byteswap.h | 59 | ||||
-rw-r--r-- | balkan/dos.c | 188 | ||||
-rw-r--r-- | balkan/dos.h | 6 | ||||
-rw-r--r-- | balkan/rw.c | 17 | ||||
-rw-r--r-- | balkan/sun.c | 136 | ||||
-rw-r--r-- | balkan/sun.h | 6 | ||||
-rwxr-xr-x | balkan/testit | 10 |
13 files changed, 0 insertions, 772 deletions
diff --git a/balkan/.cvsignore b/balkan/.cvsignore deleted file mode 100644 index 4671378ae..000000000 --- a/balkan/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -.depend diff --git a/balkan/Makefile b/balkan/Makefile deleted file mode 100644 index 057720028..000000000 --- a/balkan/Makefile +++ /dev/null @@ -1,49 +0,0 @@ -include ../Makefile.inc - -#PYTHONLIBDIR = $(DESTDIR)/usr/lib/python1.5/site-packages - -OBJECTS = rw.o dos.o sun.o bsdlabel.o -CFLAGS=-I$(PYTHONINCLUDE) -Os - -ifneq ($(ARCH), ppc) -CFLAGS+=-D_FILE_OFFSET_BITS=64 -endif - -TARGET = libbalkan.a - -ifeq (.depend,$(wildcard .depend)) -DEPTARGET=all -else -DEPTARGET=depend all -endif - -everything: $(DEPTARGET) - -all: $(TARGET) _balkanmodule.so - -_balkanmodule.so: _balkanmodule.o libbalkan.a - gcc -shared -o $@ _balkanmodule.o libbalkan.a - -_balkanmodule.o: _balkanmodule.c balkan.h - gcc $(CFLAGS) -c -fPIC -o $@ $< - -libbalkan.a: libbalkan.a($(OBJECTS)) - -clean: - rm -f *.o *.so $(TARGET) .depend - -dos.o: dos.h - -sun.o: sun.h - -install: all - mkdir -p $(DESTDIR)/$(PYTHONLIBDIR) - install -s _balkanmodule.so $(DESTDIR)/$(PYTHONLIBDIR) - - -depend: - $(CPP) -M $(CFLAGS) *.c > .depend - -ifeq (.depend,$(wildcard .depend)) -include .depend -endif diff --git a/balkan/_balkanmodule.c b/balkan/_balkanmodule.c deleted file mode 100644 index 944ee2b8d..000000000 --- a/balkan/_balkanmodule.c +++ /dev/null @@ -1,120 +0,0 @@ -#include <errno.h> -#include <fcntl.h> -#include <sys/stat.h> -#include <sys/time.h> -#include <unistd.h> - -#include "Python.h" -#include "balkan.h" - -typedef struct pythonPartTable_s { - PyObject_HEAD; - struct partitionTable table; -} pythonPartTable; - -static void emptyDestructor(PyObject * s); -static pythonPartTable * readTable(PyObject * s, PyObject * args); -static PyObject * tableGetAttr(PyObject * s, char * name); -static int tableLength(PyObject * o); -PyObject * tableItem(PyObject * o, int n); - -static PySequenceMethods pythonPartTableAsSequence = { - tableLength, /* length */ - 0, /* concat */ - 0, /* repeat */ - tableItem, /* item */ - 0, /* slice */ - 0, /* assign item */ - 0, /* assign slice */ -}; - -static PyTypeObject pythonPartTableType = { - PyObject_HEAD_INIT(&PyType_Type) - 0, /* ob_size */ - "parttable", /* tp_name */ - sizeof(pythonPartTable), /* tp_size */ - 0, /* tp_itemsize */ - emptyDestructor, /* tp_dealloc */ - 0, /* tp_print */ - tableGetAttr, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_compare */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - &pythonPartTableAsSequence, /* tp_as_sequence */ - 0, /* tp_as_mapping */ -}; - -static PyMethodDef balkanModuleMethods[] = { - { "readTable", (PyCFunction) readTable, METH_VARARGS, NULL }, - { NULL } -} ; - -static pythonPartTable * readTable(PyObject * s, PyObject * args) { - char * device; - pythonPartTable * table; - int fd; - - if (!PyArg_ParseTuple(args, "s", &device)) return NULL; - - table = PyObject_NEW(pythonPartTable, &pythonPartTableType); - - fd = open(device, O_RDONLY | O_RDONLY); - if (fd < 0) { - PyErr_SetFromErrno(PyExc_SystemError); - return NULL; - } - - balkanReadTable(fd, &table->table); - close(fd); - - return table; -} - -static int tableLength(PyObject * o) { - pythonPartTable * t = (void *) o; - - return t->table.maxNumPartitions; -} - -PyObject * tableItem(PyObject * o, int n) { - pythonPartTable * t = (void *) o; - - if (n > t->table.maxNumPartitions) { - PyErr_SetString(PyExc_IndexError, "index out of bounds"); - return NULL; - } - - return Py_BuildValue("(iii)", t->table.parts[n].type, - t->table.parts[n].startSector, - t->table.parts[n].size); -} - -static PyObject * tableGetAttr(PyObject * o, char * name) { - pythonPartTable * t = (void *) o; - - if (!strcmp(name, "allocationUnit")) { - return Py_BuildValue("i", t->table.allocationUnit); - } else if (!strcmp(name, "sectorSize")) { - return Py_BuildValue("i", t->table.sectorSize); - } - - return NULL; -} - -void init_balkan(void) { - PyObject * d, * m; - - m = Py_InitModule("_balkan", balkanModuleMethods); - - d = PyModule_GetDict(m); - - PyDict_SetItemString(d, "DOS", PyInt_FromLong(BALKAN_PART_DOS)); - PyDict_SetItemString(d, "EXT2", PyInt_FromLong(BALKAN_PART_EXT2)); - PyDict_SetItemString(d, "SWAP", PyInt_FromLong(BALKAN_PART_SWAP)); - PyDict_SetItemString(d, "RAID", PyInt_FromLong(BALKAN_PART_RAID)); - PyDict_SetItemString(d, "UFS", PyInt_FromLong(BALKAN_PART_UFS)); -} - -static void emptyDestructor(PyObject * s) { -} diff --git a/balkan/balkan.h b/balkan/balkan.h deleted file mode 100644 index bc687cd2c..000000000 --- a/balkan/balkan.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef H_BALKAN -#define H_BALKAN 1 -#define _LARGEFILE_SOURCE 1 -#define _LARGEFILE64_SOURCE 1 - -#define BALKAN_ERROR_ERRNO 1 -#define BALKAN_ERROR_BADMAGIC 2 -#define BALKAN_ERROR_BADTABLE 3 - -#define BALKAN_PART_DOS 1 -#define BALKAN_PART_EXT2 2 -#define BALKAN_PART_OTHER 3 -#define BALKAN_PART_NTFS 4 -#define BALKAN_PART_SWAP 5 -#define BALKAN_PART_UFS 6 -#define BALKAN_PART_RAID 7 - -struct partition { - long startSector; - long size; /* in sectors */ - int type; /* -1 for "not used" */ -}; - -struct partitionTable { - int allocationUnit; /* in sectors */ - int maxNumPartitions; - int sectorSize; - struct partition parts[50]; -}; - -int balkanReadTable(int fd, struct partitionTable * table); - -#endif diff --git a/balkan/bsdlabel.c b/balkan/bsdlabel.c deleted file mode 100644 index e756e5596..000000000 --- a/balkan/bsdlabel.c +++ /dev/null @@ -1,141 +0,0 @@ -/* Sun style partitioning */ - -#include <fcntl.h> -#include <unistd.h> - -#include "balkan.h" - -#define BSD_DISKMAGIC (0x82564557UL) /* The disk magic number */ -#define BSD_MAXPARTITIONS 8 -#define BSD_FS_UNUSED 0 /* disklabel unused partition entry ID */ -#define BSD_LABEL_OFFSET 64 - -struct bsd_disklabel { - unsigned int d_magic; /* the magic number */ - signed short d_type; /* drive type */ - signed short d_subtype; /* controller/d_type specific */ - char d_typename[16]; /* type name, e.g. "eagle" */ - char d_packname[16]; /* pack identifier */ - unsigned int d_secsize; /* # of bytes per sector */ - unsigned int d_nsectors; /* # of data sectors per track */ - unsigned int d_ntracks; /* # of tracks per cylinder */ - unsigned int d_ncylinders; /* # of data cylinders per unit */ - unsigned int d_secpercyl; /* # of data sectors per cylinder */ - unsigned int d_secperunit; /* # of data sectors per unit */ - unsigned short d_sparespertrack; /* # of spare sectors per track */ - unsigned short d_sparespercyl; /* # of spare sectors per cylinder */ - unsigned int d_acylinders; /* # of alt. cylinders per unit */ - unsigned short d_rpm; /* rotational speed */ - unsigned short d_interleave; /* hardware sector interleave */ - unsigned short d_trackskew; /* sector 0 skew, per track */ - unsigned short d_cylskew; /* sector 0 skew, per cylinder */ - unsigned int d_headswitch; /* head switch time, usec */ - unsigned int d_trkseek; /* track-to-track seek, usec */ - unsigned int d_flags; /* generic flags */ - #define NDDATA 5 - unsigned int d_drivedata[NDDATA]; /* drive-type specific information */ - #define NSPARE 5 - unsigned int d_spare[NSPARE]; /* reserved for future use */ - unsigned int d_magic2; /* the magic number (again) */ - unsigned short d_checksum; /* xor of data incl. partitions */ - - /* filesystem and partition information: */ - unsigned short d_npartitions; /* number of partitions in following */ - unsigned int d_bbsize; /* size of boot area at sn0, bytes */ - unsigned int d_sbsize; /* max size of fs superblock, bytes */ - struct bsd_partition { /* the partition table */ - unsigned int p_size; /* number of sectors in partition */ - unsigned int p_offset; /* starting sector */ - unsigned int p_fsize; /* filesystem basic fragment size */ - unsigned char p_fstype; /* filesystem type, see below */ - unsigned char p_frag; /* filesystem fragments per block */ - unsigned short p_cpg; /* filesystem cylinders per group */ - } d_partitions[BSD_MAXPARTITIONS]; /* actually may be more */ -}; - -#if 0 -static unsigned short xbsd_dkcksum (struct bsd_disklabel *lp) { - unsigned short *start, *end; - unsigned short sum = 0; - - lp->d_checksum = 0; - start = (u_short *)lp; - end = (u_short *)&lp->d_partitions[lp->d_npartitions]; - while (start < end) - sum ^= *start++; - return (sum); -} -#endif - -int bsdlReadTable(int fd, struct partitionTable * table) { - struct bsd_disklabel label; - int i, rc; - unsigned short *p, csum; - int s; - - table->maxNumPartitions = 8; - - for (i = 0; i < table->maxNumPartitions; i++) - table->parts[i].type = -1; - - table->sectorSize = 512; - - if (lseek(fd, BSD_LABEL_OFFSET, SEEK_SET) < 0) - return BALKAN_ERROR_ERRNO; - - if (read(fd, &label, sizeof(label)) != sizeof(label)) - return BALKAN_ERROR_ERRNO; - - if (label.d_magic != BSD_DISKMAGIC) - return BALKAN_ERROR_BADMAGIC; - -#if 0 - /* minlabel doens't write checksums :-( */ - if (xbsd_dkcksum(&label)) - return BALKAN_ERROR_BADMAGIC; -#endif - - if (label.d_npartitions > 8) - label.d_npartitions = 8; - - for (i = 0; i < label.d_npartitions; i++) { - if (label.d_partitions[i].p_size && label.d_partitions[i].p_fstype) { - table->parts[i].startSector = label.d_partitions[i].p_offset; - table->parts[i].size = label.d_partitions[i].p_size; - - switch (label.d_partitions[i].p_fstype) { - case 1: - s = BALKAN_PART_SWAP; break; - case 8: - s = BALKAN_PART_EXT2; break; - case 0xfd: - s = BALKAN_PART_RAID; break; - default: - s = BALKAN_PART_OTHER; break; - } - table->parts[i].type = s; - } - } - - return 0; -} - -#ifdef STANDALONE_TEST - -void main() { - int fd; - int i; - struct partitionTable table; - - fd = open("/dev/hda", O_RDONLY); - - printf("rc= %d\n", bsdlReadTable(fd, &table)); - - for (i = 0; i < table.maxNumPartitions; i++) { - if (table.parts[i].type == -1) continue; - - printf("%d: %x %d\n", i, table.parts[i].type, table.parts[i].size); - } -} - -#endif diff --git a/balkan/bsdlabel.h b/balkan/bsdlabel.h deleted file mode 100644 index e63022634..000000000 --- a/balkan/bsdlabel.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef H_DOS -#define H_DOS 1 - -int bsdlReadTable(int fd, struct partitionTable * table); - -#endif diff --git a/balkan/byteswap.h b/balkan/byteswap.h deleted file mode 100644 index d271146aa..000000000 --- a/balkan/byteswap.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef H_BYTESWAP -#define H_BYTESWAP 1 - -#include <endian.h> -#include <stdint.h> - -#define swab16(x) \ - ((uint16_t)( \ - (((uint16_t)(x) & (uint16_t)0x00ffU) << 8) | \ - (((uint16_t)(x) & (uint16_t)0xff00U) >> 8) )) -#define swab32(x) \ - ((uint32_t)( \ - (((uint32_t)(x) & (uint32_t)0x000000ffUL) << 24) | \ - (((uint32_t)(x) & (uint32_t)0x0000ff00UL) << 8) | \ - (((uint32_t)(x) & (uint32_t)0x00ff0000UL) >> 8) | \ - (((uint32_t)(x) & (uint32_t)0xff000000UL) >> 24) )) -#define swab64(x) \ - ((uint64_t)( \ - (uint64_t)(((uint64_t)(x) & (uint64_t)0x00000000000000ffULL) << 56) | \ - (uint64_t)(((uint64_t)(x) & (uint64_t)0x000000000000ff00ULL) << 40) | \ - (uint64_t)(((uint64_t)(x) & (uint64_t)0x0000000000ff0000ULL) << 24) | \ - (uint64_t)(((uint64_t)(x) & (uint64_t)0x00000000ff000000ULL) << 8) | \ - (uint64_t)(((uint64_t)(x) & (uint64_t)0x000000ff00000000ULL) >> 8) | \ - (uint64_t)(((uint64_t)(x) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \ - (uint64_t)(((uint64_t)(x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \ - (uint64_t)(((uint64_t)(x) & (uint64_t)0xff00000000000000ULL) >> 56) )) - -#if __BYTE_ORDER == __LITTLE_ENDIAN - -#define cpu_to_le16(x) x -#define cpu_to_le32(x) x -#define cpu_to_le64(x) x -#define le16_to_cpu(x) x -#define le32_to_cpu(x) x -#define le64_to_cpu(x) x -#define cpu_to_be16(x) swab16(x) -#define cpu_to_be32(x) swab32(x) -#define cpu_to_be64(x) swab64(x) -#define be16_to_cpu(x) swab16(x) -#define be32_to_cpu(x) swab32(x) -#define be64_to_cpu(x) swab64(x) - -#else - -#define cpu_to_le16(x) swab16(x) -#define cpu_to_le32(x) swab32(x) -#define cpu_to_le64(x) swab64(x) -#define le16_to_cpu(x) swab16(x) -#define le32_to_cpu(x) swab32(x) -#define le64_to_cpu(x) swab64(x) -#define cpu_to_be16(x) x -#define cpu_to_be32(x) x -#define cpu_to_be64(x) x -#define be16_to_cpu(x) x -#define be32_to_cpu(x) x -#define be64_to_cpu(x) x - -#endif -#endif diff --git a/balkan/dos.c b/balkan/dos.c deleted file mode 100644 index 4b9bccd2f..000000000 --- a/balkan/dos.c +++ /dev/null @@ -1,188 +0,0 @@ -/* DOS style partitioning */ -#include "balkan.h" - -#include <fcntl.h> -#include <unistd.h> -#include <sys/types.h> - -#include "byteswap.h" - -struct singlePartition { - unsigned char active; - unsigned char startHead; - unsigned char startSector; - unsigned char startCyl; - unsigned char type; - unsigned char endHead; - unsigned char endSector; - unsigned char endCyl; - unsigned int start; /* in sectors */ - unsigned int size; /* in sectors */ -}; - -struct singlePartitionTable { - struct singlePartition parts[4]; -}; - -/* Location of partition table in MBR */ -#define TABLE_OFFSET 446 -#define MBR_MAGIC 0x55aa -#define MBR_MAGIC_OFFSET 510 -#define SECTOR_SIZE 512 - -#define DOSP_TYPE_EXTENDED 5 -#define WINP_TYPE_EXTENDED 0xf -#define LINUX_TYPE_EXTENDED 0x85 - -static int readSingleTable(int fd, struct singlePartitionTable * table, - off64_t partSector) { - unsigned char sector[SECTOR_SIZE]; - unsigned short magic; - - if (lseek(fd, ((off64_t) SECTOR_SIZE * (off64_t) partSector), - SEEK_SET) < 0) - return BALKAN_ERROR_ERRNO; - - if (read(fd, sector, sizeof(sector)) != sizeof(sector)) - return BALKAN_ERROR_ERRNO; - - magic = (sector[MBR_MAGIC_OFFSET] << 8) + sector[MBR_MAGIC_OFFSET + 1]; - if (magic != MBR_MAGIC) - return BALKAN_ERROR_BADMAGIC; - - memcpy(table, sector + TABLE_OFFSET, sizeof(struct singlePartitionTable)); - - return 0; -} - -static int readNextTable(int fd, struct partitionTable * table, int nextNum, - off64_t partSector, off64_t sectorOffset) { - struct singlePartitionTable singleTable; - int rc; - int i, thisPart; - int gotExtended = 0; - - if ((rc = readSingleTable(fd, &singleTable, partSector + sectorOffset))) - return rc; - - if (nextNum >= 4) { - /* This is an extended table */ - if (singleTable.parts[2].size || singleTable.parts[3].size) - return BALKAN_ERROR_BADTABLE; - } - - for (i = 0; i < 4; i++) { - if (!singleTable.parts[i].size) continue; - if ((singleTable.parts[i].type == DOSP_TYPE_EXTENDED || - singleTable.parts[i].type == WINP_TYPE_EXTENDED || - singleTable.parts[i].type == LINUX_TYPE_EXTENDED) && - nextNum >= 4) continue; - - if (nextNum < 4) - thisPart = i; - else - thisPart = nextNum++; - - table->parts[thisPart].startSector = - le32_to_cpu(singleTable.parts[i].start) + sectorOffset; - table->parts[thisPart].size = le32_to_cpu(singleTable.parts[i].size); - table->parts[thisPart].type = singleTable.parts[i].type; - } - - if (nextNum < 4) nextNum = 4; - - /* look for extended partitions */ - for (i = 0; i < 4; i++) { - if (!singleTable.parts[i].size) continue; - - if (singleTable.parts[i].type == DOSP_TYPE_EXTENDED || - singleTable.parts[i].type == WINP_TYPE_EXTENDED || - singleTable.parts[i].type == LINUX_TYPE_EXTENDED) { - if (gotExtended) return BALKAN_ERROR_BADTABLE; - gotExtended = 1; - - if (sectorOffset) - rc = readNextTable(fd, table, nextNum > 4 ? nextNum : 4, - singleTable.parts[i].start, sectorOffset); - else - rc = readNextTable(fd, table, nextNum > 4 ? nextNum : 4, - 0, singleTable.parts[i].start); - - if (rc) return rc; - } - } - - return 0; -} - -int dospReadTable(int fd, struct partitionTable * table) { - int i, rc; - - table->maxNumPartitions = 16; - - for (i = 0; i < table->maxNumPartitions; i++) - table->parts[i].type = -1; - - table->sectorSize = SECTOR_SIZE; - - rc = readNextTable(fd, table, 0, 0, 0); - - if (!rc) { - for (i = 0; i < 16; i++) { - if (table->parts[i].type == -1) continue; - - switch (table->parts[i].type) { - case 0x01: - case 0x04: - case 0x06: - case 0x0b: - case 0x0c: - case 0x0e: - table->parts[i].type = BALKAN_PART_DOS; - break; - - case 0x7: - table->parts[i].type = BALKAN_PART_NTFS; - break; - - case 0x83: - table->parts[i].type = BALKAN_PART_EXT2; - break; - - case 0xfd: - table->parts[i].type = BALKAN_PART_RAID; - break; - - case 0x82: - table->parts[i].type = BALKAN_PART_SWAP; - break; - - default: - table->parts[i].type = BALKAN_PART_OTHER; - break; - } - } - } - - return rc; -} - -#ifdef STANDALONE_TEST - -void main() { - int fd; - int i; - struct partitionTable table; - - fd = open("/dev/hda", O_RDONLY); - - printf("rc= %d\n", dospReadTable(fd, &table)); - - for (i = 0; i < table.maxNumPartitions; i++) { - if (table.parts[i].type == -1) continue; - - printf("%d: %x %d\n", i, table.parts[i].type, table.parts[i].size); - } -} - -#endif diff --git a/balkan/dos.h b/balkan/dos.h deleted file mode 100644 index f5d2809b1..000000000 --- a/balkan/dos.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef H_DOS -#define H_DOS 1 - -int dospReadTable(int fd, struct partitionTable * table); - -#endif diff --git a/balkan/rw.c b/balkan/rw.c deleted file mode 100644 index 663dd03a4..000000000 --- a/balkan/rw.c +++ /dev/null @@ -1,17 +0,0 @@ -#include "balkan.h" -#include "dos.h" - -int balkanReadTable(int fd, struct partitionTable * table) { - int ret; - - /* Try sun labels first: they contain - both magic (tho 16bit) and checksum. */ - ret = sunpReadTable(fd, table); - if (ret != BALKAN_ERROR_BADMAGIC) - return ret; - ret = bsdlReadTable(fd, table); - if (ret != BALKAN_ERROR_BADMAGIC) - return ret; - - return dospReadTable(fd, table); -} diff --git a/balkan/sun.c b/balkan/sun.c deleted file mode 100644 index aaec233e0..000000000 --- a/balkan/sun.c +++ /dev/null @@ -1,136 +0,0 @@ -/* Sun style partitioning */ - -#include "balkan.h" - -#include <fcntl.h> -#include <unistd.h> -#include <sys/types.h> - -#include "byteswap.h" - -struct singlePartitionTable { - unsigned char info[128]; /* Informative text string */ - unsigned char spare0[14]; - struct sun_info { - unsigned char spare1; - unsigned char id; - unsigned char spare2; - unsigned char flags; - } infos[8]; - unsigned char spare1[246]; /* Boot information etc. */ - unsigned short rspeed; /* Disk rotational speed */ - unsigned short pcylcount; /* Physical cylinder count */ - unsigned short sparecyl; /* extra sects per cylinder */ - unsigned char spare2[4]; /* More magic... */ - unsigned short ilfact; /* Interleave factor */ - unsigned short ncyl; /* Data cylinder count */ - unsigned short nacyl; /* Alt. cylinder count */ - unsigned short ntrks; /* Tracks per cylinder */ - unsigned short nsect; /* Sectors per track */ - unsigned char spare3[4]; /* Even more magic... */ - struct sun_partition { - unsigned int start_cylinder; - unsigned int num_sectors; - } parts[8]; - unsigned short magic; /* Magic number */ - unsigned short csum; /* Label xor'd checksum */ -}; - -#define SUN_LABEL_MAGIC 0xDABE -#define SECTOR_SIZE 512 -#define WHOLE_DISK 5 -#define UFS_SUPER_MAGIC 0x00011954 - -int sunpReadTable(int fd, struct partitionTable * table) { - struct singlePartitionTable singleTable; - int i, rc, magic; - unsigned short *p, csum; - - table->maxNumPartitions = 8; - - for (i = 0; i < table->maxNumPartitions; i++) - table->parts[i].type = -1; - - table->sectorSize = SECTOR_SIZE; - - if (lseek(fd, 0, SEEK_SET) < 0) - return BALKAN_ERROR_ERRNO; - - if (read(fd, &singleTable, sizeof(singleTable)) != sizeof(singleTable)) - return BALKAN_ERROR_ERRNO; - - if (be16_to_cpu(singleTable.magic) != SUN_LABEL_MAGIC) - return BALKAN_ERROR_BADMAGIC; - - for (p = (unsigned short *)&singleTable, csum = 0; - p < (unsigned short *)(&singleTable+1);) - csum ^= *p++; - - if (csum) - return BALKAN_ERROR_BADMAGIC; - - for (i = 0; i < 8; i++) { - if (!singleTable.parts[i].num_sectors) continue; - - table->parts[i].startSector = - be32_to_cpu(singleTable.parts[i].start_cylinder) * - be16_to_cpu(singleTable.nsect) * - be16_to_cpu(singleTable.ntrks); - table->parts[i].size = - be32_to_cpu(singleTable.parts[i].num_sectors); - table->parts[i].type = singleTable.infos[i].id; - } - - for (i = 0; i < 8; i++) { - if (table->parts[i].type == -1) continue; - - switch (table->parts[i].type) { - case 0x83: - table->parts[i].type = BALKAN_PART_EXT2; - break; - - case 0x82: - table->parts[i].type = BALKAN_PART_SWAP; - break; - - case 0xfd: - table->parts[i].type = BALKAN_PART_RAID; - break; - - default: - if (table->parts[i].type != WHOLE_DISK && - lseek(fd, (8192 + 0x55c + SECTOR_SIZE * - (off64_t) table->parts[i].startSector), - SEEK_SET) >= 0 && - read(fd, &magic, 4) == 4 && - (magic == UFS_SUPER_MAGIC || - swab32(magic) == UFS_SUPER_MAGIC)) - table->parts[i].type = BALKAN_PART_UFS; - else - table->parts[i].type = BALKAN_PART_OTHER; - break; - } - } - - return 0; -} - -#ifdef STANDALONE_TEST - -void main() { - int fd; - int i; - struct partitionTable table; - - fd = open("/dev/hda", O_RDONLY); - - printf("rc= %d\n", sunpReadTable(fd, &table)); - - for (i = 0; i < table.maxNumPartitions; i++) { - if (table.parts[i].type == -1) continue; - - printf("%d: %x %d\n", i, table.parts[i].type, table.parts[i].size); - } -} - -#endif diff --git a/balkan/sun.h b/balkan/sun.h deleted file mode 100644 index 7c11c173c..000000000 --- a/balkan/sun.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef H_DOS -#define H_DOS 1 - -int sunpReadTable(int fd, struct partitionTable * table); - -#endif diff --git a/balkan/testit b/balkan/testit deleted file mode 100755 index bd1bb0c39..000000000 --- a/balkan/testit +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/python - -import _balkan - -p = _balkan.readTable('/dev/hda') - -for i in range(0, len(p) - 1): - (type, start, size) = p[i] - if (type != -1): - print "i:", i, p[i] |