-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce portable, endian-clean structures using shifts and masks instead of bitfields #66
Conversation
on = 2u, | ||
}; | ||
|
||
enum class decrypt_mode: std::uint8_t { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would Scott M. suggest auto instead of uint8_t here? Just curious...
The enum is so much cleaner already. Nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By default enums are sized as int
but the underlying field in the SCSI page is a single byte, so it is necessary to require a smaller size.
Is this well tested already? What is left to do before merging? |
Will need to rewrite much of scsiencrypt.cpp to use these structures before it makes sense to merge. The new tests should ensure strong coverage. |
This pull request introduces 2 alerts when merging 40e97bb into 1508f43 - view on LGTM.com new alerts:
|
…stead of bitfields
Since this is a large PR, I have broken it into 5 commits:
At each commit, the tests pass showing the SCSI data written and the interpretation of data received remains stable regardless of the representation used. This was accompanied by live testing on Linux and FreeBSD to verify normal and error behavior. |
This will also close #63 since the new |
Bitfields are nonportable and often have buggy implementations. Shifts and masks, while more verbose, have better defined semantics. This is a preview of using them for the SCSI communication structures. The end of this change will be to get rid of the need for the
#if STENC_BIG_ENDIAN
checks and the run-time endian check inmain
(yuck) and ensure that the code is endian-clean at compile time.I went back to the references of SCP-5 and SSP-5 to get the layout of the SCSI command structures and reimplemented them side-by-side with the old structures for comparison. Following NL.8 and NL.9, I went with a snake case naming convention for these structures. I also followed a style based on ARM's register naming convention:
vs
Endian conversion is handled by using
htons
/ntohs
functions - these are the most portable option since/usr/include/arpa/inet.h
should be on every UNIX system. There are some better options inendian.h
but this file is not fully standard across all UNIX variants.