⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tfscli.c

📁 完整的Bell实验室的嵌入式文件系统TFS
💻 C
📖 第 1 页 / 共 2 页
字号:
    "",    "Operations:",    " init, stat, clean, check [var], ls [filter], ld[v] {name}",    " rm {filter}, cat {name}, run {name}, freemem [var], trace [lvl]",    " info {file} {var}, log {on|off} {msg}, size {file} {var}",    " ln {src} {lnk}, fhdr {addr}, uname {prefix} {var}",    " cp {from_name} {to_name | addr}, add {name} {src_addr} {size}",#if DEFRAG_TEST_ENABLED    "",    "Operations for testing TFS defragmentation:",    " clean {E|S|F} {tag#} {sector#}",     "   E=Exit, S=SectorErase F=FlashWrite",    " rms {size} [exclude_file1] [exclude_file2] ...",     " dhdr {address}",     " dht", #endif    "",    "Flags:",    " E=exec_binary, e=exec_script, c=compressed, l=symlink",    " b=run_at_boot, B=qry_run_at_boot, i=inplace_modifiable",    " 0-3=usrlvl_0-3, u=ulvl_unreadable",    0,};/* Tfs(): *  Entry point for the tfs command through the monitor's command line *  interface.  This function provides access to most TFS functionality *  through the CLI. */intTfs(int argc, char *argv[]){    TDEV    *tdp, *tdptmp;    TFILE   *fp;    TINFO   tinfo;    long    size;    int     opt, verbose, i, more, retval, setexitflag, status;    char    *src, *name, *info, *flags, *to, *from, *devprefix;    char    *arg1, *arg2, *arg3, *arg4;    tdp = 0;    more = 0;    retval = CMD_SUCCESS;    verbose = 0;    status = TFS_OKAY;    setexitflag = 0;    info = (char *)0;    flags = (char *)0;    devprefix = (char *)0;    while ((opt = getopt(argc, argv, "d:vmf:i:x")) != -1) {        switch (opt) {        case 'd':            devprefix = optarg;            tdp = gettfsdev_fromprefix(devprefix,1);            if (!tdp)                return(CMD_FAILURE);            break;        case 'f':            flags = optarg;            break;        case 'i':            info = optarg;            break;        case 'm':            more++;            break;        case 'v':            verbose++;            break;        case 'x':            setexitflag = 1;            break;        default:            retval = CMD_PARAM_ERROR;            goto done;        }    }    arg1 = argv[optind];    arg2 = argv[optind+1];    arg3 = argv[optind+2];    arg4 = argv[optind+3];    if (argc == optind) {        retval = CMD_PARAM_ERROR;    }    else if (strcmp(arg1, "trace") == 0) {        if (argc == optind + 2)            tfsTrace = strtoul(arg2,0,0);        else if (argc == optind + 1)            printf("Current trace mode: 0x%lx\n",tfsTrace);        else            retval = CMD_PARAM_ERROR;    }    else if (strcmp(arg1, "init") == 0) {        if (getUsrLvl() < MAXUSRLEVEL) {            status = showTfsError(TFSERR_USERDENIED,0);        }        else {            _tfsinit(tdp);            tfsclear(tdp);        }    }    else if (strcmp(arg1, "log") == 0) {        retval = tfsLogCmd(argc,argv,optind);    }    else if (strcmp(arg1, "stat") == 0) {        char buf[32];        int  opencnt;        struct  tfsdat *slot;        /* Display current TFS memory usage: */        tfsmemuse(tdp,&tinfo,1);        printf("TFS Hdr size: %d\n",TFSHDRSIZ);        /* Display currently opened files: */        opencnt = 0;        slot = tfsSlots;        for (i=0;i<TFS_MAXOPEN;i++,slot++) {            if (slot->offset >= 0) {                printf("%3d: 0x%08lx %s %s\n",i,(ulong)(slot->base),                    tfsmodebtoa(slot->flagmode,buf),slot->hdr.name);                opencnt++;            }        }        printf("Total files currently opened: %d\n",opencnt);    }    else if (strcmp(arg1, "freemem") == 0) {        char *prefix;        tfsmemuse(tdp,&tinfo,0);        if (tdp)            prefix = tdp->prefix;        else            prefix = "";        if (argc == optind + 1) {            printf("0x%x (%d) bytes available to TFS %s\n",                tinfo.memfordata,tinfo.memfordata,prefix);        }        else if (argc == optind + 2) {            shell_sprintf(arg2,"0x%x",tinfo.memfordata);        }        else             retval = CMD_PARAM_ERROR;    }#if DEFRAG_TEST_ENABLED    else if (strcmp(arg1, "dht") == 0) {        if (argc == optind + 1) {            status = dumpDhdrTbl(0,0);            showTfsError(status,"dht");        }        else if (argc == optind + 3) {            status = dumpDhdrTbl((DEFRAGHDR *)strtol(arg2,0,0),                atoi(arg3));            showTfsError(status,"dht");        }        else            retval = CMD_PARAM_ERROR;    }    else if (strcmp(arg1, "dhdr") == 0) {        if (argc == optind + 2) {            status = dumpDhdr((DEFRAGHDR *)strtol(arg2,0,0));            showTfsError(status,"dhdr");        }        else            retval = CMD_PARAM_ERROR;    }#endif    else if (strcmp(arg1, "fhdr") == 0) {        if (argc == optind + 2) {            status = dumpFhdr((TFILE *)strtol(arg2,0,0));            showTfsError(status,"fhdr");        }        else            retval = CMD_PARAM_ERROR;    }    else if (strcmp(arg1, "info") == 0) {        if (argc == optind + 3) {            fp = tfsstat(arg2);            if ((!fp) ||                ((fp->flags & TFS_UNREAD) && (TFS_USRLVL(fp) > getUsrLvl())))                setenv(arg3,0);            else                setenv(arg3,fp->info);        }        else            retval = CMD_PARAM_ERROR;    }    else if (strcmp(arg1, "uname") == 0) {        if (argc == optind + 3) {            char uname[TFSNAMESIZE];            for(i=0;;i++) {                sprintf(uname,"%s%d",arg2,i);                if (!tfsstat(uname)) {                    setenv(arg3,uname);                    break;                }            }        }        else            retval = CMD_PARAM_ERROR;    }    else if (strcmp(arg1, "size") == 0) {        if (argc == optind + 3) {            fp = tfsstat(arg2);            if ((!fp) ||                ((fp->flags & TFS_UNREAD) && (TFS_USRLVL(fp) > getUsrLvl())))                setenv(arg3,0);            else {                shell_sprintf(arg3,"%ld",fp->filsize);            }        }        else            retval = CMD_PARAM_ERROR;    }    else if (strcmp(arg1, "ls") == 0) {        if (verbose > 1)            status = tfsvlist(&argv[optind+1],verbose,more << 1);        else            status = tfsqlist(&argv[optind+1],verbose,more << 3);        showTfsError(status,"ls");    }    else if (strcmp(arg1, "ln") == 0) {        if (argc == optind+3) {            from = arg2;            to = arg3;            status = tfslink(from,to);            showTfsError(status,from);        }        else            retval = CMD_PARAM_ERROR;    }    else if (strcmp(arg1, "cp") == 0) {        char    buf[16], linfo[TFSINFOSIZE];        if (argc == optind + 3) {            from = arg2;            to = arg3;            fp = tfsstat(from);            if (fp) {                if (!flags)                    flags = tfsflagsbtoa(fp->flags,buf);                if (!info)                    strcpy(linfo,fp->info);                else                    strcpy(linfo,info);                if ((fp->flags & TFS_UNREAD) &&                    (TFS_USRLVL(fp) > getUsrLvl())) {                    status = showTfsError(TFSERR_USERDENIED,from);                }                else if (to[0] == '0' && to[1] == 'x') {                    memcpy((char *)strtol(to,0,16),                        TFS_BASE(fp),TFS_SIZE(fp));                }                else {                    char *appram = (char *)getAppRamStart();                    memcpy(appram,TFS_BASE(fp),TFS_SIZE(fp));                    status = tfsadd(to,linfo,flags,appram,fp->filsize);                    showTfsError(status,to);                }            }            else                status = showTfsError(TFSERR_NOFILE,from);        }        else            retval = CMD_PARAM_ERROR;    }    else if (strcmp(arg1, "cat") == 0) {        if (argc >= optind + 2) {            for(i=optind+1;i<argc;i++) {                name = argv[i];                fp = tfsstat(name);                if (fp) {                    if ((fp->flags & TFS_UNREAD) &&                        (TFS_USRLVL(fp) > getUsrLvl())) {                        status = showTfsError(TFSERR_USERDENIED,name);                    }                    else {                        tfscat(fp,more << 3);   /* more times 8 */                    }                }                else                    status = showTfsError(TFSERR_NOFILE,name);            }        }        else            retval = CMD_PARAM_ERROR;    }#if DEFRAG_TEST_ENABLED    /* rms: "remove space".  Used for testing only... Keep removing files     * until the number of bytes freed up is greater than the argument     * to rms. Skip over all files listed after the first size argument.     * Arglist to tfs rms is...     *     *  tfs rms {SIZE} [EXCLUDEFILE1] [EXCLUDEFILE2] ...     *  where SIZE is the amount of space to freeup and EXCLUDEFILEN is     *  a filename that is not to be removed.     */    else if (strcmp(arg1, "rms") == 0) {        if (argc >= optind + 2) {            int insize, totsize;            totsize = 0;            insize = strtol(arg2,0,0);            tfsreorder();            for(i=0;tfsAlist[i];i++) {                int j;                for(j=optind+1;j<argc;j++) {                    if (!strcmp(TFS_NAME(tfsAlist[i]),argv[j]))                        break;                }                if (j != argc) {                    continue;                }                if (devprefix &&                    strncmp(TFS_NAME(tfsAlist[i]),devprefix,strlen(devprefix)))                    continue;                totsize += (TFS_SIZE(tfsAlist[i]) + TFSHDRSIZ);                if (verbose)                    printf("rms: removing %s (%ld)\n",TFS_NAME(tfsAlist[i]),                        TFS_SIZE(tfsAlist[i]) + TFSHDRSIZ);                _tfsunlink(TFS_NAME(tfsAlist[i]));                if (totsize > insize)                    break;                totsize += TFSHDRSIZ;            }        }        else            retval = CMD_PARAM_ERROR;    }#endif    else if (strcmp(arg1, "rm") == 0) {        if (argc >= optind + 2) {            status = tfsrm(&argv[optind+1]);            showTfsError(status,0);        }        else            retval = CMD_PARAM_ERROR;    }    else if (strcmp(arg1, "fix") == 0) {        tfsfixup(verbose,1);    }    else if (strcmp(arg1, "clean") == 0) {        int otrace;#if DEFRAG_TEST_ENABLED        DefragTestPoint = DefragTestSector = DefragTestType = 0;        if (argc == optind + 4) {            if (arg2[0] == 'S')                DefragTestType = DEFRAG_TEST_SERASE;            else if (arg2[0] == 'F')                DefragTestType = DEFRAG_TEST_FWRITE;            else if (arg2[0] == 'E')                DefragTestType = DEFRAG_TEST_EXIT;            else                return(CMD_PARAM_ERROR);            DefragTestPoint = atoi(arg3);            DefragTestSector = atoi(arg4);            printf("Testtype=%c, Testpoint=%d, Testsector=%d\n",                arg2[0],DefragTestPoint,DefragTestSector);        }        else #endif        if (argc != optind+1)            return(CMD_PARAM_ERROR);        /* If verbosity request is extreme, then turn on TFS trace also...         */        otrace = tfsTrace;        if (verbose >= 5)            tfsTrace = 99;        /* If tdp has been set by the -d option, only defrag the affected         * device; else, defrag all devices...         */        for (tdptmp=tfsDeviceTbl;tdptmp->start != TFSEOT;tdptmp++) {            if (!tdp || (tdp == tdptmp)) {                status = tfsclean(tdptmp,verbose+1);                showTfsError(status,tdptmp->prefix);            }        }        tfsTrace = otrace;    }    else if (strcmp(arg1, "check") == 0) {        if ((argc == optind+1) && (verbose == 0))            verbose = 1;            /* If tdp has been set by the -d option, only check the affected         * device; else, check all devices...         */        for (tdptmp=tfsDeviceTbl;tdptmp->start != TFSEOT;tdptmp++) {            if (!tdp || (tdp == tdptmp)) {                if (tfscheck(tdptmp,verbose) != TFS_OKAY)                    status = TFSERR_CORRUPT;            }        }        /* If an additional argument is provided after the "check" command         * then assume it is a shell variable name that is to be populated         * with the pass/fail status of the check...         */        if (argc == optind+2)            setenv(arg2,status == TFS_OKAY ? "PASS" : "FAIL");    }    else if (!strncmp(arg1, "ld",2)) {        if (argc == optind + 2) {            int vfy = 0;            if (arg1[2] == 'v')                vfy = 1;            else if (arg1[2] != 0)                return(-1);            name = argv[optind + 1];            status = tfsld(name,verbose,vfy);            showTfsError(status,name);        }        else            retval = CMD_PARAM_ERROR;    }    else if (strcmp(arg1, "run") == 0) {        if (argc >= optind + 2) {            name = argv[optind + 1];            status = tfsrun(&argv[optind+1],verbose);            showTfsError(status,name);        }        else            retval = CMD_PARAM_ERROR;    }    else if (!(strcmp(arg1, "add"))) {        if (argc == optind + 4) {            name = arg2;            src = (char *) strtol(arg3, (char **) 0, 0);            size = strtol(arg4, (char **) 0, 0);            status = tfsadd(name, info, flags, src, size);            showTfsError(status,name);        }        else            retval = CMD_PARAM_ERROR;    }    else        retval = CMD_PARAM_ERROR;done:#if INCLUDE_TFSSCRIPT    if ((setexitflag) && ((retval == -1) || (status != TFS_OKAY)))        ScriptExitFlag = EXIT_SCRIPT;#endif    return(retval);}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -