Skip to content

Commit

Permalink
Merge pull request #40 from arthursimchaev/dev
Browse files Browse the repository at this point in the history
Changes for 3.11.1 version
  • Loading branch information
arthur-simchaev-wdc authored Aug 23, 2022
2 parents 72c8014 + 9cfecbf commit 80f6c2f
Show file tree
Hide file tree
Showing 7 changed files with 609 additions and 363 deletions.
45 changes: 32 additions & 13 deletions options.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "ufs_rpmb.h"
#include "ufs_hmr.h"

char gl_pr_type = VERBOSE;

static int verify_and_set_idn(struct tool_options *options);
static int verify_read(struct tool_options *options);
static int verify_write(struct tool_options *options);
Expand All @@ -36,6 +38,7 @@ static int verify_and_set_hmr_method(struct tool_options *options);
static int verify_and_set_hmr_unit(struct tool_options *options);
static int verify_sg_struct(struct tool_options *options);
static int verify_output_data(struct tool_options *options);
static int verify_output_mode(struct tool_options *options);

#define MAX_ADDRESS 0xFFFF

Expand All @@ -51,9 +54,10 @@ int init_options(int opt_cnt, char *opt_arr[], struct tool_options *options)
{"local", no_argument, NULL, 'l'}, /* UFS host*/
/* output file for the descriptor file store */
{"output_file", required_argument, NULL, 'D'},
{"output_mode", required_argument, NULL, 'P'},
{NULL, 0, NULL, 0}
};
static char *short_opts = "t:p:w:i:s:O:L:n:k:m:d:x:y:g:D:rocea";
static char *short_opts = "t:p:w:i:s:O:L:n:k:m:d:x:y:g:D:P:rocea";

while (-1 !=
(curr_opt = getopt_long(opt_cnt, opt_arr, short_opts,
Expand Down Expand Up @@ -138,6 +142,9 @@ int init_options(int opt_cnt, char *opt_arr[], struct tool_options *options)
case 'D':
rc = verify_output_data(options);
break;
case 'P':
rc = verify_output_mode(options);
break;
default:
rc = -EINVAL;
break;
Expand Down Expand Up @@ -760,10 +767,8 @@ static int verify_write(struct tool_options *options)
}

options->data = (char *)malloc(QUERY_DESC_STRING_MAX_SIZE);
if (!options->data) {
print_error("Memory Allocation problem");
goto out;
}
if (!options->data)
goto out_mem_problem;

strcpy(options->data, optarg);
}
Expand All @@ -776,10 +781,8 @@ static int verify_write(struct tool_options *options)
if (options->config_type_inx == ATTR_TYPE ||
options->config_type_inx == UIC_TYPE) {
options->data = (__u32 *)calloc(1, sizeof(__u32));
if (!options->data) {
print_error("Memory Allocation problem");
goto out;
}
if (!options->data)
goto out_mem_problem;

*(__u32 *)options->data = strtol(optarg, &endptr, 16);

Expand All @@ -798,15 +801,16 @@ static int verify_write(struct tool_options *options)
goto out;
}
options->data = (char *)calloc(1, len);
if (options->data == NULL) {
print_error("Memory Allocation problem");
goto out;
} else
if (options->data == NULL)
goto out_mem_problem;
else
strcpy(options->data, optarg);
}

return OK;

out_mem_problem:
print_error("Memory Allocation problem");
out:
return ERROR;
}
Expand Down Expand Up @@ -870,3 +874,18 @@ static int verify_output_data(struct tool_options *options)
return ERROR;
}

static int verify_output_mode(struct tool_options *options)
{
if (!strcmp(optarg, "raw")) {
gl_pr_type = RAW_VALUE;
} else if (!strcmp(optarg, "json")) {
gl_pr_type = JSON;
} else if (!strcmp(optarg, "verbose")) {
gl_pr_type = VERBOSE;
} else {
print_error("Wrong output mode");
return ERROR;
}

return OK;
}
8 changes: 8 additions & 0 deletions options.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,13 @@ struct tool_options {
char path[PATH_MAX];
};

enum print_type {
VERBOSE = 0,
JSON,
RAW_VALUE
};

extern char gl_pr_type;

int init_options(int opt_cnt, char **opt_arr, struct tool_options *options);
#endif /* OPTIONS_H_ */
5 changes: 3 additions & 2 deletions ufs.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
#include "ufs_rpmb.h"
#include "ufs_hmr.h"

#define UFS_BSG_UTIL_VERSION "3.11.2"
#define UFS_BSG_UTIL_VERSION "3.11.3"

typedef int (*command_function)(struct tool_options *opt);

struct tool_command {
Expand Down Expand Up @@ -84,7 +85,7 @@ static void initialized_options(struct tool_options *options)
}

static int parse_args(int argc, char **argv, command_function *func,
struct tool_options *options)
struct tool_options *options)
{
int rc = OK;
struct tool_command *cp;
Expand Down
Loading

0 comments on commit 80f6c2f

Please sign in to comment.