int tRecursivelyCreateDirectory() { int retC; retC = Create_Directory("/d/dir2d"); if (retC < 0) return -1; retC = Create_Directory("/d/dir2d/dir3d"); return (retC >= 0) ? 1 : -1; }
bool Win32_Platform::Create_Directory(const char* path, bool recursive) { if (recursive == true) { std::vector<std::string> cracked; std::string crack_path = ""; Crack_Path(path, cracked); for (int i = 0; i < (int)cracked.size(); i++) { if (crack_path != "") { crack_path += "/"; } crack_path += cracked.at(i); if (!Is_Directory(crack_path.c_str())) { bool result = Create_Directory(crack_path.c_str(), false); if (result == false) { return false; } } } return true; } else { int result = CreateDirectoryA(path, NULL); return (result != 0); } }
int tBasicCreateDirectory() { int retC; retC = Create_Directory("/d/dir1d"); return (retC >= 0) ? 1 : -1; }
int tBasicCreateDirectory() { int retC; retC = Create_Directory("/d/dir1d"); (void)Delete("/d/dir1d", false); return (retC >= 0) ? 1 : -1; }
/* * Create directory * Params: * state->ebx - address of user string containing path of new directory * state->ecx - length of path * * Returns: 0 if successful, error code (< 0) if unsuccessful */ static int Sys_CreateDir(struct Interrupt_State *state) { char *path; int rc = get_path_from_registers(state->ebx, state->ecx, &path); if(rc) { return rc; } Enable_Interrupts(); // Print("creating %s\n", path); rc = Create_Directory(path); Disable_Interrupts(); return rc; }
int tRecursivelyCreateDirectory() { int retC; retC = Create_Directory("/d/dir2d"); if (retC < 0) { Print("failed to create directory /d/dir2d: %d\n", retC); return -1; } retC = Create_Directory("/d/dir2d/dir3d"); if (retC < 0) { Print("failed to create directory /d/dir2d/dir3d: %d\n", retC); return -1; } return (retC >= 0) ? 1 : -1; }
int tDeleteEmptyDirectory() { int retC, retD; retC = Create_Directory("/d/dir3d"); if (retC < 0) return -1; retD = Delete("/d/dir3d", false); return (retD >= 0) ? 1 : -1; }
void cResource_Manager :: Init_User_Directory( void ) { // Create user directory if( !Dir_Exists( user_data_dir ) ) { // first run if not available Create_Directory( user_data_dir ); } // Create savegame directory if( !Dir_Exists( user_data_dir + USER_SAVEGAME_DIR ) ) { Create_Directory( user_data_dir + USER_SAVEGAME_DIR ); } // Create screenshot directory if( !Dir_Exists( user_data_dir + USER_SCREENSHOT_DIR ) ) { Create_Directory( user_data_dir + USER_SCREENSHOT_DIR ); } // Create level directory if( !Dir_Exists( user_data_dir + USER_LEVEL_DIR ) ) { Create_Directory( user_data_dir + USER_LEVEL_DIR ); } // Create world directory if( !Dir_Exists( user_data_dir + USER_WORLD_DIR ) ) { Create_Directory( user_data_dir + USER_WORLD_DIR ); } // Create cache directory if( !Dir_Exists( user_data_dir + USER_IMGCACHE_DIR ) ) { Create_Directory( user_data_dir + USER_IMGCACHE_DIR ); } }
/* * Create directory * Params: * state->ebx - address of user string containing path of new directory * state->ecx - length of path * * Returns: 0 if successful, error code (< 0) if unsuccessful */ static int Sys_CreateDir(struct Interrupt_State *state) { char path[VFS_MAX_PATH_LEN] = {'\0', }; int rc; Copy_From_User(path, state->ebx, state->ecx); Enable_Interrupts(); if((rc = Create_Directory(path)) < 0){ ; } Disable_Interrupts(); return rc; //TODO("CreateDir system call"); }
int main(int argc, char *argv[]) { int rc; if (argc != 2) { Print("Usage: mkdir <directory>\n"); Exit(1); } rc = Create_Directory(argv[1]); if (rc != 0) Print("Could not create directory: %s\n", Get_Error_String(rc)); return !(rc == 0); }
int tDeleteNonEmptyDirectory() { int retC, retD, fd; retC = Create_Directory("/d/dir4d"); if (retC < 0) return -1; fd = Open("/d/dir4d/file", O_CREATE|O_READ); if (fd < 0) return -1; Close(fd); retD = Delete("/d/dir4d"); return (retD >= 0) ? -1 : 1; }
int tStatDirectory() { int fd, retS, retC; struct VFS_File_Stat s; retC = Create_Directory("/d/basic10d"); if (retC < 0) return -1; fd = Open_Directory("/d/basic10d"); if (fd < 0) return -1; retS = FStat(fd, &s); Close(fd); Delete("/d/basic10d"); return ( (retS >= 0) && (s.isDirectory) ) ? 1 : -1; }
int tDeleteNonEmptyDirectory() { int retC, retD, fd; retC = Create_Directory("/d/dir4d"); if (retC < 0) return -1; fd = Open("/d/dir4d/file", O_CREATE | O_READ); if (fd < 0) return -1; if (Close(fd) < 0) { Print("failed to close"); return -1; } retD = Delete("/d/dir4d", false); (void)Delete("/d/dir4d/file", false); (void)Delete("/d/dir4d", false); return (retD >= 0) ? -1 : 1; }
int tStatDirectory() { int fd, retS, retC; struct VFS_File_Stat s; retC = Create_Directory("/d/basic10d"); if (retC < 0) { Print("couldn't create basic10d: %d %s\n", retC, Get_Error_String(retC)); return -1; } fd = Open_Directory("/d/basic10d"); if (fd < 0) { Print("couldn't reopen basic10d: %d %s\n", fd, Get_Error_String(fd)); return -1; } retS = FStat(fd, &s); if (Close(fd) < 0) { Print("failed to close"); return -1; } (void)Delete("/d/basic10d", false); if (retS < 0) { Print("couldn't fstat opened basic10d: %d %s\n", retS, Get_Error_String(retS)); } if (!s.isDirectory) { Print("fstat didn't think basic10d was a directory\n"); } return ((retS >= 0) && (s.isDirectory)) ? 1 : -1; }
int tReadEntry() { int fd, retR, retC; struct VFS_Dir_Entry dirEntry; retC = Create_Directory("/d/basic11d"); if (retC < 0) { Print("couldn't create basic11d: %d %s\n", retC, Get_Error_String(retC)); return -1; } retC = Create_Directory("/d/basic11d/d1"); if (retC < 0) { Print("couldn't create basic11d/d1: %d %s\n", retC, Get_Error_String(retC)); return -1; } retC = Create_Directory("/d/basic11d/d2"); if (retC < 0) { Print("couldn't create basic11d/d2: %d %s\n", retC, Get_Error_String(retC)); return -1; } fd = Open("/d/basic11d/f1", O_CREATE); if (fd < 0) { Print("couldn't open basic11d/f1: %d %s\n", fd, Get_Error_String(fd)); return -1; } if (Close(fd) < 0) { Print("failed to close"); return -1; } fd = Open_Directory("/d/basic11d"); if (fd < 0) { Print("couldn't opendir basic11d: %d %s\n", fd, Get_Error_String(fd)); return -1; } retR = Read_Entry(fd, &dirEntry); if ((retR < 0) || (strncmp(dirEntry.name, "d1", 2) != 0) || (!dirEntry.stats.isDirectory)) return -1; retR = Read_Entry(fd, &dirEntry); if ((retR < 0) || (strncmp(dirEntry.name, "d2", 2) != 0) || (!dirEntry.stats.isDirectory)) return -1; retR = Read_Entry(fd, &dirEntry); if ((retR < 0) || (strncmp(dirEntry.name, "f1", 2) != 0) || (dirEntry.stats.isDirectory)) return -1; if (Close(fd) < 0) { Print("failed to close"); return -1; } fd = Open_Directory("/d/basic11d"); if (fd < 0) return -1; // no retR = Seek(fd, 2); // no if (retR < 0) // no return -1; // no retR = Read_Entry(fd, &dirEntry); // no if ((retR < 0) || // no (strncmp(dirEntry.name, "f1", 2) != 0) || // no (dirEntry.stats.isDirectory)) // no return -1; if (Close(fd) < 0) { Print("failed to close"); return -1; } (void)Delete("/d/basic11d/d1", false); (void)Delete("/d/basic11d/d2", false); (void)Delete("/d/basic11d/f1", false); (void)Delete("/d/basic11d", false); return 1; }
int tRecursiveStat() { int retC, retS, fd; struct VFS_File_Stat s; retC = Create_Directory("/d/recursive_stat1"); if (retC < 0) return -1; retC = Create_Directory("/d/recursive_stat1/recursive_stat2"); if (retC < 0) return -1; retC = Create_Directory ("/d/recursive_stat1/recursive_stat2/recursive_stat3"); if (retC < 0) return -1; fd = Open ("/d/recursive_stat1/recursive_stat2/recursive_stat3/recursive_stat4", O_CREATE | O_WRITE); if (fd < 0) return -1; retC = Close(fd); retS = Stat("/d/recursive_stat1", &s); if (retS < 0) return -1; retS = Stat("/d/recursive_stat1x", &s); if (retS == 0) return -1; retS = Stat("/d/recursive_stat1/recursive_stat2", &s); if (retS < 0) return -1; retS = Stat("/d/recursive_stat1x/recursive_stat2", &s); if (retS == 0) return -1; retS = Stat("/d/recursive_stat1/../recursive_stat1", &s); if (retS < 0) return -1; retS = Stat("/d/recursive_stat1/../recursive_stat2", &s); if (retS == 0) return -1; retS = Stat("/d/recursive_stat1/./recursive_stat2", &s); if (retS < 0) return -1; retS = Stat("/d/recursive_stat1/./recursive_stat1", &s); if (retS == 0) return -1; retS = Stat ("/d/recursive_stat1/../recursive_stat1/recursive_stat2/recursive_stat3", &s); if (retS < 0) return -1; retS = Stat ("/d/recursive_stat1/../recursive_stat2/recursive_stat2/recursive_stat3", &s); if (retS == 0) return -1; retS = Stat ("/d/recursive_stat1/./recursive_stat2/../recursive_stat2/recursive_stat3", &s); if (retS < 0) return -1; retS = Stat ("/d/recursive_stat1/./recursive_stat1../recursive_stat2/recursive_stat3", &s); if (retS == 0) return -1; (void) Delete ("/d/recursive_stat1/recursive_stat2/recursive_stat3/recursive_stat4", false); (void)Delete("/d/recursive_stat1/recursive_stat2/recursive_stat3", false); (void)Delete("/d/recursive_stat1/recursive_stat2", false); (void)Delete("/d/recursive_stat1", false); return 0; }
void cOverworld :: Save( void ) { pAudio->Play_Sound( "editor/save.ogg" ); std::string save_dir = pResource_Manager->user_data_dir + USER_WORLD_DIR + "/" + m_description->m_path; // Create directory if new world if( !Dir_Exists( save_dir ) ) { Create_Directory( save_dir ); } std::string filename = save_dir + "/world.xml"; // fixme : Check if there is a more portable way f.e. with imbue() #ifdef _WIN32 ofstream file( utf8_to_ucs2( filename ).c_str(), ios::out | ios::trunc ); #else ofstream file( filename.c_str(), ios::out | ios::trunc ); #endif if( !file ) { printf( "Error : Couldn't open world file for saving. Is the file read-only ?" ); pHud_Debug->Set_Text( _("Couldn't save world ") + filename, speedfactor_fps * 5.0f ); return; } CEGUI::XMLSerializer stream( file ); // begin stream.openTag( "overworld" ); // begin stream.openTag( "information" ); // game version Write_Property( stream, "game_version", int_to_string(SMC_VERSION_MAJOR) + "." + int_to_string(SMC_VERSION_MINOR) + "." + int_to_string(SMC_VERSION_PATCH) ); // engine version Write_Property( stream, "engine_version", world_engine_version ); // time ( seconds since 1970 ) Write_Property( stream, "save_time", static_cast<Uint64>( time( NULL ) ) ); // end information stream.closeTag(); // begin stream.openTag( "settings" ); // music Write_Property( stream, "music", m_musicfile ); // end settings stream.closeTag(); // begin stream.openTag( "background" ); // color Write_Property( stream, "color_red", static_cast<int>(m_background_color.red) ); Write_Property( stream, "color_green", static_cast<int>(m_background_color.green) ); Write_Property( stream, "color_blue", static_cast<int>(m_background_color.blue) ); // end background stream.closeTag(); // begin stream.openTag( "player" ); // start waypoint Write_Property( stream, "waypoint", m_player_start_waypoint ); // moving state Write_Property( stream, "moving_state", static_cast<int>(m_player_moving_state) ); // end player stream.closeTag(); // objects for( cSprite_List::iterator itr = m_sprite_manager->objects.begin(); itr != m_sprite_manager->objects.end(); ++itr ) { cSprite *obj = (*itr); // skip spawned and destroyed objects if( obj->m_spawned || obj->m_auto_destroy ) { continue; } // save to file stream obj->Save_To_XML( stream ); } // end overworld stream.closeTag(); file.close(); // save layer m_layer->Save( save_dir + "/layer.xml" ); // save description m_description->Save(); // show info pHud_Debug->Set_Text( _("World ") + m_description->m_name + _(" saved") ); }
int tReadEntry() { int fd, retR, retC; struct VFS_Dir_Entry dirEntry; retC = Create_Directory("/d/basic11d"); if (retC < 0) { Print("couldn't create basic11d: %d\n", retC); return -1; } retC = Create_Directory("/d/basic11d/d1"); if (retC < 0) { Print("couldn't create basic11d/d1: %d\n", retC); return -1; } retC = Create_Directory("/d/basic11d/d2"); if (retC < 0) { Print("couldn't create basic11d/d2: %d\n", retC); return -1; } fd = Open("/d/basic11d/f1", O_CREATE); if (fd < 0) { Print("couldn't create basic11d/f1: %d\n", fd); return -1; } Close(fd); fd = Open_Directory("/d/basic11d"); if (fd < 0) { Print("couldn't opendir basic11d: %d\n", fd); return -1; } do { retR = Read_Entry(fd, &dirEntry); } while(retR == 0 && dirEntry.name[0] == '.'); if ((retR < 0) || (strncmp(dirEntry.name, "d1", 2) != 0) || (! dirEntry.stats.isDirectory)) return -1; retR = Read_Entry(fd, &dirEntry); if ((retR < 0) || (strncmp(dirEntry.name, "d2", 2) != 0) || (! dirEntry.stats.isDirectory)) return -1; retR = Read_Entry(fd, &dirEntry); if ((retR < 0) || (strncmp(dirEntry.name, "f1", 2) != 0) || (dirEntry.stats.isDirectory)) return -1; Close(fd); fd = Open_Directory("/d/basic11d"); if (fd < 0) return -1; retR = Seek(fd, 2); if (retR < 0) return -1; retR = Read_Entry(fd, &dirEntry); if ((retR < 0) || (strncmp(dirEntry.name, "f1", 2) != 0) || (dirEntry.stats.isDirectory)) return -1; Close(fd); Delete("/d/basic11d/d1"); Delete("/d/basic11d/d2"); Delete("/d/basic11d/f1"); Delete("/d/basic11d"); return 1; }
int tBigDir() { int retC, retD, fi, retS; char fname[50]; struct VFS_File_Stat s; retC = Create_Directory("/d/bigdir"); if (retC == EEXIST) { Delete("/d/bigdir", false); retC = Create_Directory("/d/bigdir"); } if (retC != 0) { Print("couldn't create /d/bigdir: %d\n", retC); return -1; } for (fi = 0; fi < 100; fi++) { int fd; snprintf(fname, 50, "/d/bigdir/%04dabcdefghijklmnopqrstuvwxyz%04d", fi, fi); Print((fi % 25 == 0) ? ":" : "."); fd = Open(fname, O_WRITE | O_CREATE); if (fd < 0) { Print("bad open/creat at %d\n", fi); return -1; } if (Close(fd) < 0) { Print("failed to close"); return -1; } retS = Stat(fname, &s); if (retS < 0) { Print("bad stat at %d\n", fi); return -1; } } snprintf(fname, 50, "/d/bigdir/%04dabcdefghijklmnopqrstuvwxyz%04d", fi, fi); retS = Stat(fname, &s); if (retS == 0) { Print("bad extra stat at %d\n", fi); return -1; } for (fi = 0; fi < 100; fi++) { snprintf(fname, 50, "/d/bigdir/%04dabcdefghijklmnopqrstuvwxyz%04d", fi, fi); Print((fi % 25 == 0) ? ":" : "."); (void)Delete(fname, false); retS = Stat(fname, &s); if (retS == 0) { return -1; } } retD = Delete("/d/bigdir", false); if (retD != 0) { Print("failed to remove /d/bigdir: %d", retD); return retD; } return 0; }
int tExhaustDisk() { /* (indirect + direct) * blocksize div by B/KB */ unsigned int max_file_size_k = ((blocksize / 4) + 4) * blocksize / 1024; int files_needed_to_fill_disk = disksize_mb * 1024 * 63 / 64 / max_file_size_k; int files_needed_to_use_inodes = disksize_mb * 1024 * 1024 / 64 / sizeof(struct gfs2_inode); unsigned int i; int fi, retC, retW, retD; char writeme[512]; char fname[50]; char dirname[25] = ""; int repetition; Print("need %d files to fill disk, %d to use all inodes\n", files_needed_to_fill_disk, files_needed_to_use_inodes); if (files_needed_to_fill_disk > files_needed_to_use_inodes) { files_needed_to_fill_disk = files_needed_to_use_inodes; } #define MARK Print("%d:", __LINE__); retC = Create_Directory("/d/exhaust"); if (retC != 0) { Print("couldn't create /d/exhaust\n"); return -1; } for (i = 0; i < sizeof(writeme); i++) { writeme[i] = i % 256; } for (repetition = 0; repetition < 3; repetition++) { int files_worked_on; retW = 0; for (fi = 0; retW >= 0 && fi < files_needed_to_fill_disk; fi++) { int fd; unsigned long b; if (fi % 100 == 0) { snprintf(dirname, 25, "/d/exhaust/%d", fi / 100); retC = Create_Directory(dirname); Print("%d/%d", fi, files_needed_to_fill_disk); } snprintf(fname, 50, "%s/%d", dirname, fi); Print((fi % 25 == 0) ? ":" : "."); fd = Open(fname, O_WRITE | O_CREATE); if (fd < 0) { Print("failed to open %s\n", fname); return -1; } for (b = 0; b < (unsigned long)max_file_size_k * 1024 - 100; b += retW) { retW = Write(fd, writeme, 100); if (retW < 0) { Print("write %s %lu failed: %d", fname, b, retW); break; } } if (Close(fd) < 0) { Print("failed to close"); return -1; } } files_worked_on = fi; for (; fi >= 0; fi--) { snprintf(dirname, 25, "/d/exhaust/%d", fi / 100); snprintf(fname, 50, "%s/%d", dirname, fi); (void)Delete(fname, false); } for (fi = 0; fi < files_worked_on; fi += 100) { snprintf(dirname, 25, "/d/exhaust/%d", fi / 100); if (Delete(dirname, false) < 0) { Print("couldnt remove %s", dirname); return -1; } } } retD = Delete("/d/exhaust", false); if (retD != 0) { Print("failed to remove /d/exhaust: %d", retD); return retD; } return 0; }
int tReadEntry() { int fd, retR, retC; struct VFS_Dir_Entry dirEntry; retC = Create_Directory("/d/basic11d"); if (retC < 0) return -1; retC = Create_Directory("/d/basic11d/d1"); if (retC < 0) return -1; retC = Create_Directory("/d/basic11d/d2"); if (retC < 0) return -1; fd = Open("/d/basic11d/f1", O_CREATE); if (fd < 0) return -1; Close(fd); Print("all file/dir created.\n"); fd = Open_Directory("/d/basic11d"); if (fd < 0) return -1; retR = Read_Entry(fd, &dirEntry); Print("read 1 entry.\n"); if ((retR < 0) || (strncmp(dirEntry.name, "d1", 2) != 0) || (! dirEntry.stats.isDirectory)) return -1; retR = Read_Entry(fd, &dirEntry); Print("read 2 entry.\n"); if ((retR < 0) || (strncmp(dirEntry.name, "d2", 2) != 0) || (! dirEntry.stats.isDirectory)) return -1; retR = Read_Entry(fd, &dirEntry); Print("read 3 entry.\n"); if ((retR < 0) || (strncmp(dirEntry.name, "f1", 2) != 0) || (dirEntry.stats.isDirectory)) return -1; Close(fd); fd = Open_Directory("/d/basic11d"); if (fd < 0) return -1; Print("opened basic11d.\n"); retR = Seek(fd, 2); if (retR < 0) { Print("failed seek.\n"); return -1; } retR = Read_Entry(fd, &dirEntry); Print("read no2 entry.\n"); if ((retR < 0) || (strncmp(dirEntry.name, "f1", 2) != 0) || (dirEntry.stats.isDirectory)) return -1; Close(fd); Delete("/d/basic11d/d1"); Delete("/d/basic11d/d2"); Delete("/d/basic11d/f1"); Delete("/d/basic11d"); Print("all files deleted.\n"); return 1; }