fix coverity 314850, and textual changes

This commit is contained in:
iceman1001 2021-04-05 08:47:03 +02:00
commit 1b59b38058
3 changed files with 21 additions and 26 deletions

View file

@ -549,16 +549,12 @@ void rdv40_spiffs_safe_print_fsinfo(void) {
rdv40_spiffs_fsinfo fsinfo; rdv40_spiffs_fsinfo fsinfo;
rdv40_spiffs_getfsinfo(&fsinfo, RDV40_SPIFFS_SAFETY_SAFE); rdv40_spiffs_getfsinfo(&fsinfo, RDV40_SPIFFS_SAFETY_SAFE);
DbpString(_CYAN_("Flash Memory FileSystem Info (SPIFFS)")); Dbprintf(" Logical block size......... " _YELLOW_("%d")" bytes", fsinfo.blockSize);
Dbprintf(" Logical page size.......... " _YELLOW_("%d")" bytes", fsinfo.pageSize);
Dbprintf(" Max open files............. " _YELLOW_("%d")" file descriptors", fsinfo.maxOpenFiles);
Dbprintf(" Logical Block Size........." _YELLOW_("%d")" bytes", fsinfo.blockSize); Dbprintf(" Max path length............ " _YELLOW_("%d")" chars", fsinfo.maxPathLength);
Dbprintf(" Logical Page Size.........." _YELLOW_("%d")" bytes", fsinfo.pageSize);
Dbprintf("");
Dbprintf(" Max Open Files............." _YELLOW_("%d")" file descriptors", fsinfo.maxOpenFiles);
Dbprintf(" Max Path Length............" _YELLOW_("%d")" chars", fsinfo.maxPathLength);
DbpString(""); DbpString("");
Dbprintf(" filesystem size used available use% mounted"); Dbprintf(" Filesystem size used available use% mounted");
Dbprintf(" spiffs %6d B %6d B %6d B " _YELLOW_("%2d%")" /" Dbprintf(" spiffs %6d B %6d B %6d B " _YELLOW_("%2d%")" /"
, fsinfo.totalBytes , fsinfo.totalBytes
, fsinfo.usedBytes , fsinfo.usedBytes
@ -574,20 +570,13 @@ void rdv40_spiffs_safe_print_fsinfo(void) {
// maintaining prefix list sorting, unique_checking, THEN outputing precomputed // maintaining prefix list sorting, unique_checking, THEN outputing precomputed
// tree Other solutio nwould be to add directory support to SPIFFS, but that we // tree Other solutio nwould be to add directory support to SPIFFS, but that we
// dont want, as prefix are way easier and lighter in every aspect. // dont want, as prefix are way easier and lighter in every aspect.
void rdv40_spiffs_safe_print_tree(uint8_t banner) { void rdv40_spiffs_safe_print_tree(void) {
if (banner) {
DbpString(_CYAN_("Flash Memory FileSystem tree (SPIFFS)"));
Dbprintf("-------------------------------------");
}
int changed = rdv40_spiffs_lazy_mount(); int changed = rdv40_spiffs_lazy_mount();
spiffs_DIR d; spiffs_DIR d;
struct spiffs_dirent e; struct spiffs_dirent e;
struct spiffs_dirent *pe = &e; struct spiffs_dirent *pe = &e;
SPIFFS_opendir(&fs, "/", &d); SPIFFS_opendir(&fs, "/", &d);
Dbprintf(" \t \t/");
while ((pe = SPIFFS_readdir(&d, pe))) { while ((pe = SPIFFS_readdir(&d, pe))) {
char resolvedlink[11 + SPIFFS_OBJ_NAME_LEN]; char resolvedlink[11 + SPIFFS_OBJ_NAME_LEN];
@ -601,10 +590,9 @@ void rdv40_spiffs_safe_print_tree(uint8_t banner) {
memset(resolvedlink, 0, sizeof(resolvedlink)); memset(resolvedlink, 0, sizeof(resolvedlink));
} }
Dbprintf("[%04x]\t %ibytes \t|-- %s%s", pe->obj_id, pe->size, pe->name, resolvedlink); Dbprintf("[%04x]\t " _YELLOW_("%i") " B |-- %s%s", pe->obj_id, pe->size, pe->name, resolvedlink);
} }
SPIFFS_closedir(&d); SPIFFS_closedir(&d);
rdv40_spiffs_lazy_mount_rollback(changed); rdv40_spiffs_lazy_mount_rollback(changed);
} }
@ -651,7 +639,7 @@ void test_spiffs(void) {
int changed = rdv40_spiffs_lazy_mount(); int changed = rdv40_spiffs_lazy_mount();
Dbprintf(" Printing tree.............."); Dbprintf(" Printing tree..............");
rdv40_spiffs_safe_print_tree(false); rdv40_spiffs_safe_print_tree();
Dbprintf(" Writing 'I love Proxmark3 RDV4' in a testspiffs.txt"); Dbprintf(" Writing 'I love Proxmark3 RDV4' in a testspiffs.txt");
@ -660,13 +648,13 @@ void test_spiffs(void) {
rdv40_spiffs_write((char *)"testspiffs.txt", (uint8_t *)"I love Proxmark3 RDV4", 21, RDV40_SPIFFS_SAFETY_SAFE); rdv40_spiffs_write((char *)"testspiffs.txt", (uint8_t *)"I love Proxmark3 RDV4", 21, RDV40_SPIFFS_SAFETY_SAFE);
Dbprintf(" Printing tree again......."); Dbprintf(" Printing tree again.......");
rdv40_spiffs_safe_print_tree(false); rdv40_spiffs_safe_print_tree();
Dbprintf(" Making a symlink to testspiffs.txt"); Dbprintf(" Making a symlink to testspiffs.txt");
rdv40_spiffs_make_symlink((char *)"testspiffs.txt", (char *)"linktotestspiffs.txt", RDV40_SPIFFS_SAFETY_SAFE); rdv40_spiffs_make_symlink((char *)"testspiffs.txt", (char *)"linktotestspiffs.txt", RDV40_SPIFFS_SAFETY_SAFE);
Dbprintf(" Printing tree again......."); Dbprintf(" Printing tree again.......");
rdv40_spiffs_safe_print_tree(false); rdv40_spiffs_safe_print_tree();
// TODO READBACK, rename,print tree read back, remove, print tree; // TODO READBACK, rename,print tree read back, remove, print tree;
Dbprintf(" Rollbacking The mount status IF things have changed"); Dbprintf(" Rollbacking The mount status IF things have changed");

View file

@ -45,7 +45,7 @@ int rdv40_spiffs_read_as_symlink(char *filename, uint8_t *dst, uint32_t size, RD
void write_to_spiffs(const char *filename, uint8_t *src, uint32_t size); void write_to_spiffs(const char *filename, uint8_t *src, uint32_t size);
void read_from_spiffs(const char *filename, uint8_t *dst, uint32_t size); void read_from_spiffs(const char *filename, uint8_t *dst, uint32_t size);
void test_spiffs(void); void test_spiffs(void);
void rdv40_spiffs_safe_print_tree(uint8_t banner); void rdv40_spiffs_safe_print_tree(void);
int rdv40_spiffs_unmount(void); int rdv40_spiffs_unmount(void);
int rdv40_spiffs_mount(void); int rdv40_spiffs_mount(void);
int rdv40_spiffs_is_symlink(const char *s); int rdv40_spiffs_is_symlink(const char *s);

View file

@ -39,8 +39,11 @@ int flashmem_spiffs_load(char *destfn, uint8_t *data, size_t datalen) {
flashmem_write_t *payload = calloc(1, sizeof(flashmem_write_t) + bytes_in_packet); flashmem_write_t *payload = calloc(1, sizeof(flashmem_write_t) + bytes_in_packet);
payload->append = (bytes_sent > 0); payload->append = (bytes_sent > 0);
payload->fnlen = strlen(destfn);
memcpy(payload->fn, destfn, strlen(destfn)); uint8_t fnlen = MIN(sizeof(payload->fn), strlen(destfn));
payload->fnlen = fnlen;
memcpy(payload->fn, destfn, fnlen);
payload->bytes_in_packet = bytes_in_packet; payload->bytes_in_packet = bytes_in_packet;
memset(payload->data, 0, bytes_in_packet); memset(payload->data, 0, bytes_in_packet);
@ -158,6 +161,8 @@ static int CmdFlashMemSpiFFSTree(const char *Cmd) {
}; };
CLIExecWithReturn(ctx, Cmd, argtable, true); CLIExecWithReturn(ctx, Cmd, argtable, true);
CLIParserFree(ctx); CLIParserFree(ctx);
PrintAndLogEx(INFO, "--- " _CYAN_("Flash Memory tree (SPIFFS)") " -----------------");
clearCommandBuffer(); clearCommandBuffer();
SendCommandNG(CMD_SPIFFS_PRINT_TREE, NULL, 0); SendCommandNG(CMD_SPIFFS_PRINT_TREE, NULL, 0);
return PM3_SUCCESS; return PM3_SUCCESS;
@ -175,6 +180,8 @@ static int CmdFlashMemSpiFFSInfo(const char *Cmd) {
}; };
CLIExecWithReturn(ctx, Cmd, argtable, true); CLIExecWithReturn(ctx, Cmd, argtable, true);
CLIParserFree(ctx); CLIParserFree(ctx);
PrintAndLogEx(INFO, "--- " _CYAN_("Flash Memory info (SPIFFS)") " -----------------");
clearCommandBuffer(); clearCommandBuffer();
SendCommandNG(CMD_SPIFFS_PRINT_FSINFO, NULL, 0); SendCommandNG(CMD_SPIFFS_PRINT_FSINFO, NULL, 0);
return PM3_SUCCESS; return PM3_SUCCESS;