|
1 | 1 | /*
|
| 2 | + * Copyright (c) 2012 - 2025 Deutsches Elektronen-Synchroton, |
| 3 | + * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY |
| 4 | + * |
2 | 5 | * This library is free software; you can redistribute it and/or modify
|
3 | 6 | * it under the terms of the GNU Library General Public License as
|
4 | 7 | * published by the Free Software Foundation; either version 2 of the
|
@@ -40,8 +43,6 @@ public class FileHandle {
|
40 | 43 | private final static int VERSION = 1;
|
41 | 44 | private final static int MAGIC = 0xCAFFEE;
|
42 | 45 | private final static byte[] EMPTY_FH = new byte[0];
|
43 |
| - private final static byte[] FH_V0_REG = new byte[] {0x30, 0x3a}; |
44 |
| - private final static byte[] FH_V0_PFS = new byte[] {0x32, 0x35, 0x35, 0x3a}; |
45 | 46 |
|
46 | 47 | private final int version;
|
47 | 48 | private final int magic;
|
@@ -69,43 +70,22 @@ public FileHandle(byte[] bytes) {
|
69 | 70 |
|
70 | 71 | int magic_version = b.getInt();
|
71 | 72 | int geussVersion = (magic_version & 0xFF000000) >>> 24;
|
72 |
| - if (geussVersion == VERSION) { |
73 |
| - version = geussVersion; |
74 |
| - magic = magic_version & 0x00FFFFFF; |
75 |
| - if (magic != MAGIC) { |
76 |
| - throw new IllegalArgumentException("Bad magic number"); |
77 |
| - } |
78 |
| - |
79 |
| - generation = b.getInt(); |
80 |
| - exportIdx = b.getInt(); |
81 |
| - type = (int) b.get(); |
82 |
| - int olen = (int) b.get(); |
83 |
| - fs_opaque = new byte[olen]; |
84 |
| - b.get(fs_opaque); |
85 |
| - |
86 |
| - } else if (arrayEquals(bytes, FH_V0_REG, FH_V0_REG.length) |
87 |
| - || arrayEquals(bytes, FH_V0_PFS, FH_V0_PFS.length)) { |
88 |
| - magic = MAGIC; |
89 |
| - generation = 0; |
90 |
| - type = bytes[1] == FH_V0_REG[1] ? 0 : 1; |
91 |
| - if (type == 1) { |
92 |
| - /* |
93 |
| - * convert pseudo inode into real one: '255:' => '0:' NOTICE: the converted handle will present himself |
94 |
| - * as version 1 |
95 |
| - */ |
96 |
| - version = 1; |
97 |
| - exportIdx = 0; |
98 |
| - fs_opaque = new byte[bytes.length - 2]; |
99 |
| - System.arraycopy(bytes, 2, fs_opaque, 0, fs_opaque.length); |
100 |
| - fs_opaque[0] = 0x30; |
101 |
| - } else { |
102 |
| - version = 0; |
103 |
| - exportIdx = -1; |
104 |
| - fs_opaque = bytes; |
105 |
| - } |
106 |
| - } else { |
| 73 | + if (geussVersion != VERSION) { |
107 | 74 | throw new IllegalArgumentException("Unsupported version: " + geussVersion);
|
108 | 75 | }
|
| 76 | + |
| 77 | + version = geussVersion; |
| 78 | + magic = magic_version & 0x00FFFFFF; |
| 79 | + if (magic != MAGIC) { |
| 80 | + throw new IllegalArgumentException("Bad magic number"); |
| 81 | + } |
| 82 | + |
| 83 | + generation = b.getInt(); |
| 84 | + exportIdx = b.getInt(); |
| 85 | + type = (int) b.get(); |
| 86 | + int olen = (int) b.get(); |
| 87 | + fs_opaque = new byte[olen]; |
| 88 | + b.get(fs_opaque); |
109 | 89 | }
|
110 | 90 |
|
111 | 91 | public int getVersion() {
|
@@ -152,17 +132,6 @@ public String toString() {
|
152 | 132 | return BaseEncoding.base16().lowerCase().encode(this.bytes());
|
153 | 133 | }
|
154 | 134 |
|
155 |
| - private static boolean arrayEquals(byte[] a1, byte[] a2, int len) { |
156 |
| - if (a1.length < len || a2.length < len) |
157 |
| - return false; |
158 |
| - for (int i = 0; i < len; i++) { |
159 |
| - if (a1[i] != a2[i]) { |
160 |
| - return false; |
161 |
| - } |
162 |
| - } |
163 |
| - return true; |
164 |
| - } |
165 |
| - |
166 | 135 | public static class FileHandleBuilder {
|
167 | 136 | private int version = VERSION;
|
168 | 137 | private int magic = MAGIC;
|
|
0 commit comments