+
+ return rc;
+}
+
+/* Display the path in the same format as sysctl
+ * For eg. obdfilter.lustre-OST0000.stats */
+static char *display_name(char *filename)
+{
+ char *tmp;
+
+ filename += strlen("/proc/");
+ if (strncmp(filename, "fs/", strlen("fs/")) == 0)
+ filename += strlen("fs/");
+ else
+ filename += strlen("sys/");
+
+ if (strncmp(filename, "lustre/", strlen("lustre/")) == 0)
+ filename += strlen("lustre/");
+
+ /* replace '/' with '.' to match conf_param and sysctl */
+ tmp = filename;
+ while ((tmp = strchr(tmp, '/')) != NULL)
+ *tmp = '.';
+
+ return filename;
+}
+
+/* Find a character in a length limited string */
+/* BEWARE - kernel definition of strnchr has args in different order! */
+static char *strnchr(const char *p, char c, size_t n)
+{
+ if (!p)
+ return (0);
+
+ while (n-- > 0) {
+ if (*p == c)
+ return ((char *)p);
+ p++;
+ }
+ return (0);
+}
+
+int jt_lcfg_getparam(int argc, char **argv)
+{
+ int fp;
+ int rc = 0, i, show_path = 0, only_path = 0;
+ char pattern[PATH_MAX];
+ char *path, *tmp, *buf;
+ glob_t glob_info;
+
+ if (argc == 3 && (strcmp(argv[1], "-n") == 0 || strcmp(argv[1], "-N") == 0)) {
+ path = argv[2];
+ if (strcmp(argv[1], "-N") == 0) {
+ only_path = 1;
+ show_path = 1;
+ }
+ } else if (argc == 2) {
+ show_path = 1;
+ path = argv[1];
+ } else {
+ return CMD_HELP;
+ }
+
+ /* If the input is in form Eg. obdfilter.*.stats */
+ if (strchr(path, '.')) {
+ tmp = path;
+ while (*tmp != '\0') {
+ if (*tmp == '.')
+ *tmp = '/';
+ tmp ++;
+ }
+ }
+
+ /* If the entire path is specified as input */
+ fp = open(path, O_RDONLY);
+ if (fp < 0)
+ snprintf(pattern, PATH_MAX, "/proc/{fs,sys}/{lnet,lustre}/%s",
+ path);
+ else {
+ strcpy(pattern, path);
+ close(fp);
+ }
+
+ rc = glob(pattern, GLOB_BRACE, NULL, &glob_info);
+ if (rc) {
+ fprintf(stderr, "error : glob %s: %s \n", pattern,strerror(rc));
+ return rc;
+ }
+
+ buf = malloc(CFS_PAGE_SIZE);
+ for (i = 0; i < glob_info.gl_pathc; i++) {
+ char *valuename = NULL;
+
+ memset(buf, 0, CFS_PAGE_SIZE);
+ if (show_path) {
+ char *filename;
+ filename = strdup(glob_info.gl_pathv[i]);
+ valuename = display_name(filename);
+ if (valuename && only_path) {
+ printf("%s\n", valuename);
+ continue;
+ }
+ }
+
+ /* Write the contents of file to stdout */
+ fp = open(glob_info.gl_pathv[i], O_RDONLY);
+ if (fp < 0) {
+ fprintf(stderr, "error: %s: opening('%s') failed: %s\n",
+ jt_cmdname(argv[0]), glob_info.gl_pathv[i],
+ strerror(errno));
+ continue;
+ }