Skip to content

Commit c6457fa

Browse files
committed
Implement reading BtrfsSubvolCommand
1 parent 2232e99 commit c6457fa

File tree

3 files changed

+56
-22
lines changed

3 files changed

+56
-22
lines changed

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import nl.gmta.btrfs.structure.stream.BtrfsAttributeType;
1212
import nl.gmta.btrfs.structure.stream.BtrfsChmodCommand;
1313
import nl.gmta.btrfs.structure.stream.BtrfsChownCommand;
14+
import nl.gmta.btrfs.structure.stream.BtrfsCommandHeader;
1415
import nl.gmta.btrfs.structure.stream.BtrfsCommandType;
1516
import nl.gmta.btrfs.structure.stream.BtrfsEndCommand;
1617
import nl.gmta.btrfs.structure.stream.BtrfsInodeCommand;
@@ -23,9 +24,9 @@
2324
import nl.gmta.btrfs.structure.stream.BtrfsRenameCommand;
2425
import nl.gmta.btrfs.structure.stream.BtrfsSnapshotCommand;
2526
import nl.gmta.btrfs.structure.stream.BtrfsStreamCommand;
26-
import nl.gmta.btrfs.structure.stream.BtrfsCommandHeader;
2727
import nl.gmta.btrfs.structure.stream.BtrfsStreamElement;
2828
import nl.gmta.btrfs.structure.stream.BtrfsStreamHeader;
29+
import nl.gmta.btrfs.structure.stream.BtrfsSubvolCommand;
2930
import nl.gmta.btrfs.structure.stream.BtrfsSymlinkCommand;
3031
import nl.gmta.btrfs.structure.stream.BtrfsTimespec;
3132
import nl.gmta.btrfs.structure.stream.BtrfsTruncateCommand;
@@ -64,7 +65,7 @@ private Object readAttribute(BtrfsAttributeType type) throws IOException {
6465
// Read and verify attribute type
6566
int readType = this.reader.readLE16();
6667
if (readType != type.getId()) {
67-
throw new BtrfsStructureException(String.format("Expected attribute type %04X but got %04X", type.getId(), readType));
68+
throw new BtrfsStructureException(String.format("Expected attribute type %04x but got %04x", type.getId(), readType));
6869
}
6970

7071
// Read attribute value
@@ -128,6 +129,8 @@ private BtrfsStreamCommand readCommand() throws IOException {
128129
return this.readRenameCommand(header);
129130
case SNAPSHOT:
130131
return this.readSnapshotCommand(header);
132+
case SUBVOL:
133+
return this.readSubvolCommand(header);
131134
case TRUNCATE:
132135
return this.readTruncateCommand(header);
133136
case UPDATE_EXTENT:
@@ -270,6 +273,14 @@ private BtrfsSnapshotCommand readSnapshotCommand(BtrfsCommandHeader header) thro
270273
return new BtrfsSnapshotCommand(header, path, UUID, CTransID, cloneUUID, cloneCTransID);
271274
}
272275

276+
private BtrfsSubvolCommand readSubvolCommand(BtrfsCommandHeader header) throws IOException {
277+
String path = (String) this.readAttribute(BtrfsAttributeType.PATH);
278+
UUID UUID = (UUID) this.readAttribute(BtrfsAttributeType.UUID);
279+
long CTransID = (Long) this.readAttribute(BtrfsAttributeType.CTRANSID);
280+
281+
return new BtrfsSubvolCommand(header, path, UUID, CTransID);
282+
}
283+
273284
private BtrfsTruncateCommand readTruncateCommand(BtrfsCommandHeader header) throws IOException {
274285
String path = (String) this.readAttribute(BtrfsAttributeType.PATH);
275286
long size = (Long) this.readAttribute(BtrfsAttributeType.SIZE);

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

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,17 @@
33
import java.util.Objects;
44
import java.util.UUID;
55

6-
public class BtrfsSnapshotCommand extends BtrfsStreamCommand {
7-
private final String path;
8-
private final UUID UUID;
9-
private final long CTransID;
6+
public class BtrfsSnapshotCommand extends BtrfsSubvolCommand {
107
private final UUID cloneUUID;
118
private final long cloneCTransID;
129

1310
public BtrfsSnapshotCommand(BtrfsCommandHeader header, String path, UUID UUID, long CTransID, UUID cloneUUID, long cloneCTransID) {
14-
super(header);
11+
super(header, path, UUID, CTransID);
1512

16-
this.path = Objects.requireNonNull(path);
17-
this.UUID = Objects.requireNonNull(UUID);
18-
this.CTransID = CTransID;
1913
this.cloneUUID = Objects.requireNonNull(cloneUUID);
2014
this.cloneCTransID = cloneCTransID;
2115
}
2216

23-
public String getPath() {
24-
return this.path;
25-
}
26-
27-
public UUID getUUID() {
28-
return this.UUID;
29-
}
30-
31-
public long getCTransID() {
32-
return this.CTransID;
33-
}
34-
3517
public UUID getCloneUUID() {
3618
return this.cloneUUID;
3719
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package nl.gmta.btrfs.structure.stream;
2+
3+
import java.util.UUID;
4+
5+
public class BtrfsSubvolCommand extends BtrfsStreamCommand {
6+
protected final String path;
7+
protected final UUID UUID;
8+
protected final long CTransID;
9+
10+
public BtrfsSubvolCommand(BtrfsCommandHeader header, String path, UUID UUID, long CTransID) {
11+
super(header);
12+
13+
this.path = path;
14+
this.UUID = UUID;
15+
this.CTransID = CTransID;
16+
}
17+
18+
public String getPath() {
19+
return this.path;
20+
}
21+
22+
public UUID getUUID() {
23+
return this.UUID;
24+
}
25+
26+
public long getCTransID() {
27+
return this.CTransID;
28+
}
29+
30+
@Override
31+
public String toString() {
32+
return String.format(
33+
"%s{header=%s path='%s' UUID=%s CTransID=%d}",
34+
this.getClass().getSimpleName(),
35+
this.header,
36+
this.path,
37+
this.UUID,
38+
this.CTransID
39+
);
40+
}
41+
}

0 commit comments

Comments
 (0)