📄 flashfs.c
字号:
} else { m->errno = EINVAL; } sendreply(m); return;}static void flashfs_msgFstat(ATMOS_MESSAGE *m){ MSG_D_FSTAT(f, m); OPENFILE *optr = (OPENFILE *)f->fp->devuse; struct stat *statbuf = f->stat; memset( statbuf, 0, sizeof(struct stat) ); statbuf->st_ino = optr->datptr - sizeof (FLASHFS_DIRENT); statbuf->st_mode = (S_IFREG | S_IRUSR | S_IRGRP | S_IROTH); statbuf->st_blksize = 1; statbuf->st_blocks = optr->fmax; statbuf->st_size = optr->fmax; sendreply(m); return;}static void flashfs_msgFsinfo(ATMOS_MESSAGE *m){ MSG_D_FSINFO(f, m); struct fsinfo *fsinfobuf = f->fsinfo; if (f->path) { OPENFILE slot; m->errno = flashfs_ParseFilename (f->path, slot.name, &slot.partition); if (ESUCCESS == m->errno) { flashfs_PartitionChange (slot.partition); m->errno = flashfs_SysInfo (slot.partition, fsinfobuf); } } else { m->errno = ENOENT; } sendreply(m); return;}static void flashfs_msgReaddir(ATMOS_MESSAGE *m){ MSG_D_READDIR(r, m); if (!(r->dp->flags & _IOB_OPEN)) m->errno = ENOENT; else if (!(r->dp->flags & _IOB_DIRECTORY)) m->errno = ENOTDIR; else if (r->dp->flags & _IOB_EOF) m->errno = ESPIPE; else { /* An open directory ... */ OPENFILE *optr = (OPENFILE *)r->dp->devuse; FLASHFS_DIRENT entry; flashfs_PartitionChange (optr->partition); m->errno = ESUCCESS; /* anything in queue */ if (optr->datptr == 0) { /* Have we done the dynamic files, if so do fixed ones ... */ if (optr->fpos == DYNAMIC) { optr->datptr = flashfsRoot.first.fixed; optr->fpos = FIXED; } } /* anything in queue, again */ if (optr->datptr) { flash_read_fs_data(optr->datptr, (BYTE *)&entry, sizeof entry); strcpy(r->dirent->d_name, entry.name); r->dirent->d_namlen = strlen(entry.name); r->dirent->d_reclen = entry.len; r->dirent->d_fileno = 0; /* not used in flashfs */ optr->datptr = entry.next; } else { /* no more files to list, set end of file marker */ r->dp->flags |= _IOB_EOF; m->errno = ESPIPE; } } sendreply(m);}static BOOL flashfs_getPartition (char *buffer, U32 *partition, BOOL required){ BOOL rc = FALSE; if (sscanf (buffer, "%u", partition) != 1) { if (!required) { *partition = currentDefaultPartition; rc = TRUE; } else { printf ("No partition specified\n"); } } else { /* ** Partitions are numbered from 1 for the user */ (*partition)--; if (*partition < flashfslib_PartitionCount ()) { rc = TRUE; } else { printf ("Bad partition (range is 1 ... %u)\n", flashfslib_PartitionCount ()); } } return rc;}static void flashfs_msgTell(ATMOS_MESSAGE *m){ MSG_D_TELL(t, m); char *p; enum { CMD_NONE=0,#ifdef USE_OLD_FS_CONSOLE CMD_CAT, CMD_LS,#endif CMD_DEFAULT, CMD_FORMAT, CMD_PARTITION, CMD_CONFIG, CMD_FSCK, CMD_ID, CMD_REWRITE, CMD_TRACE, CMD_UPDATE, CMD_VERSION, CMD_WIPE, CMD_INFO }; const CmdAltEntry commands[] = {#ifdef USE_OLD_FS_CONSOLE {0, "cat", CMD_CAT, "<file> - show file contents"},#endif {0, "config", CMD_CONFIG, "- display flash configuration"}, {0, "default", CMD_DEFAULT, "[partition] - show/set default partition"}, {0, "fsck", CMD_FSCK, "[partition] - file system check, checks FLASH integrity"}, {0, "format", CMD_FORMAT, "[partition] - format a partition"}, {0, "id", CMD_ID, "<x> - display chip ID for device x"}, {0, "info", CMD_INFO, "- display file system information"},#ifdef USE_OLD_FS_CONSOLE {0, "ls", CMD_LS, "[-l] - list FLASHFS files [more detail]"},#endif {0, "partitions", CMD_PARTITION, "- list partitions"},#ifdef FLASHFS_REWRITE {0, "rewrite", CMD_REWRITE, "<file> - rewrite boot area with ISFS file <file>"},#endif {0, "trace", CMD_TRACE, "[level] - show/set tracing level"}, {0, "update", CMD_UPDATE, "[partition] - commit ISFS files to FLASH"}, {0, "version", CMD_VERSION, "- display version number"}, {0, "wipe", CMD_WIPE, "[partition] - irreversibly erase FLASH contents"} }; const int numCommands = sizeof(commands) / sizeof(commands[0]); const char *argv[2] = { t->cmd, NULL }; int argc; U32 token = 0; foreground_output_begin(); /* move along line until EOL */ for (p = t->cmd; *p != '\0'; p++) { if (*p == ' ') { /* first space, terminate first parameter, bump ptr, exit loop. */ *p++ = '\0'; break; } } /* while not end of the original line, move on searching for non-space. */ /* p is then pointer to second parameter, or \0 if there isn't one ! */ while (*p == ' ') p++; if (*p != '\0') { argv[1] = p; argc = 2; } else { argc = 1; } /* now check commands */ if (AltInterpretCommand(0, commands, numCommands, argc, argv, &token) == ESUCCESS) { switch (token) { case CMD_DEFAULT: if (!*p) { printf ("default is %d\n", currentDefaultPartition + 1); } else { U32 newDefault; if (flashfs_getPartition (p, &newDefault, TRUE)) { currentDefaultPartition = newDefault; } } break; case CMD_FORMAT: { U32 par; if (flashfs_getPartition (p, &par, FALSE)) { if (ESUCCESS != flashfslib_PartitionFormat (par)) { printf ("format failed\n"); } } break; } case CMD_PARTITION: { U32 i; printf ("Number of partitions: %u\n", flashfslib_PartitionCount ()); for (i = 0; i < flashfslib_PartitionCount (); i++) { U32 s, e; int rc; (void) flashfslib_PartitionDetails (i, &s, &e); rc = flashfslib_PartitionValid (i); printf ("Partition %u: 0x%08x ... 0x%08x is %svalid\n", i + 1, s, e, (ESUCCESS == rc) ? "" : "in"); } break; } case CMD_UPDATE: { U32 par; if (flashfs_getPartition (p, &par, FALSE)) { int rc; printf("Updating flash filing system ...\n"); /* write new files using regular ISFS volroot */ rc = write_boot (isfs1_volroot, par); if (ESUCCESS == rc) { printf("done\n"); } else { printf("*** FLASH UPDATE FAILED (%s) ***\n", strerror (rc)); } } break; }#ifdef USE_OLD_FS_CONSOLE case CMD_LS: { flashfs_PartitionChange (currentDefaultPartition); flashfs_ls(p); break; } case CMD_CAT: { flashfs_PartitionChange (currentDefaultPartition); flashfs_cat(p); break; }#endif case CMD_CONFIG: { flash_config (); break; }#ifdef FLASHFS_REWRITE case CMD_REWRITE: { flashfs_rewrite(p); break; }#endif case CMD_FSCK: { U32 par; if (flashfs_getPartition (p, &par, FALSE)) { /* set flag after user requested test */ flashGood = flashfs_fsck(par); if (flashGood) { /* tell user, if bad system error already noted ... */ printf("valid flash filing system detected\n"); } } break; } case CMD_INFO: { flashfs_PartitionChange (currentDefaultPartition); printf("Current file system: 0x%x - 0x%x (%u kBytes)\n", flashStartOffset, flashStartOffset + flashfsSize, flashfsSize / 1024); printf("Devices supported: %d\n", NUM_FLASH_DEVICES); break; } case CMD_VERSION: { printf("FLASHFS v%d.%02d\n", FLASHFS_VERSION/100, FLASHFS_VERSION%100); break; } case CMD_ID: { if (!*p) { printf("no device specified\n"); } else { U32 device; if (sscanf(p, "%u", &device) != 1) printf ("illegal input\n"); else if (device < NUM_FLASH_DEVICES) flash_display_chip_info (device); else printf("non-existent device selected\n"); } break; } case CMD_TRACE: { if (!*p) { printf("no level specified: current trace level is %d\n", flashfsTraceLevel); } else { U32 level; if (sscanf(p, "%u", &level) != 1) printf("illegal input\n"); else if (level <= MAX_TRACE_LEVEL) flashfsTraceLevel = level; else printf("illegal trace level setting, use 0-%d\n", MAX_TRACE_LEVEL); } break; } case CMD_WIPE: { U32 par; if (flashfs_getPartition (p, &par, FALSE)) { if (ESUCCESS == check_flash_chips_writable ()) { flashfslib_PartitionCheckOffset (par); /* ** Wipe the partition (writes 0xff) */ flashfslib_PartitionErase (par); /* ** Ensure that local structures updated. */ if (par == currentPartition) { currentPartition = NO_PARTITION; flashfs_PartitionChange (par); } } } break; } } } else { printf("Unknown command '%s' - try 'help'\n", t->cmd); } foreground_output_end(); sendreply(m);} /* flashfs_tell */static void flashfs_msgUpdate (ATMOS_MESSAGE *m){ ISFS_ROOT * newvolroot; MSG_D_FLASHFS_UPDATE (u, m); /* ** Default volroot. */ newvolroot = (ISFS_ROOT *) u->volroot; if (NULL == newvolroot) { newvolroot = isfs1_volroot; } /* (Apparently) valid filing system root? */ if (strncmp(newvolroot->volser, "ISFSV1", sizeof newvolroot->volser) == 0) { m->errno = write_boot(newvolroot, currentDefaultPartition); } else { /* No 'ISFSV1' volser found at new ISFS root address */ m->errno = EFAULT; } sendreply (m);}static void flashfs_msgUpdatePartition (ATMOS_MESSAGE *m){ ISFS_ROOT * newvolroot; MSG_D_F
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -