partition table

Allan Lee <[email protected]> Mon, 24 May 2004 12:04:33 -0400
Newsgroups gmane.linux.arklinux.devel
Message-ID <[email protected]>
This is the code that I have that I'm getting the compile errors
itionTable.o(.text+0x16c): In function 
`PartitionTable::PartitionTable[in-charge](std::basic_string<char, 
std::char_traits<char>, std::allocator<char> > const&)':
/home/arklinux/newsource/test/PartitionTable.cpp:43: undefined reference 
to `VTT for PartitionTable'
PartitionTable.o(.text+0x188):/home/arklinux/newsource/test/PartitionTable.cpp:43: 
undefined reference to `vtable for PartitionTable'
PartitionTable.o(.text+0x198):/home/arklinux/newsource/test/PartitionTable.cpp:43: 
undefined reference to `vtable for PartitionTable'
PartitionTable.o(.text+0x24b):/home/arklinux/newsource/test/PartitionTable.cpp:46: 
undefined reference to `VTT for PartitionTable'
collect2: ld returned 1 exit status
make: *** [main] Error 1
PartitionTable.h (text/plain, 6.1 KB)
#include <string.h>
#include <vector>
#include <list>
#include <map>
#include <set>

#include <pclasses/pexception.h>
#include <System/StorageDevice.h>

#define SIZE(a)	(int) (sizeof(a)/sizeof(a[0]))
#define PHYSICAL_PARTITION_LIMIT 4

#define EMPTY_PARTITION		0
#define EXTENDED_PARTITION	5
#define WIN98_EXTENDED		0x0f
#define DM6_AUX1PARTITION	0x51
#define DM6_AUX3PARTITION	0x53
#define DM6_PARTITION		0x54
#define EZD_PARTITION		0x55
#define LINUX_SWAP              0x82
#define LINUX_NATIVE	        0x83
#define LINUX_EXTENDED		0x85
#define BSD_PARTITION		0xa5
#define NETBSD_PARTITION	0xa9

#define DOS_TYPE	0
#define BSD_TYPE	1
#define BSD_DISKMAGIC   (0x82564557UL)
#define BSD_MAXPARTITIONS       16
#define BSD_FS_UNUSED	   0

#define MAKE_VERSION(p,q,r)     (65536*(p) + 256*(q) + (r))
#define PROC_PARTITIONS	"/proc/partitions"

#define FSTAB_FILE "/etc/fstab"
#define FSTAB_BACKUP "/tmp/fstab"
#define FSTAB_ENTRIES 100

using namespace std;
using namespace System;
struct sectorStruct {
    struct sectorStruct *next;
    unsigned long sectorNumber;
    char data[512];
};

/*
 * We consider several geometries for a disk:
 * B - the BIOS geometry, gotten from the kernel via HDIO_GETGEO
 * F - the fileDescriptorisk geometry
 * U - the user-specified geometry
 *
 * 0 means unspecified / unknown
 * used to get disk size will it be needed?
 * */
struct diskGeometryStruct {
	unsigned long cylinderSize;
	unsigned long heads, sectors, cylinders;
	unsigned long start;
};

typedef struct { unsigned char h,s,c; } chs; /* has some c bits in s */

typedef struct { unsigned long h,s,c; } longchs;

//this is data that will be part of partitionDescStruct
struct partitionStruct {
    unsigned char bootable;		/* 0 or 0x80 */
    chs begin_chs;
    unsigned char systemType;
    chs end_chs;
    unsigned int startSector;	/* starting sector counting from 0 */
    unsigned int numberSectors;		/* nr of sectors in partition */
};


/* Roughly speaking, Linux doesn't use any of the above fields except
   for partitionStruct type, start sector and number of sectors. (However,
   see also linux/drivers/scsi/fileDescriptoromain.c.)
   The only way partition type is used (in the kernel) is the comparison
   for equality with EXTENDED_PARTITION (and these Disk Manager types). */

struct partitionDescStruct{
    unsigned long start;
    unsigned long size;
    unsigned long sector, offset; /* disk location of this info */
    char linuxName[100];
    struct partitionStruct p;
    struct partitionDescStruct *ep;	  /* extended partition containing this one */
    int ptype;
} ;
// this is actually the partition table
//
struct diskDescription {
    struct partitionDescStruct partitions[512]; // should probably be replaced by a vector
    int partitionNumber; 	//number of partitions
};

typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
struct  bsdPartitionStruct {         /* the partition table */
                u32   p_size;         /* number of sectors in partition */
                u32   p_offset;       /* starting sector */
                u32   p_fsize;        /* filesystem basic fragment size */
                u8    p_fstype;       /* filesystem type, see below */
                u8    p_frag;         /* filesystem fragments per block */
                u16   p_cpg;          /* filesystem cylinders per group */
     };
struct bsdDiskLabel {
	u32	d_magic;
	char	d_junk1[4];
	char    d_typename[16];
	char    d_packname[16];
	char	d_junk2[92];
	u32	d_magic2;
	char	d_junk3[2];
	u16	d_npartitions;          /* number of partitions in following */
	char	d_junk4[8];
     struct  bsdPartitionStruct d_partitions[BSD_MAXPARTITIONS];      /* actually may be more */
};

class _PartitionTableEntry{
	public:
	unsigned long start;
	unsigned long size;
	unsigned long sector;
	unsigned long offset; /* disk location of this info */
	char linuxName[100];
	struct partitionStruct p;
	struct partitionDescStruct *ep;	  /* extended partition containing this one */
	int ptype;
	_PartitionTableEntry operator=(vector<_PartitionTableEntry>::iterator a){ 
		start=a->start;
		size=a->size;
		sector=a->sector;
		offset=a->offset;
		strncpy(linuxName,a->linuxName,sizeof(linuxName));
		p=a->p;
		ep=a->ep;
		ptype=a->ptype;
		return *this;
	};
	_PartitionTableEntry operator=(_PartitionTableEntry a){ 
		start=a.start;
		size=a.size;
		sector=a.sector;
		offset=a.offset;
		strncpy(linuxName,a.linuxName,sizeof(linuxName));
		p=a.p;
		ep=a.ep;
		ptype=a.ptype;
		return *this;
	};

};

class PartitionTable : public StorageDevice {
	private:
	vector <_PartitionTableEntry> partitionTable;
	public:

	struct diskGeometryStruct BiosGeometry, F, UserGeometry;


	PartitionTable::PartitionTable(const std::string &device);
	PartitionTable::~PartitionTable() throw ();
	struct sectorStruct *readSector(unsigned long sectorNumber) throw (P::IOError); 			// used by findMsdosSignature
	struct diskGeometryStruct determineDiskGeometry(int fileDescriptor);		// uses ioctl to get size, heads, sectors etc
	int checkBsdPartition(char *device, partitionDescStruct *pd, diskDescription *dd);		// checks to see if it's a bsd partition using data from checkMsdosPartition
	int checkExtendedPartition(char *device, partitionDescStruct *pd, diskDescription *dd);		// ExtendedPartition if the systemType is extended
	int checkMsdosPartition(char *device, diskDescription *dd);		// entry into partition types MSDOS and others, otherwise it's unknown!!
	int determinePartitionType (char *device, partitionDescStruct pd, diskDescription dd);
	int findMsdosSignature(sectorStruct *s);
	vector<_PartitionTableEntry>::iterator begin() { return partitionTable.begin();};
	vector<_PartitionTableEntry>::iterator end() { return partitionTable.end();};
	_PartitionTableEntry at(int a) { return partitionTable.at(a);};
	void clear() { return partitionTable.clear();};
	int size () { return partitionTable.size();};
	bool empty() { return partitionTable.empty();};
	vector<_PartitionTableEntry>::iterator insert(vector<_PartitionTableEntry>::iterator location, _PartitionTableEntry value) { return partitionTable.insert(location,value);};
	vector<_PartitionTableEntry>::iterator erase(vector<_PartitionTableEntry>::iterator a) { return partitionTable.erase(a);};
};