static void test_fs_async_copy(const char *test_name, struct fs *fs) { struct fs_file *src, *dest; struct test_fs_file *test_file; test_begin(t_strdup_printf("%s: async copy", test_name)); src = fs_file_init(fs, "foo", FS_OPEN_MODE_REPLACE); test_assert(fs_write(src, "source", 6) == 0); dest = fs_file_init(fs, "bar", FS_OPEN_MODE_REPLACE | FS_OPEN_FLAG_ASYNC); test_assert(fs_copy(src, dest) == -1 && errno == EAGAIN); test_file = test_fs_file_get(fs, "bar"); test_file->wait_async = FALSE; test_assert(fs_copy_finish_async(dest) == 0); test_assert(test_file->contents->used > 0); fs_file_deinit(&dest); fs_file_deinit(&src); test_end(); }
/* * Copies source file path to destination * * req: TLV_TYPE_FILE_PATH - The file path to expand */ DWORD request_fs_file_copy(Remote *remote, Packet *packet) { Packet *response = packet_create_response(packet); DWORD result = ERROR_SUCCESS; char *oldpath; char *newpath; oldpath = packet_get_tlv_value_string(packet, TLV_TYPE_FILE_NAME); newpath = packet_get_tlv_value_string(packet, TLV_TYPE_FILE_PATH); if (!oldpath) { result = ERROR_INVALID_PARAMETER; } else { result = fs_copy(oldpath, newpath); } return packet_transmit_response(result, remote, response); }
bool test_fs_manip() { char *str; printf("testing simple read/write... "); fs_writestr("testfile", "str-TEST"); str = fs_readstr("testfile"); if(!str_isequal(str, "str-TEST")) return printf("failed\n"), false; mem_free(str); printf("okay\n"); printf("testing file copy... "); fs_copy("copyfile", "testfile"); str = fs_readstr("copyfile"); if(!str_isequal(str, "str-TEST")) return printf("failed\n"), false; mem_free(str); printf("okay\n"); printf("testing file deletion... "); fs_rmfile("testfile"); fs_rmfile("copyfile"); if(fs_exists("testfile") || fs_exists("copyfile")) return printf("failed\n"), false; printf("okay\n"); return true; }
void DC_LoadMaps() { DC_CheckForMaps("/cd"); DC_CLS(); fs_chdir(dcwolf3dpath); #ifdef SPEAR #ifndef SPEARDEMO fs_copy("audiohed.sod", "/ram/audiohed.sod"); fs_copy("audiot.sod", "/ram/audiot.sod"); fs_copy("vgadict.sod", "/ram/vgadict.sod"); fs_copy("vgagraph.sod", "/ram/vgagraph.sod"); fs_copy("vgahead.sod", "/ram/vgahead.sod"); switch(param_mission) { case 0: fs_copy("gamemaps.sod", "/ram/gamemaps.sod"); fs_copy("maphead.sod", "/ram/maphead.sod"); fs_copy("vswap.sod", "/ram/vswap.sod"); break; case 1: fs_copy("gamemaps.sd1", "/ram/gamemaps.sd1"); fs_copy("maphead.sd1", "/ram/maphead.sd1"); fs_copy("vswap.sd1", "/ram/vswap.sd1"); break; case 2: fs_copy("gamemaps.sd2", "/ram/gamemaps.sd2"); fs_copy("maphead.sd2", "/ram/maphead.sd2"); fs_copy("vswap.sd2", "/ram/vswap.sd2"); break; case 3: fs_copy("gamemaps.sd3", "/ram/gamemaps.sd3"); fs_copy("maphead.sd3", "/ram/maphead.sd3"); fs_copy("vswap.sd3", "/ram/vswap.sd3"); break; } #else fs_copy("audiohed.sdm", "/ram/audiohed.sdm"); fs_copy("audiot.sdm", "/ram/audiot.sdm"); fs_copy("vgadict.sdm", "/ram/vgadict.sdm"); fs_copy("vgagraph.sdm", "/ram/vgagraph.sdm"); fs_copy("vgahead.sdm", "/ram/vgahead.sdm"); fs_copy("gamemaps.sdm", "/ram/gamemaps.sdm"); fs_copy("maphead.sdm", "/ram/maphead.sdm"); fs_copy("vswap.sdm", "/ram/vswap.sdm"); #endif #else #ifndef UPLOAD fs_copy("audiohed.wl6", "/ram/audiohed.wl6"); fs_copy("audiot.wl6", "/ram/audiot.wl6"); fs_copy("vgadict.wl6", "/ram/vgadict.wl6"); fs_copy("vgagraph.wl6", "/ram/vgagraph.wl6"); fs_copy("vgahead.wl6", "/ram/vgahead.wl6"); fs_copy("gamemaps.wl6", "/ram/gamemaps.wl6"); fs_copy("maphead.wl6", "/ram/maphead.wl6"); fs_copy("vswap.wl6", "/ram/vswap.wl6"); #else fs_copy("audiohed.wl1", "/ram/audiohed.wl1"); fs_copy("audiot.wl1", "/ram/audiot.wl1"); fs_copy("vgadict.wl1", "/ram/vgadict.wl1"); fs_copy("vgagraph.wl1", "/ram/vgagraph.wl1"); fs_copy("vgahead.wl1", "/ram/vgahead.wl1"); fs_copy("gamemaps.wl1", "/ram/gamemaps.wl1"); fs_copy("maphead.wl1", "/ram/maphead.wl1"); fs_copy("vswap.wl1", "/ram/vswap.wl1"); #endif #endif fs_chdir("/ram"); }
void cl_fixture_sandbox(const char *fixture_name) { fs_copy(cl_fixture(fixture_name), _clay_path); }
static int update_op(struct update_context *uc) { fs_rid_vector *vec[4]; switch (uc->op->type) { case RASQAL_UPDATE_TYPE_UNKNOWN: add_message(uc, "Unknown update operation", 0); return 1; case RASQAL_UPDATE_TYPE_CLEAR: fs_clear(uc, graph_arg(uc->op->graph_uri)); return 0; case RASQAL_UPDATE_TYPE_CREATE: return 0; case RASQAL_UPDATE_TYPE_DROP: fs_clear(uc, graph_arg(uc->op->graph_uri)); return 0; case RASQAL_UPDATE_TYPE_LOAD: fs_load(uc, graph_arg(uc->op->document_uri), graph_arg(uc->op->graph_uri)); return 0; #if RASQAL_VERSION >= 924 case RASQAL_UPDATE_TYPE_ADD: fs_add(uc, graph_arg(uc->op->graph_uri), graph_arg(uc->op->document_uri)); return 0; case RASQAL_UPDATE_TYPE_MOVE: fs_move(uc, graph_arg(uc->op->graph_uri), graph_arg(uc->op->document_uri)); return 0; case RASQAL_UPDATE_TYPE_COPY: fs_copy(uc, graph_arg(uc->op->graph_uri), graph_arg(uc->op->document_uri)); return 0; #endif case RASQAL_UPDATE_TYPE_UPDATE: break; } fs_hash_freshen(); raptor_sequence *todel = NULL; raptor_sequence *toins = NULL; if (uc->op->delete_templates && !uc->op->where) { int where = 0; /* check to see if it's a DELETE WHERE { } */ for (int t=0; t<raptor_sequence_size(uc->op->delete_templates); t++) { rasqal_triple *tr = raptor_sequence_get_at(uc->op->delete_templates, t); if (any_vars(tr)) { where = 1; break; } } if (where) { fs_error(LOG_ERR, "DELETE WHERE { x } not yet supported"); add_message(uc, "DELETE WHERE { x } not yet supported, use DELETE { x } WHERE { x }", 0); return 1; } } #if RASQAL_VERSION >= 923 if (uc->op->where) { todel = raptor_new_sequence(NULL, NULL); toins = raptor_new_sequence(NULL, NULL); raptor_sequence *todel_p = raptor_new_sequence(NULL, NULL); raptor_sequence *toins_p = raptor_new_sequence(NULL, NULL); raptor_sequence *vars = raptor_new_sequence(NULL, NULL); fs_query *q = calloc(1, sizeof(fs_query)); uc->q = q; q->qs = uc->qs; q->rq = uc->rq; q->flags = FS_BIND_DISTINCT; #ifdef DEBUG_MERGE q->flags |= FS_QUERY_CONSOLE_OUTPUT; #endif q->boolean = 1; q->opt_level = 3; q->soft_limit = -1; q->segments = fsp_link_segments(uc->link); q->link = uc->link; q->bb[0] = fs_binding_new(); q->bt = q->bb[0]; /* hashtable to hold runtime created resources */ q->tmp_resources = g_hash_table_new_full(fs_rid_hash, fs_rid_equal, g_free, fs_free_cached_resource); /* add column to denote join ordering */ fs_binding_create(q->bb[0], "_ord", FS_RID_NULL, 0); if (uc->op->delete_templates) { for (int t=0; t<raptor_sequence_size(uc->op->delete_templates); t++) { rasqal_triple *tr = raptor_sequence_get_at(uc->op->delete_templates, t); if (any_vars(tr)) { fs_check_cons_slot(q, vars, tr->subject); fs_check_cons_slot(q, vars, tr->predicate); fs_check_cons_slot(q, vars, tr->object); raptor_sequence_push(todel_p, tr); } else { raptor_sequence_push(todel, tr); } } } if (uc->op->insert_templates) { for (int t=0; t<raptor_sequence_size(uc->op->insert_templates); t++) { rasqal_triple *tr = raptor_sequence_get_at(uc->op->insert_templates, t); if (any_vars(tr)) { fs_check_cons_slot(q, vars, tr->subject); fs_check_cons_slot(q, vars, tr->predicate); fs_check_cons_slot(q, vars, tr->object); raptor_sequence_push(toins_p, tr); } else { raptor_sequence_push(toins, tr); } } } q->num_vars = raptor_sequence_size(vars); for (int i=0; i < q->num_vars; i++) { rasqal_variable *v = raptor_sequence_get_at(vars, i); fs_binding_add(q->bb[0], v, FS_RID_NULL, 1); } /* perform the WHERE match */ fs_query_process_pattern(q, uc->op->where, vars); q->length = fs_binding_length(q->bb[0]); for (int s=0; s<4; s++) { vec[s] = fs_rid_vector_new(0); } for (int t=0; t<raptor_sequence_size(todel_p); t++) { rasqal_triple *triple = raptor_sequence_get_at(todel_p, t); for (int row=0; row < q->length; row++) { delete_rasqal_triple(uc, vec, triple, row); } if (fs_rid_vector_length(vec[0]) > 1000) { fsp_delete_quads_all(uc->link, vec); } } if (fs_rid_vector_length(vec[0]) > 0) { fsp_delete_quads_all(uc->link, vec); } for (int s=0; s<4; s++) { //fs_rid_vector_print(vec[s], 0, stdout); fs_rid_vector_free(vec[s]); vec[s] = NULL; } for (int t=0; t<raptor_sequence_size(toins_p); t++) { rasqal_triple *triple = raptor_sequence_get_at(toins_p, t); for (int row=0; row < q->length; row++) { insert_rasqal_triple(uc, triple, row); } } /* must not free the rasqal_query */ q->rq = NULL; fs_query_free(q); uc->q = NULL; } else { todel = uc->op->delete_templates; toins = uc->op->insert_templates; } #else if (uc->op->where) { fs_error(LOG_ERR, "DELETE/INSERT WHERE requires Rasqal 0.9.23 or newer"); add_message(uc, "DELETE/INSERT WHERE requires Rasqal 0.9.23 or newer", 0); } #endif /* delete constant triples */ if (todel) { for (int s=0; s<4; s++) { vec[s] = fs_rid_vector_new(0); } for (int t=0; t<raptor_sequence_size(todel); t++) { rasqal_triple *triple = raptor_sequence_get_at(todel, t); if (any_vars(triple)) { continue; } delete_rasqal_triple(uc, vec, triple, 0); } if (fs_rid_vector_length(vec[0]) > 0) { fsp_delete_quads_all(uc->link, vec); } for (int s=0; s<4; s++) { fs_rid_vector_free(vec[s]); vec[s] = NULL; } } /* insert constant triples */ if (toins) { for (int t=0; t<raptor_sequence_size(toins); t++) { rasqal_triple *triple = raptor_sequence_get_at(toins, t); if (any_vars(triple)) { continue; } insert_rasqal_triple(uc, triple, 0); } } fs_hash_freshen(); return 0; }
int main() { int i; int j; int k; heavyLine(); printf("filesystem self test\n"); heavyLine(); printf("\n"); fs_initialize(); // import programs fs_import("./programs.cpu/prog1out.cpu", "prog1"); fs_import("./programs.cpu/prog2out.cpu", "prog2"); // list the files fs_ls(); // remove file with id of 2 fs_removeFile(2); printf("\n"); // list the files fs_ls(); // invalid data int invalidData[3] = {FS_NULL, FS_NULL, FS_NULL}; // add invalid data int pStart[1] = {0}; int pSize[1] = {3}; fs_addFile("invalid data", 3, 1, pStart, pSize, invalidData); // list the files fs_ls(); fs_import("./programs.cpu/prog3out.cpu", "prog2"); // list the files fs_ls(); // remove all files fs_removeAllFiles(); // list the files fs_ls(); fs_import("./programs.cpu/prog1out.cpu", "prog1"); fs_import("./programs.cpu/prog2out.cpu", "prog2"); fs_import("./programs.cpu/prog3out.cpu", "prog3"); fs_import("./programs.cpu/prog4out.cpu", "prog4"); fs_ls(); fs_removeFile(6); heavyLine(); fs_dumpAllData(); fs_ls(); fs_copy(5, "progA"); fs_ls(); // testing paging INode* node; node = fs_getNode(4); int* page; page = calloc(PAGE_SIZE, sizeof(int)); for (i = 0; i < node->processes; i++) { heavyLine(); printf("process: %d \n", i); for (j = 0; j < (node->processSize[i] / PAGE_SIZE); j++) { page=fs_getPage(4, i, j * PAGE_SIZE, PAGE_SIZE); for (k = 0; k < PAGE_SIZE; k++) printf("%4d ", page[k]); printf("\n"); } } heavyLine(); //Since I cannot implementation of certain things at this point, we either need to have a memory leak //or do the following when finished with a set of inodes free(node->name); free(node); // fs_close(); return 0; }