//CSU 480 File System Project
//2/17/06
//Ken Eimer, Brandon Schory, Brian Tobia
//disk.h

#ifndef _DISK_H_
#define _DISK_H_

#include <stdio.h>

// class Disk simulates the disk.
// At the beginning of the disk, there are some control information:
//   two integers: blocksize, numblocks, 
//   and a list of (numblocks) bytes, one indicating whether a block is used.
//   We use 1 to represent used, and 0 to represent non-used.
// Note that here we for simplicity use one byte to indicate whether every block is available,
// while in practice people use one bit.

class Disk {
  FILE* disk;     // the open file pointer
  int blocksize;  // the number of bytes one block has.
  int numblocks;  // the number of blocks that the simulated disk has (not including the bitmap)
  int offset;     // the number of bytes for the control information.
  bool* used;     // the bitmap

 public:
  // constructor and destructor

  Disk( FILE* _disk, int _blocksize, int _numblocks );  // create a new disk simulation file
  Disk( FILE* _disk );  // open an existing disk simulation file
  ~Disk();

  // Read/Write the content of a block to buffer.
  // Return whether successfully read/write.

  bool ReadBlock( int blocknumber, char* buffer );
  bool WriteBlock( int blocknumber, char* buffer );

  // Allocate a new block. Return -1 if not block is available.
  int AllocateBlock();

  // Frees a block.
  void FreeBlock( int blocknumber );
};
   
#endif

