Skip to content

Commit 55eff15

Browse files
committed
feat: Finish reassign_blocks
Finishing adding support for CLI option to reassign blocks on a SCSI device
1 parent 1745c2d commit 55eff15

22 files changed

+214
-85
lines changed

include/openseachest_util_options.h

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2493,6 +2493,18 @@ extern "C"
24932493
}
24942494
#define SCSI_DEFECTS_LONG_OPTS SCSI_DEFECTS_LONG_OPT, SCSI_DEFECTS_MODE_LONG_OPTS
24952495

2496+
// Reallocate Blocks Options
2497+
#define SCSI_REALLOCATE_BLOCKS_LIST scsiReallocateBlocksList
2498+
#define SCSI_REALLOCATE_BLOCKS_LIST_LENGTH scsiReallocateBlocksListLength
2499+
#define SCSI_REALLOCATE_BLOCKS_LIST_VARS \
2500+
ptrErrorLBA SCSI_REALLOCATE_BLOCKS_LIST = M_NULLPTR; \
2501+
uint32_t SCSI_REALLOCATE_BLOCKS_LIST_LENGTH = UINT32_C(0);
2502+
#define SCSI_REALLOCATE_BLOCKS_LIST_LONG_OPT_STRING "reallocateBlocks"
2503+
#define SCSI_REALLOCATE_BLOCKS_LIST_LONG_OPT \
2504+
{ \
2505+
SCSI_REALLOCATE_BLOCKS_LIST_LONG_OPT_STRING, required_argument, M_NULLPTR, 0 \
2506+
}
2507+
24962508
// logTransferLength
24972509
#define LOG_TRANSFER_LENGTH_BYTES logTransferLengthBytes
24982510
#define LOG_TRANSFER_LENGTH_BYTES_VAR \
@@ -3645,20 +3657,15 @@ extern "C"
36453657

36463658
void print_Elevated_Privileges_Text(void);
36473659

3648-
//-----------------------------------------------------------------------------
3649-
//
3650-
// print_Final_newline()
3651-
//
3652-
//! \brief Description: This function prints out a single newline character. This is meant to be used with
3653-
//! atexit() for a newline space before returning to the command prompt.
3654-
//
3655-
// Entry:
3656-
//!
3657-
// Exit:
3660+
//! \fn void atexit_Print_Final_newline(void)
3661+
//! \brief Prints a final newline for the program and flushes stderr and stdout. Used in atexit().
3662+
//! \see https://wiki.sei.cmu.edu/confluence/display/c/FIO23-C.+Do+not+exit+with+unflushed+data+in+stdout+or+stderr
3663+
void atexit_Print_Final_newline(void);
36583664

3659-
//
3660-
//-----------------------------------------------------------------------------
3661-
void print_Final_newline(void);
3665+
M_DEPRECATED_REASON("Use atexit_Print_Final_newline instead.") M_INLINE void print_Final_newline(void)
3666+
{
3667+
atexit_Print_Final_newline();
3668+
}
36623669

36633670
//-----------------------------------------------------------------------------
36643671
//
@@ -3677,7 +3684,12 @@ extern "C"
36773684
//-----------------------------------------------------------------------------
36783685
void print_Scan_Help(bool shortHelp, const char* helpdeviceHandleExample);
36793686

3680-
void print_Agressive_Scan_Help(bool shortHelp);
3687+
void print_Aggressive_Scan_Help(bool shortHelp);
3688+
3689+
M_DEPRECATED_REASON("Use print_Aggressive_Scan_Help instead. This one is misspelled.") M_INLINE void print_Agressive_Scan_Help(bool shortHelp)
3690+
{
3691+
print_Aggressive_Scan_Help(shortHelp);
3692+
}
36813693

36823694
//-----------------------------------------------------------------------------
36833695
//
@@ -4850,6 +4862,8 @@ extern "C"
48504862

48514863
void print_SCSI_Defects_Format_Help(bool shortHelp);
48524864

4865+
void print_Reallocate_LBAs_Help(bool shortHelp);
4866+
48534867
void print_Log_Transfer_Length_Help(bool shortHelp);
48544868

48554869
void print_Log_Length_Help(bool shortHelp);

