;
}
+void die(int code)
+{
+ puts("die with code 0x");
+ putxval(code, 4);
+ puts(".\n");
+ while (1) { }
+}
+
int main(void)
{
static char buf[16];
FATFS fatfs; /* File system object */
DIR dir; /* Directory object */
FILINFO fno; /* File information object */
+ WORD bw, br, i;
+ BYTE buff[64];
+ int rc;
puts("\nMount a volume.\n");
- int rc = pf_mount(&fatfs);
- puts("Result=");
- putxval(rc, 4);
+ rc = pf_mount(&fatfs);
+ if (rc) die(rc);
+
+ puts("\nOpen a test file (message.txt).\n");
+ rc = pf_open("MESSAGE.TXT");
+ if (rc) die(rc);
+
+ puts("\nType the file content.\n");
+ for (;;) {
+ rc = pf_read(buff, sizeof(buff), &br); /* Read a chunk of file */
+ if (rc || !br) break; /* Error or end of file */
+ for (i = 0; i < br; i++) /* Type the data */
+ putc(buff[i]);
+ }
+ if (rc) die(rc);
+
+#if _USE_WRITE
+ puts("\nOpen a file to write (write.txt).\n");
+ rc = pf_open("WRITE.TXT");
+ if (rc) die(rc);
+
+ puts("\nWrite a text data. (Hello world!)\n");
+ rc = pf_write("Hello world!\r\n", 14, &bw);
+ if (rc) die(rc);
+
+ puts("\nTerminate the file write process.\n");
+ rc = pf_write(0, 0, &bw);
+ if (rc) die(rc);
+#endif
+
+#if _USE_DIR
+ puts("\nOpen root directory.\n");
+ rc = pf_opendir(&dir, "");
+ if (rc) die(rc);
+
+ puts("\nDirectory listing...\n");
+ for (;;) {
+ rc = pf_readdir(&dir, &fno); /* Read a directory item */
+ if (rc || !fno.fname[0]) break; /* Error or end of dir */
+ if (fno.fattrib & AM_DIR) {
+ puts("<d>");
+ puts(fno.fname);
+ puts("\n");
+ } else {
+ puts("<f>");
+ puts(fno.fname);
+ puts("\n");
+ }
+ }
+ if (rc) die(rc);
+#endif
+
+ puts("\nTest completed.\n");
+ for (;;) ;
#endif
return 0;