[prev] 37 [next]

Single-file Disk Manager (cont)

// managing contents of mapping table is complex
// assume a list of (offset,length,status) tuples

// allocate n new pages at end of file
PageId allocate_pages(int n) {
   int endfile = lseek(db->fd, 0, SEEK_END);
   addNewEntry(db->map, endfile, n);
   // note that file itself is not changed
}
// drop n pages starting from p
void deallocate_pages(PageId p, int n) {
   markUnused(db->map, p, n);
   // note that file itself is not changed
}