summaryrefslogtreecommitdiff
path: root/firmware/test
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
parent1df1e51a030e3a7c87f7e882f67b3c7588353300 (diff)
downloadrockbox-b7b48fea02fdac51071eef084a980cee4bcba221.zip
rockbox-b7b48fea02fdac51071eef084a980cee4bcba221.tar.gz
rockbox-b7b48fea02fdac51071eef084a980cee4bcba221.tar.bz2
rockbox-b7b48fea02fdac51071eef084a980cee4bcba221.tar.xz
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')
-rw-r--r--firmware/test/fat/README25
-rw-r--r--firmware/test/fat/ata-sim.c7
-rw-r--r--firmware/test/fat/main.c52
3 files changed, 79 insertions, 5 deletions
diff --git a/firmware/test/fat/README b/firmware/test/fat/README
new file mode 100644
index 0000000..76141c0
--- /dev/null
+++ b/firmware/test/fat/README
@@ -0,0 +1,25 @@
+This code is for testing the Rockbox fat code on a dummy drive image file.
+
+Dummy image
+-----------
+Here's how to create a 1 gig dummy drive image in linux:
+
+# dd if=/dev/hda of=disk.img bs=1M count=1024
+
+You can then format disk.img as a FAT32 partition:
+
+# mkdosfs -F 32 disk.img
+
+To mount the image, your linux kernel must include the loopback device:
+
+# mount -o loop disk.img /mnt/image
+
+Now copy some test data to the disk, umount it and start testing.
+
+
+Test code
+---------
+The files in this dir build the 'fat' program. It will read 'disk.img' and
+treat is as a real disk, thanks to the ata-sim.c module.
+
+Modify the main.c source code to make it perform the tests you want.
diff --git a/firmware/test/fat/ata-sim.c b/firmware/test/fat/ata-sim.c
index ab7266d..a37fabc 100644
--- a/firmware/test/fat/ata-sim.c
+++ b/firmware/test/fat/ata-sim.c
@@ -24,6 +24,13 @@ int ata_read_sectors(unsigned long start, unsigned char count, void* buf)
int ata_write_sectors(unsigned long start, unsigned char count, void* buf)
{
+ DEBUGF("Writing block 0x%lx\n",start);
+
+ if (start == 0) {
+ DEBUGF("Holy crap! You're writing on sector 0!\n");
+ exit(0);
+ }
+
if(fseek(file,start*BLOCK_SIZE,SEEK_SET)) {
perror("fseek");
return -1;
diff --git a/firmware/test/fat/main.c b/firmware/test/fat/main.c
index 4a11e0a..1b9fd22 100644
--- a/firmware/test/fat/main.c
+++ b/firmware/test/fat/main.c
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <stdarg.h>
#include "fat.h"
#include "debug.h"
#include "disk.h"
@@ -14,6 +15,15 @@ void dbg_dump_sector(int sec);
void dbg_dump_buffer(unsigned char *buf);
void dbg_console(void);
+void panicf( char *fmt, ...)
+{
+ va_list ap;
+ va_start( ap, fmt );
+ vprintf( fmt, ap );
+ va_end( ap );
+ exit(0);
+}
+
void dbg_dump_sector(int sec)
{
unsigned char buf[512];
@@ -75,14 +85,16 @@ void dbg_dir(char* currdir)
void dbg_mkfile(char* name)
{
char* text = "Detta är en dummy-text\n";
+ int i;
int fd = open(name,O_WRONLY);
if (fd<0) {
DEBUGF("Failed creating file\n");
return;
}
- if (write(fd, text, strlen(text)) < 0)
- DEBUGF("Failed writing data\n");
-
+ for (i=0;i<200;i++)
+ if (write(fd, text, strlen(text)) < 0)
+ DEBUGF("Failed writing data\n");
+
close(fd);
}
@@ -168,6 +180,33 @@ void dbg_tail(char* name)
close(fd);
}
+void dbg_head(char* name)
+{
+ unsigned char buf[SECTOR_SIZE*5];
+ int fd,rc;
+
+ fd = open(name,O_RDONLY);
+ if (fd<0)
+ return;
+ DEBUGF("Got file descriptor %d\n",fd);
+
+ rc = read(fd, buf, SECTOR_SIZE);
+ if( rc > 0 )
+ {
+ buf[rc]=0;
+ printf("%d: %s\n", strlen(buf), buf);
+ }
+ else if ( rc == 0 ) {
+ DEBUGF("EOF\n");
+ }
+ else
+ {
+ DEBUGF("Failed reading file: %d\n",rc);
+ }
+
+ close(fd);
+}
+
char current_directory[256] = "\\";
int last_secnum = 0;
@@ -284,9 +323,12 @@ int main(int argc, char *argv[])
}
//dbg_console();
- //dbg_tail("/fat.h");
//dbg_dir("/");
- dbg_mkfile("/apa.txt");
+#if 1
+ dbg_head("/bepa.txt");
+#else
+ dbg_mkfile("/bepa.txt");
+#endif
dbg_dir("/");
return 0;