Skip to content

Commit b0bea6f

Browse files
committed
Worked on options and manpages
1 parent 2531517 commit b0bea6f

12 files changed

Lines changed: 464 additions & 86 deletions

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ AC_PREREQ([2.71])
22

33
AC_INIT(
44
[libsmdev],
5-
[20260623],
5+
[20260624],
66
[https://github.com/libyal/libsmdev/issues])
77

88
AC_CONFIG_SRCDIR(

manuals/Makefile.am

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ man_MANS = \
33
smdevinfo.1
44

55
EXTRA_DIST = \
6-
libsmdev.3 \
7-
smdevinfo.1
6+
$(man_MANS)
87

98
DISTCLEANFILES = \
109
Makefile \

manuals/libsmdev.3

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.Dd June 15, 2026
1+
.Dd June 24, 2026
22
.Dt LIBSMDEV 3
33
.Os
44
.Sh NAME
@@ -451,7 +451,8 @@ To compile libsmdev with wide character support use:
451451
during compilation.
452452
.sp
453453
.Ar LIBSMDEV_WIDE_CHARACTER_TYPE
454-
in libsmdev/features.h can be used to determine if libsmdev was compiled with wide character support.
454+
in libsmdev/features.h can be used to determine if libsmdev was compiled with \
455+
wide character support.
455456
.Sh SEE ALSO
456457
.In libsmdev.h
457458
.Sh AUTHORS

smdevtools/info_handle.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -594,17 +594,17 @@ int info_handle_tracks_fprint(
594594
return( result );
595595
}
596596

597-
/* Prints the handle information
597+
/* Prints the device information
598598
* Returns 1 if successful or -1 on error
599599
*/
600-
int info_handle_handle_fprint(
600+
int info_handle_device_fprint(
601601
info_handle_t *info_handle,
602602
libcerror_error_t **error )
603603
{
604604
uint8_t media_information_value[ 64 ];
605605
system_character_t byte_size_string[ 16 ];
606606

607-
static char *function = "info_handle_handle_fprint";
607+
static char *function = "info_handle_device_fprint";
608608
size64_t media_size = 0;
609609
uint32_t bytes_per_sector = 0;
610610
uint8_t bus_type = 0;

smdevtools/info_handle.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ int info_handle_tracks_fprint(
8181
info_handle_t *info_handle,
8282
libcerror_error_t **error );
8383

84-
int info_handle_handle_fprint(
84+
int info_handle_device_fprint(
8585
info_handle_t *info_handle,
8686
libcerror_error_t **error );
8787

smdevtools/smdevinfo.c

Lines changed: 71 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Shows information obtained from storage media (SM) devices
2+
* Shows information obtained from a storage media (SM) device.
33
*
44
* Copyright (C) 2010-2026, Joachim Metz <joachim.metz@gmail.com>
55
*
@@ -56,27 +56,6 @@
5656
info_handle_t *smdevinfo_info_handle = NULL;
5757
int smdevinfo_abort = 0;
5858

59-
/* Prints the executable usage information
60-
*/
61-
void usage_fprint(
62-
FILE *stream )
63-
{
64-
if( stream == NULL )
65-
{
66-
return;
67-
}
68-
fprintf( stream, "Use smdevinfo to determine information about storage\n"
69-
"media (SM) device(s)\n\n" );
70-
71-
fprintf( stream, "Usage: smdevinfo [ -hivV ] source\n\n" );
72-
73-
fprintf( stream, "\tsource: the source device file\n\n" );
74-
75-
fprintf( stream, "\t-h: shows this help\n" );
76-
fprintf( stream, "\t-v: verbose output to stderr\n" );
77-
fprintf( stream, "\t-V: print version\n" );
78-
}
79-
8059
/* Signal handler for smdevinfo
8160
*/
8261
void smdevinfo_signal_handler(
@@ -89,19 +68,21 @@ void smdevinfo_signal_handler(
8968

9069
smdevinfo_abort = 1;
9170

92-
if( ( smdevinfo_info_handle != NULL )
93-
&& ( info_handle_signal_abort(
94-
smdevinfo_info_handle,
95-
&error ) != 1 ) )
71+
if( smdevinfo_info_handle != NULL )
9672
{
97-
libcnotify_printf(
98-
"%s: unable to signal info handle to abort.\n",
99-
function );
100-
101-
libcnotify_print_error_backtrace(
102-
error );
103-
libcerror_error_free(
104-
&error );
73+
if( info_handle_signal_abort(
74+
smdevinfo_info_handle,
75+
&error ) != 1 )
76+
{
77+
libcnotify_printf(
78+
"%s: unable to signal info handle to abort.\n",
79+
function );
80+
81+
libcnotify_print_error_backtrace(
82+
error );
83+
libcerror_error_free(
84+
&error );
85+
}
10586
}
10687
/* Force stdin to close otherwise any function reading it will remain blocked
10788
*/
@@ -127,10 +108,22 @@ int wmain( int argc, wchar_t * const argv[] )
127108
int main( int argc, char * const argv[] )
128109
#endif
129110
{
130-
libcerror_error_t *error = NULL;
111+
const char *description = \
112+
"Use smdevinfo to determine information about a storage media (SM) device.";
113+
114+
smdevtools_option_t options[ ] = {
115+
{ 'h', NULL, "shows this help" },
116+
{ 'v', NULL, "verbose output to stderr" },
117+
{ 'V', NULL, "print version" },
118+
{ 0, "source", "the source device" },
119+
};
120+
system_character_t options_string[ 32 ];
121+
122+
libsmdev_error_t *error = NULL;
131123
system_character_t *source = NULL;
132124
char *program = "smdevinfo";
133125
system_integer_t option = 0;
126+
int number_of_options = (int) ( sizeof( options ) / sizeof( smdevtools_option_t ) );
134127
int verbose = 0;
135128

136129
#if defined( __MINGW32__ ) && defined( HAVE_MINGW_BINMODE )
@@ -145,7 +138,7 @@ int main( int argc, char * const argv[] )
145138
1 );
146139

147140
if( libclocale_initialize(
148-
"smdevtools",
141+
"smdevtools",
149142
&error ) != 1 )
150143
{
151144
fprintf(
@@ -154,24 +147,36 @@ int main( int argc, char * const argv[] )
154147

155148
goto on_error;
156149
}
157-
if( smdevtools_output_initialize(
158-
_IONBF,
159-
&error ) != 1 )
150+
if( smdevtools_output_initialize(
151+
_IONBF,
152+
&error ) != 1 )
160153
{
161154
fprintf(
162155
stderr,
163156
"Unable to initialize output settings.\n" );
164157

165158
goto on_error;
166159
}
167-
smdevoutput_version_fprint(
160+
smdevtools_output_version_fprint(
168161
stdout,
169162
program );
170163

164+
if( smdevtools_getopt_get_options_string(
165+
options,
166+
number_of_options,
167+
options_string,
168+
32 ) != 1 )
169+
{
170+
fprintf(
171+
stderr,
172+
"Unable to determine options string.\n" );
173+
174+
goto on_error;
175+
}
171176
while( ( option = smdevtools_getopt(
172177
argc,
173178
argv,
174-
_SYSTEM_STRING( "hvV" ) ) ) != (system_integer_t) -1 )
179+
options_string ) ) != (system_integer_t) -1 )
175180
{
176181
switch( option )
177182
{
@@ -182,14 +187,22 @@ int main( int argc, char * const argv[] )
182187
"Invalid argument: %" PRIs_SYSTEM "\n",
183188
argv[ optind - 1 ] );
184189

185-
usage_fprint(
186-
stdout );
190+
smdevtools_getopt_usage_fprint(
191+
stdout,
192+
program,
193+
description,
194+
options,
195+
number_of_options );
187196

188197
return( EXIT_FAILURE );
189198

190199
case (system_integer_t) 'h':
191-
usage_fprint(
192-
stdout );
200+
smdevtools_getopt_usage_fprint(
201+
stdout,
202+
program,
203+
description,
204+
options,
205+
number_of_options );
193206

194207
return( EXIT_SUCCESS );
195208

@@ -199,7 +212,7 @@ int main( int argc, char * const argv[] )
199212
break;
200213

201214
case (system_integer_t) 'V':
202-
smdevoutput_copyright_fprint(
215+
smdevtools_output_copyright_fprint(
203216
stdout );
204217

205218
return( EXIT_SUCCESS );
@@ -209,10 +222,14 @@ int main( int argc, char * const argv[] )
209222
{
210223
fprintf(
211224
stderr,
212-
"Missing source file.\n" );
225+
"Missing source device.\n" );
213226

214-
usage_fprint(
215-
stdout );
227+
smdevtools_getopt_usage_fprint(
228+
stdout,
229+
program,
230+
description,
231+
options,
232+
number_of_options );
216233

217234
return( EXIT_FAILURE );
218235
}
@@ -230,13 +247,9 @@ int main( int argc, char * const argv[] )
230247
&smdevinfo_info_handle,
231248
&error ) != 1 )
232249
{
233-
smdevoutput_version_fprint(
234-
stderr,
235-
program );
236-
237250
fprintf(
238251
stderr,
239-
"Unable to create info handle.\n" );
252+
"Unable to initialize info handle.\n" );
240253

241254
goto on_error;
242255
}
@@ -260,18 +273,17 @@ int main( int argc, char * const argv[] )
260273
{
261274
fprintf(
262275
stderr,
263-
"Unable to open file: %" PRIs_SYSTEM ".\n",
264-
source );
276+
"Unable to open source device.\n" );
265277

266278
goto on_error;
267279
}
268-
if( info_handle_handle_fprint(
280+
if( info_handle_device_fprint(
269281
smdevinfo_info_handle,
270282
&error ) != 1 )
271283
{
272284
fprintf(
273285
stderr,
274-
"Unable to print information.\n" );
286+
"Unable to print device information.\n" );
275287

276288
goto on_error;
277289
}
@@ -333,5 +345,5 @@ int main( int argc, char * const argv[] )
333345
NULL );
334346
}
335347
return( EXIT_FAILURE );
336-
337348
}
349+

smdevtools/smdevtools_output.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ int smdevtools_output_initialize(
9292

9393
/* Prints the copyright information
9494
*/
95-
void smdevoutput_copyright_fprint(
95+
void smdevtools_output_copyright_fprint(
9696
FILE *stream )
9797
{
9898
if( stream == NULL )
@@ -117,7 +117,7 @@ void smdevoutput_copyright_fprint(
117117

118118
/* Prints the version information
119119
*/
120-
void smdevoutput_version_fprint(
120+
void smdevtools_output_version_fprint(
121121
FILE *stream,
122122
const char *program )
123123
{
@@ -138,7 +138,7 @@ void smdevoutput_version_fprint(
138138

139139
/* Prints the detailed version information
140140
*/
141-
void smdevoutput_version_detailed_fprint(
141+
void smdevtools_output_version_detailed_fprint(
142142
FILE *stream,
143143
const char *program )
144144
{

smdevtools/smdevtools_output.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ int smdevtools_output_initialize(
3636
int stdio_mode,
3737
libcerror_error_t **error );
3838

39-
void smdevoutput_copyright_fprint(
39+
void smdevtools_output_copyright_fprint(
4040
FILE *stream );
4141

42-
void smdevoutput_version_fprint(
42+
void smdevtools_output_version_fprint(
4343
FILE *stream,
4444
const char *program );
4545

46-
void smdevoutput_version_detailed_fprint(
46+
void smdevtools_output_version_detailed_fprint(
4747
FILE *stream,
4848
const char *program );
4949

tests/test_library.ps1

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ If (-Not (Test-Path ${TestExecutablesDirectory}))
1515
Exit ${ExitFailure}
1616
}
1717

18-
$Result = ${ExitIgnore}
18+
$Result = ${ExitSuccess}
1919

2020
Foreach (${TestName} in ${LibraryTests} -split " ")
2121
{
@@ -24,11 +24,11 @@ Foreach (${TestName} in ${LibraryTests} -split " ")
2424
{
2525
Continue
2626
}
27-
$Result = RunTestBinary ${TestExecutablesDirectory} "smdev_test_${TestName}"
27+
$ResultRun = RunTestBinary ${TestExecutablesDirectory} "smdev_test_${TestName}"
2828

29-
If ((${Result} -ne ${ExitSuccess}) -And (${Result} -ne ${ExitIgnore}))
29+
If ((${ResultRun} -ne ${ExitSuccess}) -And (${ResultRun} -ne ${ExitIgnore}))
3030
{
31-
Break
31+
$Result = ${ResultRun}
3232
}
3333
}
3434

@@ -43,17 +43,13 @@ Foreach (${TestName} in ${LibraryTestsWithInput} -split " ")
4343
}
4444
ForEach ($TestInput in ${TestInputs})
4545
{
46-
$Result = RunTestBinaryWithInput ${TestExecutablesDirectory} "smdev_test_${TestName}" ${TestInput}
46+
$ResultRun = RunTestBinaryWithInput ${TestExecutablesDirectory} "smdev_test_${TestName}" ${TestInput}
4747

48-
If ((${Result} -ne ${ExitSuccess}) -And (${Result} -ne ${ExitIgnore}))
48+
If ((${ResultRun} -ne ${ExitSuccess}) -And (${ResultRun} -ne ${ExitIgnore}))
4949
{
50-
Break
50+
$Result = ${ResultRun}
5151
}
5252
}
53-
If ((${Result} -ne ${ExitSuccess}) -And (${Result} -ne ${ExitIgnore}))
54-
{
55-
Break
56-
}
5753
}
5854

5955
Exit ${Result}

0 commit comments

Comments
 (0)