void POSCALL nos_regDelSysKey(NOSREGTYPE_t type, NOSGENERICHANDLE_t handle, REGELEM_t re) { REGELEM_t rl = REEUNKNOWN; posSemaGet(reglist_sema_g); if (re == NULL) { for (re = reglist_syselem_g[type], rl = NULL; re != NULL; rl = re, re = re->next) { if (!IS_DELETED(re) && (re->handle.generic == handle)) break; } } if (re != NULL) { if (!IS_DELETED(re)) { MARK_DELETED(re); n_remove(re, rl, type); } } posSemaSignal(reglist_sema_g); }
VAR_t POSCALL nosRegDel(const char *keyname) { REGELEM_t re, rl; VAR_t i; posSemaGet(reglist_sema_g); for (re = reglist_syselem_g[REGTYPE_USER], rl = NULL; re != NULL; rl = re, re = re->next) { if (!IS_DELETED(re)) { for (i=0; i<NOS_MAX_REGKEYLEN; ++i) { if (re->name[i] != keyname[i]) break; if ((keyname[i] == 0) || (i == NOS_MAX_REGKEYLEN-1)) { MARK_DELETED(re); n_remove(re, rl, REGTYPE_USER); posSemaSignal(reglist_sema_g); return E_OK; } } } } posSemaSignal(reglist_sema_g); return -E_FAIL; }
/* * Find directory entry in specified sector. * The fat vnode data is filled if success. * * @fmp: fatfs mount point * @sec: sector# * @name: file name * @node: pointer to fat node */ static int fat_lookup_dirent(struct fatfsmount *fmp, u_long sec, char *name, struct fatfs_node *np) { struct fat_dirent *de; u_long i; int err; err = fat_read_dirent(fmp, sec); if (err) return err; de = (struct fat_dirent *)fmp->dir_buf; for (i = 0; i < DIR_PER_SEC; i++) { /* Find specific file or directory name */ if (IS_EMPTY(de)) return ENOENT; if (!IS_VOL(de) && !fat_compare_name((char *)de->name, name)) { /* Found. Fill the fat vnode data. */ *(&np->dirent) = *de; np->sector = sec; np->offset = sizeof(struct fat_dirent) * i; DPRINTF(("fat_lookup_dirent: found sec=%d\n", sec)); return 0; } if (!IS_DELETED(de)) DPRINTF(("fat_lookup_dirent: %s\n", de->name)); de++; } return EAGAIN; }
/* * Find empty directory entry and put new entry on it. * * @fmp: fatfs mount point * @sec: sector# * @np: pointer to fat node */ static int fat_add_dirent(struct fatfsmount *fmp, u_long sec, struct fatfs_node *np) { struct fat_dirent *de; int err; u_long i; err = fat_read_dirent(fmp, sec); if (err) return err; de = (struct fat_dirent *)fmp->dir_buf; for (i = 0; i < DIR_PER_SEC; i++) { if (IS_DELETED(de) || IS_EMPTY(de)) goto found; DPRINTF(("fat_add_dirent: scan %s\n", de->name)); de++; } return ENOENT; found: DPRINTF(("fat_add_dirent: found. sec=%d\n", sec)); memcpy(de, &np->dirent, sizeof(struct fat_dirent)); err = fat_write_dirent(fmp, sec); return err; }
/* * Get directory entry for specified index in sector. * The directory entry is filled if success. * * @fmp: fatfs mount point * @sec: sector# * @target: target index * @index: current index * @np: pointer to fat node */ static int fat_get_dirent(struct fatfsmount *fmp, u_long sec, int target, int *index, struct fatfs_node *np) { struct fat_dirent *de; u_long i; int err; err = fat_read_dirent(fmp, sec); if (err) return err; de = (struct fat_dirent *)fmp->dir_buf; for (i = 0; i < DIR_PER_SEC; i++) { if (IS_EMPTY(de)) return ENOENT; if (!IS_DELETED(de) && !IS_VOL(de)) { /* valid file */ if (*index == target) { *(&np->dirent) = *de; np->sector = sec; np->offset = sizeof(struct fat_dirent) * i; DPRINTF(("fat_get_dirent: found index=%d\n", *index)); return 0; } (*index)++; } DPRINTF(("fat_get_dirent: %s\n", de->name)); de++; } return EAGAIN; }
static REGELEM_t POSCALL n_findKeyByHandle(NOSREGTYPE_t type, NOSGENERICHANDLE_t handle) { REGELEM_t re; for (re = reglist_syselem_g[type]; re != NULL; re = re->next) { if ((re->handle.generic == handle) && !IS_DELETED(re)) break; } return re; }
void Forest::CompactTopLevel() { DynArray < node_idx > *arc_temp_array; //Store the new arcs for level K arc_temp_array = new DynArray < node_idx > (0); node_idx i; arc_idx j; tail[K] = 0; //Clear the arc array int numvalidnodes = 1; //Start at 1, because 0 is valid #ifdef BRIEF_DEBUG printf("Compact Top Level\n"); #endif for (i = 1; i < last[K]; i++) UT->remove(K, i); for (i = 1; i < last[K]; i++) { //Scan throught the NODE list (except node 0) Node *nodeI = &FDDL_NODE(K, i); if (!IS_DELETED(nodeI)) { //If it's not deleted, //Copy (and compact) the arcs. int newdown = tail[K]; if (nodeI->flags & FLAG_SPARSE) { //If it's sparse, compact for (j = 0; j < nodeI->size; j++) { //its arcs this way. (*(*arc_temp_array)[tail[K]]) = SPARSE_INDEX(K, nodeI, j); (*(*arc_temp_array)[tail[K] + 1]) = SPARSE_ARC(K, nodeI, j); tail[K] += 2; } } else { //Otherwise, do it in full. for (j = 0; j < nodeI->size; j++) { (*(*arc_temp_array)[tail[K]]) = FULL_ARC(K, nodeI, j); tail[K]++; } } nodeI->down = newdown; UT->add(K, i); numvalidnodes++; } //If it IS deleted, all we do is take it out of the unique table. //It should have been "deleted downstream" earlier. } delete arcs[K]; arcs[K] = arc_temp_array; FlushCaches(K); }
static REGELEM_t POSCALL n_findKeyByName(NOSREGTYPE_t type, const char *keyname) { REGELEM_t re; VAR_t i; for (re = reglist_syselem_g[type]; re != NULL; re = re->next) { if (!IS_DELETED(re)) { for (i=0; i<NOS_MAX_REGKEYLEN; ++i) { if (re->name[i] != keyname[i]) break; if ((keyname[i] == 0) || (i == NOS_MAX_REGKEYLEN-1)) return re; } } } return NULL; }
void Forest::Compact(level k) { #ifdef BRIEF_DEBUG printf("Compact Level %d\n", k); #endif compactions++; #ifdef NOCOMPACT return; #endif //Don't compact bad levels if (k > K) return; if (k == K) { //The Top Level is special. CompactTopLevel(); return; } DynArray < node_idx > *arc_temp_array; //Store the new arcs for level k arc_temp_array = new DynArray < node_idx > (0); DynArray < Node > *node_temp_array; node_temp_array = new DynArray < Node >; //Store the nodes here //Store a mapping of old->new of node indices so that we can re-hash and also update the level above. DynArray<node_idx> *node_remap_array = new DynArray < node_idx > (0); node_idx i; arc_idx j; arc_idx arc; tail[k] = 0; //Clear the arc array int numvalidnodes = 1; //Start at 1, because 0 is valid (*(*node_remap_array)[0]) = 0; for (i = 1; i < last[k]; i++) { //Scan throught the NODE list (except node 0) Node *nodeI = &FDDL_NODE(k, i); //If it's not deleted, copy it. // if (nodeI->in > 0) if (!(nodeI->flags & FLAG_DELETED)) { //Save the "old" idx of the node //into a temp array. (*(*node_remap_array)[i]) = numvalidnodes; (*(*node_temp_array)[numvalidnodes]) = (*nodeI); //Copy (and compact) the arcs, too. int newdown = tail[k]; if (nodeI->flags & FLAG_SPARSE) { //If it's sparse, compact //its arcs this way. for (j = 0; j < nodeI->size; j++) { (*(*arc_temp_array)[tail[k]]) = SPARSE_INDEX(k, nodeI, j); (*(*arc_temp_array)[tail[k] + 1]) = SPARSE_ARC(k, nodeI, j); tail[k] += 2; } } else { //Otherwise, do it in full. for (j = 0; j < nodeI->size; j++) { (*(*arc_temp_array)[tail[k]]) = FULL_ARC(k, nodeI, j); tail[k]++; } } (*(*node_temp_array)[numvalidnodes]).down = newdown; numvalidnodes++; } else { //If it IS deleted, "DeleteDownstream" it. UT->remove(k, i); assert(nodeI->flags & FLAG_DELETED); if (k >= 2) { for (j = 0; j < nodeI->size; j++) { if (nodeI->flags & FLAG_SPARSE) arc = SPARSE_ARC(k, nodeI, j); else arc = FULL_ARC(k, nodeI, j); Node *nodeJ = &FDDL_NODE(k - 1, arc); SetArc(k, i, j, 0); //Compaction should ALWAYS be done if (nodeJ->in == 0) //Top Down so that Deletion Marking DeleteNode(k - 1, arc); //Actually Deletes -Downstream- } } } } last[k] = numvalidnodes; delete nodes[k]; nodes[k] = node_temp_array; UT->remap(k, node_remap_array); //Update all the unique table entries delete arcs[k]; arcs[k] = arc_temp_array; for (i = 1; i < last[k + 1]; i++) { //Now fix our upstairs pointers. Node *nodeI = &FDDL_NODE(k + 1, i); if (!IS_DELETED(nodeI)) { if (nodeI->flags & FLAG_SPARSE) { for (j = 0; j < nodeI->size; j++) { assert((*(*node_remap_array) [SPARSE_ARC(k + 1, nodeI, j)]) >= 0); SPARSE_ARC(k + 1, nodeI, j) = (*(*node_remap_array) [SPARSE_ARC (k + 1, nodeI, j)]); } } else { for (j = 0; j < nodeI->size; j++) { assert((*(*node_remap_array) [FULL_ARC(k + 1, nodeI, j)]) >= 0); FULL_ARC(k + 1, nodeI, j) = (*(*node_remap_array) [FULL_ARC (k + 1, nodeI, j)]); } } } } //Reinsert nodes into Unique table. Check that this does not violate //integrity with an assert. for (i = 1; i < last[k + 1]; i++) { Node *nodeI = &FDDL_NODE(k + 1, i); if ((nodeI->flags & FLAG_CHECKED_IN) && !IS_DELETED(nodeI)) { int s = UT->add(k + 1, i); //@@@DEBUG: Removed for testing. @@@// assert(s == i); } } FlushCaches(k); delete node_remap_array; }