📄 hcl.c
字号:
if (!labelcl_info) return(-1); /* * Create a symbolic link devfs entry. */ status = devfs_mk_symlink(de, name, flags, link, &new_devfs_handle, labelcl_info); if ( (!new_devfs_handle) || (!status) ){ labelcl_info_destroy((labelcl_info_t *)labelcl_info); return(-1); } /* * If the caller provides a private data pointer, save it in the * labelcl info structure(fastinfo). This can be retrieved via * hwgraph_fastinfo_get() */ if (info) hwgraph_fastinfo_set(new_devfs_handle, (arbitrary_info_t)info); *handle = new_devfs_handle; return(0);}/* * hwgraph_vertex_destroy - Destroy the devfs entry */inthwgraph_vertex_destroy(vertex_hdl_t de){ void *labelcl_info = NULL; labelcl_info = devfs_get_info(de); devfs_unregister(de); if (labelcl_info) labelcl_info_destroy((labelcl_info_t *)labelcl_info); return(0);}/* * hwgraph_edge_add - This routines has changed from the original conext. * All it does now is to create a symbolic link from "from" to "to". *//* ARGSUSED */inthwgraph_edge_add(vertex_hdl_t from, vertex_hdl_t to, char *name){ char *path; char *s1; char *index; int name_start; vertex_hdl_t handle = NULL; int rv; int i, count; path = kmalloc(1024, GFP_KERNEL); memset(path, 0x0, 1024); name_start = devfs_generate_path (from, path, 1024); s1 = &path[name_start]; count = 0; while (1) { index = strstr (s1, "/"); if (index) { count++; s1 = ++index; } else { count++; break; } } memset(path, 0x0, 1024); name_start = devfs_generate_path (to, path, 1024); for (i = 0; i < count; i++) { strcat(path,"../"); } strcat(path, &path[name_start]); /* * Otherwise, just create a symlink to the vertex. * In this case the vertex was previous created with a REAL pathname. */ rv = devfs_mk_symlink (from, (const char *)name, DEVFS_FL_DEFAULT, path, &handle, NULL); name_start = devfs_generate_path (handle, path, 1024); return(rv); }/* ARGSUSED */inthwgraph_edge_get(vertex_hdl_t from, char *name, vertex_hdl_t *toptr){ int namelen = 0; vertex_hdl_t target_handle = NULL; if (name == NULL) return(-1); if (toptr == NULL) return(-1); /* * If the name is "." just return the current devfs entry handle. */ if (!strcmp(name, HWGRAPH_EDGELBL_DOT)) { if (toptr) { *toptr = from; } } else if (!strcmp(name, HWGRAPH_EDGELBL_DOTDOT)) { /* * Hmmm .. should we return the connect point or parent .. * see in hwgraph, the concept of parent is the connectpt! * * Maybe we should see whether the connectpt is set .. if * not just return the parent! */ target_handle = hwgraph_connectpt_get(from); if (target_handle) { /* * Just return the connect point. */ *toptr = target_handle; return(0); } target_handle = devfs_get_parent(from); *toptr = target_handle; } else { /* * Call devfs to get the devfs entry. */ namelen = (int) strlen(name); target_handle = devfs_find_handle (from, name, 0, 0, 0, 1); /* Yes traverse symbolic links */ if (target_handle == NULL) return(-1); else *toptr = target_handle; } return(0);}/* * hwgraph_info_add_LBL - Adds a new label for the device. Mark the info_desc * of the label as INFO_DESC_PRIVATE and store the info in the label. *//* ARGSUSED */inthwgraph_info_add_LBL( vertex_hdl_t de, char *name, arbitrary_info_t info){ return(labelcl_info_add_LBL(de, name, INFO_DESC_PRIVATE, info));}/* * hwgraph_info_remove_LBL - Remove the label entry for the device. *//* ARGSUSED */inthwgraph_info_remove_LBL( vertex_hdl_t de, char *name, arbitrary_info_t *old_info){ return(labelcl_info_remove_LBL(de, name, NULL, old_info));}/* * hwgraph_info_replace_LBL - replaces an existing label with * a new label info value. *//* ARGSUSED */inthwgraph_info_replace_LBL( vertex_hdl_t de, char *name, arbitrary_info_t info, arbitrary_info_t *old_info){ return(labelcl_info_replace_LBL(de, name, INFO_DESC_PRIVATE, info, NULL, old_info));}/* * hwgraph_info_get_LBL - Get and return the info value in the label of the * device. *//* ARGSUSED */inthwgraph_info_get_LBL( vertex_hdl_t de, char *name, arbitrary_info_t *infop){ return(labelcl_info_get_LBL(de, name, NULL, infop));}/* * hwgraph_info_get_exported_LBL - Retrieve the info_desc and info pointer * of the given label for the device. The weird thing is that the label * that matches the name is return irrespective of the info_desc value! * Do not understand why the word "exported" is used! *//* ARGSUSED */inthwgraph_info_get_exported_LBL( vertex_hdl_t de, char *name, int *export_info, arbitrary_info_t *infop){ int rc; arb_info_desc_t info_desc; rc = labelcl_info_get_LBL(de, name, &info_desc, infop); if (rc == 0) *export_info = (int)info_desc; return(rc);}/* * hwgraph_info_get_next_LBL - Returns the next label info given the * current label entry in place. * * Once again this has no locking or reference count for protection. * *//* ARGSUSED */inthwgraph_info_get_next_LBL( vertex_hdl_t de, char *buf, arbitrary_info_t *infop, labelcl_info_place_t *place){ return(labelcl_info_get_next_LBL(de, buf, NULL, infop, place));}/* * hwgraph_info_export_LBL - Retrieve the specified label entry and modify * the info_desc field with the given value in nbytes. *//* ARGSUSED */inthwgraph_info_export_LBL(vertex_hdl_t de, char *name, int nbytes){ arbitrary_info_t info; int rc; if (nbytes == 0) nbytes = INFO_DESC_EXPORT; if (nbytes < 0) return(-1); rc = labelcl_info_get_LBL(de, name, NULL, &info); if (rc != 0) return(rc); rc = labelcl_info_replace_LBL(de, name, nbytes, info, NULL, NULL); return(rc);}/* * hwgraph_info_unexport_LBL - Retrieve the given label entry and change the * label info_descr filed to INFO_DESC_PRIVATE. *//* ARGSUSED */inthwgraph_info_unexport_LBL(vertex_hdl_t de, char *name){ arbitrary_info_t info; int rc; rc = labelcl_info_get_LBL(de, name, NULL, &info); if (rc != 0) return(rc); rc = labelcl_info_replace_LBL(de, name, INFO_DESC_PRIVATE, info, NULL, NULL); return(rc);}/* * hwgraph_path_lookup - return the handle for the given path. * */inthwgraph_path_lookup( vertex_hdl_t start_vertex_handle, char *lookup_path, vertex_hdl_t *vertex_handle_ptr, char **remainder){ *vertex_handle_ptr = devfs_find_handle(start_vertex_handle, /* start dir */ lookup_path, /* path */ 0, /* major */ 0, /* minor */ 0, /* char | block */ 1); /* traverse symlinks */ if (*vertex_handle_ptr == NULL) return(-1); else return(0);}/* * hwgraph_traverse - Find and return the devfs handle starting from de. * */graph_error_thwgraph_traverse(vertex_hdl_t de, char *path, vertex_hdl_t *found){ /* * get the directory entry (path should end in a directory) */ *found = devfs_find_handle(de, /* start dir */ path, /* path */ 0, /* major */ 0, /* minor */ 0, /* char | block */ 1); /* traverse symlinks */ if (*found == NULL) return(GRAPH_NOT_FOUND); else return(GRAPH_SUCCESS);}/* * hwgraph_path_to_vertex - Return the devfs entry handle for the given * pathname .. assume traverse symlinks too!. */vertex_hdl_thwgraph_path_to_vertex(char *path){ return(devfs_find_handle(NULL, /* start dir */ path, /* path */ 0, /* major */ 0, /* minor */ 0, /* char | block */ 1)); /* traverse symlinks */}/* * hwgraph_inventory_remove - Removes an inventory entry. * * Remove an inventory item associated with a vertex. It is the caller's * responsibility to make sure that there are no races between removing * inventory from a vertex and simultaneously removing that vertex.*/inthwgraph_inventory_remove( vertex_hdl_t de, int class, int type, major_t controller, minor_t unit, int state){ return(0); /* Just a Stub for IRIX code. */}/* * Find the canonical name for a given vertex by walking back through * connectpt's until we hit the hwgraph root vertex (or until we run * out of buffer space or until something goes wrong). * * COMPATIBILITY FUNCTIONALITY * Walks back through 'parents', not necessarily the same as connectpts. * * Need to resolve the fact that devfs does not return the path from * "/" but rather it just stops right before /dev .. */inthwgraph_vertex_name_get(vertex_hdl_t vhdl, char *buf, uint buflen){ char *locbuf; int pos; if (buflen < 1) return(-1); /* XXX should be GRAPH_BAD_PARAM ? */ locbuf = kmalloc(buflen, GFP_KERNEL); pos = devfs_generate_path(vhdl, locbuf, buflen); if (pos < 0) { kfree(locbuf); return pos; } strcpy(buf, &locbuf[pos]); kfree(locbuf); return 0;}/*** vertex_to_name converts a vertex into a canonical name by walking** back through connect points until we hit the hwgraph root (or until** we run out of buffer space).**** Usually returns a pointer to the original buffer, filled in as** appropriate. If the buffer is too small to hold the entire name,** or if anything goes wrong while determining the name, vertex_to_name** returns "UnknownDevice".*/#define DEVNAME_UNKNOWN "UnknownDevice"char *vertex_to_name(vertex_hdl_t vhdl, char *buf, uint buflen){ if (hwgraph_vertex_name_get(vhdl, buf, buflen) == GRAPH_SUCCESS) return(buf); else return(DEVNAME_UNKNOWN);}graph_error_thwgraph_edge_remove(vertex_hdl_t from, char *name, vertex_hdl_t *toptr){ printk("WARNING: hwgraph_edge_remove NOT supported.\n"); return(GRAPH_ILLEGAL_REQUEST);}graph_error_thwgraph_vertex_unref(vertex_hdl_t vhdl){ return(GRAPH_ILLEGAL_REQUEST);}EXPORT_SYMBOL(hwgraph_mk_dir);EXPORT_SYMBOL(hwgraph_path_add);EXPORT_SYMBOL(hwgraph_register);EXPORT_SYMBOL(hwgraph_vertex_destroy);EXPORT_SYMBOL(hwgraph_fastinfo_get);EXPORT_SYMBOL(hwgraph_fastinfo_set);EXPORT_SYMBOL(hwgraph_connectpt_set);EXPORT_SYMBOL(hwgraph_connectpt_get);EXPORT_SYMBOL(hwgraph_info_add_LBL);EXPORT_SYMBOL(hwgraph_info_remove_LBL);EXPORT_SYMBOL(hwgraph_info_replace_LBL);EXPORT_SYMBOL(hwgraph_info_get_LBL);EXPORT_SYMBOL(hwgraph_info_get_exported_LBL);EXPORT_SYMBOL(hwgraph_info_get_next_LBL);EXPORT_SYMBOL(hwgraph_info_export_LBL);EXPORT_SYMBOL(hwgraph_info_unexport_LBL);EXPORT_SYMBOL(hwgraph_path_lookup);EXPORT_SYMBOL(hwgraph_traverse);EXPORT_SYMBOL(hwgraph_vertex_name_get);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -