0e39ef7245108861b961ae2140611795289ac303
[openwrt/staging/linusw.git] /
1 From 6039bd1b7e5e71a0a171406cf980d2d61a6e79d4 Mon Sep 17 00:00:00 2001
2 From: Ioana Ciornei <ioana.ciornei@nxp.com>
3 Date: Tue, 24 Oct 2017 16:29:37 +0000
4 Subject: [PATCH 02/12] dprc: add --full-path option to dprc list command
5
6 Instead of printing an indented dprc list, activating
7 the --full-path option restool will print the entire path
8 of the dprc.
9 Example:
10
11 root@rodos:~# restool dprc list --full-path
12 dprc.1
13 dprc.1/dprc.3
14 dprc.1/dprc.2
15 dprc.1/dprc.2/dprc.4
16
17 Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
18 ---
19 dprc_commands.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++-----------
20 1 file changed, 50 insertions(+), 11 deletions(-)
21
22 diff --git a/dprc_commands.c b/dprc_commands.c
23 index e1a8f16..8de2f0e 100644
24 --- a/dprc_commands.c
25 +++ b/dprc_commands.c
26 @@ -76,13 +76,16 @@ C_ASSERT(ARRAY_SIZE(dprc_sync_options) <= MAX_NUM_CMD_LINE_OPTIONS + 1);
27 */
28 enum dprc_list_options {
29 LIST_OPT_HELP = 0,
30 + LIST_OPT_FULL_PATH,
31 };
32
33 static struct option dprc_list_options[] = {
34 [LIST_OPT_HELP] = {
35 .name = "help",
36 },
37 -
38 + [LIST_OPT_FULL_PATH] = {
39 + .name = "full-path",
40 + },
41 { 0 },
42 };
43
44 @@ -421,17 +424,33 @@ static int cmd_dprc_sync(void)
45 * Lists nested DPRCs inside a given DPRC, recursively
46 */
47 static int list_dprc(uint32_t dprc_id, uint16_t dprc_handle,
48 - int nesting_level, bool show_non_dprc_objects)
49 + int nesting_level, bool show_non_dprc_objects,
50 + char *full_path)
51 {
52 + char *updated_full_path = NULL;
53 int num_child_devices;
54 int error = 0;
55 + int full_path_len;
56
57 assert(nesting_level <= MAX_DPRC_NESTING);
58
59 - for (int i = 0; i < nesting_level; i++)
60 - printf(" ");
61 -
62 - printf("dprc.%u\n", dprc_id);
63 + if (full_path) {
64 + full_path_len = strlen(full_path);
65 + updated_full_path = malloc(full_path_len + 10);
66 + if (!updated_full_path) {
67 + ERROR_PRINTF("Could not alloc memory for full-path!\n");
68 + return -ENOMEM;
69 + }
70 + if (full_path_len != 0)
71 + sprintf(updated_full_path, "%s/dprc.%d", full_path, dprc_id);
72 + else
73 + sprintf(updated_full_path, "dprc.%d", dprc_id);
74 + printf("%s\n", updated_full_path);
75 + } else {
76 + for (int i = 0; i < nesting_level; i++)
77 + printf(" ");
78 + printf("dprc.%u\n", dprc_id);
79 + }
80
81 error = dprc_get_obj_count(&restool.mc_io, 0,
82 dprc_handle,
83 @@ -475,8 +494,11 @@ static int list_dprc(uint32_t dprc_id, uint16_t dprc_handle,
84 if (error < 0)
85 goto out;
86
87 - error = list_dprc(obj_desc.id, child_dprc_handle,
88 - nesting_level + 1, show_non_dprc_objects);
89 + error = list_dprc(obj_desc.id,
90 + child_dprc_handle,
91 + nesting_level + 1,
92 + show_non_dprc_objects,
93 + updated_full_path);
94
95 error2 = dprc_close(&restool.mc_io, 0, child_dprc_handle);
96 if (error2 < 0) {
97 @@ -491,6 +513,9 @@ static int list_dprc(uint32_t dprc_id, uint16_t dprc_handle,
98 }
99
100 out:
101 + if (full_path)
102 + free(updated_full_path);
103 +
104 return error;
105 }
106
107 @@ -498,8 +523,14 @@ static int cmd_dprc_list(void)
108 {
109 static const char usage_msg[] =
110 "\n"
111 - "Usage: restool dprc list\n"
112 + "Usage: restool dprc list [OPTIONS]\n"
113 + "\n"
114 + "OPTIONS:\n"
115 + "--full-path\n"
116 + " prints the dprc list in a full-path\n"
117 + " format like: dprc.1/dprc.2\n"
118 "\n";
119 + bool full_path = false;
120
121 if (restool.cmd_option_mask & ONE_BIT_MASK(LIST_OPT_HELP)) {
122 puts(usage_msg);
123 @@ -507,6 +538,12 @@ static int cmd_dprc_list(void)
124 return 0;
125 }
126
127 +
128 + if (restool.cmd_option_mask & ONE_BIT_MASK(LIST_OPT_FULL_PATH)) {
129 + restool.cmd_option_mask &= ~ONE_BIT_MASK(LIST_OPT_FULL_PATH);
130 + full_path = true;
131 + }
132 +
133 if (restool.obj_name != NULL) {
134 ERROR_PRINTF(
135 "Unexpected argument: \'%s\'\n\n", restool.obj_name);
136 @@ -514,8 +551,10 @@ static int cmd_dprc_list(void)
137 return -EINVAL;
138 }
139
140 - return list_dprc(
141 - restool.root_dprc_id, restool.root_dprc_handle, 0, false);
142 + return list_dprc(restool.root_dprc_id,
143 + restool.root_dprc_handle,
144 + 0, false,
145 + full_path ? "" : NULL);
146 }
147
148 static int show_one_resource_type(uint16_t dprc_handle,
149 --
150 2.14.1
151