/** * @brief Lookup a route entry. */ int tils_route_lookup(char *source, char **dest) { return htable_lookup(_routes, source, (void **)dest); }
struct inode * kfs_mkdirent(struct inode * parent, const char * name, const struct inode_operations * i_ops, const struct kfs_fops * f_ops, unsigned mode, void * priv, size_t priv_len) { char buf[MAX_PATHLEN]; if ( parent ) { get_full_path(parent, buf); } dbg( "name=`%s/%s`\n", buf, name ); struct inode * inode = NULL; int new_entry = 0; if(parent) { if(parent->link_target) parent = parent->link_target; if(!S_ISDIR(parent->mode)) { printk(KERN_WARNING "%s is not a directory.\n", name); return NULL; } } // Try a lookup in the parent first, then allocate a new file if( parent && name ) inode = htable_lookup( parent->files, name ); if( !inode ) { inode = kfs_create_inode(); if (!inode) return NULL; new_entry = 1; } #if 0 else { printk( KERN_WARNING "%s: '%s' already exists\n", __func__, name ); } #endif // If this is a new allocation, create the directory table // \todo Do this only when a sub-file is created if( !inode->files && S_ISDIR(mode) ) inode->files = htable_create(7, offsetof( struct inode, name ), offsetof( struct inode, ht_link ), kfs_hash_filename, kfs_compare_filename); // \todo This will overwrite any existing file; should it warn? inode->parent = parent; inode->i_fop = f_ops; inode->i_op = i_ops; inode->priv = priv; inode->priv_len = priv_len; inode->mode = mode; if ( i_ops && i_ops->create ) { if ( i_ops->create( inode, mode ) ) { printk("%s:%d() ????\n",__FUNCTION__,__LINE__); return NULL; } } /* note: refs is initialized to 0 in kfs_create_inode() */ if( name ) { // Copy up to the first / or nul, stopping before we over run int offset = 0; while( *name && *name != '/' && offset < sizeof(inode->name)-1 ) inode->name[offset++] = *name++; inode->name[offset] = '\0'; } if( parent && new_entry ) htable_add( parent->files, inode ); return inode; }
/** * Extended XML formatting of a tree. * * Namespaces, if any, are automatically assigned a prefix, whose format * is "ns%u", the counter being incremented from 0. * * Users can supply a vector mapping namespaces to prefixes, so that they * can force specific prefixes for a given well-known namespace. * * If there is a default namespace, all the tags belonging to that namespace * are emitted without any prefix. * * The output stream must be explicitly closed by the user upon return. * * Options can be supplied to tune the output: * * - XFMT_O_SKIP_BLANKS will skip pure white space nodes. * - XFMT_O_COLLAPSE_BLANKS will replace consecutive blanks with 1 space * - XFMT_O_NO_INDENT requests that no indentation of the tree be made. * - XFMT_O_PROLOGUE emits a leading <?xml?> prologue. * - XFMT_O_FORCE_10 force generation of XML 1.0 * - XFMT_O_SINGLE_LINE emits XML as one big line (implies XFMT_O_NO_INDENT). * * @param root the root of the tree to dump * @param os the output stream where tree is dumped * @param options formatting options, as documented above * @param pvec a vector of prefixes to be used for namespaces * @param pvcnt amount of entries in vector * @param default_ns default namespace to install at root element * * @return TRUE on success. */ bool xfmt_tree_extended(const xnode_t *root, ostream_t *os, uint32 options, const struct xfmt_prefix *pvec, size_t pvcnt, const char *default_ns) { struct xfmt_pass1 xp1; struct xfmt_pass2 xp2; struct xfmt_invert_ctx ictx; const char *dflt_ns; g_assert(root != NULL); g_assert(os != NULL); if (options & XFMT_O_COLLAPSE_BLANKS) { /* FIXME */ g_carp("XFMT_O_COLLAPSE_BLANKS not supported yet"); stacktrace_where_print(stderr); } if (options & XFMT_O_SINGLE_LINE) options |= XFMT_O_NO_INDENT; /* * First pass: look at namespaces and construct a table recording the * earliest tree depth at which a namespace is used. */ ZERO(&xp1); xp1.uri2node = htable_create(HASH_KEY_STRING, 0); xp1.uri2prefix = nv_table_make(FALSE); if (default_ns != NULL) xp1.attr_uris = hset_create(HASH_KEY_STRING, 0); htable_insert_const(xp1.uri2node, VXS_XML_URI, root); xnode_tree_enter_leave(deconstify_pointer(root), xfmt_handle_pass1_enter, xfmt_handle_pass1_leave, &xp1); g_assert(0 == xp1.depth); /* Sound traversal */ /* * If there was a default namespace, make sure it is used in the tree. * Otherwise, discard it. */ if (default_ns != NULL) { if (NULL == htable_lookup(xp1.uri2node, default_ns)) { g_carp("XFMT default namespace '%s' is not needed", default_ns); dflt_ns = NULL; } else { dflt_ns = default_ns; } } else { dflt_ns = NULL; } /* * Prepare context for second pass. */ ZERO(&xp2); xp2.node2uri = htable_create(HASH_KEY_SELF, 0); xp2.os = os; xp2.options = options; xp2.default_ns = dflt_ns; xp2.attr_uris = xp1.attr_uris; xp2.uri2prefix = xp1.uri2prefix; xp2.uris = symtab_make(); xp2.prefixes = symtab_make(); xp2.depth = 0; xp2.pcount = 0; xp2.last_was_nl = TRUE; /* * Iterate over the hash table we've built to create a table indexed * by tree node and listing the namespaces to declare for that node. */ ictx.uri2node = xp1.uri2node; ictx.node2uri = xp2.node2uri; htable_foreach(xp1.uri2node, xfmt_invert_uri_kv, &ictx); htable_free_null(&xp1.uri2node); /* * Emit prologue if requested. */ if (options & XFMT_O_PROLOGUE) { if (options & XFMT_O_FORCE_10) { ostream_write(os, XFMT_DECL_10, CONST_STRLEN(XFMT_DECL_10)); } else { ostream_write(os, XFMT_DECL, CONST_STRLEN(XFMT_DECL)); } if (!(options & XFMT_O_SINGLE_LINE)) { ostream_putc(os, '\n'); } } xfmt_prefix_declare(&xp2, VXS_XML_URI, VXS_XML); /* * Prepare user-defined URI -> prefix mappings. */ if (pvcnt != 0) { size_t i; for (i = 0; i < pvcnt; i++) { const struct xfmt_prefix *p = &pvec[i]; xfmt_prefix_declare(&xp2, p->uri, p->prefix); } } /* * Second pass: generation. */ xnode_tree_enter_leave(deconstify_pointer(root), xfmt_handle_pass2_enter, xfmt_handle_pass2_leave, &xp2); g_assert(0 == xp2.depth); /* Sound traversal */ /* * Done, cleanup. */ nv_table_free_null(&xp2.uri2prefix); symtab_free_null(&xp2.prefixes); symtab_free_null(&xp2.uris); htable_free_null(&xp2.node2uri); hset_free_null(&xp2.attr_uris); return !ostream_has_ioerr(os); }
struct inode * kfs_lookup(struct inode * root, const char * dirname, unsigned create_mode) { dbg("name=`%s`\n", dirname ); // Special case -- use the root if root is null. if( !root ) root = kfs_root; while(1) { /* resolve possible link */ if( root->link_target ) root = root->link_target; // Trim any leading / characters while( *dirname && *dirname == '/' ) dirname++; // Special case -- if the file is empty, return the root if( *dirname == '\0' ) return root; // Find the next slash in the directory name char * next_slash = strchr( dirname, '/' ); // If there is no next slash and we're in create mode, // then we have reached the end of the lookup and we // return a pointer to the directory that will contain // the file once the caller creates it. if( !next_slash && create_mode ) return root; // If we have a mount point descend into its lookup routine if( root->i_op && root->i_op->lookup ) return (struct inode *) root->i_op->lookup( root, (struct dentry*) dirname, (struct nameidata*) (unsigned long) create_mode ); /* current entry is not a directory, so we can't search any further */ if( !S_ISDIR(root->mode) ) return NULL; // Search for the next / char struct inode *child = htable_lookup(root->files, dirname); // If it does not exist and we're not auto-creating // then return no match if( !child && !create_mode ) return NULL; // If it does not exist, but we are auto-creating, // create a subdirectory entry for this position with // the default operations. if( !child ) child = kfs_mkdirent(root, dirname, NULL, &kfs_default_fops, (create_mode & ~S_IFMT) | S_IFDIR, 0, 0); // If we do not have another component to search, // we return the found child if( !next_slash ) return child; // Move to the next component of the directory dirname = next_slash + 1; root = child; } }
/** * Find an ul_stats structure associated with the given name and size. * * Given the filename and it's size, iterate through the list of * all ul_stats and find the one that matches up. * * @param name The filename of we are looking for. * @param size The size of the file. * @param model The model associated with the tree_view. * @param iter The iterator where the ul_stats structure was found. * * @return The ul_stats structure associated with the name and size * parameters. * */ static struct upload_data * upload_stats_gui_find(const struct ul_stats *us) { return htable_lookup(ht_uploads, us); }
static struct gdbio_state *gdbio_htable_lookup(char *gdbcons){ spin_lock(&htable_lock); struct gdbio_state *gs = htable_lookup(gdbio_htable, gdbcons); spin_unlock(&htable_lock); return gs; }
/** * Fetches the node_data that holds the data about the given node * and knows the GtkTreeIter. */ static inline struct node_data * find_node(const struct nid *node_id) { return htable_lookup(nodes_handles, node_id); }