g_fs_transaction_id g_fs_delegate_ramdisk::request_discovery(g_thread* requester, g_fs_node* parent, char* child, g_fs_transaction_handler_discovery* handler) { // the ramdisk handler is doing it's work immediately and doesn't request another process g_fs_transaction_id id = g_fs_transaction_store::next_transaction(); // find on ramdisk g_ramdisk_entry* ramdisk_parent; if (parent->type == G_FS_NODE_TYPE_MOUNTPOINT) { ramdisk_parent = g_kernel_ramdisk->getRoot(); } else { ramdisk_parent = g_kernel_ramdisk->findById(parent->phys_fs_id); } if (ramdisk_parent) { g_ramdisk_entry* ramdisk_node = g_kernel_ramdisk->findChild(ramdisk_parent, child); if (ramdisk_node) { // create the vfs node g_fs_node* node = create_vfs_node(ramdisk_node, parent); handler->status = G_FS_DISCOVERY_SUCCESSFUL; } else { handler->status = G_FS_DISCOVERY_NOT_FOUND; } } else { handler->status = G_FS_DISCOVERY_NOT_FOUND; } g_fs_transaction_store::set_status(id, G_FS_TRANSACTION_FINISHED); return id; }
g_fs_transaction_id g_fs_delegate_ramdisk::request_directory_refresh(g_thread* requester, g_fs_node* folder, g_fs_transaction_handler_directory_refresh* handler) { g_fs_transaction_id id = g_fs_transaction_store::next_transaction(); g_ramdisk_entry* rd_folder = g_kernel_ramdisk->findById(folder->phys_fs_id); if (rd_folder == 0) { handler->status = G_FS_DIRECTORY_REFRESH_ERROR; } else { // create all nodes that not yet exist int position = 0; g_ramdisk_entry* rd_child; while ((rd_child = g_kernel_ramdisk->getChildAt(folder->phys_fs_id, position++)) != 0) { // get real path to parent g_local<char> absolute(new char[G_PATH_MAX]); g_filesystem::get_real_path_to_node(folder, absolute()); // append child name int abs_cur_len = g_string::length((const char*) absolute()); int childlen = g_string::length(rd_child->name); g_memory::copy(&absolute()[abs_cur_len], "/", 1); g_memory::copy(&absolute()[abs_cur_len + 1], rd_child->name, childlen); absolute()[abs_cur_len + 1 + childlen] = 0; // check if file exists as vfs node g_fs_node* fs_childs_parent = 0; g_fs_node* fs_child = 0; g_local<char> current(new char[G_PATH_MAX]); g_filesystem::find_existing(absolute(), &fs_childs_parent, &fs_child, current(), true); // if not, create it if (fs_child == 0) { fs_child = create_vfs_node(rd_child, folder); } } // finish the transaction folder->contents_valid = true; handler->status = G_FS_DIRECTORY_REFRESH_SUCCESSFUL; } g_fs_transaction_store::set_status(id, G_FS_TRANSACTION_FINISHED); return id; }
g_fs_transaction_id g_fs_delegate_ramdisk::request_open(g_thread* requester, g_fs_node* node, char* filename, int32_t flags, int32_t mode, g_fs_transaction_handler_open* handler) { g_fs_transaction_id id = g_fs_transaction_store::next_transaction(); g_ramdisk_entry* ramdisk_node = g_kernel_ramdisk->findById(node->phys_fs_id); if (handler->discovery_status == G_FS_DISCOVERY_SUCCESSFUL) { if (ramdisk_node->type != G_RAMDISK_ENTRY_TYPE_FILE) { g_log_warn("%! only files can be opened, given node was a %i", "filesystem", ramdisk_node->type); handler->status = G_FS_OPEN_ERROR; } else { // truncate file if requested if (flags & G_FILE_FLAG_MODE_TRUNCATE) { // only applies when data no more used from ramdisk memory if (!ramdisk_node->data_on_ramdisk) { // completely remove the buffer ramdisk_node->datalength = 0; ramdisk_node->not_on_rd_buffer_length = 0; delete ramdisk_node->data; ramdisk_node->data = 0; } } handler->status = G_FS_OPEN_SUCCESSFUL; } } else if (handler->discovery_status == G_FS_DISCOVERY_NOT_FOUND) { if (flags & G_FILE_FLAG_MODE_CREATE) { // create the filesystem file g_ramdisk_entry* new_ramdisk_entry = g_kernel_ramdisk->createChild(ramdisk_node, filename); handler->node = create_vfs_node(new_ramdisk_entry, node); handler->status = G_FS_OPEN_SUCCESSFUL; } else { // return with failure handler->status = G_FS_OPEN_NOT_FOUND; } } g_fs_transaction_store::set_status(id, G_FS_TRANSACTION_FINISHED); return id; }