int FuseLink::write(const char *path, const char *in, size_t length, off_t offset, struct fuse_file_info *options) { FuseLink::filesystem->setuid(fuse_get_context()->uid); FuseLink::filesystem->setgid(fuse_get_context()->gid); // Write data to the file. try { if (offset > MSIZE_FILE || ((uint64_t) offset + (uint64_t) length) > MSIZE_FILE) return -EFBIG; FuseLink::filesystem->touch(path, "cma"); FSFile file = FuseLink::filesystem->open(path); file.seekp(offset); file.write(in, length); file.close(); if (file.fail() || file.bad()) return -EIO; return length; } catch (std::exception& e) { return FuseLink::handleException(e, "write"); } }
void FS::symlink(std::string linkPath, std::string targetPath) { auto configuration = [&](LowLevel::INode& buf) { }; this->performCreation(LowLevel::INodeType::INT_SYMLINK, linkPath, 0755, configuration); // We just created the file, so if this fails then // it's an internal inconsistency. LowLevel::INode buf; if (!this->retrievePathToINode(linkPath, buf)) throw Exception::FileNotFound(); try { FSFile f = this->filesystem->getFile(buf.inodeid); f.open(); f.write(targetPath.c_str(), targetPath.length()); f.close(); if (f.fail() || f.bad()) throw Exception::InternalInconsistency(); } catch (...) { // Delete the file from disk since we failed to // write to it (at least in some manner). Then // rethrow the exception. this->unlink(linkPath); throw; } }
void GameManager::set_frame(int index) { ignore_controls = false; #ifdef CHOWDREN_IS_DEMO idle_timer = 0.0; idle_timer_started = false; #endif #ifndef CHOWDREN_SAMPLES_OVER_FRAMES media.stop_samples(); #endif if (frame->index != -1) frame->on_end(); if (index == -2) { platform_begin_draw(); media.stop_samples(); Render::clear(Color(0, 0, 0, 255)); platform_swap_buffers(); #ifdef CHOWDREN_IS_DEMO reset_timer = 0.0; #endif index = 0; // reset_global_data(); reset_globals(); } std::cout << "Setting frame: " << index << std::endl; #ifdef CHOWDREN_USER_PROFILER std::string logline = "Setting frame: " + number_to_string(index) + "\n"; user_log.write(&logline[0], logline.size()); #endif frame->set_index(index); std::cout << "Frame set" << std::endl; }
bool GameManager::update() { #ifdef CHOWDREN_USE_DYNAMIC_NUMBER static int save_time = 0; save_time--; if (save_time <= 0) { save_alterable_debug(); save_time += 60; } #endif #ifdef SHOW_STATS bool show_stats = false; static int measure_time = 0; measure_time -= 1; if (measure_time <= 0) { measure_time = 200; show_stats = true; } #endif #ifdef CHOWDREN_USER_PROFILER static int frame = 0; frame++; std::stringstream ss; ss << "Frame " << frame << ": " << fps_limit.dt << " "; #endif // update input keyboard.update(); mouse.update(); platform_poll_events(); #ifdef CHOWDREN_USE_GWEN gwen.update(); #endif // player controls int new_control = get_player_control_flags(1); player_press_flags = new_control & ~(player_flags); player_flags = new_control; // joystick controls new_control = get_joystick_control_flags(1); joystick_press_flags = new_control & ~(joystick_flags); joystick_release_flags = joystick_flags & ~(new_control); joystick_flags = new_control; #ifdef CHOWDREN_USE_JOYTOKEY for (int i = 0; i < simulate_count; i++) { if (simulate_keys[i].down) { simulate_keys[i].down = false; continue; } keyboard.remove(simulate_keys[i].key); simulate_keys[i] = simulate_keys[simulate_count-1]; i--; simulate_count--; } for (int i = 0; i < CHOWDREN_BUTTON_MAX-1; i++) { int key = key_mappings[i]; if (key == -1) continue; if (is_joystick_pressed_once(1, i+1)) keyboard.add(key); else if (is_joystick_released_once(1, i+1)) keyboard.remove(key); } axis_moved = false; for (int i = 0; i < CHOWDREN_AXIS_MAX-1; i++) { float value = get_joystick_axis(1, i+1); int pos = axis_pos_mappings[i]; int neg = axis_neg_mappings[i]; int axis_value = 0; if (value > deadzone) { last_axis = i; if (pos != -1 && axis_values[i] != 1) keyboard.add(pos); axis_value = 1; } else { if (pos != -1 && axis_values[i] == 1) keyboard.remove(pos); } if (value < -deadzone) { last_axis = i; if (neg != -1 && axis_values[i] != -1) keyboard.add(neg); axis_value = -1; } else { if (neg != -1 && axis_values[i] == -1) keyboard.remove(neg); } axis_values[i] = axis_value; static bool last_move = false; bool new_move = axis_value != 0; if (new_move && new_move != last_move) axis_moved = true; last_move = new_move; } static bool last_connected = false; bool connected = is_joystick_attached(1); pad_selected = connected && last_connected != connected; pad_disconnected = !connected && last_connected != connected; last_connected = connected; #endif // update mouse position platform_get_mouse_pos(&mouse_x, &mouse_y); #ifdef SHOW_STATS if (show_stats) std::cout << "Framerate: " << fps_limit.current_framerate << std::endl; #endif if (platform_has_error()) { if (platform_display_closed()) return false; } else { double event_update_time = platform_get_time(); int ret = update_frame(); #ifdef CHOWDREN_USER_PROFILER ss << (platform_get_time() - event_update_time) << " "; #endif #ifdef SHOW_STATS if (show_stats) std::cout << "Event update took " << platform_get_time() - event_update_time << std::endl; #endif if (ret == 0) return false; else if (ret == 2) return true; if (platform_display_closed()) return false; } double draw_time = platform_get_time(); draw(); #ifdef CHOWDREN_USER_PROFILER ss << (platform_get_time() - draw_time) << " "; #endif #ifdef SHOW_STATS if (show_stats) { std::cout << "Draw took " << platform_get_time() - draw_time << std::endl; #ifndef NDEBUG print_instance_stats(); #endif platform_print_stats(); } #endif fps_limit.finish(); #ifdef CHOWDREN_USER_PROFILER ss << "\n"; std::string logline = ss.str(); user_log.write(&logline[0], logline.size()); #endif #ifdef CHOWDREN_USE_PROFILER static int profile_time = 0; profile_time -= 1; if (profile_time <= 0) { profile_time += 500; PROFILE_UPDATE(); PROFILE_OUTPUT("data:/profile.txt"); } #endif return true; }