0002-dprc-add-full-path-option-to-dprc-list-command.patch 3.9 KB

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