-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathiso9660.c
79 lines (64 loc) · 1.81 KB
/
iso9660.c
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "DiskFile.h"
#include "iso9660.h"
#include "kernel.h"
DiskFile g_files[256];
void *sector(void *baseptr, unsigned int sectornum)
{
u8 *cdimg = baseptr;
return &cdimg[sectornum * 2048];
}
const DirectoryRecord *get_first_entry(void *baseptr)
{
const PrimaryVolumeDescriptor *pvd = sector(baseptr, 16);
const DirectoryRecord *rootrecord = &pvd->root_directory_record;
assert(rootrecord->record_len == sizeof(DirectoryRecord) + rootrecord->id_len);
const DirectoryRecord *entry = sector(baseptr, rootrecord->data_sector);
return entry;
}
DiskFile * iso9660_enumfiles(void *baseptr)
{
const DirectoryRecord *entry = get_first_entry(baseptr);
int i=0;
do {
DiskFile *fp = &g_files[i++];
strncpy(fp->filename, entry->id, entry->id_len);
fp->data = sector(baseptr, entry->data_sector);
fp->length = entry->data_len;
printf("CD file: %s at 0x%x (%u bytes)\n",
fp->filename, fp->data, fp->length);
entry = NEXT_DIR_ENTRY(entry);
} while (entry->record_len > 0);
g_files[i].filename[0] = 0;
g_files[i].data = NULL;
g_files[i].length = 0;
return g_files;
}
DiskFile *
iso9660_fopen_r(void *baseptr, const char *filename)
{
DiskFile *files = iso9660_enumfiles(baseptr);
int i=0;
for ( ; files[i].data; ++i)
{
DiskFile *df = &files[i];
if (strncmp(df->filename, filename, sizeof(filename)) == 0)
{
printf("found file '%s'\n", df->filename);
return df;
}
else
{
printf("skipping file '%s'\n", df->filename);
}
}
return NULL;
}
DiskFile *
iso9660_fopen_w(void *baseptr, const char *filename)
{
return NULL;
}