CS350 COS
COS
Loading...
Searching...
No Matches
disk.c File Reference
#include <stdbool.h>
#include <stdint.h>
#include <sys/kassert.h>
#include <sys/kdebug.h>
#include <sys/queue.h>
#include <sys/sga.h>
#include <sys/disk.h>
#include <sys/spinlock.h>
Include dependency graph for disk.c:

Go to the source code of this file.

Functions

 LIST_HEAD (DiskList, Disk)
 
void Disk_RemoveDisk (Disk *disk)
 
DiskDisk_GetByID (uint64_t ctrlNo, uint64_t diskNo)
 
int Disk_Read (Disk *disk, void *buf, SGArray *sga, DiskCB cb, void *arg)
 
int Disk_Write (Disk *disk, void *buf, SGArray *sga, DiskCB cb, void *arg)
 
int Disk_Flush (Disk *disk, void *buf, SGArray *sga, DiskCB cb, void *arg)
 
static void Debug_Disks (int argc, const char *argv[])
 
 REGISTER_DBGCMD (disks, "List disks", Debug_Disks)
 
static void Debug_DumpDisk (int argc, const char *argv[])
 
 REGISTER_DBGCMD (dumpdisk, "Dump disk sector", Debug_DumpDisk)
 

Function Documentation

◆ Debug_Disks()

static void Debug_Disks ( int  argc,
const char *  argv[] 
)
static

Definition at line 62 of file disk.c.

63{
64 Disk *d;
65
66 LIST_FOREACH(d, &diskList, entries) {
67 kprintf("disk%lld.%lld: %lld Sectors\n",
68 d->ctrlNo, d->diskNo, d->sectorCount);
69 }
70}
int kprintf(const char *fmt,...)
Definition: printf.c:210
#define LIST_FOREACH(var, head, field)
Definition: queue.h:410
Definition: disk.h:11
uint64_t ctrlNo
Definition: disk.h:13
uint64_t sectorCount
Definition: disk.h:16
uint64_t diskNo
Definition: disk.h:14
Here is the call graph for this function:

◆ Debug_DumpDisk()

static void Debug_DumpDisk ( int  argc,
const char *  argv[] 
)
static

Definition at line 75 of file disk.c.

76{
77 uint64_t ctrlNo, diskNo;
78 uint64_t sector;
79 char buf[512];
80 SGArray sga;
81
82 if (argc != 4) {
83 kprintf("dumpdisk requires 4 arguments!\n");
84 return;
85 }
86
87 ctrlNo = Debug_StrToInt(argv[1]);
88 diskNo = Debug_StrToInt(argv[2]);
89 sector = Debug_StrToInt(argv[3]);
90
91 Disk *d = Disk_GetByID(ctrlNo, diskNo);
92
93 sga.len = 1;
94 sga.entries[0].offset = sector;
95 sga.entries[0].length = 512;
96
97 kprintf("Reading Sector %lld from disk%lld.%lld\n", sector, ctrlNo, diskNo);
98
99 Disk_Read(d, &buf, &sga, NULL, NULL);
100 Debug_PrintHex((const char *)&buf, 512, 0, 512);
101}
int Disk_Read(Disk *disk, void *buf, SGArray *sga, DiskCB cb, void *arg)
Definition: disk.c:44
Disk * Disk_GetByID(uint64_t ctrlNo, uint64_t diskNo)
Definition: disk.c:31
static char buf[4096]
Definition: ethdump.c:10
uint64_t Debug_StrToInt(const char *s)
Definition: debug.c:124
void Debug_PrintHex(const char *data, size_t length, off_t off, size_t limit)
Definition: debug.c:30
uint64_t length
Definition: sga.h:10
SGEntry entries[SGARRAY_MAX_ENTRIES]
Definition: sga.h:16
uint32_t len
Definition: sga.h:15
uint64_t offset
Definition: sga.h:9
Definition: sga.h:14
#define NULL
Definition: stddef.h:6
unsigned long uint64_t
Definition: types.h:13
Here is the call graph for this function:

◆ Disk_Flush()

int Disk_Flush ( Disk disk,
void *  buf,
SGArray sga,
DiskCB  cb,
void *  arg 
)

Definition at line 56 of file disk.c.

57{
58 return disk->flush(disk, buf, sga, cb, arg);
59}
int(* flush)(Disk *, void *, SGArray *, DiskCB, void *)
Definition: disk.h:20

◆ Disk_GetByID()

Disk * Disk_GetByID ( uint64_t  ctrlNo,
uint64_t  diskNo 
)

Definition at line 31 of file disk.c.

32{
33 Disk *d;
34
35 LIST_FOREACH(d, &diskList, entries) {
36 if (d->ctrlNo == ctrlNo && d->diskNo == diskNo)
37 return d;
38 }
39
40 return NULL;
41}
Here is the caller graph for this function:

◆ Disk_Read()

int Disk_Read ( Disk disk,
void *  buf,
SGArray sga,
DiskCB  cb,
void *  arg 
)

Definition at line 44 of file disk.c.

45{
46 return disk->read(disk, buf, sga, cb, arg);
47}
int(* read)(Disk *, void *, SGArray *, DiskCB, void *)
Definition: disk.h:18
Here is the caller graph for this function:

◆ Disk_RemoveDisk()

void Disk_RemoveDisk ( Disk disk)

Definition at line 25 of file disk.c.

26{
27 LIST_REMOVE(disk, entries);
28}
#define LIST_REMOVE(elm, field)
Definition: queue.h:465

◆ Disk_Write()

int Disk_Write ( Disk disk,
void *  buf,
SGArray sga,
DiskCB  cb,
void *  arg 
)

Definition at line 50 of file disk.c.

51{
52 return disk->write(disk, buf, sga, cb, arg);
53}
int(* write)(Disk *, void *, SGArray *, DiskCB, void *)
Definition: disk.h:19
Here is the caller graph for this function:

◆ LIST_HEAD()

LIST_HEAD ( DiskList  ,
Disk   
)

Definition at line 16 of file disk.c.

20{
21 LIST_INSERT_HEAD(&diskList, disk, entries);
22}
#define LIST_INSERT_HEAD(head, elm, field)
Definition: queue.h:451

◆ REGISTER_DBGCMD() [1/2]

REGISTER_DBGCMD ( disks  ,
"List disks"  ,
Debug_Disks   
)

◆ REGISTER_DBGCMD() [2/2]

REGISTER_DBGCMD ( dumpdisk  ,
"Dump disk sector"  ,
Debug_DumpDisk   
)