Skip to content

Commit e0846fa

Browse files
committed
Shrink CRC checksums from longs to ints
1 parent c6457fa commit e0846fa

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

btrfs-io/src/main/java/nl/gmta/btrfs/io/BtrfsStreamReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ private BtrfsCommandHeader readCommandHeader() throws IOException {
166166

167167
// The CRC32 checksum of the header + body (w/ zeroes for the checksum value itself)
168168
this.reader.setChecksumZeroBytes(true);
169-
long crc = this.reader.readLE32() & 0xFFFFFFFFL;
169+
int crc = this.reader.readLE32();
170170
this.reader.setChecksumZeroBytes(false);
171171

172172
return new BtrfsCommandHeader(length, command, crc);

btrfs-io/src/main/java/nl/gmta/btrfs/io/VerifyingDataReader.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class VerifyingDataReader extends DataReader {
1717
private final Checksum checksum = new CRC32C();
1818
private boolean checksumZeroBytes = false;
1919
private long commandEndPosition;
20-
private long expectedChecksum;
20+
private int expectedChecksum;
2121

2222
VerifyingDataReader(InputStream is) {
2323
super(is);
@@ -57,7 +57,7 @@ protected byte[] readBytes(int length) throws IOException {
5757

5858
// If we've reached the command's end position, verify the checksum
5959
if (verify && (this.position >= this.commandEndPosition)) {
60-
long checksumValue = this.checksum.getValue();
60+
int checksumValue = (int) this.checksum.getValue();
6161
if (checksumValue != this.expectedChecksum) {
6262
throw new BtrfsStructureException(String.format(
6363
"Command body checksum mismatch: expected %08x but got %08x",
@@ -89,7 +89,7 @@ void setChecksumZeroBytes(boolean checksumZeroBytes) {
8989
* @param size The size of the command's body in bytes
9090
* @param crc32c The CRC32C checksum value of the command's body
9191
*/
92-
void setCommandVerification(int size, long crc32c) {
92+
void setCommandVerification(int size, int crc32c) {
9393
if (this.commandEndPosition > 0) {
9494
throw new IllegalStateException("Command verification cannot be set while a command is still in progress");
9595
}

btrfs-structures/src/main/java/nl/gmta/btrfs/structure/stream/BtrfsCommandHeader.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
public class BtrfsCommandHeader {
44
private final int length;
55
private final BtrfsCommandType command;
6-
private final long crc;
6+
private final int crc;
77

8-
public BtrfsCommandHeader(int length, BtrfsCommandType command, long crc) {
8+
public BtrfsCommandHeader(int length, BtrfsCommandType command, int crc) {
99
this.length = length;
1010
this.command = command;
1111
this.crc = crc;
@@ -19,7 +19,7 @@ public BtrfsCommandType getCommand() {
1919
return this.command;
2020
}
2121

22-
public long getCrc() {
22+
public int getCrc() {
2323
return this.crc;
2424
}
2525

0 commit comments

Comments
 (0)