-
Notifications
You must be signed in to change notification settings - Fork 60
/
options.c
907 lines (773 loc) · 19.5 KB
/
options.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
// SPDX-License-Identifier: GPL-2.0-or-later
/* Copyright (C) 2019 Western Digital Corporation or its affiliates */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <errno.h>
#include "options.h"
#include "ufs.h"
#include "unipro.h"
#include "ufs_ffu.h"
#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);
static int verify_and_set_flag_operation(int opr_type,
struct tool_options *options);
static int verify_and_set_device_path(struct tool_options *options);
static int verify_arg_and_set_default(struct tool_options *options);
static int verify_and_set_index(struct tool_options *options);
static int verify_and_set_selector(struct tool_options *options);
static int verify_target(struct tool_options *options, int target);
static int verify_and_set_ffu_chunk_size(struct tool_options *options);
static int verify_length(struct tool_options *options);
static int verify_offset(struct tool_options *options);
static int verify_and_set_start_addr(struct tool_options *options);
static int verify_and_set_num_block(struct tool_options *options);
static int verify_lun(struct tool_options *options);
static int verify_and_set_key_path(struct tool_options *options);
static int verify_region(struct tool_options *options);
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
int init_options(int opt_cnt, char *opt_arr[], struct tool_options *options)
{
int rc = -EINVAL;
int curr_opt = 0;
int opt = 0;
static struct option long_opts[] = {
{"peer", no_argument, NULL, 'u'}, /* UFS device */
{"local", no_argument, NULL, 'l'}, /* UFS host*/
{"static", no_argument, NULL, 'S'},
/* 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:P:rocea";
while (-1 !=
(curr_opt = getopt_long(opt_cnt, opt_arr, short_opts,
long_opts, &opt))) {
switch (curr_opt) {
case 'a':
rc = verify_read(options);
if (!rc)
options->opr = READ_ALL;
break;
case 't':
rc = verify_and_set_idn(options);
break;
case 'r':
rc = verify_read(options);
if (!rc)
options->opr = READ;
break;
case 'w':
rc = verify_write(options);
if (!rc)
options->opr = WRITE;
break;
case 'c':
rc = verify_and_set_flag_operation(CLEAR_FLAG,
options);
break;
case 'e':
rc = verify_and_set_flag_operation(SET_FLAG, options);
break;
case 'o':
rc = verify_and_set_flag_operation(TOGGLE_FLAG,
options);
break;
case 'p':
rc = verify_and_set_device_path(options);
break;
case 'i':
rc = verify_and_set_index(options);
break;
case 's':
if (options->config_type_inx == FFU_TYPE)
rc = verify_and_set_ffu_chunk_size(options);
else if (options->config_type_inx == RPMB_CMD_TYPE ||
options->config_type_inx == ARPMB_CMD_TYPE)
rc = verify_and_set_start_addr(options);
else
rc = verify_and_set_selector(options);
break;
case 'u':
rc = verify_target(options, DME_PEER);
break;
case 'l':
rc = verify_target(options, DME_LOCAL);
break;
case 'd':
rc = verify_lun(options);
break;
case 'L':
rc = verify_length(options);
break;
case 'O':
rc = verify_offset(options);
break;
case 'n':
rc = verify_and_set_num_block(options);
break;
case 'k':
rc = verify_and_set_key_path(options);
break;
case 'm':
rc = verify_region(options);
break;
case 'x':
rc = verify_and_set_hmr_method(options);
break;
case 'y':
rc = verify_and_set_hmr_unit(options);
break;
case 'g':
rc = verify_sg_struct(options);
break;
case 'D':
rc = verify_output_data(options);
break;
case 'P':
rc = verify_output_mode(options);
break;
case 'S':
if (options->config_type_inx == UIC_TYPE)
options->set_type = ATTR_SET_ST;
break;
default:
rc = -EINVAL;
break;
}
if (rc)
break;
}
if (!rc)
rc = verify_arg_and_set_default(options);
return rc;
}
static int verify_target(struct tool_options *options, int target)
{
if (options->target != INVALID) {
print_error("duplicated operate target.");
goto out;
}
options->target = target;
return OK;
out:
return ERROR;
}
static int verify_and_set_index(struct tool_options *options)
{
int index = INVALID;
if (options->index != INVALID) {
print_error("duplicated index");
goto out;
}
/* In case atoi returned 0 . Check that is real 0 and not error
* arguments . Also check that the value is in correct range
*/
if (strstr(optarg, "0x") || strstr(optarg, "0X"))
index = (int)strtol(optarg, NULL, 0);
else
index = atoi(optarg);
if ((index == 0 && strcmp(optarg, "0")) || index < 0) {
print_error("Invalid argument for index");
goto out;
}
options->index = index;
return OK;
out:
return ERROR;
}
static int verify_and_set_ffu_chunk_size(struct tool_options *options)
{
int chunk_size_kb = atoi(optarg);
if (!chunk_size_kb) {
print_error("Invalid chunk_size %d ", chunk_size_kb);
goto out;
}
options->size = chunk_size_kb * 1024;
if ((options->size > MAX_IOCTL_BUF_SIZE) ||
(options->size % ALIGNMENT_CHUNK_SIZE)) {
print_error("The chunk should be multiple value of 4k, between 4k and %dk",
MAX_IOCTL_BUF_SIZE / 1024);
goto out;
}
return OK;
out:
return ERROR;
}
static int verify_and_set_selector(struct tool_options *options)
{
int selector = INVALID;
if (options->selector != INVALID) {
print_error("duplicated selector");
goto out;
}
/* In case atoi returned 0 . Check that is real 0 and not error
* arguments . Also check that the value is in correct range
*/
selector = atoi(optarg);
if ((selector == 0 && strcmp(optarg, "0")) || selector < 0) {
print_error("Invalid argument for selector");
goto out;
}
options->selector = selector;
return OK;
out:
return ERROR;
}
static int verify_and_set_idn(struct tool_options *options)
{
int idn = INVALID;
char *endptr;
errno = 0;
if (options->idn != INVALID) {
print_error("duplicated type option");
goto out;
}
idn = (int)strtol(optarg, &endptr, 0);
if (errno != 0 || *endptr != '\0' || idn < 0) {
print_error("Invalid argument for idn");
goto out;
}
switch (options->config_type_inx) {
case DESC_TYPE:
if (idn > QUERY_DESC_IDN_MAX) {
print_error("Invalid descriptor idn %d", idn);
goto out;
}
break;
case ATTR_TYPE:
case FLAG_TYPE:
break;
case UIC_TYPE:
if (idn >= MAX_UNIPRO_IDN) {
print_error("Invalid UIC idn %d", idn);
goto out;
}
break;
case FFU_TYPE:
if (idn >= UFS_FFU_MAX) {
print_error("Invalid ffu cmd %d", idn);
goto out;
}
break;
case RPMB_CMD_TYPE:
case ARPMB_CMD_TYPE:
if (idn >= RPMB_CMD_MAX) {
print_error("Invalid rpmb cmd %d", idn);
goto out;
}
break;
default:
print_error("Invalid UFS configuration type %d", idn);
goto out;
}
options->idn = idn;
return OK;
out:
return ERROR;
}
static int verify_length(struct tool_options *options)
{
int len = INVALID;
if (options->len != INVALID) {
print_error("duplicated length option");
goto out;
}
/* In case atoi returned 0. Check that is real 0 and not error
* arguments. Also check that the value is in correct range
*/
len = atoi(optarg);
if (len == 0 || len < 0 || len > BLOCK_SIZE) {
print_error("Invalid argument for length. The value should be between 1 to %dB",
BLOCK_SIZE);
goto out;
}
options->len = len;
return OK;
out:
return ERROR;
}
static int verify_offset(struct tool_options *options)
{
int offset = INVALID;
if (options->offset != INVALID) {
print_error("duplicated offset option");
goto out;
}
if (strstr(optarg, "0x") || strstr(optarg, "0X"))
offset = (int)strtol(optarg, NULL, 0);
else
offset = atoi(optarg);
if ((offset == 0 && strcmp(optarg, "0")) || offset < 0) {
print_error("Invalid argument for offset");
goto out;
}
options->offset = offset;
return OK;
out:
return ERROR;
}
static int verify_and_set_start_addr(struct tool_options *options)
{
int start_block = 0;
if (options->config_type_inx != RPMB_CMD_TYPE && options->config_type_inx != ARPMB_CMD_TYPE) {
print_error("start block address using only for rpmb cmd");
goto out;
}
start_block = atoi(optarg);
if ((start_block == 0 && strcmp(optarg, "0")) ||
start_block < 0 || start_block > MAX_ADDRESS) {
print_error("Invalid start address");
goto out;
} else
options->start_block = start_block;
return OK;
out:
return ERROR;
}
static int verify_and_set_num_block(struct tool_options *options)
{
int num_block = 0;
if (options->config_type_inx != RPMB_CMD_TYPE && options->config_type_inx != ARPMB_CMD_TYPE) {
print_error("num_block using only for rpmb cmd");
goto out;
}
num_block = atoi(optarg);
if ((num_block == 0 && strcmp(optarg, "0")) || num_block < 0) {
print_error("Invalid numbers of block");
goto out;
} else
options->num_block = num_block;
return OK;
out:
return ERROR;
}
static int verify_and_set_key_path(struct tool_options *options)
{
if (options->config_type_inx != RPMB_CMD_TYPE && options->config_type_inx != ARPMB_CMD_TYPE) {
print_error("key path using only for rpmb cmd");
goto out;
}
if (options->keypath[0] != '\0') {
print_error("Duplicate Key path");
goto out;
}
if ((optarg == NULL) || (optarg[0] == 0)) {
print_error("Key path missed");
goto out;
}
if (strlen(optarg) >= PATH_MAX) {
print_error("Key path is too long");
goto out;
}
strcpy(options->keypath, optarg);
return OK;
out:
return ERROR;
}
static int verify_sg_struct(struct tool_options *options)
{
int8_t sg_type;
if ((0 == (sg_type = atoi(optarg)) && 0 != (strcmp(optarg, "0"))) ||
((sg_type != SG3_TYPE) && (sg_type != SG4_TYPE))) {
print_error("Invalid SG struct");
return ERROR;
} else
options->sg_type = sg_type;
return OK;
}
static int verify_lun(struct tool_options *options)
{
int8_t lun = 0;
lun = atoi(optarg);
if ((lun == 0 && strcmp(optarg, "0")) || lun < 0) {
print_error("Invalid lun");
return ERROR;
}
options->lun = lun;
return OK;
}
static int verify_region(struct tool_options *options)
{
int8_t region = 0;
region = atoi(optarg);
if ((region == 0 && strcmp(optarg, "0")) || region < 0
|| region > 3) {
print_error("Invalid RPMB region");
return ERROR;
}
options->region = region;
return OK;
}
static int verify_rpmb_arg(struct tool_options *options)
{
int ret = OK;
if (options->region == INVALID)
options->region = 0;
switch (options->idn) {
case AUTHENTICATION_KEY:
if (options->keypath[0] == 0) {
print_error("Key path is missed");
ret = ERROR;
}
break;
case READ_RPMB:
if (!options->data) {
print_error("Output data file missed");
ret = ERROR;
}
break;
case READ_SEC_RPMB_CONF_BLOCK:
if (!options->data) {
print_error("Output data file missed");
ret = ERROR;
}
if (options->lun == INVALID) {
print_error("LUN parameter is missed");
ret = ERROR;
}
if (options->region > 0) {
print_error("Config block exist only in region 0");
ret = ERROR;
}
break;
case WRITE_RPMB:
if (!options->data) {
print_error("Input data file missed");
ret = ERROR;
}
if (options->keypath[0] == 0) {
print_error("Key path is missed");
ret = ERROR;
}
if (options->num_block == INVALID)
options->num_block = 1;
if (options->start_block == INVALID)
options->start_block = 0;
break;
case WRITE_SEC_RPMB_CONF_BLOCK:
if (!options->data) {
print_error("Input data file missed");
ret = ERROR;
}
if (options->keypath[0] == 0) {
print_error("Key path is missed");
ret = ERROR;
}
if (options->region > 0) {
print_error("Config block exist only in region 0");
ret = ERROR;
}
break;
case READ_WRITE_COUNTER:
break;
case PURGE_ENABLE:
if (options->keypath[0] == 0) {
print_error("Key path is missed");
ret = ERROR;
}
break;
case READ_PURGE_STATUS:
break;
default:
print_error("Unsupported RPMB cmd %d",
options->idn);
break;
}
return ret;
}
static int verify_and_set_hmr_method(struct tool_options *options)
{
int ret = ERROR;
long result;
if (options->hmr_method != INVALID) {
print_error("Duplicated hmr method option");
goto out;
}
ret = str_to_long(optarg, 10, &result);
if (ret == ERROR) {
print_error("Invalid argument for hmr method: not convertable");
goto out;
}
if (result < HMR_METHOD_FORCE || result >= HMR_METHOD_MAX) {
print_error("Invalid argument for hmr method: out of range");
ret = ERROR;
goto out;
}
options->hmr_method = result;
out:
return ret;
}
static int verify_and_set_hmr_unit(struct tool_options *options)
{
int ret = ERROR;
long result;
if (options->hmr_unit != INVALID) {
print_error("Duplicated hmr unit option");
goto out;
}
ret = str_to_long(optarg, 10, &result);
if (ret == ERROR) {
print_error("Invalid argument for hmr unit: not convertable");
goto out;
}
if (result < HMR_UNIT_MIN || result >= HMR_UNIT_MAX) {
print_error("Invalid argument for hmr unit: out of range");
ret = ERROR;
goto out;
}
options->hmr_unit = result;
out:
return ret;
}
static int verify_arg_and_set_default(struct tool_options *options)
{
if (options->path[0] == '\0') {
print_error("Missing device path type");
goto out;
}
if (options->opr == INVALID)
options->opr = READ;
if (options->opr == WRITE && !options->data) {
print_error("Data missed for the write operation");
goto out;
}
if (options->config_type_inx != ERR_HIST_TYPE &&
options->config_type_inx != VENDOR_BUFFER_TYPE &&
options->config_type_inx != HMR_TYPE &&
options->config_type_inx != SPEC_VERSION &&
options->opr != READ_ALL &&
options->idn == INVALID) {
print_error("The type idn is missed");
goto out;
}
if (options->config_type_inx == DESC_TYPE &&
options->idn == QUERY_DESC_IDN_STRING &&
options->index == INVALID) {
print_error("The index is missed");
goto out;
}
if (options->config_type_inx == UIC_TYPE) {
if (options->idn == INVALID) {
/*
* As for the Unipro attributes access, should always
* specify idn.
*/
print_error("idn of Unipro attributes is missed");
goto out;
}
if (options->opr == WRITE && options->target != DME_PEER &&
options->target != DME_LOCAL) {
/*
* As for Unipro attributes write, should
* specify accessing target.
*/
print_error("accessing target is missed");
goto out;
}
if (options->index == INVALID &&
(options->opr == READ || options->opr == WRITE)) {
print_error("ID of Unipro attributes is missed");
goto out;
}
}
if (options->index == INVALID)
options->index = 0;
if (options->selector == INVALID)
options->selector = 0;
if (options->config_type_inx == FFU_TYPE) {
if (options->size == INVALID)
options->size = MAX_IOCTL_BUF_SIZE;
if (options->idn == INVALID)
/*Default operation*/
options->idn = UFS_FFU;
if ((options->idn != UFS_CHECK_FFU_STATUS) &&
(options->data == NULL)) {
print_error("The FW file name is missing");
goto out;
}
}
if ((options->config_type_inx == VENDOR_BUFFER_TYPE) &&
(options->len == INVALID))
options->len = BLOCK_SIZE;
if (options->config_type_inx == RPMB_CMD_TYPE || options->config_type_inx == ARPMB_CMD_TYPE) {
if (verify_rpmb_arg(options))
goto out;
}
if (options->config_type_inx == HMR_TYPE) {
if (options->hmr_method == INVALID)
options->hmr_method = HMR_METHOD_SELECTIVE;
if (options->hmr_unit == INVALID)
options->hmr_unit = HMR_UNIT_MIN;
}
return OK;
out:
return ERROR;
}
static int verify_and_set_device_path(struct tool_options *options)
{
if (options->path[0] != '\0') {
print_error("Duplicate Device path %d", options->path[0]);
goto out;
}
if (optarg[0] == 0) {
print_error("Device path missed");
goto out;
}
if (strlen(optarg) >= PATH_MAX) {
print_error("Device path is too long");
goto out;
}
strcpy(options->path, optarg);
return OK;
out:
return ERROR;
}
static int verify_read(struct tool_options *options)
{
if (options->opr != INVALID) {
print_error("duplicated operation option(read)");
goto out;
}
return OK;
out:
return ERROR;
}
static int verify_write(struct tool_options *options)
{
char *endptr;
errno = 0;
if (options->opr != INVALID) {
print_error("duplicated operation option(write)");
goto out;
}
if (optarg[0] == 0) {
print_error("Data is missed");
goto out;
}
if (options->config_type_inx == DESC_TYPE) {
int arg_len = strlen(optarg);
int str_desc_max_len = QUERY_DESC_STRING_MAX_SIZE/2 - 2;
if (options->idn != QUERY_DESC_IDN_CONFIGURAION &&
options->idn != QUERY_DESC_IDN_STRING) {
print_error("write unavailable for descriptor = %d",
options->idn);
goto out;
}
if (arg_len > str_desc_max_len) {
print_error("Input data is too big");
goto out;
}
options->data = (char *)malloc(QUERY_DESC_STRING_MAX_SIZE);
if (!options->data)
goto out_mem_problem;
strcpy(options->data, optarg);
}
if (options->config_type_inx == FLAG_TYPE) {
print_error("Please use 'c', 'e', or 'o' for flag operations");
goto out;
}
if (options->config_type_inx == ATTR_TYPE ||
options->config_type_inx == UIC_TYPE) {
options->data = (__u32 *)calloc(1, sizeof(__u32));
if (!options->data)
goto out_mem_problem;
*(__u32 *)options->data = strtol(optarg, &endptr, 16);
if (errno != 0 || *endptr != '\0') {
print_error("Wrong data");
goto out;
}
}
if (options->config_type_inx == FFU_TYPE ||
options->config_type_inx == VENDOR_BUFFER_TYPE ||
options->config_type_inx == RPMB_CMD_TYPE ||
options->config_type_inx == ARPMB_CMD_TYPE) {
int len = strlen(optarg) + 1;
if (len >= PATH_MAX) {
print_error("Input file path is too long");
goto out;
}
options->data = (char *)calloc(1, len);
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;
}
static int
verify_and_set_flag_operation(int opr_type, struct tool_options *options)
{
if (options->opr != INVALID) {
print_error("duplicated operation option");
goto out;
}
if (options->config_type_inx != FLAG_TYPE) {
print_error("-c | -o | -e operation only for the flag type");
goto out;
}
if (opr_type < CLEAR_FLAG || opr_type > TOGGLE_FLAG) {
print_error("Incorrect operation for the flag type");
goto out;
}
options->opr = opr_type;
return OK;
out:
return ERROR;
}
static int verify_output_data(struct tool_options *options)
{
int len;
if (options->data != 0) {
print_error("Duplicate Output path %d",
options->data);
goto out;
}
if (optarg == 0) {
print_error("Output path missed");
goto out;
}
len = strlen(optarg);
if (len >= PATH_MAX) {
print_error("Output path is too long");
goto out;
}
options->data = (char *)calloc(1, len);
if (!options->data) {
print_error("Memory Allocation problem");
goto out;
}
strcpy(options->data, optarg);
return OK;
out:
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;
}