void ZP_CreateLogFile(void) { char file[50]; uint32_t ul_hour, ul_minute, ul_second; uint32_t ul_year, ul_month, ul_day, ul_week; rtc_get_time(RTC, &ul_hour, &ul_minute, &ul_second); rtc_get_date(RTC, &ul_year, &ul_month, &ul_day, &ul_week); f_mkdir("0:Logs"); sprintf(file, "0:logs/%04u", ul_year); f_mkdir((char const *)file); sprintf(file, "0:logs/%04u/%02u", ul_year, ul_month); f_mkdir((char const *)file); sprintf(file, "0:logs/%04u/%02u/%02u", ul_year, ul_month, ul_day); f_mkdir((char const *)file); sprintf(file, "0:Logs/%04u/%02u/%02u/Flight_Log_%02u.%02u.%02u.log", ul_year, ul_month, ul_day, ul_hour, ul_minute, ul_second); f_open(&f_log, (char const *)file, FA_CREATE_ALWAYS | FA_WRITE); f_puts("Goblin-Tech", &f_log); f_puts("GT101-0001", &f_log); f_puts("00.00.00", &f_log); uint16_t size = f_size(&f_script); uint8_t dummy; f_write(&f_log, &size, 2, &dummy); f_write(&f_log, &Script, size, &dummy); f_sync(&f_log); }
void Initialize(){ DrawString(TOP_SCREEN, " INITIALIZE... ", 0, 240-8, WHITE, BLACK); if(FSInit()){ DrawString(TOP_SCREEN, " LOADING... ", 0, 240-8, WHITE, BLACK); }else{ DrawString(TOP_SCREEN, " ERROR! ", 0, 240-8, RED, BLACK); } LoadPack(); //Console Stuff memset(TOP_SCREEN, 0x00, 0x46500); memset(TOP_SCREEN2, 0x00, 0x46500); ConsoleSetXY(15, 15); ConsoleSetWH(370, 160); ConsoleSetBorderColor(BLUE); ConsoleSetTextColor(WHITE); ConsoleSetBackgroundColor(BLACK); ConsoleSetSpecialColor(BLUE); ConsoleSetSpacing(2); ConsoleSetBorderWidth(3); //Check that the data is installed f_mkdir ("rxTools"); f_mkdir ("rxTools/nand"); InstallConfigData(); SplashScreen(); for(int i = 0; i < 0x333333*6; i++){ u32 pad = GetInput(); if(pad & BUTTON_R1 && i > 0x333333) goto rxTools_boot; } rxModeQuickBoot(); rxTools_boot: memset(TOP_SCREEN, 0x00, 0x46500); memset(TOP_SCREEN2, 0x00, 0x46500); }
/********************************************************************** functionName:FRESULT report_save(char *type,char *file,REPORT_TypeDef *report) description:保存结果,type:试验类型 file:文件名 report:实验报告 **********************************************************************/ FRESULT report_save_usb(uint8_t type,char *file,REPORT_TypeDef *report) { FRESULT fresult; FIL file_obj; uint32_t br; char path[PATH_BUF_SIZE]; usprintf(path,"%s/%s.bin",test_path_usb[type].path,file); fresult=f_open(&file_obj,path,FA_CREATE_ALWAYS|FA_WRITE); if(fresult==FR_NO_PATH) { fresult=f_mkdir("1:/test"); fresult=f_mkdir(test_path_usb[type].path); fresult=f_open(&file_obj,path,FA_CREATE_NEW|FA_WRITE); if(fresult!=FR_OK) return fresult; } else if(fresult!=FR_OK) return fresult; fresult=f_write(&file_obj,report,sizeof(REPORT_TypeDef),&br); f_close(&file_obj); return fresult; }
/********************************************************************** functionName: FRESULT pcm_backup(void) description:上位机参数备份到SD卡 **********************************************************************/ FRESULT pcm_backup( uint8_t type ) { uint8_t *dat = NULL; uint32_t pcm_len=0; FRESULT fresult; FIL file_obj; uint32_t br; switch ( type ) { case BACKUP_SD: fresult=f_open(&file_obj,"0:/sys/pcm.bin",FA_CREATE_ALWAYS|FA_WRITE); if(fresult==FR_NO_PATH) { f_mkdir("0:/sys"); fresult=f_open(&file_obj,"0:/sys/pcm.bin",FA_CREATE_ALWAYS|FA_WRITE); if(fresult!=FR_OK) return fresult; } else if(fresult!=FR_OK) { return fresult; } break; case BACKUP_USB: fresult=f_open(&file_obj,"1:/sys/pcm.bin",FA_CREATE_ALWAYS|FA_WRITE); if(fresult==FR_NO_PATH) { f_mkdir("1:/sys"); fresult=f_open(&file_obj,"1:/sys/pcm.bin",FA_CREATE_ALWAYS|FA_WRITE); if(fresult!=FR_OK) return fresult; } else if(fresult!=FR_OK) { return fresult; } break; } dat=pcm_ram; pcm_len=PCM_MEM_SIZE; while(pcm_len) { if(pcm_len>BACKUP_BUF_SIZE) { f_write(&file_obj,dat,BACKUP_BUF_SIZE,&br); dat+=BACKUP_BUF_SIZE; pcm_len-=BACKUP_BUF_SIZE; } else { f_write(&file_obj,dat,pcm_len,&br); pcm_len=0; } } f_close(&file_obj); return FR_OK; }
static void prvCreateDemoFileUsing_f_putc( void ) { unsigned char ucReturn; int iByte, iReturned; F_FILE *pxFile; char cFileName[ fsMAX_FILE_NAME_LEN ]; /* Obtain and print out the working directory. */ f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE ); /* Create a sub directory. */ ucReturn = f_mkdir( pcDirectory1 ); configASSERT( ucReturn == F_NO_ERROR ); /* Move into the created sub-directory. */ ucReturn = f_chdir( pcDirectory1 ); configASSERT( ucReturn == F_NO_ERROR ); /* Obtain and print out the working directory. */ f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE ); /* Create a subdirectory in the new directory. */ ucReturn = f_mkdir( pcDirectory2 ); configASSERT( ucReturn == F_NO_ERROR ); /* Move into the directory just created - now two directories down from the root. */ ucReturn = f_chdir( pcDirectory2 ); configASSERT( ucReturn == F_NO_ERROR ); /* Obtain and print out the working directory. */ f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE ); configASSERT( strcmp( cRAMBuffer, pcFullPath ) == 0 ); /* Generate the file name. */ sprintf( cFileName, "%s.txt", pcDirectory2 ); /* Print out the file name and the directory into which the file is being written. */ pxFile = f_open( cFileName, "w" ); /* Create a file 1 byte at a time. The file is filled with incrementing ascii characters starting from '0'. */ for( iByte = 0; iByte < fsPUTC_FILE_SIZE; iByte++ ) { iReturned = f_putc( ( ( int ) '0' + iByte ), pxFile ); configASSERT( iReturned == ( ( int ) '0' + iByte ) ); } /* Finished so close the file. */ f_close( pxFile ); /* Move back to the root directory. */ ucReturn = f_chdir( "../.." ); configASSERT( ucReturn == F_NO_ERROR ); /* Obtain and print out the working directory. */ f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE ); configASSERT( strcmp( cRAMBuffer, pcRoot ) == 0 ); }
void logger_start() { if (!config.logger.enabled) return; logger_next_flight(); if (!storage_ready()) { gui_showmessage_P(PSTR("SD card error!")); fc.logger_state = LOGGER_ERROR; return; } uint8_t sec; uint8_t min; uint8_t hour; uint8_t day; uint8_t wday; uint8_t month; uint16_t year; datetime_from_epoch(time_get_utc(), &sec, &min, &hour, &day, &wday, &month, &year); char path[128]; //base dir sprintf_P(path, PSTR("%S"), LOG_DIR); f_mkdir(path); //year sprintf_P(path, PSTR("%S/%04d"), LOG_DIR, year); f_mkdir(path); //month sprintf_P(path, PSTR("%S/%04d/%02d"), LOG_DIR, year, month); f_mkdir(path); //day sprintf_P(path, PSTR("%S/%04d/%02d/%02d"), LOG_DIR, year, month, day); f_mkdir(path); switch (config.logger.format) { case(LOGGER_IGC): fc.logger_state = igc_start(path); break; case(LOGGER_KML): fc.logger_state = kml_start(path); break; case(LOGGER_RAW): fc.logger_state = raw_start(path); break; } }
void M_MakeDirectory(char *path) { #ifdef _WIN32 mkdir(path); #else #if ORIGCODE mkdir(path, 0755); #else FRESULT res; char* path_mod; int len; // remove trailing slash len = strlen (path); path_mod = (char*)malloc (len + 1); strncpy (path_mod, path, len); if (path_mod[len - 1] == '/') { path_mod[len - 1] = 0; } res = f_mkdir (path_mod); if ((res != FR_OK) && (res != FR_EXIST)) { I_Error ("M_MakeDirectory: path = '%s', path_mod = '%s', res = %i", path, path_mod, res); } free (path_mod); #endif #endif }
TEST(SDLog, log_topic_integration_test) { // init logging log_init(); log_handler_t stdout_log; log_handler_register(&stdout_log, LOG_LVL_WARNING, [](log_level_t lvl, const char *msg, size_t len) { std::cout << msg << std::endl; }); // initialize messagebus msgbus_t bus; msgbus_init(&bus); msgbus_topic_t topic; test_t topic_buf; msgbus_topic_create(&topic, &bus, &test_type, &topic_buf, "/test"); // create and mount filesystem FATFS fs; FRESULT mkfs_res = f_mkfs("", FM_ANY, 0, NULL, 0); CHECK_EQUAL(FR_OK, mkfs_res); FRESULT mount_res = f_mount(&fs, "", 1); CHECK_EQUAL(FR_OK, mount_res); FRESULT mkdir_res = f_mkdir("/log"); CHECK_EQUAL(FR_OK, mkdir_res); // initialize logger & scheduler msgbus_scheduler_t sched; msgbus_scheduler_task_buffer_space_t buf[10]; msgbus_scheduler_init(&sched, &bus, buf, 10); static struct logfile_s log_files[] = { {.topic="/test"}, };
/** * @brief Make a directory. */ bool CFile::mkDir() { bool rc = false; if ( f_mkdir(mPath.data()) == FR_OK ) rc = true; return rc; }
bool fileWrite(const void *buffer, const char *path, u32 size) { FIL file; FRESULT result; switch(f_open(&file, path, FA_WRITE | FA_OPEN_ALWAYS)) { case FR_OK: { unsigned int written; result = f_write(&file, buffer, size, &written); if(result == FR_OK) result = f_truncate(&file); result |= f_close(&file); return result == FR_OK && (u32)written == size; } case FR_NO_PATH: for(u32 i = 1; path[i] != 0; i++) if(path[i] == '/') { char folder[i + 1]; memcpy(folder, path, i); folder[i] = 0; result = f_mkdir(folder); } return result == FR_OK && fileWrite(buffer, path, size); default: return false; } }
void fatfs_test(void) { FATFS Fatfs; FIL fp; const uint8_t w_b[10] = {0,1,2,3,4,5,6,7,8,9}; const char *str = "dir test"; uint8_t r_b[10]; uint32_t w_n, r_n; f_mount(1, &Fatfs); //MMC == 1 // f_mkfs(1, 0, _MAX_SS); f_open(&fp, "1:/test.txt", FA_READ|FA_WRITE|FA_OPEN_ALWAYS); f_write(&fp, w_b, 10, &w_n); f_lseek(&fp, 0); f_read(&fp, r_b, 10, &r_n); f_lseek(&fp, 4); f_read(&fp, r_b, 10, &r_n); f_close(&fp); f_mkdir("1:/dir"); f_open(&fp, "1:/dir/test.txt", FA_READ|FA_WRITE|FA_OPEN_ALWAYS); f_write(&fp, str, strlen(str)+1, &w_n); f_lseek(&fp, 0); f_read(&fp, r_b, 10, &r_n); f_lseek(&fp, 4); f_read(&fp, r_b, 10, &r_n); f_close(&fp); return; }
void LTK_creat_dir(void) { FATFS fs; FRESULT res; char path[20]; res = f_mount(0,&fs); if (res != FR_OK) { printf("mont file system error, error code: %u\n",res); return; } printf("please input the directory name terminated by enter\n"); scanf("%[^\n]",path); res = f_mkdir(path); if (res == FR_OK) { printf("directory created successfully\n"); } else { printf("failed to create directory, error code: %u", res); } f_mount(0,NULL); }
/******************************************************************************* * Function Name : Test_f_mkdir * Description : 创建目录 * Input : * Return : res *******************************************************************************/ FRESULT Test_f_mkdir(const TCHAR* path)//创建一个新目录,输入目录的路径Test_f_mkdir("/dir");只能一级一级的建立目录 { fatfs_res=f_mkdir(path);//创建一个新目录 return fatfs_res; }
void MessageStorage::createDirectory(char * dir) { module_debug_strg("mkdir %s", dir); m_fr = f_mkdir(dir); if(m_fr != FR_OK) module_debug_strg("mkdir failed! %s : %d", dir, m_fr); }
FIO_status start_load_curve_list(void) { SDFS_status_type res; res = SDFS_scandir("0:/" CURVE_DIR_NAME, &curves_list); if (res != SDFS_OK) { //Curve directory is not found f_mkdir("0:/" CURVE_DIR_NAME); curves_list.num = 0; } return FIO_OK; }
bool MassStorage::MakeDirectory(const char *directory) { if (f_mkdir(directory) != FR_OK) { reprap.GetPlatform().MessageF(ErrorMessage, "Failed to create directory %s\n", directory); return false; } return true; }
int FATFileSystem::mkdir(const char *name, mode_t mode) { // Added by Embedded Artists to fix implementation when using more than one volume debug_if(FFS_DBG, "mkdir(%s) on filesystem [%s], drv [%d]\n", name, _name, _fsid); char n[64]; snprintf(n, 64, "%d:/%s", _fsid, name); FRESULT res = f_mkdir(n); return res == 0 ? 0 : -1; }
int maketree (void) { HANDLE hdir; int slen, dlen, rv = 0; DWORD br; UINT bw; slen = strlen(SrcPath); dlen = strlen(DstPath); sprintf(&SrcPath[slen], "/*"); hdir = FindFirstFile(SrcPath, &Fd); /* Open directory */ if (hdir == INVALID_HANDLE_VALUE) { printf("Failed to open directory.\n"); } else { for (;;) { sprintf(&SrcPath[slen], "/%s", Fd.cFileName); sprintf(&DstPath[dlen], "/%s", Fd.cFileName); if (Fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { /* The item is a directory */ if (strcmp(Fd.cFileName, ".") && strcmp(Fd.cFileName, "..")) { if (f_mkdir(DstPath)) { /* Create destination directory */ printf("Failed to create directory.\n"); break; } if (!maketree()) break; /* Enter the directory */ Dirs++; } } else { /* The item is a file */ printf("%s\n", SrcPath); if ((SrcFile = CreateFile(SrcPath, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0)) == INVALID_HANDLE_VALUE) { /* Open source file */ printf("Failed to open source file.\n"); break; } if (f_open(&DstFile, DstPath, FA_CREATE_ALWAYS | FA_WRITE)) { /* Create destination file */ printf("Failed to create destination file.\n"); break; } do { /* Copy source file to destination file */ ReadFile(SrcFile, Buff, sizeof Buff, &br, 0); if (br == 0) break; f_write(&DstFile, Buff, (UINT)br, &bw); } while (br == bw); CloseHandle(SrcFile); f_close(&DstFile); if (br && br != bw) { printf("Failed to write file.\n"); break; } Files++; } if (!FindNextFile(hdir, &Fd)) { rv = 1; break; } } FindClose(hdir); } SrcPath[slen] = 0; DstPath[dlen] = 0; return rv; }
static int _mkdir (vfs_mount_t *mountp, const char *name, mode_t mode) { fatfs_desc_t *fs_desc = (fatfs_desc_t *)mountp->private_data; (void) mode; snprintf(fs_desc->abs_path_str_buff, FATFS_MAX_ABS_PATH_SIZE, "%d:/%s", fs_desc->vol_idx, name); return fatfs_err_to_errno(f_mkdir(fs_desc->abs_path_str_buff)); }
/* * ======== mkdir ======== */ int mkdir(const char * path, unsigned int mode) { (void)mode; if (f_mkdir(path) == FR_OK) { return (0); } else { return (-1); } }
// Create a new directory bool MassStorage::MakeDirectory(const char *parentDir, const char *dirName) { String<MaxFilenameLength> location; CombineName(location.GetRef(), parentDir, dirName); if (f_mkdir(location.c_str()) != FR_OK) { reprap.GetPlatform().MessageF(ErrorMessage, "Failed to create directory %s\n", location.c_str()); return false; } return true; }
//----------------------------------------------------------------------------- // If there's no "nanibox" directory, create it, doesn't do anything if it // exists static uint8_t make_dirs(void) { FRESULT stat; DIR naniBox_dir; stat = f_opendir(&naniBox_dir, NANIBOX_DNAME); if (FR_NO_PATH == stat) { stat = f_mkdir(NANIBOX_DNAME); } return stat; }
static int fatfs_mkdir(mount_point_t *point, const char *path, mode_t mode) { FRESULT res; res = f_mkdir(point->ctx, path); if (res == FR_OK) { return 0; } else { fatfs_result_to_errno(res); return -1; } }
int FATFileSystem::mkdir(const char *path, mode_t mode) { Deferred<const char*> fpath = fat_path_prefix(_id, path); lock(); FRESULT res = f_mkdir(fpath); unlock(); if (res != FR_OK) { debug_if(FFS_DBG, "f_mkdir() failed: %d\n", res); } return fat_error_remap(res); }
bool TestExtFile::test_is_dir() { f_mkdir("test/tmp_dir"); VERIFY(!f_is_dir("test/test_ext_file.txt")); VERIFY(f_is_dir("test/tmp_dir")); VERIFY(!f_is_dir("tmp_dir")); f_chdir("test"); VERIFY(!f_is_dir("test/tmp_dir")); VERIFY(f_is_dir("tmp_dir")); f_rmdir("test/tmp_dir"); f_chdir(".."); return Count(true); }
int main(int argc, char** argv) { size_t part = 1024* 1024* 1024; //10485760; uint32_t inode_number = 128; uint32_t block_size = 128; char* filename; int option = 0; while((option = getopt(argc, argv, "i:b:s:")) != -1) { switch(option) { case 'i': inode_number = atoi(optarg); break; case 'b': block_size = atoi(optarg); break; case 's': part = atoi(optarg); break; } } if(optind == argc) return -1; filename = argv[opterr]; FILE* fh = fopen(filename, "w+"); fseek(fh, part, SEEK_SET); fputc('\0', fh); fclose(fh); void* p = fext_init(filename); mkfs(p, part, inode_number, block_size); f_mkdir(p, 0, "foo"); f_mkdir(p, 0, "foo0"); f_tree(p); }
void ev3rt_load_configuration() { /** * Create '/ev3rt/etc/' */ f_mkdir("/ev3rt"); f_mkdir("/ev3rt/etc"); static char localname[100]; ini_gets("Bluetooth", "LocalName", "Mindstorms EV3", localname, 100, CFG_INI_FILE); ini_puts("Bluetooth", "LocalName", localname, CFG_INI_FILE); ev3rt_bluetooth_local_name = localname; static char pincode[17]; ini_gets("Bluetooth", "PinCode", "0000", pincode, 17, CFG_INI_FILE); ini_puts("Bluetooth", "PinCode", pincode, CFG_INI_FILE); ev3rt_bluetooth_pin_code = pincode; static bool_t disable_port_1; disable_port_1 = ini_getbool("Sensors", "DisablePort1", false, CFG_INI_FILE); ini_putl("Sensors", "DisablePort1", disable_port_1, CFG_INI_FILE); ev3rt_sensor_port_1_disabled = &disable_port_1; }
STATIC mp_obj_t os_mkdir(mp_obj_t path_o) { const char *path = mp_obj_str_get_str(path_o); FRESULT res = f_mkdir(path); switch (res) { case FR_OK: return mp_const_none; case FR_EXIST: // TODO should be FileExistsError nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "File exists: '%s'", path)); default: nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "Error creating directory '%s'", path)); } }
static int fat_mkdir(struct device_d *dev, const char *pathname) { struct fat_priv *priv = dev->priv; int ret; ret = f_mkdir(&priv->fat, pathname); if (ret) return ret; cdev_flush(priv->cdev); return 0; }
static bool switchToMainDir(bool isSd) { const char *mainDir = isSd ? "/luma" : "/rw/luma"; switch(f_chdir(mainDir)) { case FR_OK: return true; case FR_NO_PATH: return f_mkdir(mainDir) == FR_OK && switchToMainDir(isSd); default: return false; } }