+/* Display the path in the same format as sysctl
+ * For eg. obdfilter.lustre-OST0000.stats */
+static char *display_name(char *filename, int show_type)
+{
+ char *tmp;
+ struct stat st;
+
+ if (show_type) {
+ if (lstat(filename, &st) < 0)
+ return NULL;
+ }
+
+ 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/");
+ else if (strncmp(filename, "lnet/", strlen("lnet/")) == 0)
+ filename += strlen("lnet/");
+
+ /* replace '/' with '.' to match conf_param and sysctl */
+ tmp = filename;
+ while ((tmp = strchr(tmp, '/')) != NULL)
+ *tmp = '.';
+
+ /* append the indicator to entries */
+ if (show_type) {
+ if (S_ISDIR(st.st_mode))
+ strcat(filename, "/");
+ else if (S_ISLNK(st.st_mode))
+ strcat(filename, "@");
+ else if (st.st_mode & S_IWUSR)
+ strcat(filename, "=");
+ }
+
+ 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);
+}
+
+static char *globerrstr(int glob_rc)
+{
+ switch(glob_rc) {
+ case GLOB_NOSPACE:
+ return "Out of memory";
+ case GLOB_ABORTED:
+ return "Read error";
+ case GLOB_NOMATCH:
+ return "Found no match";
+ }
+ return "Unknown error";
+}
+
+static void clean_path(char *path)
+{
+ char *tmp;
+
+ /* If the input is in form Eg. obdfilter.*.stats */
+ if (strchr(path, '.')) {
+ tmp = path;
+ while (*tmp != '\0') {
+ if ((*tmp == '.') &&
+ (tmp != path) && (*(tmp - 1) != '\\'))
+ *tmp = '/';
+ tmp ++;
+ }
+ }
+ /* get rid of '\', glob doesn't like it */
+ if ((tmp = strrchr(path, '\\')) != NULL) {
+ char *tail = path + strlen(path);
+ while (tmp != path) {
+ if (*tmp == '\\') {
+ memmove(tmp, tmp + 1, tail - tmp);
+ --tail;
+ }
+ --tmp;
+ }
+ }
+}
+
+/* Supporting file paths creates perilous behavoir: LU-888.
+ * Path support is deprecated.
+ * If a path is supplied it must begin with /proc. */
+static void lprocfs_param_pattern(const char *cmd, const char *path, char *buf,
+ size_t buf_size)
+{
+ /* test path to see if it begins with '/proc/' */
+ if (strncmp(path, "/proc/", strlen("/proc/")) == 0) {
+ static int warned;
+ if (!warned) {
+ fprintf(stderr, "%s: specifying parameters via "
+ "full paths is deprecated.\n", cmd);
+#if LUSTRE_VERSION_CODE >= OBD_OCD_VERSION(2,6,50,0)
+#warning "remove deprecated full path tunable access"
+#endif
+ warned = 1;
+ }
+ snprintf(buf, buf_size, "%s", path);
+ } else {
+ snprintf(buf, buf_size, "/proc/{fs,sys}/{lnet,lustre}/%s",
+ path);
+ }
+}
+
+struct param_opts {
+ int only_path:1;
+ int show_path:1;
+ int show_type:1;
+ int recursive:1;
+};
+
+static int listparam_cmdline(int argc, char **argv, struct param_opts *popt)
+{
+ int ch;
+
+ popt->show_path = 1;
+ popt->only_path = 1;
+ popt->show_type = 0;
+ popt->recursive = 0;
+
+ while ((ch = getopt(argc, argv, "FR")) != -1) {
+ switch (ch) {
+ case 'F':
+ popt->show_type = 1;
+ break;
+ case 'R':
+ popt->recursive = 1;
+ break;
+ default:
+ return -1;
+ }
+ }
+
+ return optind;
+}
+
+static int listparam_display(struct param_opts *popt, char *pattern)