const DC3Error_t DB_isValid( const DC3AccessType_t accessType ) { DC3Error_t status = ERR_NONE; /* keep track of success/failure */ uint32_t db_magicWord = 0; status = DB_read( _DC3_DB_MAGIC_WORD, _DC3_ACCESS_BARE, sizeof(db_magicWord), (uint8_t *)&db_magicWord ); if ( ERR_NONE != status ) { goto DB_isValid_ERR_HANDLE; /* Stop and jump to error handling */ } else { if ( db_magicWord != DB_MAGIC_WORD_DEF ) { wrn_slow_printf( "Magic word in DB (0x%08x) doesn't match expected (0x%08x)\n", db_magicWord, DB_MAGIC_WORD_DEF ); return( ERR_DB_NOT_INIT); } } uint16_t db_version = 0; status = DB_read( _DC3_DB_VERSION, _DC3_ACCESS_BARE, sizeof(db_version), (uint8_t *)&db_version ); if ( ERR_NONE != status ) { goto DB_isValid_ERR_HANDLE; /* Stop and jump to error handling */ } else { if ( db_version != DB_VERSION_DEF ) { wrn_slow_printf( "DB version in EEPROM (0x%04x) doesn't match expected (0x%04x)\n", db_version, DB_VERSION_DEF ); return( ERR_DB_VER_MISMATCH); } } DB_isValid_ERR_HANDLE: /* Handle any error that may have occurred. */ ERR_COND_OUTPUT( status, accessType, "Validating the settings DB: Error 0x%08x\n", status ); return( status ); }
int command_list_db(int argc, char **argv, int optind, int flags) { struct DBItem dbi = DBITEM_NULL; struct DBItem *e = NULL; char *p = NULL; int do_free_p = 0; int i = 0; for(i = optind; i < argc; ++i) { DBITEM_SET_NULL(dbi); e = NULL; if(access(argv[i], F_OK | R_OK) != 0 || DB_read(argv[i], &dbi) != 0) { log_failure(argv[i], "doesn't exist or isn't a valid database"); continue; } if(dbi.kbuf == NULL) { log_info(argv[i], "is empty"); continue; } e = &dbi; do { p = e->kbuf; if(flags & USE_REALPATH) p = get_realpath((const char*) e->kbuf, &do_free_p); log_success(argv[i], "%s -> %08X", p, e->crc); if(do_free_p == 1) { free(p); do_free_p = 0; } } while((e = e->next) != NULL); if(dbi.next != NULL) DB_item_free(dbi.next); } return EXIT_SUCCESS; }