diff options
author | Matt Wilson <msw@redhat.com> | 1999-09-11 15:43:56 +0000 |
---|---|---|
committer | Matt Wilson <msw@redhat.com> | 1999-09-11 15:43:56 +0000 |
commit | 67b133020bb2a5ba90005ac6da55a0d5d1424799 (patch) | |
tree | 68eae41b81639206b3de7dc12b4a3c1335144048 /balkan | |
parent | e0e974477f07b1eb16c7553528b3f64d5d520ce5 (diff) | |
download | anaconda-67b133020bb2a5ba90005ac6da55a0d5d1424799.tar.gz anaconda-67b133020bb2a5ba90005ac6da55a0d5d1424799.tar.xz anaconda-67b133020bb2a5ba90005ac6da55a0d5d1424799.zip |
patch from jj, misc fixesbefore.po.msgmerge
Diffstat (limited to 'balkan')
-rw-r--r-- | balkan/Makefile | 4 | ||||
-rw-r--r-- | balkan/balkan.h | 1 | ||||
-rw-r--r-- | balkan/byteswap.h | 59 | ||||
-rw-r--r-- | balkan/dos.c | 7 | ||||
-rw-r--r-- | balkan/rw.c | 8 | ||||
-rw-r--r-- | balkan/sun.c | 132 | ||||
-rw-r--r-- | balkan/sun.h | 6 |
7 files changed, 213 insertions, 4 deletions
diff --git a/balkan/Makefile b/balkan/Makefile index 0aec850e3..9ed6826d8 100644 --- a/balkan/Makefile +++ b/balkan/Makefile @@ -1,6 +1,6 @@ PYTHONLIBDIR = $(DESTDIR)/usr/lib/python1.5/site-packages -OBJECTS = rw.o dos.o +OBJECTS = rw.o dos.o sun.o TARGET = libbalkan.a @@ -19,5 +19,7 @@ clean: dos.o: dos.h +sun.o: sun.h + install: all cp _balkanmodule.so $(PYTHONLIBDIR) diff --git a/balkan/balkan.h b/balkan/balkan.h index e80094ede..6afa061c0 100644 --- a/balkan/balkan.h +++ b/balkan/balkan.h @@ -10,6 +10,7 @@ #define BALKAN_PART_OTHER 3 #define BALKAN_PART_NTFS 4 #define BALKAN_PART_SWAP 5 +#define BALKAN_PART_UFS 6 struct partition { long startSector; diff --git a/balkan/byteswap.h b/balkan/byteswap.h new file mode 100644 index 000000000..d271146aa --- /dev/null +++ b/balkan/byteswap.h @@ -0,0 +1,59 @@ +#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 index a0534966e..e02163790 100644 --- a/balkan/dos.c +++ b/balkan/dos.c @@ -4,6 +4,7 @@ #include <unistd.h> #include "balkan.h" +#include "byteswap.h" struct singlePartition { unsigned char active; @@ -79,9 +80,9 @@ static int readNextTable(int fd, struct partitionTable * table, int nextNum, else thisPart = nextNum++; - table->parts[thisPart].startSector = singleTable.parts[i].start + - sectorOffset; - table->parts[thisPart].size = singleTable.parts[i].size; + 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; } diff --git a/balkan/rw.c b/balkan/rw.c index f715952e3..bd7278459 100644 --- a/balkan/rw.c +++ b/balkan/rw.c @@ -2,5 +2,13 @@ #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; + return dospReadTable(fd, table); } diff --git a/balkan/sun.c b/balkan/sun.c new file mode 100644 index 000000000..67e30eb56 --- /dev/null +++ b/balkan/sun.c @@ -0,0 +1,132 @@ +/* Sun style partitioning */ + +#include <fcntl.h> +#include <unistd.h> + +#include "balkan.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 + +long long llseek(int fd, long long offset, int whence); + +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; + + default: + if (table->parts[i].type != WHOLE_DISK && + llseek(fd, (8192 + 0x55c + SECTOR_SIZE * + (unsigned long long)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 new file mode 100644 index 000000000..5d7bdcb5e --- /dev/null +++ b/balkan/sun.h @@ -0,0 +1,6 @@ +#ifndef H_DOS +#define H_DOS 1 + +int sunpReadTable(int fd, struct partitionTable * table); + +#endif; |