src/openseachest_util_options.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ void print_Elevated_Privileges_Text(void)
126126
# elif defined(__DragonFly__)
127127
print_str("In DragonFlyBSD, put sudo before the command. This may require inputting your login password.\n");
128128
print_str("In DragonFlyBSD, log in to a root terminal (su), then execute the command. This requires the root "
129-
"password.\n");
129+
"password.\n");
130130
# elif defined(__FreeBSD__)
131131
print_str("In FreeBSD, put sudo before the command. This may require inputting your login password.\n");
132132
print_str(
@@ -257,7 +257,7 @@ void utility_Full_Version_Info(const char* utilityName,
257257

258258
// This function is used in at_exit() only.
259259
// It will flush stdout and stderr after printing one final newline character.
260-
void print_Final_newline(void)
260+
void atexit_Print_Final_newline(void)
261261
{
262262
print_str("\n");
263263
// Flushing stdout and stderr
@@ -373,7 +373,7 @@ void print_Scan_Help(bool shortHelp, const char* helpdeviceHandleExample)
373373
}
374374
}
375375

376-
void print_Agressive_Scan_Help(bool shortHelp)
376+
void print_Aggressive_Scan_Help(bool shortHelp)
377377
{
378378
printf("\t-%c, --%s\n", AGRESSIVE_SCAN_SHORT_OPT, AGRESSIVE_SCAN_LONG_OPT_STRING);
379379
if (!shortHelp)
@@ -3824,6 +3824,19 @@ void print_SCSI_Defects_Format_Help(bool shortHelp)
38243824
}
38253825
}
38263826

3827+
void print_Reallocate_LBAs_Help(bool shortHelp)
3828+
{
3829+
printf("\t--%s [address,address,...]\t(SAS Only)\n", SCSI_REALLOCATE_BLOCKS_LIST_LONG_OPT_STRING);
3830+
if (!shortHelp)
3831+
{
3832+
print_str("\t\tThis option will reallocate the specified LBAs on a SCSI device.\n");
3833+
print_str("\t\tMultiple LBAs can be specified by separating them with commas.\n");
3834+
print_str("\t\tFor SATA and NVMe devices, this will be passed to a SCSI translator\n");
3835+
print_str("\t\twhich will handle all translation of this command.\n");
3836+
print_str("\t\tEx: --reallocate-blocks 123456,234567,345678\n\n");
3837+
}
3838+
}
3839+
38273840
void print_Show_Concurrent_Position_Ranges_Help(bool shortHelp)
38283841
{
38293842
printf("\t--%s\n", SHOW_CONCURRENT_RANGES_LONG_OPT_STRING);

utils/C/openSeaChest/openSeaChest_Basics.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ int main(int argc, char* argv[])
147147
CAPACITY_MODEL_NUMBER_MAPPING_LONG_OPT,
148148
CHANGE_ID_STRING_LONG_OPT,
149149
SAT_INFO_LONG_OPT,
150-
150+
151151
SCAN_LONG_OPT,
152152
NO_BANNER_OPT,
153153
AGRESSIVE_SCAN_LONG_OPT,
@@ -709,7 +709,7 @@ int main(int argc, char* argv[])
709709
}
710710
}
711711

712-
if (0 != atexit(print_Final_newline))
712+
if (0 != atexit(atexit_Print_Final_newline))
713713
{
714714
perror("Registering final newline print");
715715
}
@@ -2519,7 +2519,7 @@ void utility_Usage(bool shortUsage)
25192519
// Common (across utilities) - alphabetized
25202520
print_Scan_Help(shortUsage, deviceHandleExample);
25212521
print_Scan_Flags_Help(shortUsage);
2522-
print_Agressive_Scan_Help(shortUsage);
2522+
print_Aggressive_Scan_Help(shortUsage);
25232523
print_Device_Help(shortUsage, deviceHandleExample);
25242524
print_Device_Information_Help(shortUsage);
25252525
print_Low_Level_Info_Help(shortUsage);

utils/C/openSeaChest/openSeaChest_Configure.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ int main(int argc, char* argv[])
149149
CAPACITY_MODEL_NUMBER_MAPPING_LONG_OPT,
150150
CHANGE_ID_STRING_LONG_OPT,
151151
SAT_INFO_LONG_OPT,
152-
152+
153153
SCAN_LONG_OPT,
154154
AGRESSIVE_SCAN_LONG_OPT,
155155
SCAN_FLAGS_LONG_OPT,
@@ -1523,7 +1523,7 @@ int main(int argc, char* argv[])
15231523
}
15241524
}
15251525

1526-
if (0 != atexit(print_Final_newline))
1526+
if (0 != atexit(atexit_Print_Final_newline))
15271527
{
15281528
perror("Registering final newline print");
15291529
}
@@ -4692,7 +4692,7 @@ void utility_Usage(bool shortUsage)
46924692
print_Device_Information_Help(shortUsage);
46934693
print_Low_Level_Info_Help(shortUsage);
46944694
print_Scan_Help(shortUsage, deviceHandleExample);
4695-
print_Agressive_Scan_Help(shortUsage);
4695+
print_Aggressive_Scan_Help(shortUsage);
46964696
print_SAT_Info_Help(shortUsage);
46974697
print_Test_Unit_Ready_Help(shortUsage);
46984698
print_Fast_Discovery_Help(shortUsage);

0 commit comments

Comments
 (0)