19
19
*/
20
20
package org .dcache .nfs .vfs ;
21
21
22
- import java .nio .ByteBuffer ;
23
- import java .nio .ByteOrder ;
24
-
25
- import com .google .common .io .BaseEncoding ;
26
-
27
- /**
28
- * NFS file handle on wire representation format v1.
29
- *
30
- * <pre>
31
- * byte fh_version; // file handle format version number; version 1 description
32
- * byte[3] fh_magic // 0xcaffee
33
- * uint32 fh_generation; // server boot time or 0 for permanent handles
34
- * uint32 export_index; // index into export table
35
- * byte fh_type // 1 if pseudo fs
36
- * byte fh_olen; // length of opaque data
37
- * byte[] fh_opaque; // FS specific opaque data <= 114
38
- * </pre>
39
- */
40
- public class FileHandle {
41
-
42
- private final static int MIN_LEN = 14 ;
43
- private final static int VERSION = 1 ;
44
- private final static int MAGIC = 0xCAFFEE ;
22
+ @ Deprecated (forRemoval = true )
23
+ public class FileHandle extends Inode {
45
24
private final static byte [] EMPTY_FH = new byte [0 ];
46
25
47
- private final int version ;
48
- private final int magic ;
49
- private final int generation ;
50
- private final int exportIdx ;
51
- private final int type ;
52
- private final byte [] fs_opaque ;
53
-
54
- public FileHandle (int generation , int exportIdx , int type , byte [] fs_opaque ) {
55
- this .version = VERSION ;
56
- this .magic = MAGIC ;
57
- this .generation = generation ;
58
- this .exportIdx = exportIdx ;
59
- this .type = type ;
60
- this .fs_opaque = fs_opaque ;
61
- }
62
-
63
26
public FileHandle (byte [] bytes ) {
64
- if (bytes .length < MIN_LEN ) {
65
- throw new IllegalArgumentException ("too short" );
66
- }
67
-
68
- ByteBuffer b = ByteBuffer .wrap (bytes );
69
- b .order (ByteOrder .BIG_ENDIAN );
70
-
71
- int magic_version = b .getInt ();
72
- int geussVersion = (magic_version & 0xFF000000 ) >>> 24 ;
73
- if (geussVersion != VERSION ) {
74
- throw new IllegalArgumentException ("Unsupported version: " + geussVersion );
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 );
89
- }
90
-
91
- public int getVersion () {
92
- return version ;
27
+ super (bytes );
93
28
}
94
29
95
- public int getMagic () {
96
- return magic ;
97
- }
98
-
99
- public int getGeneration () {
100
- return generation ;
101
- }
102
-
103
- public int getExportIdx () {
104
- return exportIdx ;
105
- }
106
-
107
- public int getType () {
108
- return type ;
109
- }
110
-
111
- public byte [] getFsOpaque () {
112
- return fs_opaque ;
113
- }
114
-
115
- public byte [] bytes () {
116
- int len = fs_opaque .length + MIN_LEN ;
117
- byte [] bytes = new byte [len ];
118
- ByteBuffer b = ByteBuffer .wrap (bytes );
119
- b .order (ByteOrder .BIG_ENDIAN );
120
-
121
- b .putInt (version << 24 | magic );
122
- b .putInt (generation );
123
- b .putInt (exportIdx );
124
- b .put ((byte ) type );
125
- b .put ((byte ) fs_opaque .length );
126
- b .put (fs_opaque );
127
- return bytes ;
128
- }
129
-
130
- @ Override
131
- public String toString () {
132
- return BaseEncoding .base16 ().lowerCase ().encode (this .bytes ());
30
+ public FileHandle (int generation , int exportIdx , int type , byte [] fs_opaque ) {
31
+ super (generation , exportIdx , type , fs_opaque );
133
32
}
134
33
34
+ @ Deprecated (forRemoval = true )
135
35
public static class FileHandleBuilder {
136
- private int version = VERSION ;
137
- private int magic = MAGIC ;
138
36
private int generation = 0 ;
139
37
private int export_idx = 0 ;
140
38
private int type = 0 ;
@@ -160,12 +58,6 @@ public FileHandleBuilder setFsOpaque(byte[] fs_opaque) {
160
58
return this ;
161
59
}
162
60
163
- /**
164
- * A shortcut with defaults
165
- *
166
- * @param opaque
167
- * @return
168
- */
169
61
public FileHandle build (byte [] opaque ) {
170
62
return new FileHandle (generation , export_idx , type , opaque );
171
63
}
@@ -174,4 +66,32 @@ public FileHandle build() {
174
66
return build (fs_opaque );
175
67
}
176
68
}
69
+
70
+ public int getVersion () {
71
+ return handleVersion ();
72
+ }
73
+
74
+ public int getMagic () {
75
+ return super .getMagic ();
76
+ }
77
+
78
+ public int getGeneration () {
79
+ return super .getGeneration ();
80
+ }
81
+
82
+ public int getExportIdx () {
83
+ return exportIndex ();
84
+ }
85
+
86
+ public int getType () {
87
+ return super .getType ();
88
+ }
89
+
90
+ public byte [] getFsOpaque () {
91
+ return getFileId ();
92
+ }
93
+
94
+ public byte [] bytes () {
95
+ return toNfsHandle ();
96
+ }
177
97
}
0 commit comments