status_t IORequest::_CopyData(void* _buffer, off_t offset, size_t size, bool copyIn) { if (size == 0) return B_OK; uint8* buffer = (uint8*)_buffer; if (offset < fOffset || offset + size > fOffset + fLength) { panic("IORequest::_CopyData(): invalid range: (%lld, %lu)", offset, size); return B_BAD_VALUE; } // If we can, we directly copy from/to the virtual buffer. The memory is // locked in this case. status_t (*copyFunction)(void*, void*, size_t, team_id, bool); if (fBuffer->IsPhysical()) { copyFunction = &IORequest::_CopyPhysical; } else { copyFunction = fBuffer->IsUser() ? &IORequest::_CopyUser : &IORequest::_CopySimple; } // skip bytes if requested iovec* vecs = fBuffer->Vecs(); size_t skipBytes = offset - fOffset; size_t vecOffset = 0; while (skipBytes > 0) { if (vecs[0].iov_len > skipBytes) { vecOffset = skipBytes; break; } skipBytes -= vecs[0].iov_len; vecs++; } // copy iovec-wise while (size > 0) { size_t toCopy = min_c(size, vecs[0].iov_len - vecOffset); status_t error = copyFunction(buffer, (uint8*)vecs[0].iov_base + vecOffset, toCopy, fTeam, copyIn); if (error != B_OK) return error; buffer += toCopy; size -= toCopy; vecs++; vecOffset = 0; } return B_OK; }
static void test_ksDupFun (const size_t storagePlugin, const char * tmpFile, KeySet * copyFunction (const KeySet * source)) { Key * parentKey = keyNew (TEST_ROOT_KEY, KEY_VALUE, tmpFile, KEY_END); open_storage_plugin (storagePlugin); Plugin * plugin = plugins[storagePlugin]; KeySet * ks = simpleTestKeySet (); succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful"); succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbGet was not successful"); KeySet * dupKs = copyFunction (ks); compare_keyset (dupKs, ks); compare_keyset (ks, dupKs); ksDel (dupKs); keyDel (parentKey); ksDel (ks); closeStoragePlugin (storagePlugin); }
static void test_mmap_ksDupFun (const char * tmpFile, KeySet * copyFunction (const KeySet * source)) { Key * parentKey = keyNew (TEST_ROOT_KEY, KEY_VALUE, tmpFile, KEY_END); KeySet * conf = ksNew (0, KS_END); PLUGIN_OPEN ("mmapstorage"); KeySet * ks = simpleTestKeySet (); succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful"); succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbGet was not successful"); succeed_if ((ks->flags & KS_FLAG_MMAP_ARRAY) == KS_FLAG_MMAP_ARRAY, "KeySet array not in mmap"); KeySet * dupKs = copyFunction (ks); compare_keyset (dupKs, ks); compare_keyset (ks, dupKs); ksDel (dupKs); keyDel (parentKey); ksDel (ks); PLUGIN_CLOSE (); }
// // Clone a device // void DeviceManagerView::slotClone() { QListViewItem* item = m_listView->currentItem(); // Get the device id and name t_device_id old_id = item->text(KColumnID).toInt(); DeviceClass* dc = _app->doc()->device(old_id)->deviceClass(); assert(dc); QString new_name; new_name = item->text(KColumnName); new_name += "_new"; // Add new device Device* d = _app->doc()->newDevice(dc, new_name, 0); assert(d); for (t_function_id id = 0; id < KFunctionArraySize; id++) { Function* f = _app->doc()->function(id); if (!f) { continue; } //copy only functions that belong to parent device if (f->device() == old_id) { copyFunction(f, d); } } QString newid; newid.setNum(d->id()); m_listView->setCurrentItem(m_listView->findItem(newid, KColumnID)); slotProperties(); }
void FunctionManager::slotClone() { QListIterator <QTreeWidgetItem*> it(m_tree->selectedItems()); while (it.hasNext() == true) copyFunction(it.next()->text(KColumnID).toInt()); }