static struct fd_info *make_fdinfo(struct tracy_child *child, unsigned int fd, char *filename) { struct fd_info *fdi = (void *)malloc(sizeof(struct fd_info)); memset(fdi, 0, sizeof(fdi[0])); fdi->child = child; fdi->fd = fd; fdi->filename = filename; // check if we need to redirect this partition struct fstab_rec *fstabrec = get_fstab_rec(fdi->filename); if (fstabrec) { fdi->device = strdup(fstabrec->stub_device); // get fstype const char *fstype = get_fstype(fdi->device); if (!fstype) fstype = "ext4"; fdi->fs_type = strdup(fstype); } fdi->fs_pdata = NULL; fs_pre(fdi); return fdi; }
static int df_man_readable_handler(FAR const char *mountpoint, FAR struct statfs *statbuf, FAR void *arg) { FAR struct nsh_vtbl_s *vtbl = (FAR struct nsh_vtbl_s *)arg; uint32_t size; uint32_t used; uint32_t free; int which; char sizelabel; char freelabel; char usedlabel; const char labels[5] = { 'B', 'K', 'M', 'G', 'T' }; DEBUGASSERT(mountpoint && statbuf && vtbl); size = statbuf->f_bsize * statbuf->f_blocks; free = statbuf->f_bsize * statbuf->f_bavail; used = size - free; /* Find the label for size */ which = 0; while (size >= 1024) { which++; size >>= 10; } sizelabel = labels[which]; /* Find the label for free */ which = 0; while (free >= 1024) { which++; free >>= 10; } freelabel = labels[which]; /* Find the label for used */ which = 0; while (used >= 1024) { which++; used >>= 10; } usedlabel = labels[which]; nsh_output(vtbl, "%-10s %6ld%c %8ld%c %8ld%c %s\n", get_fstype(statbuf), size, sizelabel, used, usedlabel, free, freelabel, mountpoint); return OK; }
static int df_man_readable_handler(FAR const char *mountpoint, FAR struct statfs *statbuf, FAR void *arg) { uint32_t size; uint32_t used; uint32_t free; int which; char sizelabel; char freelabel; char usedlabel; const char labels[5] = { 'B', 'K', 'M', 'G', 'T' }; size = statbuf->f_bsize * statbuf->f_blocks; free = statbuf->f_bsize * statbuf->f_bavail; used = size - free; /* Find the label for size */ which = 0; while (size >= 9999 || ((size & 0x3ff) == 0 && size != 0)) { which++; size >>= 10; } sizelabel = labels[which]; /* Find the label for free */ which = 0; while (free >= 9999 || ((free & 0x3ff) == 0 && free != 0)) { which++; free >>= 10; } freelabel = labels[which]; /* Find the label for used */ which = 0; while (used >= 9999 || ((used & 0x3ff) == 0 && used != 0)) { which++; used >>= 10; } usedlabel = labels[which]; printf("%-10s %6ld%c %8ld%c %8ld%c %s\n", get_fstype(statbuf), size, sizelabel, used, usedlabel, free, freelabel, mountpoint); return OK; }
static int mount_handler(FAR const char *mountpoint, FAR struct statfs *statbuf, FAR void *arg) { FAR struct nsh_vtbl_s *vtbl = (FAR struct nsh_vtbl_s *)arg; FAR const char *fstype; DEBUGASSERT(mountpoint && statbuf && vtbl); /* Get the file system type */ fstype = get_fstype(statbuf); nsh_output(vtbl, " %s type %s\n", mountpoint, fstype); return OK; }
void disklabel_edit(struct disklabel *lp) { int i; printf("Select disk type. Valid types:\n"); for (i = 0; i < DKMAXTYPES; i++) printf("%d %s\n", i, dktypenames[i]); printf("\n"); GETNUM("Disk type (number)? [%d] ", lp->d_type); GETSTR("Disk model name? [%s] ", lp->d_typename); GETSTR("Disk pack name? [%s] ", lp->d_packname); FLAGS("Bad sectoring? [%c] ", D_BADSECT); FLAGS("Ecc? [%c] ", D_ECC); FLAGS("Removable? [%c] ", D_REMOVABLE); printf("\n"); GETNUM("Interleave? [%d] ", lp->d_interleave); GETNUM("Rpm? [%d] ", lp->d_rpm); GETNUM("Trackskew? [%d] ", lp->d_trackskew); GETNUM("Cylinderskew? [%d] ", lp->d_cylskew); GETNUM("Headswitch? [%d] ", lp->d_headswitch); GETNUM("Track-to-track? [%d] ", lp->d_trkseek); GETNUM("Drivedata 0? [%d] ", lp->d_drivedata[0]); GETNUM("Drivedata 1? [%d] ", lp->d_drivedata[1]); GETNUM("Drivedata 2? [%d] ", lp->d_drivedata[2]); GETNUM("Drivedata 3? [%d] ", lp->d_drivedata[3]); GETNUM("Drivedata 4? [%d] ", lp->d_drivedata[4]); printf("\n"); GETNUM("Bytes/sector? [%d] ", lp->d_secsize); GETNUM("Sectors/track? [%d] ", lp->d_nsectors); GETNUM("Tracks/cylinder? [%d] ", lp->d_ntracks); if (lp->d_secpercyl == 0) lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors; GETNUM("Sectors/cylinder? [%d] ", lp->d_secpercyl); GETNUM("Cylinders? [%d] ", lp->d_ncylinders); if (lp->d_secperunit == 0) lp->d_secperunit = lp->d_ncylinders * lp->d_secpercyl; GETNUM("Total sectors? [%d] ", lp->d_secperunit); printf( "Enter partition table. Note, sizes and offsets are in sectors.\n\n"); lp->d_npartitions = MAXPARTITIONS; for (i = 0; i < lp->d_npartitions; ++i) { GETNUM2("%c partition: offset? [%d] ", ('a' + i), lp->d_partitions[i].p_offset); GETNUM(" size? [%d] ", lp->d_partitions[i].p_size); get_fstype(lp, i); } /* Perform magic. */ lp->d_magic = lp->d_magic2 = DISKMAGIC; /* Calculate disklabel checksum. */ lp->d_checksum = 0; lp->d_checksum = dkcksum(lp); }
// get locations from our device.info void getLocations() { FILE *fp; int tmpInt; char tmpText[50]; if (strcmp(get_fstype(),"mtd") == 0) { fp = __popen("cat /proc/mtd", "r"); } else if (strcmp(get_fstype(),"emmc") == 0) { fp = __popen("cat /proc/emmc", "r"); } if (fp == NULL) { ui_print("\n=> Halp! Could not determine flash type!\n"); } else { while (fscanf(fp,"%s %*s %*s %*c%s",tmp.dev,tmp.mnt) != EOF) { if (strcmp(tmp.dev,"dev:") != 0) { tmp.dev[strlen(tmp.dev)-1] = '\0'; tmp.mnt[strlen(tmp.mnt)-1] = '\0'; if (sscanf(tmp.dev,"mtd%d",&tmpInt) == 1) { sprintf(tmpText,"%smtdblock%d",tw_block,tmpInt); strcpy(tmp.blk,tmpText); sprintf(tmpText,"%s%s",tw_mtd,tmp.dev); strcpy(tmp.dev,tmpText); } else { sprintf(tmpText,"%s%s",tw_block,tmp.dev); strcpy(tmp.dev,tmpText); strcpy(tmp.blk,tmp.dev); } } if (strcmp(tmp.mnt,"system") == 0) { // read in system line strcpy(sys.mnt,tmp.mnt); strcpy(sys.dev,tmp.dev); strcpy(sys.blk,tmp.blk); } if (strcmp(tmp.mnt,"userdata") == 0) { strcpy(dat.mnt,"data"); strcpy(dat.dev,tmp.dev); strcpy(dat.blk,tmp.blk); } if (strcmp(tmp.mnt,"boot") == 0) { strcpy(boo.mnt,tmp.mnt); strcpy(boo.dev,tmp.dev); strcpy(boo.blk,tmp.blk); } if (strcmp(tmp.mnt,"recovery") == 0) { strcpy(rec.mnt,tmp.mnt); strcpy(rec.dev,tmp.dev); strcpy(rec.blk,tmp.blk); } if (strcmp(tmp.mnt,"cache") == 0) { strcpy(cac.mnt,tmp.mnt); strcpy(cac.dev,tmp.dev); strcpy(cac.blk,tmp.blk); } if (strcmp(tmp.mnt,"wimax") == 0 || strcmp(tmp.mnt,"efs") == 0) { strcpy(wim.mnt,tmp.mnt); strcpy(wim.dev,tmp.dev); strcpy(wim.blk,tmp.blk); } } pclose(fp); readRecFstab(); } get_device_id(); }
int main(int argc, char *argv[]) { struct stat sb; struct timeval start; fstype_t *fstype; fsinfo_t fsoptions; fsnode *root; int ch, i, len; char *subtree; char *specfile; setprogname(argv[0]); debug = 0; if ((fstype = get_fstype(DEFAULT_FSTYPE)) == NULL) errx(1, "Unknown default fs type `%s'.", DEFAULT_FSTYPE); /* set default fsoptions */ (void)memset(&fsoptions, 0, sizeof(fsoptions)); fsoptions.fd = -1; fsoptions.sectorsize = -1; if (fstype->prepare_options) fstype->prepare_options(&fsoptions); specfile = NULL; if (gettimeofday(&start, NULL) == -1) err(1, "Unable to get system time"); start_time.tv_sec = start.tv_sec; start_time.tv_nsec = start.tv_usec * 1000; while ((ch = getopt(argc, argv, "B:b:Dd:f:F:M:m:N:o:pr:s:S:t:xZ")) != -1) { switch (ch) { case 'B': if (strcmp(optarg, "be") == 0 || strcmp(optarg, "4321") == 0 || strcmp(optarg, "big") == 0) { #if BYTE_ORDER == LITTLE_ENDIAN fsoptions.needswap = 1; #endif } else if (strcmp(optarg, "le") == 0 || strcmp(optarg, "1234") == 0 || strcmp(optarg, "little") == 0) { #if BYTE_ORDER == BIG_ENDIAN fsoptions.needswap = 1; #endif } else { warnx("Invalid endian `%s'.", optarg); usage(); } break; case 'b': len = strlen(optarg) - 1; if (optarg[len] == '%') { optarg[len] = '\0'; fsoptions.freeblockpc = strsuftoll("free block percentage", optarg, 0, 99); } else { fsoptions.freeblocks = strsuftoll("free blocks", optarg, 0, LLONG_MAX); } break; case 'D': dupsok = 1; break; case 'd': debug = strtoll(optarg, NULL, 0); break; case 'f': len = strlen(optarg) - 1; if (optarg[len] == '%') { optarg[len] = '\0'; fsoptions.freefilepc = strsuftoll("free file percentage", optarg, 0, 99); } else { fsoptions.freefiles = strsuftoll("free files", optarg, 0, LLONG_MAX); } break; case 'F': specfile = optarg; break; case 'M': fsoptions.minsize = strsuftoll("minimum size", optarg, 1LL, LLONG_MAX); break; case 'N': if (! setup_getid(optarg)) errx(1, "Unable to use user and group databases in `%s'", optarg); break; case 'm': fsoptions.maxsize = strsuftoll("maximum size", optarg, 1LL, LLONG_MAX); break; case 'o': { char *p; while ((p = strsep(&optarg, ",")) != NULL) { if (*p == '\0') errx(1, "Empty option"); if (! fstype->parse_options(p, &fsoptions)) usage(); } break; } case 'p': /* Deprecated in favor of 'Z' */ fsoptions.sparse = 1; break; case 'r': /* Round image size up to specified block size */ fsoptions.roundup = strsuftoll("roundup", optarg, 0, LLONG_MAX); break; case 's': fsoptions.minsize = fsoptions.maxsize = strsuftoll("size", optarg, 1LL, LLONG_MAX); break; case 'S': fsoptions.sectorsize = (int)strsuftoll("sector size", optarg, 1LL, INT_MAX); break; case 't': /* Check current one and cleanup if necessary. */ if (fstype->cleanup_options) fstype->cleanup_options(&fsoptions); fsoptions.fs_specific = NULL; if ((fstype = get_fstype(optarg)) == NULL) errx(1, "Unknown fs type `%s'.", optarg); fstype->prepare_options(&fsoptions); break; case 'x': fsoptions.onlyspec = 1; break; case 'Z': /* Superscedes 'p' for compatibility with NetBSD makefs(8) */ fsoptions.sparse = 1; break; case '?': default: usage(); /* NOTREACHED */ } } if (debug) { printf("debug mask: 0x%08x\n", debug); printf("start time: %ld.%ld, %s", (long)start_time.tv_sec, (long)start_time.tv_nsec, ctime(&start_time.tv_sec)); } argc -= optind; argv += optind; if (argc < 2) usage(); /* -x must be accompanied by -F */ if (fsoptions.onlyspec != 0 && specfile == NULL) errx(1, "-x requires -F mtree-specfile."); /* Accept '-' as meaning "read from standard input". */ if (strcmp(argv[1], "-") == 0) sb.st_mode = S_IFREG; else { if (stat(argv[1], &sb) == -1) err(1, "Can't stat `%s'", argv[1]); } switch (sb.st_mode & S_IFMT) { case S_IFDIR: /* walk the tree */ subtree = argv[1]; TIMER_START(start); root = walk_dir(subtree, ".", NULL, NULL); TIMER_RESULTS(start, "walk_dir"); break; case S_IFREG: /* read the manifest file */ subtree = "."; TIMER_START(start); root = read_mtree(argv[1], NULL); TIMER_RESULTS(start, "manifest"); break; default: errx(1, "%s: not a file or directory", argv[1]); /* NOTREACHED */ } /* append extra directory */ for (i = 2; i < argc; i++) { if (stat(argv[i], &sb) == -1) err(1, "Can't stat `%s'", argv[i]); if (!S_ISDIR(sb.st_mode)) errx(1, "%s: not a directory", argv[i]); TIMER_START(start); root = walk_dir(argv[i], ".", NULL, root); TIMER_RESULTS(start, "walk_dir2"); } if (specfile) { /* apply a specfile */ TIMER_START(start); apply_specfile(specfile, subtree, root, fsoptions.onlyspec); TIMER_RESULTS(start, "apply_specfile"); } if (debug & DEBUG_DUMP_FSNODES) { printf("\nparent: %s\n", subtree); dump_fsnodes(root); putchar('\n'); } /* build the file system */ TIMER_START(start); fstype->make_fs(argv[0], subtree, root, &fsoptions); TIMER_RESULTS(start, "make_fs"); free_fsnodes(root); exit(0); /* NOTREACHED */ }
static int df_man_readable_handler(FAR const char *mountpoint, FAR struct statfs *statbuf, FAR void *arg) { FAR struct nsh_vtbl_s *vtbl = (FAR struct nsh_vtbl_s *)arg; uint32_t size; uint32_t used; uint32_t free; int which; char sizelabel; char freelabel; char usedlabel; const char labels[5] = { 'B', 'K', 'M', 'G', 'T' }; DEBUGASSERT(mountpoint && statbuf && vtbl); size = statbuf->f_bsize * statbuf->f_blocks; free = statbuf->f_bsize * statbuf->f_bavail; used = size - free; /* Find the label for size */ which = 0; while (size >= 9999 || ((size & 0x3ff) == 0 && size != 0)) { which++; size >>= 10; } sizelabel = labels[which]; /* Find the label for free */ which = 0; while (free >= 9999 || ((free & 0x3ff) == 0 && free != 0)) { which++; free >>= 10; } freelabel = labels[which]; /* Find the label for used */ which = 0; while (used >= 9999 || ((used & 0x3ff) == 0 && used != 0)) { which++; used >>= 10; } usedlabel = labels[which]; #if !defined(CONFIG_BUILD_PROTECTED) && !defined(CONFIG_BUILD_KERNEL) nsh_output(vtbl, "%-10s %6ld%c %8ld%c %8ld%c %s\n", get_fstype(statbuf), size, sizelabel, used, usedlabel, free, freelabel, mountpoint); #else nsh_output(vtbl, "%6ld%c %8ld%c %8ld%c %s\n", size, sizelabel, used, usedlabel, free, freelabel, mountpoint); #endif return OK; }