[prev] 32 [next]

Single-file Disk Manager

Simple disk manager for a single-file database:

// Disk Manager data/functions
#define PAGESIZE 2048   // bytes per page
typedef int PageId;     // PageId is block index

typedef struct DBdescriptor {
   char *dbname;     // copy of database name
   int   fd;         // the database file
   SpaceTable map;   // map of free/used areas 
   NameTable names;  // map names to areas + sizes
   ...
} *DB;

typedef struct RelDescriptor {
   char *relname;    // copy of table name
   int   start;      // page index of start of table data
   int   npages;     // number of pages of table data
   ...
} *Reln;