s32 FS_DeleteFile( char *Path ) { #ifdef USEATTR //delete attribute file char *AttrFile = (char*)heap_alloc_aligned( 0, 0x80, 0x40 ); _sprintf( AttrFile, "%s.attr", Path ); f_unlink( AttrFile ); heap_free( 0, AttrFile ); #endif switch( f_unlink( Path ) ) { case FR_DENIED: //Folder is not empty and can't be removed without deleting the content first return FS_Delete( Path ); case FR_OK: return FS_SUCCESS; case FR_EXIST: return FS_EEXIST2; case FR_NO_FILE: case FR_NO_PATH: return FS_ENOENT2; default: break; } return FS_EFATAL; }
/** * @brief file_scan处理非递归过程, * 删除旧的playlist(用于存储歌曲路径,用于文件定位)和lcdlist(用于存储歌曲列表,用于显示) * @param path:初始扫描路径 * @retval none */ static void file_scan(char* path) { fres = f_unlink("0:mp3player/playlist.txt");//删除旧的playlist fres = f_unlink("0:mp3player/lcdlist.txt"); //删除旧的playlist fres = scan_files(path); //递归扫描歌曲文件 }
s32 FS_Delete( char *Path ) { // dbgprintf("FS_Delete(\"%s\")\n", Path ); char *FilePath = (char*)heap_alloc_aligned( 0, 0x80, 0x40 ); //normal clean up DIR d; if( f_opendir( &d, Path ) == FR_OK ) { FILINFO FInfo; s32 res = f_readdir( &d, &FInfo ); if( res != FR_OK ) { heap_free( 0, FilePath ); return FS_EFATAL; } while( res == FR_OK ) { memset32( FilePath, 0, 0x40 ); strcpy( FilePath, Path ); //insert slash FilePath[strlen(Path)] = '/'; if( FInfo.lfsize ) { //dbgprintf("\"%s\"\n", FInfo.lfname ); memcpy( FilePath+strlen(Path)+1, FInfo.lfname, strlen(FInfo.lfname) ); } else { //dbgprintf("\"%s\"\n", FInfo.fname ); memcpy( FilePath+strlen(Path)+1, FInfo.fname, strlen(FInfo.fname) ); } res = f_unlink( FilePath ); if( res != FR_OK ) { //dbgprintf("\"%s\":%d\n", FilePath, res ); if( FInfo.fattrib&AM_DIR ) { FS_Delete( FilePath ); f_unlink( FilePath ); } else { heap_free( 0, FilePath ); return FS_EFATAL; } } res = f_readdir( &d, &FInfo ); } } heap_free( 0, FilePath ); return FS_SUCCESS; }
void configStart() { // Load the config from EEPROM readConfigFromEEPROM(); // Check for config file on SD card FRESULT fr = f_stat("config.txt", NULL); switch (fr) { case FR_OK: // Config file exists break; case FR_NO_FILE: // Config file does not exist, create default readConfigDefault(); writeConfigToFile(); break; default: // Unknown file read error error(ERROR_READ_CONFIG); } fr = f_stat(converterFn, NULL); switch (fr) { case FR_OK: // Converter file exists break; case FR_NO_FILE: // Create exe file from binary writeConverterToFile(); break; default: // Unknown file read error f_unlink(converterFn); error(ERROR_READ_CONFIG); } fr = f_stat(userGuideFn, NULL); switch (fr) { case FR_OK: // User Guide file exists break; case FR_NO_FILE: writeUserGuideToFile(); break; default: // Unknown file read error f_unlink(userGuideFn); error(ERROR_READ_CONFIG); } // Read config file from card readConfigFromFile(); // Write config back to card writeConfigToFile(); // Update the config back to EEPROM writeConfigToEEPROM(); }
bool TestExtOpenssl::test_openssl_pkey_export_to_file() { const char *tmp = "test/test_pkey.tmp"; f_unlink(tmp); VS(f_file_get_contents(tmp), false); Variant privkey = f_openssl_pkey_new(); VERIFY(!privkey.isNull()); f_openssl_pkey_export_to_file(privkey, tmp, "1234"); VERIFY(f_file_get_contents(tmp).toString().size() > 400); f_unlink(tmp); return Count(true); }
bool TestExtOpenssl::test_openssl_csr_export_to_file() { Variant csr = f_openssl_csr_new(null, null); VERIFY(!csr.isNull()); const char *tmp = "test/test_csr.tmp"; f_unlink(tmp); VS(f_file_get_contents(tmp), false); f_openssl_csr_export_to_file(csr, tmp); VERIFY(f_file_get_contents(tmp).toString().size() > 400); f_unlink(tmp); return Count(true); }
bool TestExtOpenssl::test_openssl_pkcs12_export_to_file() { Variant privkey = f_openssl_pkey_new(); VERIFY(!privkey.isNull()); Variant csr = f_openssl_csr_new(null, privkey); VERIFY(!csr.isNull()); Variant scert = f_openssl_csr_sign(csr, null, privkey, 365); const char *tmp = "test/test_pkcs12.tmp"; f_unlink(tmp); VS(f_file_get_contents(tmp), false); f_openssl_pkcs12_export_to_file(scert, tmp, privkey, "1234"); VERIFY(f_file_get_contents(tmp).toString().size() > 400); f_unlink(tmp); return Count(true); }
bool TestExtOpenssl::test_openssl_pkcs7_encrypt() { Variant privkey = f_openssl_pkey_new(); VERIFY(!privkey.isNull()); Variant csr = f_openssl_csr_new(null, privkey); VERIFY(!csr.isNull()); Variant scert = f_openssl_csr_sign(csr, null, privkey, 365); Variant pubkey = f_openssl_csr_get_public_key(csr); VERIFY(!pubkey.isNull()); String data = "some secret data"; const char *infile = "test/test_pkcs7.in"; const char *outfile = "test/test_pkcs7.out"; f_unlink(infile); f_unlink(outfile); f_file_put_contents(infile, data); VERIFY(f_openssl_pkcs7_encrypt (infile, outfile, scert, CREATE_MAP2("To", "*****@*****.**","From", "*****@*****.**"))); f_unlink(infile); VERIFY(f_openssl_pkcs7_decrypt(outfile, infile, scert, privkey)); Variant decrypted = f_file_get_contents(infile); f_var_dump(decrypted); f_unlink(infile); f_unlink(outfile); /* * PHP didn't work either: $privkey = openssl_pkey_new(); $csr = openssl_csr_new(array(), $privkey); $scert = openssl_csr_sign($csr, null, $privkey, 365); $data = "some secret data"; $infile = "test_pkcs7.in"; $outfile = "test_pkcs7.out"; file_put_contents($infile, $data); openssl_pkcs7_encrypt($infile, $outfile, $scert, array("To" => "*****@*****.**", "From" => "*****@*****.**")); var_dump(openssl_pkcs7_decrypt($outfile, $infile, $scert, $privkey)); $decrypted = file_get_contents($infile);var_dump($decrypted); */ return Count(true); }
s32 FS_Move( char *sPath, char *dPath ) { switch( f_rename( sPath, dPath ) ) { case FR_OK: return FS_SUCCESS; case FR_NO_PATH: case FR_NO_FILE: return FS_ENOENT2; case FR_EXIST: //On normal IOS Rename overwrites the target! if( f_unlink( dPath ) == FR_OK ) { if( f_rename( sPath, dPath ) == FR_OK ) { return FS_SUCCESS; } } default: break; } return FS_EFATAL; }
/******************************************************************************* * @函数名称 dir_totle * @函数说明 计算文件夹的总数,多余的将其删除 * @输入参数 路径结构体指针、文件信息结构体指针 * @输出参数 无 * @返回参数 文件夹的总数 *******************************************************************************/ uint16_t dir_totle(DIR *path, FILINFO* file_info){ uint16_t dir_num = 0; static TCHAR *fn; while(1){ if(f_readdir(path,file_info) == FR_OK){ if (file_info->fname[0] == 0) break; if(file_info->fattrib == AM_DIR){ dir_num++; #if _USE_LFN fn = *file_info->lfname ? file_info->lfname : file_info->fname; #else fn = file_info->fname; #endif if(!Queue_Push(&Q_dir,fn)){ /* first pop */ msg_t *delete_file; delete_file = Queue_Pop(&Q_dir); f_unlink((const TCHAR*)delete_file->buf); memset(delete_file->buf,0,sizeof(delete_file->buf)); /* next push */ memcpy(Q_dir.m_Msg[Q_dir.rear].buf,fn,C_MAX_BUF_SIZE); Q_dir.next = Q_dir.rear; Q_dir.rear = (Q_dir.rear + 1) % Q_dir.totle_num; } } } } return dir_num; }
bool TestExtFile::test_unlink() { f_touch("test/test_ext_file.tmp"); VERIFY(f_file_exists("test/test_ext_file.tmp")); f_unlink("test/test_ext_file.tmp"); VERIFY(!f_file_exists("test/test_ext_file.tmp")); return Count(true); }
void LTK_delete_file(void) { FATFS fs; FRESULT res; uint8_t name[16] = {0}; printf("please input the file name that you want to delete\n"); scanf("%[^\n]",name); res = f_mount(0,&fs); if (res != FR_OK) { printf("mont file system error, error code: %u\n",res); return; } res = f_unlink((TCHAR *)name); if (res == FR_OK) { printf("file deleted successfully!\n"); } else if (res == FR_NO_FILE) { printf("no such file or directory\n"); } else if (res == FR_NO_PATH) { printf("no such path\n"); } else { printf("error code: %u\n",res); } f_mount(0,NULL); }
void writeConverterToFile() { FIL converter; if (f_open(&converter, converterFn, FA_CREATE_ALWAYS | FA_WRITE) != FR_OK) { f_unlink(converterFn); error(ERROR_WRITE_CONFIG); } uint32_t writtenBytes; f_write(&converter, consoleConverterBinary, sizeof(consoleConverterBinary), &writtenBytes); f_close(&converter); if(writtenBytes != sizeof(consoleConverterBinary)){ f_unlink(converterFn); error(ERROR_WRITE_CONFIG); } }
void writeUserGuideToFile() { FIL userGuide; if (f_open(&userGuide, userGuideFn, FA_CREATE_ALWAYS | FA_WRITE) != FR_OK) { f_unlink(userGuideFn); error(ERROR_WRITE_CONFIG); } uint32_t writtenBytes; f_write(&userGuide, userGuideText, sizeof(userGuideText)-1, &writtenBytes); f_close(&userGuide); if(writtenBytes != sizeof(userGuideText)-1){ f_unlink(userGuideFn); error(ERROR_WRITE_CONFIG); } }
/** * @brief einzelen Datei löschen * @param Name der Datei * @param Dateityo (1 oder 2) */ void delete_file(int fileID, int type){ SetCurrentFileID(fileID, type); if(FileExists(fileID) == 1) f_unlink((char*) sdcFilename); }
int dfs_elm_unlink(struct dfs_filesystem *fs, const char *path) { FRESULT result; #if _VOLUMES > 1 int vol; char *drivers_fn; extern int elm_get_vol(FATFS *fat); /* add path for ELM FatFS driver support */ vol = elm_get_vol((FATFS *)fs->data); if (vol < 0) return -DFS_STATUS_ENOENT; drivers_fn = rt_malloc(256); if (drivers_fn == RT_NULL) return -DFS_STATUS_ENOMEM; rt_snprintf(drivers_fn, 256, "%d:%s", vol, path); #else const char *drivers_fn; drivers_fn = path; #endif result = f_unlink(drivers_fn); #if _VOLUMES > 1 rt_free(drivers_fn); #endif return elm_result_to_dfs(result); }
int fatfs_unlink(vnode_t * dir, const char * name) { struct fatfs_sb * ffsb = get_ffsb_of_sb(dir->sb); struct fatfs_inode * indir = get_inode_of_vnode(dir); char * in_fpath; FRESULT err; int retval; if (!S_ISDIR(dir->vn_mode)) return -ENOTDIR; in_fpath = format_fpath(indir, name); if (!in_fpath) return -ENOMEM; /* TODO May need checks if file/dir is opened */ err = f_unlink(&ffsb->ff_fs, in_fpath); if (err) retval = fresult2errno(err); else retval = 0; kfree(in_fpath); return retval; }
int dihapus(char * nama) { FRESULT res; int flag=10; char namanya[255]; strcpy(namanya, nama); //printf("_______NAMANYA : %s",nama); //return 0; res = f_unlink(namanya); if (res == FR_OK) { printf("......dihapus\r\n"); return 0; } if (res == FR_WRITE_PROTECTED) { printf("......FR_WRITE_PROTECTED\r\n"); flag= -2; } if (res == FR_NO_FILE) { printf("......FR_NO_FILE\r\n"); flag= -2; } if (res == FR_NO_PATH) { printf("......FR_NO_PATH\r\n"); flag= -2; } if (res == FR_INVALID_NAME) { printf("......FR_INVALID_NAME\r\n"); flag= -2; } if (res == FR_DENIED) { printf("......FR_DENIED\r\n"); flag= -1; } return flag; }
/** * @brief Remove a directory */ bool CFile::rmDir() { bool rc = false; if ( f_unlink(mPath.data()) == FR_OK ) rc = true; return rc; }
void check_sd_firmware() { int r; printf("Check SD\n"); f_mount(0, &fat); if ((r = f_open(&file, firmware_file, FA_READ)) == FR_OK) { printf("Flashing firmware...\n"); uint8_t buf[512]; unsigned int r = sizeof(buf); uint32_t address = USER_FLASH_START; while (r == sizeof(buf)) { if (f_read(&file, buf, sizeof(buf), &r) != FR_OK) { f_close(&file); return; } setleds((address - USER_FLASH_START) >> 15); printf("\t0x%lx\n", address); write_flash((void *) address, (char *)buf, sizeof(buf)); address += r; } f_close(&file); if (address > USER_FLASH_START) { printf("Complete!\n"); r = f_unlink(firmware_old); r = f_rename(firmware_file, firmware_old); } }
void delete_file(char *fname) { FRESULT res; res = f_unlink(fname); if(res != FR_OK) printf("Error deleting file:%u\r\n", res); return; }
static void CreateSqliteTestTable() { f_unlink("/tmp/foo.db"); p_SQLite3 db(NEWOBJ(c_SQLite3)()); db->t_open("/tmp/foo.db"); db->t_exec("CREATE TABLE foo (bar STRING)"); db->t_exec("INSERT INTO foo VALUES ('ABC')"); db->t_exec("INSERT INTO foo VALUES ('DEF')"); }
bool TestExtOpenssl::test_openssl_x509_export_to_file() { Variant fcert = f_file_get_contents("test/test_x509.crt"); Variant cert = f_openssl_x509_read(fcert); const char *tmp = "test/test_x509.tmp"; f_unlink(tmp); VS(f_file_get_contents(tmp), false); VERIFY(f_openssl_x509_export_to_file(cert, tmp)); Variant fcert2 = f_file_get_contents(tmp); Variant cert2 = f_openssl_x509_read(fcert2); Variant info = f_openssl_x509_parse(cert2); VS(info["subject"]["O"], "RSA Data Security, Inc."); f_unlink(tmp); return Count(true); }
int FATFileSystem::remove(const char *filename) { FRESULT res = f_unlink(filename); if (res) { debug_if(FFS_DBG, "f_unlink() failed: %d\n", res); return -1; } return 0; }
/******************************************************************************* * Function Name : Test_f_deldir * Description : 删除目录 * Input : * Return : res *******************************************************************************/ FRESULT Test_f_deldir(const TCHAR* path)//删除一个目录,输入目录的路径;目录里的内容是空的才能删除Test_f_deldir("/dir"); { fatfs_res=f_unlink(path);//删除一个目录 return fatfs_res; }
/* * ======== rmdir ======== */ int rmdir(const char * path) { if (f_unlink(path) == FR_OK) { return (0); } else { return (-1); } }
static int _unlink(vfs_mount_t *mountp, const char *name) { fatfs_desc_t *fs_desc = (fatfs_desc_t *)mountp->private_data; 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_unlink(fs_desc->abs_path_str_buff)); }
void gui_set_debug_delete_fc(uint8_t ret) { if (ret == GUI_DIALOG_YES) { assert(f_unlink(DEBUG_FILE) == FR_OK); } gui_switch_task(GUI_SET_DEBUG); }
bool TestExtFile::test_chown() { Variant f = f_fopen("test/test_ext_file.tmp", "w"); f_fputs(f, "testing\nchown\n"); f_fclose(f); VERIFY(f_chmod("test/test_ext_file.txt", 0777)); //VERIFY(f_chown("test/test_ext_file.tmp", "hzhao")); f_unlink("test/test_ext_file.tmp"); return Count(true); }
bool TestExtFile::test_linkinfo() { if (f_file_exists("test/test_ext_file2.tmp")) { f_unlink("test/test_ext_file2.tmp"); VERIFY(!f_file_exists("test/test_ext_file2.tmp")); } f_touch("test/test_ext_file.tmp"); f_symlink("test/test_ext_file.tmp", "test/test_ext_file2.tmp"); VERIFY(more(f_linkinfo("test/test_ext_file2.tmp"), 0)); return Count(true); }