summaryrefslogtreecommitdiffstats
path: root/util.h
blob: 65166f422ae692ed3a7ffafa7287ddb17c8c176c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef UTIL_H
#define UTIL_H

#include <stdlib.h>
#include <stdio.h>

struct diskfmt {
  const char *name;
  unsigned char c, h, s;
  int sectors;			/* Total sectors (max 1911 clusters) */
  unsigned int cluster_shift;	/* Size of a cluster, log2 */
  int syssec;			/* First system sector (bitmap) */
  int dirsec[2];		/* First directory sector (main, backup) */
  int dirsecs;			/* Number of directory sectors */
};

struct disk;

struct directory {
  struct disk *disk;		/* This directory belongs to... */
  unsigned char *bitmap;	/* Directory entry "bitmap" area */
  unsigned char *dirsec;	/* Actual directory sector */
  unsigned int block;		/* UFD block pointer (0 for MFD) */
};

struct disk {
  const struct diskfmt *fmt;	/* Format descriptor */
  unsigned char *image;		/* Image of the disk */
  unsigned char *bitmap;	/* Pointer to the bitmap inside the disk */
  struct directory mfd;		/* MFD directory descriptor */
};

const struct diskfmt *get_format(const char *);
void show_formats(FILE *);
struct disk *allocate_disk(const struct diskfmt *fmt);

extern const char *program;
void *xmalloc(size_t);

static inline void mark_used(struct disk *disk, unsigned int cluster)
{
  disk->bitmap[cluster >> 3] |= (0x80 >> (cluster & 7));
}

static inline int is_used(struct disk *disk, unsigned int cluster)
{
  return !!(disk->bitmap[cluster >> 3] & (0x80 >> (cluster & 7)));
}


#endif /* UTIL_H */