int main (int argc, char *argv[]) { if (argc == 6 && !strcmp (argv[1], "format")) { u_int nb_b = atoi (argv[3]); u_int size_b = atoi (argv[4]); u_int nb_i = atoi (argv[5]); return fs_format (argv[2], nb_b, size_b, nb_i) == -1; } if ((argc == 3 || argc == 4) && !strcmp (argv[1], "mount")) { FileSystem fs; size size_cache = 0; if (argc == 4) size_cache = atoi (argv[3]); if (fs_mount (&fs, argv[2], size_cache) == -1) return 1; launch_interface (&fs); return fs_umount (&fs) == -1; } usage (argv[0]); return 1; }
int init_fs(struct v7 *v7) { struct fs_info fs0, fs1; int r, r0, r1; r0 = fs_get_info(0, &fs0); r1 = fs_get_info(1, &fs1); dprintf(("r0 = %d, r1 = %d\n", r0, r1)); if (r0 == 0 && r1 == 0) { if (fs0.seq < fs1.seq) { r1 = -1; } else { r0 = -1; } } if (r0 == 0) { r = fs_mount(0, &s_fsm); } else if (r1 == 0) { r = fs_mount(1, &s_fsm); } else { r = fs_format(0); if (r != 0) return r; r = fs_mount(0, &s_fsm); } return r; }
int main(int argc, char *argv[]) { if (argc == 2 && strcmp(argv[1], "list") == 0) { FILE* data_file = fopen(DATA_FILE, "r+"); fseek(data_file, 0, SEEK_SET); char pre_h[HEADERS_COUNT]; fread(pre_h, 1, HEADERS_COUNT, data_file); for (int i = 0; i < HEADERS_COUNT; i++) { if (pre_h[i]) { header_t header = fs_read_header(data_file, i); printf("id: %d, ", i); print_header(header); } } fclose(data_file); printf("that is all\n"); } if (argc == 2 && strcmp(argv[1], "format") == 0) { FILE* data_file = fopen(DATA_FILE, "r+"); fs_format(data_file); fclose(data_file); printf("formated\n"); } if (argc == 3 && strcmp(argv[1], "add") == 0) { FILE* data_file = fopen(DATA_FILE, "r+"); header_t header = {0, "", 0, 0}; strcpy(header.name, argv[2]); fs_create_header(data_file, header); fclose(data_file); printf("inserted\n"); } if (argc == 3 && strcmp(argv[1], "search") == 0) { FILE* data_file = fopen(DATA_FILE, "r+"); int id = fs_search_header(data_file, argv[2]); printf("hid: %d\n", id); fclose(data_file); printf("completed\n"); } return 0; }
/* * Routine to handle scrolling the directory window a certain number * of file names. */ static WORD fs_nscroll(LONG tree, WORD *psel, WORD curr, WORD count, WORD touchob, WORD n) { register WORD i, newcurr, diffcurr; WORD sy, dy, neg; GRECT r[2]; /* single scroll n times*/ newcurr = curr; for (i=0; i<n; i++) newcurr = fs_1scroll(newcurr, count, touchob); /* if things changed */ /* then redraw */ diffcurr = newcurr - curr; if (diffcurr) { curr = newcurr; fs_sel(*psel, NORMAL); *psel = 0; fs_format(tree, curr, count); gsx_gclip(&r[1]); ob_actxywh(tree, F1NAME, &r[0]); if (( neg = (diffcurr < 0)) != 0 ) diffcurr = -diffcurr; if (diffcurr < NM_NAMES) { sy = r[0].g_y + (r[0].g_h * diffcurr); dy = r[0].g_y; if (neg) { dy = sy; sy = r[0].g_y; } bb_screen(S_ONLY, r[0].g_x, sy, r[0].g_x, dy, r[0].g_w, r[0].g_h * (NM_NAMES - diffcurr) ); if ( !neg ) r[0].g_y += r[0].g_h * (NM_NAMES - diffcurr); } else diffcurr = NM_NAMES; r[0].g_h *= diffcurr; for(i=0; i<2; i++) { gsx_sclip(&r[i]); ob_draw(tree, ((i) ? FSVSLID : FILEBOX), MAX_DEPTH); } } return(curr); }
// Lua: format() static int file_format( lua_State* L ) { size_t len; file_close(L); if( !fs_format() ) { NODE_ERR( "\ni*** ERROR ***: unable to format. FS might be compromised.\n" ); NODE_ERR( "It is advised to re-flash the NodeMCU image.\n" ); } else{ NODE_ERR( "format done.\n" ); } return 0; }
int16_t parse_cmd_fs_format (char *cmd, char *output, uint16_t len) { (void) cmd; (void) output; (void) len; if (fs_format (&fs) != FS_OK) return ECMD_FINAL(snprintf_P(output, len, PSTR("fs: error while formating"))); if (fs_init () != FS_OK) return ECMD_FINAL(snprintf_P(output, len, PSTR("fs: error while initializing"))); return ECMD_FINAL_OK; }
/** * def format(path) */ static mp_obj_t os_format(mp_obj_t path_in) { int res; res = fs_format(mp_obj_str_get_str(path_in)); if (res != 0) { nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "Format failed with %d", res)); } return (mp_const_none); }
void nodemcu_init(void) { NODE_ERR("\n"); // Initialize platform first for lua modules. if( platform_init() != PLATFORM_OK ) { // This should never happen NODE_DBG("Can not init platform for modules.\n"); return; } #if defined(FLASH_SAFE_API) if( flash_safe_get_size_byte() != flash_rom_get_size_byte()) { NODE_ERR("Self adjust flash size.\n"); // Fit hardware real flash size. flash_rom_set_size_byte(flash_safe_get_size_byte()); if( !fs_format() ) { NODE_ERR( "\ni*** ERROR ***: unable to format. FS might be compromised.\n" ); NODE_ERR( "It is advised to re-flash the NodeMCU image.\n" ); } else { NODE_ERR( "format done.\n" ); } fs_unmount(); // mounted by format. // Reboot to get SDK to use (or write) init data at new location system_restart (); // Don't post the start_lua task, we're about to reboot... return; } #endif // defined(FLASH_SAFE_API) #if defined ( BUILD_SPIFFS ) fs_mount(); // test_spiffs(); #endif // endpoint_setup(); task_post_low(task_get_id(start_lua),'s'); }
static WORD fs_newdir(BYTE *fpath, BYTE *pspec, LONG tree, WORD *pcount) { const BYTE *ptmp; BYTE *ftitle; OBJECT *obj; TEDINFO *tedinfo; WORD len, len_ftitle, i, fill; /* load the filenames matching pspec, */ /* sort them, and insert the names in */ /* the file selector scroll box */ ob_draw(tree, FSDIRECT, MAX_DEPTH); fs_active(fpath, pspec, pcount); fs_format(tree, 0, *pcount); /* ensure that mask fits within */ /* FTITLE, surround it with */ /* spaces, and centre it */ obj = ((OBJECT *)tree) + FTITLE; tedinfo = (TEDINFO *)obj->ob_spec; ftitle = (BYTE *)tedinfo->te_ptext; len_ftitle = tedinfo->te_txtlen - 1; len = strlen(pspec); if (len > len_ftitle) len = len_ftitle; fill = len_ftitle - len; for (i = 0; i < fill/2; i++) *ftitle++ = ' '; memcpy(ftitle, pspec, len); ftitle += len; for ( ; i < fill; i++) *ftitle++ = ' '; *ftitle = '\0'; ptmp = &gl_fsobj[0]; /* redraw file selector objects */ while(*ptmp) ob_draw(tree, *ptmp++, MAX_DEPTH); return(TRUE); }
main() { sock_init(); /* reset it all! */ InitAllState(); sspec_init(); fs_format(0, FS_NUM_BLOCKS, 1); /* backup the reset data to flash */ dtp_backup_id(); printf("Parameters reset.\n"); /* wait in an endless loop (instead of running over and over in run mode) */ while (1) /* do nothing */; /* pull this in to let it compile properly */ sock_init(); tcp_tick(NULL); }
void nodemcu_init(void) { NODE_ERR("\n"); // Initialize platform first for lua modules. if( platform_init() != PLATFORM_OK ) { // This should never happen NODE_DBG("Can not init platform for modules.\n"); return; } #if defined(FLASH_SAFE_API) if( flash_safe_get_size_byte() != flash_rom_get_size_byte()) { NODE_ERR("Self adjust flash size.\n"); // Fit hardware real flash size. flash_rom_set_size_byte(flash_safe_get_size_byte()); // Flash init data at FLASHSIZE - 0x04000 Byte. flash_init_data_default(); // Flash blank data at FLASHSIZE - 0x02000 Byte. flash_init_data_blank(); if( !fs_format() ) { NODE_ERR( "\ni*** ERROR ***: unable to format. FS might be compromised.\n" ); NODE_ERR( "It is advised to re-flash the NodeMCU image.\n" ); } else{ NODE_ERR( "format done.\n" ); } fs_unmount(); // mounted by format. } #endif // defined(FLASH_SAFE_API) if( !flash_init_data_written() ){ NODE_ERR("Restore init data.\n"); // Flash init data at FLASHSIZE - 0x04000 Byte. flash_init_data_default(); // Flash blank data at FLASHSIZE - 0x02000 Byte. flash_init_data_blank(); } #if defined( BUILD_WOFS ) romfs_init(); // if( !wofs_format() ) // { // NODE_ERR( "\ni*** ERROR ***: unable to erase the flash. WOFS might be compromised.\n" ); // NODE_ERR( "It is advised to re-flash the NodeWifi image.\n" ); // } // else // NODE_ERR( "format done.\n" ); // test_romfs(); #elif defined ( BUILD_SPIFFS ) fs_mount(); // test_spiffs(); #endif // endpoint_setup(); // char* lua_argv[] = { (char *)"lua", (char *)"-e", (char *)"print(collectgarbage'count');ttt={};for i=1,100 do table.insert(ttt,i*2 -1);print(i);end for k, v in pairs(ttt) do print('<'..k..' '..v..'>') end print(collectgarbage'count');", NULL }; // lua_main( 3, lua_argv ); // char* lua_argv[] = { (char *)"lua", (char *)"-i", NULL }; // lua_main( 2, lua_argv ); // char* lua_argv[] = { (char *)"lua", (char *)"-e", (char *)"pwm.setup(0,100,50) pwm.start(0) pwm.stop(0)", NULL }; // lua_main( 3, lua_argv ); // NODE_DBG("Flash sec num: 0x%x\n", flash_get_sec_num()); task_init(); system_os_post(USER_TASK_PRIO_0,SIG_LUA,'s'); }
int process_request(const char *line, FILE *fp, FileSystem *fs) { char command[4096]; #ifdef DEBUG fprintf(stderr, "process request `%s`\n", line); #endif sscanf(line, "%s", command); #ifdef DEBUG fprintf(stderr, "command is `%s`\n", command); #endif if (0 == strcmp("f", command)) { fs_format(fs); return RESULT_DONE; } else if (0 == strcmp("mk", command)) { char f[4096]; char parent_path[4096]; sscanf(line + 2, "%s", f); #ifdef DEBUG fprintf(stderr, "> mk `%s`\n", f); #endif if (fs_exists(fs, f)) { #ifdef DEBUG fprintf(stderr, "> `%s` already exists\n", f); #endif return RESULT_NO; } else { #ifdef DEBUG fprintf(stderr, "> going to create `%s`\n", f); #endif } fs_split_path(f, parent_path, NULL); if (fs_isdir(fs, parent_path)) { if (fs_create(fs, f)) { #ifdef DEBUG fprintf(stderr, "> failed to create `%s`\n", f); #endif return RESULT_NO; } return RESULT_YES; } #ifdef DEBUG fprintf(stderr, "> parent path `%s` is not a directory\n", parent_path); #endif return RESULT_NO; } else if (0 == strcmp("mkdir", command)) { char d[4096]; char parent_path[4096]; sscanf(line + 5, "%s", d); if (fs_exists(fs, d)) { return RESULT_NO; } fs_split_path(d, parent_path, NULL); if (fs_isdir(fs, parent_path)) { if (fs_mkdir(fs, d)) { return RESULT_NO; } return RESULT_YES; } return RESULT_NO; } else if (0 == strcmp("rm", command)) { char f[4096]; sscanf(line + 2, "%s", f); if (fs_isfile(fs, f)) { if (fs_unlink(fs, f)) { return RESULT_NO; } return RESULT_YES; } return RESULT_NO; } else if (0 == strcmp("cd", command)) { char path[4096]; sscanf(line + 2, "%s", path); if (fs_isdir(fs, path)) { if (fs_chdir(fs, path)) { return RESULT_NO; } return RESULT_YES; } #ifdef DEBUG fprintf(stderr, "`%s` is not a directory\n", path); #endif return RESULT_NO; } else if (0 == strcmp("rmdir", command)) { char d[4096]; sscanf(line + 5, "%s", d); if (fs_isdir(fs, d)) { if (fs_rmdir(fs, d)) { return RESULT_NO; } return RESULT_YES; } return RESULT_NO; } else if (0 == strcmp("ls", command)) { fs_ls(fs, fp); return RESULT_ELSE; } else if (0 == strcmp("cat", command)) { char f[4096]; sscanf(line + 3, "%s", f); if (fs_isfile(fs, f)) { fs_cat(fs, f, fp); return RESULT_ELSE; } return RESULT_NO; } else if (0 == strcmp("w", command)) { char f[4096]; int l; char data[4096]; sscanf(line + 1, "%s %d %[^\n]", f, &l, data); if (fs_isfile(fs, f)) { if (fs_write(fs, f, l, data)) { return RESULT_NO; } return RESULT_YES; } return RESULT_NO; } else if (0 == strcmp("i", command)) { char f[4096]; int pos; int l; char data[4096]; sscanf(line + 1, "%s %d %d %[^\n]", f, &pos, &l, data); if (fs_isfile(fs, f)) { if (fs_insert(fs, f, pos, l, data)) { return RESULT_NO; } return RESULT_YES; } return RESULT_NO; } else if (0 == strcmp("d", command)) { char f[4096]; int pos; int l; sscanf(line + 1, "%s %d %d", f, &pos, &l); if (fs_isfile(fs, f)) { if (fs_delete(fs, f, pos, l)) { return RESULT_NO; } return RESULT_YES; } return RESULT_NO; } else if (0 == strcmp("e", command)) { return RESULT_EXIT; } return RESULT_ELSE; }
int main( int argc, char *argv[] ) { char line[1024]; char cmd[1024]; char arg1[1024]; char arg2[1024]; int result, args; if(argc!=3) { printf("use: %s <diskfile> <nblocks>\n",argv[0]); return 1; } if(!disk_init(argv[1],atoi(argv[2]))) { printf("couldn't initialize %s: %s\n",argv[1],strerror(errno)); return 1; } printf("opened emulated disk image %s with %d blocks\n",argv[1],disk_size()); while(1) { printf(" prompt> "); fflush(stdout); if(!fgets(line,sizeof(line),stdin)) break; if(line[0]=='\n') continue; line[strlen(line)-1] = 0; args = sscanf(line,"%s %s %s",cmd,arg1,arg2); if(args==0) continue; if(!strcmp(cmd,"format")) { if(args==1) { if(!fs_format()) { printf("disk formatted.\n"); } else { printf("format failed!\n"); } } else { printf("use: format\n"); } } else if(!strcmp(cmd,"mount")) { if(args==1) { if(!fs_mount()) { printf("disk mounted.\n"); } else { printf("mount failed!\n"); } } else { printf("use: mount\n"); } } else if(!strcmp(cmd,"debug")) { if(args==1) { fs_debug(); } else { printf("use: debug\n"); } } else if(!strcmp(cmd,"getsize")) { if(args==2) { result = fs_getsize(arg1); if(result>=0) { printf("file %s has size %d\n",arg1,result); } else { printf("getsize failed!\n"); } } else { printf("use: getsize <filename>\n"); } } else if(!strcmp(cmd,"create")) { if(args==2) { result = fs_create(arg1); if(result==0) { printf("created file %s\n",arg1); } else { printf("create failed!\n"); } } else { printf("use: create <filename>\n"); } } else if(!strcmp(cmd,"delete")) { if(args==2) { if(!fs_delete(arg1)) { printf("file %s deleted.\n",arg1); } else { printf("delete failed!\n"); } } else { printf("use: delete <filename>\n"); } } else if(!strcmp(cmd,"cat")) { if(args==2) { if(!do_copyout(arg1,"/dev/stdout")) { printf("cat failed!\n"); } } else { printf("use: cat <name>\n"); } } else if(!strcmp(cmd,"copyin")) { if(args==3) { if(do_copyin(arg1,arg2)) { printf("copied file %s to %s\n",arg1,arg2); } else { printf("copy failed!\n"); } } else { printf("use: copyin <filename in host system> <filename in fs-miei-02>\n"); } } else if(!strcmp(cmd,"copyout")) { if(args==3) { if(do_copyout(arg1,arg2)) { printf("copied myfs_file %s to file %s\n", arg1,arg2); } else { printf("copy failed!\n"); } } else { printf("use: copyout <inumber> <filename>\n"); } } else if(!strcmp(cmd,"help")) { printf("Commands are:\n"); printf(" format\n"); printf(" mount\n"); printf(" debug\n"); printf(" create\n"); printf(" delete <filename>\n"); printf(" cat <filename>\n"); printf(" getsize <filename>\n"); printf(" copyin <file name in host system> <miei02-filename>\n"); printf(" copyout <miei02-filename> <file name in host system>\n"); printf(" dump <number_of_block_with_text_contents>\n"); printf(" help\n"); printf(" quit\n"); printf(" exit\n"); } else if(!strcmp(cmd,"quit")) { break; } else if(!strcmp(cmd,"exit")) { break; } else if (!strcmp(cmd, "dump")){ if(args==2) { int blNo = atoi(arg1); printf("Dumping disk block %d\n", blNo); char b[4096]; disk_read( blNo, b); printf("------------------------------\n"); printf("%s", b); printf("\n------------------------------\n"); } else { printf("use: dump <block_number>\n"); } } else { printf("unknown command: %s\n",cmd); printf("type 'help' for a list of commands.\n"); result = 1; } } printf("closing emulated disk.\n"); disk_close(); return 0; }
int main( int argc, char *argv[] ) { char line[1024]; char cmd[1024]; char arg1[1024]; char arg2[1024]; int inumber, result, args; if(argc!=3) { printf("use: %s <diskfile> <nblocks>\n",argv[0]); return 1; } if(!disk_init(argv[1],atoi(argv[2]))) { printf("couldn't initialize %s: %s\n",argv[1],strerror(errno)); return 1; } printf("opened emulated disk image %s with %d blocks\n",argv[1],disk_size()); while(1) { printf(" prompt> "); fflush(stdout); if(!fgets(line,sizeof(line),stdin)) break; if(line[0]=='\n') continue; line[strlen(line)-1] = 0; args = sscanf(line,"%s %s %s",cmd,arg1,arg2); if(args==0) continue; if(!strcmp(cmd,"format")) { if(args==1) { if(fs_format()) { printf("disk formatted.\n"); } else { printf("format failed!\n"); } } else { printf("use: format\n"); } } else if(!strcmp(cmd,"mount")) { if(args==1) { if(fs_mount()) { printf("disk mounted.\n"); } else { printf("mount failed!\n"); } } else { printf("use: mount\n"); } } else if(!strcmp(cmd,"umount")) { if(args==1) { if(fs_umount()) { printf("disk umounted.\n"); } else { printf("umount failed!\n"); } } else { printf("use: mount\n"); } } else if(!strcmp(cmd,"debug")) { if(args==1) { fs_debug(); } else { printf("use: debug\n"); } } else if(!strcmp(cmd,"getsize")) { if(args==2) { inumber = atoi(arg1); result = fs_getsize(inumber); if(result>=0) { printf("inode %d has size %d\n",inumber,result); } else { printf("getsize failed!\n"); } } else { printf("use: getsize <inumber>\n"); } } else if(!strcmp(cmd,"create")) { if(args==1) { inumber = fs_create(); if(inumber>=0) { printf("created inode %d\n",inumber); } else { printf("create failed!\n"); } } else { printf("use: create\n"); } } else if(!strcmp(cmd,"delete")) { if(args==2) { inumber = atoi(arg1); if(fs_delete(inumber)) { printf("inode %d deleted.\n",inumber); } else { printf("delete failed!\n"); } } else { printf("use: delete <inumber>\n"); } } else if(!strcmp(cmd,"cat")) { if(args==2) { inumber = atoi(arg1); if(!do_copyout(inumber,"/dev/stdout")) { printf("cat failed!\n"); } } else { printf("use: cat <inumber>\n"); } } else if(!strcmp(cmd,"copyin")) { if(args==3) { inumber = atoi(arg2); if(do_copyin(arg1,inumber)) { printf("copied file %s to inode %d\n",arg1,inumber); } else { printf("copy failed!\n"); } } else { printf("use: copyin <filename> <inumber>\n"); } } else if(!strcmp(cmd,"copyout")) { if(args==3) { inumber = atoi(arg1); if(do_copyout(inumber,arg2)) { printf("copied inode %d to file %s\n",inumber,arg2); } else { printf("copy failed!\n"); } } else { printf("use: copyout <inumber> <filename>\n"); } } else if(!strcmp(cmd,"help")) { printf("Commands are:\n"); printf(" format\n"); printf(" mount\n"); printf(" umount\n"); printf(" debug\n"); printf(" create\n"); printf(" delete <inode>\n"); printf(" getsize <inode>\n"); printf(" cat <inode>\n"); printf(" copyin <file> <inode>\n"); printf(" copyout <inode> <file>\n"); printf(" help\n"); printf(" quit\n"); printf(" exit\n"); } else if(!strcmp(cmd,"quit")) { break; } else if(!strcmp(cmd,"exit")) { break; } else { printf("unknown command: %s\n",cmd); printf("type 'help' for a list of commands.\n"); result = 1; } } printf("closing emulated disk.\n"); disk_close(); return 0; }