summaryrefslogtreecommitdiff
path: root/firmware/test/fat/main.c
diff options
context:
space:
mode:
authorBjörn Stenberg <bjorn@haxx.se>2002-10-20 22:50:58 +0000
committerBjörn Stenberg <bjorn@haxx.se>2002-10-20 22:50:58 +0000
commitb7b48fea02fdac51071eef084a980cee4bcba221 (patch)
treeca2e1f55fd67cda98b395eb0259d14426865af4f /firmware/test/fat/main.c
parent1df1e51a030e3a7c87f7e882f67b3c7588353300 (diff)
downloadrockbox-b7b48fea02fdac51071eef084a980cee4bcba221.tar.gz
rockbox-b7b48fea02fdac51071eef084a980cee4bcba221.zip
Snapshot of file writing code. Bugs remain. Only short names are supported yet.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2726 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/test/fat/main.c')
-rw-r--r--firmware/test/fat/main.c52
1 files changed, 47 insertions, 5 deletions
diff --git a/firmware/test/fat/main.c b/firmware/test/fat/main.c
index 4a11e0a08a..1b9fd22183 100644
--- a/firmware/test/fat/main.c
+++ b/firmware/test/fat/main.c
@@ -1,6 +1,7 @@
1#include <stdio.h> 1#include <stdio.h>
2#include <stdlib.h> 2#include <stdlib.h>
3#include <string.h> 3#include <string.h>
4#include <stdarg.h>
4#include "fat.h" 5#include "fat.h"
5#include "debug.h" 6#include "debug.h"
6#include "disk.h" 7#include "disk.h"
@@ -14,6 +15,15 @@ void dbg_dump_sector(int sec);
14void dbg_dump_buffer(unsigned char *buf); 15void dbg_dump_buffer(unsigned char *buf);
15void dbg_console(void); 16void dbg_console(void);
16 17
18void panicf( char *fmt, ...)
19{
20 va_list ap;
21 va_start( ap, fmt );
22 vprintf( fmt, ap );
23 va_end( ap );
24 exit(0);
25}
26
17void dbg_dump_sector(int sec) 27void dbg_dump_sector(int sec)
18{ 28{
19 unsigned char buf[512]; 29 unsigned char buf[512];
@@ -75,14 +85,16 @@ void dbg_dir(char* currdir)
75void dbg_mkfile(char* name) 85void dbg_mkfile(char* name)
76{ 86{
77 char* text = "Detta är en dummy-text\n"; 87 char* text = "Detta är en dummy-text\n";
88 int i;
78 int fd = open(name,O_WRONLY); 89 int fd = open(name,O_WRONLY);
79 if (fd<0) { 90 if (fd<0) {
80 DEBUGF("Failed creating file\n"); 91 DEBUGF("Failed creating file\n");
81 return; 92 return;
82 } 93 }
83 if (write(fd, text, strlen(text)) < 0) 94 for (i=0;i<200;i++)
84 DEBUGF("Failed writing data\n"); 95 if (write(fd, text, strlen(text)) < 0)
85 96 DEBUGF("Failed writing data\n");
97
86 close(fd); 98 close(fd);
87} 99}
88 100
@@ -168,6 +180,33 @@ void dbg_tail(char* name)
168 close(fd); 180 close(fd);
169} 181}
170 182
183void dbg_head(char* name)
184{
185 unsigned char buf[SECTOR_SIZE*5];
186 int fd,rc;
187
188 fd = open(name,O_RDONLY);
189 if (fd<0)
190 return;
191 DEBUGF("Got file descriptor %d\n",fd);
192
193 rc = read(fd, buf, SECTOR_SIZE);
194 if( rc > 0 )
195 {
196 buf[rc]=0;
197 printf("%d: %s\n", strlen(buf), buf);
198 }
199 else if ( rc == 0 ) {
200 DEBUGF("EOF\n");
201 }
202 else
203 {
204 DEBUGF("Failed reading file: %d\n",rc);
205 }
206
207 close(fd);
208}
209
171char current_directory[256] = "\\"; 210char current_directory[256] = "\\";
172int last_secnum = 0; 211int last_secnum = 0;
173 212
@@ -284,9 +323,12 @@ int main(int argc, char *argv[])
284 } 323 }
285 324
286 //dbg_console(); 325 //dbg_console();
287 //dbg_tail("/fat.h");
288 //dbg_dir("/"); 326 //dbg_dir("/");
289 dbg_mkfile("/apa.txt"); 327#if 1
328 dbg_head("/bepa.txt");
329#else
330 dbg_mkfile("/bepa.txt");
331#endif
290 dbg_dir("/"); 332 dbg_dir("/");
291 333
292 return 0; 334 return 0;