BlinkenArea - GitList
Repositories
Blog
Wiki
flaneth
Code
Commits
Branches
Tags
Search
Tree:
2b483ef
Branches
Tags
master
flaneth
firmware
apps.c
put filesystem stuff into own C file
Stefan Schuermans
commited
2b483ef
at 2012-05-04 18:56:53
apps.c
Blame
History
Raw
/* flaneth - flash and ethernet Copyright (C) 2007-2012 Stefan Schuermans <stefan@schuermans.info> Copyleft: GNU public license V2 - http://www.gnu.org/copyleft/gpl.html a BlinkenArea project - http://www.blinkenarea.org/ */ #include <string.h> #include "apps.h" #include "debug.h" #include "dosfs.h" // list files and static void AppsListDump(uint8_t sectorBuf[SECTOR_SIZE], VOLINFO *vi) { DIRINFO di; DIRENT de; uint8_t filename[12]; FILEINFO fi; uint8_t buf[64]; uint32_t len, i; // list files in root directory di.scratch = sectorBuf; if (DFS_OpenDir(vi, (uint8_t *)"", &di) != 0) { debug_apps_printf("cannot open root directory"); return; } debug_apps_printf("files in root directory:"); while (DFS_GetNext(vi, &di, &de) == 0) { if (de.attr == ATTR_LONG_NAME) { // ignore long names } else if (de.attr & ATTR_VOLUME_ID) { debug_apps_printf("volume ID: %-11.11s", de.name); } else if (de.attr & ATTR_DIRECTORY) { debug_apps_printf("directory: %-11.11s", de.name); } else { debug_apps_printf("file: %-11.11s", de.name); memcpy(filename, de.name, 11); // remember last filename filename[11] = 0; } } // dump last file if (DFS_OpenFile(vi, filename, DFS_READ, sectorBuf, &fi) != 0) { debug_apps_printf("cannot open file %s", filename); return; } debug_apps_printf("dumping file %s (max. %u bytes):", filename, sizeof(buf)); len = 0; DFS_ReadFile(&fi, sectorBuf, buf, &len, sizeof(buf)); for (i = 0; i < len; ++i) debug_apps_printf("%3lu: %02hX", i, buf[i]); debug_apps_printf("done", filename); } // run applications void AppsRun(void) // (extern) { uint8_t sectorBuf[SECTOR_SIZE]; uint32_t partStart, partSize; uint8_t partAct, partType; VOLINFO vi; const char *sec_clus, *fstype; // get start of first partition partStart = DFS_GetPtnStart(0, sectorBuf, 0, &partAct, &partType, &partSize); if (partStart == 0xFFFFFFFF) { debug_apps_printf("cannot find first partition"); return; } debug_apps_printf("partition: start %lu size %lu", partStart, partSize); // get volume info if (DFS_GetVolInfo(0, sectorBuf, partStart, &vi) != 0) { debug_apps_printf("cannot get volume info"); return; } switch (vi.filesystem) { case FAT12: sec_clus = "sector: "; fstype = "FAT12"; break; case FAT16: sec_clus = "sector: "; fstype = "FAT16"; break; case FAT32: sec_clus = "cluster:"; fstype = "FAT32"; break; default: sec_clus = "sector: "; fstype = "unknown"; break; } debug_apps_printf("filesystem: %s", fstype); debug_apps_printf("volume label: %-11.11s", vi.label); debug_apps_printf("sector/s per cluster: %hu", vi.secperclus); debug_apps_printf("reserved sector/s: %hu", vi.reservedsecs); debug_apps_printf("volume total sectors: %lu", vi.numsecs); debug_apps_printf("sectors per FAT: %lu", vi.secperfat); debug_apps_printf("first FAT at sector: %lu", vi.fat1); debug_apps_printf("root dir at %s %lu", sec_clus, vi.rootdir); debug_apps_printf("root dir entries: %hu", vi.rootentries); debug_apps_printf("data area commences at sector: %lu", vi.dataarea); debug_apps_printf("clusters in data area: %lu", vi.numclusters); debug_apps_printf("sectors per cluster: %hu", vi.secperclus); // list directory, dump file AppsListDump(sectorBuf, &vi); }