int dev_no; /* Device 0 or 1 for master or slave. */
bool is_ata; /* 1=This device is an ATA disk. */
- disk_sector_no capacity; /* Capacity in sectors (if is_ata is true). */
+ disk_sector_t capacity; /* Capacity in sectors (if is_ata is true). */
};
/* An ATA channel (aka controller).
static bool check_device_type (struct disk *);
static void identify_ata_device (struct disk *);
-static void select_sector (struct disk *, disk_sector_no);
+static void select_sector (struct disk *, disk_sector_t);
static void issue_pio_command (struct channel *, uint8_t command);
static void input_sector (struct channel *, void *);
static void output_sector (struct channel *, const void *);
/* Returns the size of disk D, measured in DISK_SECTOR_SIZE-byte
sectors. */
-disk_sector_no
+disk_sector_t
disk_size (struct disk *d)
{
ASSERT (d != NULL);
/* Reads sector SEC_NO from disk D into BUFFER, which must have
room for DISK_SECTOR_SIZE bytes. */
void
-disk_read (struct disk *d, disk_sector_no sec_no, void *buffer)
+disk_read (struct disk *d, disk_sector_t sec_no, void *buffer)
{
struct channel *c;
DISK_SECTOR_SIZE bytes. Returns after the disk has
acknowledged receiving the data. */
void
-disk_write (struct disk *d, disk_sector_no sec_no, const void *buffer)
+disk_write (struct disk *d, disk_sector_t sec_no, const void *buffer)
{
struct channel *c;
writes SEC_NO to the disk's sector selection registers. (We
use LBA mode.) */
static void
-select_sector (struct disk *d, disk_sector_no sec_no)
+select_sector (struct disk *d, disk_sector_t sec_no)
{
struct channel *c = d->channel;
#include <inttypes.h>
#include <stdint.h>
+/* Size of a disk sector in bytes. */
#define DISK_SECTOR_SIZE 512
-typedef uint32_t disk_sector_no;
-#define PRDSNu PRIu32 /* For use with printk(). */
+/* Index of a disk sector within a disk.
+ Good enough for disks up to 2 TB. */
+typedef uint32_t disk_sector_t;
+
+/* Format specifier for printk(), e.g.:
+ printk ("sector=%"PRDSNu"\n", sector); */
+#define PRDSNu PRIu32
void disk_init (void);
struct disk *disk_get (int chan_no, int dev_no);
-disk_sector_no disk_size (struct disk *);
-void disk_read (struct disk *, disk_sector_no, void *);
-void disk_write (struct disk *, disk_sector_no, const void *);
+disk_sector_t disk_size (struct disk *);
+void disk_read (struct disk *, disk_sector_t, void *);
+void disk_write (struct disk *, disk_sector_t, const void *);
#endif /* disk.h */
bool
dir_lookup (const struct dir *d, const char *name,
- disk_sector_no *filehdr_sector)
+ disk_sector_t *filehdr_sector)
{
const struct dir_entry *e;
}
bool
-dir_add (struct dir *d, const char *name, disk_sector_no filehdr_sector)
+dir_add (struct dir *d, const char *name, disk_sector_t filehdr_sector)
{
size_t i;
{
bool in_use;
char name[FILENAME_LEN_MAX + 1];
- disk_sector_no filehdr_sector;
+ disk_sector_t filehdr_sector;
};
struct file;
void dir_destroy (struct dir *);
void dir_read (struct dir *, struct file *);
void dir_write (struct dir *, struct file *);
-bool dir_lookup (const struct dir *, const char *name, disk_sector_no *);
-bool dir_add (struct dir *, const char *name, disk_sector_no);
+bool dir_lookup (const struct dir *, const char *name, disk_sector_t *);
+bool dir_add (struct dir *, const char *name, disk_sector_t);
bool dir_remove (struct dir *, const char *name);
void dir_list (const struct dir *);
void dir_dump (const struct dir *);
#include "filesys.h"
bool
-file_open (struct file *file, disk_sector_no hdr_sector)
+file_open (struct file *file, disk_sector_t hdr_sector)
{
file->hdr = filehdr_read (hdr_sector);
file->bounce = malloc (DISK_SECTOR_SIZE);
off_t pos;
};
-bool file_open (struct file *, disk_sector_no);
+bool file_open (struct file *, disk_sector_t);
void file_close (struct file *);
off_t file_read (struct file *, void *, off_t);
off_t file_read_at (struct file *, void *, off_t size, off_t start);
}
struct filehdr *
-filehdr_read (disk_sector_no filehdr_sector)
+filehdr_read (disk_sector_t filehdr_sector)
{
struct filehdr *h = calloc (1, sizeof *h);
if (h == NULL)
}
void
-filehdr_write (const struct filehdr *h, disk_sector_no filehdr_sector)
+filehdr_write (const struct filehdr *h, disk_sector_t filehdr_sector)
{
ASSERT (h != NULL);
ASSERT (sizeof *h == DISK_SECTOR_SIZE);
free (h);
}
-disk_sector_no
+disk_sector_t
filehdr_byte_to_sector (const struct filehdr *h, off_t pos)
{
size_t idx;
ASSERT (h != NULL);
idx = pos / DISK_SECTOR_SIZE;
- return idx < h->sector_cnt ? h->sectors[idx] : (disk_sector_no) -1;
+ return idx < h->sector_cnt ? h->sectors[idx] : (disk_sector_t) -1;
}
off_t
#include "off_t.h"
#define DIRECT_CNT ((DISK_SECTOR_SIZE - sizeof (off_t) * 2) \
- / sizeof (disk_sector_no))
+ / sizeof (disk_sector_t))
struct filehdr
{
off_t length;
size_t sector_cnt;
- disk_sector_no sectors[DIRECT_CNT];
+ disk_sector_t sectors[DIRECT_CNT];
};
struct bitmap;
struct filehdr *filehdr_allocate (struct bitmap *, off_t length);
void filehdr_deallocate (struct filehdr *, struct bitmap *);
-struct filehdr *filehdr_read (disk_sector_no);
-void filehdr_write (const struct filehdr *, disk_sector_no);
+struct filehdr *filehdr_read (disk_sector_t);
+void filehdr_write (const struct filehdr *, disk_sector_t);
void filehdr_destroy (struct filehdr *);
-disk_sector_no filehdr_byte_to_sector (const struct filehdr *, off_t);
+disk_sector_t filehdr_byte_to_sector (const struct filehdr *, off_t);
off_t filehdr_length (const struct filehdr *);
void filehdr_print (const struct filehdr *);
{
struct dir dir;
struct bitmap free_map;
- disk_sector_no hdr_sector;
+ disk_sector_t hdr_sector;
struct filehdr *filehdr;
bool success = false;
filesys_open (const char *name, struct file *file)
{
struct dir dir;
- disk_sector_no hdr_sector;
+ disk_sector_t hdr_sector;
bool success = false;
if (!dir_init (&dir, NUM_DIR_ENTRIES))
filesys_remove (const char *name)
{
struct dir dir;
- disk_sector_no hdr_sector;
+ disk_sector_t hdr_sector;
struct filehdr *filehdr;
struct bitmap free_map;
bool success = false;
{
struct disk *src;
struct file dst;
- disk_sector_no sector;
+ disk_sector_t sector;
void *buffer;
/* Open source disk. */