Mercurial > sos > sos
annotate src/testFS.c @ 52:2de1c2597a60
Modified getFSize so it now returns a value indicating success/failure
Also modified the lookup function so it does not load the file into the cache
author | Jonathan Pevarnek <pevarnj@gmail.com> |
---|---|
date | Sat, 09 Apr 2011 01:28:06 -0400 |
parents | eda059d74100 |
children | 39fcefab46ed |
rev | line source |
---|---|
35
f806eec33c45
Added a very hacked together (and barely functional) start to a filesystem
Jonathan Pevarnek <pevarnj@gmail.com>
parents:
diff
changeset
|
1 #include <std.h> |
51
eda059d74100
Started to librarize (is that a word) the filesystem
Jonathan Pevarnek <pevarnj@gmail.com>
parents:
46
diff
changeset
|
2 #include <fs.h> |
36
3acc1f944c7b
Added more functionality to the filesystem file
Jonathan Pevarnek <pevarnj@gmail.com>
parents:
35
diff
changeset
|
3 |
37
b2bb007e5789
The filesytem stuff actually does something now
Jonathan Pevarnek <pevarnj@gmail.com>
parents:
36
diff
changeset
|
4 void dumpText(char *text, int size) |
b2bb007e5789
The filesytem stuff actually does something now
Jonathan Pevarnek <pevarnj@gmail.com>
parents:
36
diff
changeset
|
5 { |
b2bb007e5789
The filesytem stuff actually does something now
Jonathan Pevarnek <pevarnj@gmail.com>
parents:
36
diff
changeset
|
6 do { |
b2bb007e5789
The filesytem stuff actually does something now
Jonathan Pevarnek <pevarnj@gmail.com>
parents:
36
diff
changeset
|
7 putline(text, (size > CON_LEN)?CON_LEN:size); |
b2bb007e5789
The filesytem stuff actually does something now
Jonathan Pevarnek <pevarnj@gmail.com>
parents:
36
diff
changeset
|
8 size -= CON_LEN; |
b2bb007e5789
The filesytem stuff actually does something now
Jonathan Pevarnek <pevarnj@gmail.com>
parents:
36
diff
changeset
|
9 text += CON_LEN; |
b2bb007e5789
The filesytem stuff actually does something now
Jonathan Pevarnek <pevarnj@gmail.com>
parents:
36
diff
changeset
|
10 } while(size > 0); |
b2bb007e5789
The filesytem stuff actually does something now
Jonathan Pevarnek <pevarnj@gmail.com>
parents:
36
diff
changeset
|
11 } |
b2bb007e5789
The filesytem stuff actually does something now
Jonathan Pevarnek <pevarnj@gmail.com>
parents:
36
diff
changeset
|
12 |
35
f806eec33c45
Added a very hacked together (and barely functional) start to a filesystem
Jonathan Pevarnek <pevarnj@gmail.com>
parents:
diff
changeset
|
13 void start(u64 __memsize) |
f806eec33c45
Added a very hacked together (and barely functional) start to a filesystem
Jonathan Pevarnek <pevarnj@gmail.com>
parents:
diff
changeset
|
14 { |
45 | 15 init_io_int(); |
16 init_console(); | |
51
eda059d74100
Started to librarize (is that a word) the filesystem
Jonathan Pevarnek <pevarnj@gmail.com>
parents:
46
diff
changeset
|
17 malloc_init(__memsize - HEAP_START); |
36
3acc1f944c7b
Added more functionality to the filesystem file
Jonathan Pevarnek <pevarnj@gmail.com>
parents:
35
diff
changeset
|
18 char buffer[256]; |
51
eda059d74100
Started to librarize (is that a word) the filesystem
Jonathan Pevarnek <pevarnj@gmail.com>
parents:
46
diff
changeset
|
19 if(fsInit(0x100)) goto END; |
37
b2bb007e5789
The filesytem stuff actually does something now
Jonathan Pevarnek <pevarnj@gmail.com>
parents:
36
diff
changeset
|
20 |
b2bb007e5789
The filesytem stuff actually does something now
Jonathan Pevarnek <pevarnj@gmail.com>
parents:
36
diff
changeset
|
21 while(1) { |
b2bb007e5789
The filesytem stuff actually does something now
Jonathan Pevarnek <pevarnj@gmail.com>
parents:
36
diff
changeset
|
22 //Prints off the name of each file |
51
eda059d74100
Started to librarize (is that a word) the filesystem
Jonathan Pevarnek <pevarnj@gmail.com>
parents:
46
diff
changeset
|
23 listFiles(); |
37
b2bb007e5789
The filesytem stuff actually does something now
Jonathan Pevarnek <pevarnj@gmail.com>
parents:
36
diff
changeset
|
24 char fname[28]; |
b2bb007e5789
The filesytem stuff actually does something now
Jonathan Pevarnek <pevarnj@gmail.com>
parents:
36
diff
changeset
|
25 sPrint("Please enter the file to read: "); |
b2bb007e5789
The filesytem stuff actually does something now
Jonathan Pevarnek <pevarnj@gmail.com>
parents:
36
diff
changeset
|
26 getFname(fname); |
51
eda059d74100
Started to librarize (is that a word) the filesystem
Jonathan Pevarnek <pevarnj@gmail.com>
parents:
46
diff
changeset
|
27 u32 fid = lookupFile(fname); |
eda059d74100
Started to librarize (is that a word) the filesystem
Jonathan Pevarnek <pevarnj@gmail.com>
parents:
46
diff
changeset
|
28 if(!fid) continue; //if fid is 0, the file was not found |
52
2de1c2597a60
Modified getFSize so it now returns a value indicating success/failure
Jonathan Pevarnek <pevarnj@gmail.com>
parents:
51
diff
changeset
|
29 u32 fileSize; |
2de1c2597a60
Modified getFSize so it now returns a value indicating success/failure
Jonathan Pevarnek <pevarnj@gmail.com>
parents:
51
diff
changeset
|
30 if(getFSize(fid, &fileSize)) continue; |
51
eda059d74100
Started to librarize (is that a word) the filesystem
Jonathan Pevarnek <pevarnj@gmail.com>
parents:
46
diff
changeset
|
31 char *text = malloc(fileSize); |
52
2de1c2597a60
Modified getFSize so it now returns a value indicating success/failure
Jonathan Pevarnek <pevarnj@gmail.com>
parents:
51
diff
changeset
|
32 if(getFData(fid, text)) continue; |
51
eda059d74100
Started to librarize (is that a word) the filesystem
Jonathan Pevarnek <pevarnj@gmail.com>
parents:
46
diff
changeset
|
33 dumpText(text, fileSize); |
eda059d74100
Started to librarize (is that a word) the filesystem
Jonathan Pevarnek <pevarnj@gmail.com>
parents:
46
diff
changeset
|
34 free(text); |
35
f806eec33c45
Added a very hacked together (and barely functional) start to a filesystem
Jonathan Pevarnek <pevarnj@gmail.com>
parents:
diff
changeset
|
35 } |
37
b2bb007e5789
The filesytem stuff actually does something now
Jonathan Pevarnek <pevarnj@gmail.com>
parents:
36
diff
changeset
|
36 |
35
f806eec33c45
Added a very hacked together (and barely functional) start to a filesystem
Jonathan Pevarnek <pevarnj@gmail.com>
parents:
diff
changeset
|
37 END: |
f806eec33c45
Added a very hacked together (and barely functional) start to a filesystem
Jonathan Pevarnek <pevarnj@gmail.com>
parents:
diff
changeset
|
38 sPrint("DONE\n"); |
f806eec33c45
Added a very hacked together (and barely functional) start to a filesystem
Jonathan Pevarnek <pevarnj@gmail.com>
parents:
diff
changeset
|
39 for(;;) { |
f806eec33c45
Added a very hacked together (and barely functional) start to a filesystem
Jonathan Pevarnek <pevarnj@gmail.com>
parents:
diff
changeset
|
40 sGet(buffer, 0); |
f806eec33c45
Added a very hacked together (and barely functional) start to a filesystem
Jonathan Pevarnek <pevarnj@gmail.com>
parents:
diff
changeset
|
41 } |
f806eec33c45
Added a very hacked together (and barely functional) start to a filesystem
Jonathan Pevarnek <pevarnj@gmail.com>
parents:
diff
changeset
|
42 } |