/**************************************************************************** * Name: tash_mksmartfs * * Description: * Make SmartFS file system on the specified block device. * Put -f option will LLFORMAT smartfs by force. * * Usage: * mksmartfs <source directory> [-f] <target directory> ****************************************************************************/ static int tash_mksmartfs(int argc, char **args) { const char *src; const char *fmt; bool force = false; int option; #ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS int nrootdirs = 1; #endif optind = -1; while ((option = getopt(argc, args, "f")) != ERROR) { switch (option) { case 'f': force = true; break; case '?': default: fmt = INVALID_ARGS; goto errout_with_fmt; } } if (optind >= argc) { fmt = MISSING_ARGS; goto errout_with_fmt; } /* Set path for registered block driver */ src = args[optind]; if (optind + 1 < argc) { #ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS nrootdirs = atoi(args[optind++]); } if (nrootdirs > 8 || nrootdirs < 1) { FSCMD_OUTPUT(INVALID_ARGS "Invalid number of root directories specified\n", args[0]); return ERROR; } if (optind + 1 < argc) { #endif fmt = TOO_MANY_ARGS; goto errout_with_fmt; } #ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS return mksmartfs(src, nrootdirs, force); #else return mksmartfs(src, force); #endif errout_with_fmt: #ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS FSCMD_OUTPUT(fmt, " : [-f] <source> [<nrootdir>]\n", args[0]); #else FSCMD_OUTPUT(fmt, " : [-f] <source>\n", args[0]); #endif return ERROR; }
void tc_fs_smartfs_mksmartfs(void) { int ret; ret = mksmartfs(SMARTFS_DEV_PATH, 1); TC_ASSERT_EQ("mksmartfs", ret, OK); ret = mksmartfs(INVALID_PATH, 1); TC_ASSERT_NEQ("mksmartfs", ret, OK); ret = mksmartfs(SMARTFS_DEV_PATH, 0); TC_ASSERT_EQ("mksmartfs", ret, OK); TC_SUCCESS_RESULT(); }
int cmd_mksmartfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { char *fullpath = nsh_getfullpath(vtbl, argv[1]); int ret = ERROR; #ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS int nrootdirs = 1; #endif if (fullpath) { /* Test if number of root directories was supplied */ #ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS if (argc == 3) { nrootdirs = atoi(argv[2]); } if (nrootdirs > 8 || nrootdirs < 1) { nsh_output(vtbl, "Invalid number of root directories specified\n"); } else #endif { #ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS ret = mksmartfs(fullpath, nrootdirs); #else ret = mksmartfs(fullpath); #endif if (ret < 0) { nsh_output(vtbl, g_fmtcmdfailed, argv[0], "mksmartfs", NSH_ERRNO); } } nsh_freefullpath(fullpath); } return ret; }
int smart_main(int argc, char *argv[]) { FAR struct mtd_dev_s *mtd; unsigned int i; int ret; /* Seed the random number generated */ srand(0x93846); /* Create and initialize a RAM MTD device instance */ #ifdef CONFIG_EXAMPLES_SMART_ARCHINIT mtd = smart_archinitialize(); #else mtd = rammtd_initialize(g_simflash, EXAMPLES_SMART_BUFSIZE); #endif if (!mtd) { message("ERROR: Failed to create RAM MTD instance\n"); msgflush(); exit(1); } /* Initialize to provide SMART on an MTD interface */ MTD_IOCTL(mtd, MTDIOC_BULKERASE, 0); ret = smart_initialize(1, mtd); if (ret < 0) { message("ERROR: SMART initialization failed: %d\n", -ret); msgflush(); exit(2); } /* Creaet a SMARTFS filesystem */ ret = mksmartfs("/dev/smart1"); /* Mount the file system */ ret = mount("/dev/smart1", CONFIG_EXAMPLES_SMART_MOUNTPT, "smartfs", 0, NULL); if (ret < 0) { message("ERROR: Failed to mount the SMART volume: %d\n", errno); msgflush(); exit(3); } /* Set up memory monitoring */ #ifdef CONFIG_CAN_PASS_STRUCTS g_mmbefore = mallinfo(); g_mmprevious = g_mmbefore; #else (void)mallinfo(&g_mmbefore); memcpy(&g_mmprevious, &g_mmbefore, sizeof(struct mallinfo)); #endif /* Loop a few times ... file the file system with some random, files, * delete some files randomly, fill the file system with more random file, * delete, etc. This beats the FLASH very hard! */ #if CONFIG_EXAMPLES_SMART_NLOOPS == 0 for (i = 0; ; i++) #else for (i = 1; i <= CONFIG_EXAMPLES_SMART_NLOOPS; i++) #endif { /* Write a files to the SMART file system until either (1) all of the * open file structures are utilized or until (2) SMART reports an error * (hopefully that the file system is full) */ message("\n=== FILLING %d =============================\n", i); ret = smart_fillfs(); message("Filled file system\n"); message(" Number of files: %d\n", g_nfiles); message(" Number deleted: %d\n", g_ndeleted); /* Directory listing */ smart_directory(); /* Verify all files written to FLASH */ ret = smart_verifyfs(); if (ret < 0) { message("ERROR: Failed to verify files\n"); message(" Number of files: %d\n", g_nfiles); message(" Number deleted: %d\n", g_ndeleted); } else { #if CONFIG_EXAMPLES_SMART_VERBOSE != 0 message("Verified!\n"); message(" Number of files: %d\n", g_nfiles); message(" Number deleted: %d\n", g_ndeleted); #endif } /* Delete some files */ message("\n=== DELETING %d ============================\n", i); ret = smart_delfiles(); if (ret < 0) { message("ERROR: Failed to delete files\n"); message(" Number of files: %d\n", g_nfiles); message(" Number deleted: %d\n", g_ndeleted); } else { message("Deleted some files\n"); message(" Number of files: %d\n", g_nfiles); message(" Number deleted: %d\n", g_ndeleted); } /* Directory listing */ smart_directory(); /* Verify all files written to FLASH */ ret = smart_verifyfs(); if (ret < 0) { message("ERROR: Failed to verify files\n"); message(" Number of files: %d\n", g_nfiles); message(" Number deleted: %d\n", g_ndeleted); } else { #if CONFIG_EXAMPLES_SMART_VERBOSE != 0 message("Verified!\n"); message(" Number of files: %d\n", g_nfiles); message(" Number deleted: %d\n", g_ndeleted); #endif } /* Show memory usage */ smart_loopmemusage(); msgflush(); } /* Delete all files then show memory usage again */ smart_delallfiles(); smart_endmemusage(); msgflush(); return 0; }
int board_initialize(void) { int ret; char partref[4]; char devname[16]; #ifdef CONFIG_MTD FAR struct mtd_dev_s *mtd; FAR struct mtd_geometry_s geo; FAR struct mtd_dev_s *mtd_part; #endif int partno = QEMU_SMARTFS_PARTITION_PARTNO; int minorno = QEMU_SMARTFS_PARTITION_MINORNO; int partoffset = QEMU_SMARTFS_PARTITION_START; int partsize = QEMU_SMARTFS_PARTITION_SIZE; #ifdef CONFIG_MTD mtd = up_flashinitialize(); if (!mtd) { lldbg("ERROR : up_flashinitializ failed\n"); return ERROR; } if (mtd->ioctl(mtd, MTDIOC_GEOMETRY, (unsigned long)&geo) < 0) { lldbg("ERROR: mtd->ioctl failed\n"); return ERROR; } #ifdef CONFIG_MTD_PARTITION mtd_part = mtd_partition(mtd, partoffset, partsize / geo.blocksize, partno); if (!mtd_part) { lldbg("ERROR: failed to create partition.\n"); return ERROR; } #endif /* CONFIG_MTD_PARTITION */ ret = snprintf(partref, sizeof(partref), "p%d", partno); if (ret < 0) { lldbg("ERROR: snprintf failed while constructing partref, ret = %d\n", ret); return ERROR; } if (ret >= sizeof(partref)) { lldbg("WARNING: snprintf output might have truncated, ret = %d\n", ret); } ret = snprintf(devname, sizeof(devname), "/dev/smart%d%s", minorno, partref); if (ret < 0) { lldbg("ERROR: snprintf failed while constructing devname, ret = %d\n", ret); return ERROR; } if (ret >= sizeof(devname)) { lldbg("WARNING: snprintf output might have truncated, ret = %d\n", ret); } #if defined(CONFIG_MTD_SMART) && defined(CONFIG_FS_SMARTFS) smart_initialize(minorno, mtd_part, partref); #endif /* defined(CONFIG_MTD_SMART) && defined(CONFIG_FS_SMARTFS) */ #endif /* CONFIG_MTD */ ret = mksmartfs(devname, false); if (ret != OK) { lldbg("ERROR: mksmartfs on %s failed, ret = %d\n", devname, ret); } else { ret = mount(devname, QEMU_SMARTFS_MOUNT_POINT, "smartfs", 0, NULL); if (ret != OK) { lldbg("ERROR: mounting '%s' failed, ret = %d\n", devname, ret); } else { lldbg("%s is mounted successfully at %s \n", devname, QEMU_SMARTFS_MOUNT_POINT); } } return OK; }