KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jcifs > smb > Trans2QueryFSInformationResponse


1 /* jcifs smb client library in Java
2  * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package jcifs.smb;
20
21 import java.io.UnsupportedEncodingException JavaDoc;
22
23 class Trans2QueryFSInformationResponse extends SmbComTransactionResponse {
24
25     // information levels
26
static final int SMB_INFO_ALLOCATION = 1;
27     static final int SMB_QUERY_FS_SIZE_INFO = 0x103;
28     static final int SMB_FS_FULL_SIZE_INFORMATION = 1007;
29
30     class SmbInfoAllocation implements AllocInfo {
31         long alloc; // Also handles SmbQueryFSSizeInfo
32
long free;
33         int sectPerAlloc;
34         int bytesPerSect;
35
36         public long getCapacity() {
37             return alloc * sectPerAlloc * bytesPerSect;
38         }
39         public long getFree() {
40             return free * sectPerAlloc * bytesPerSect;
41         }
42         public String JavaDoc toString() {
43             return new String JavaDoc( "SmbInfoAllocation[" +
44                 "alloc=" + alloc + ",free=" + free +
45                 ",sectPerAlloc=" + sectPerAlloc +
46                 ",bytesPerSect=" + bytesPerSect + "]" );
47         }
48     }
49
50     private int informationLevel;
51
52     AllocInfo info;
53
54     Trans2QueryFSInformationResponse( int informationLevel ) {
55         this.informationLevel = informationLevel;
56         command = SMB_COM_TRANSACTION2;
57         subCommand = SmbComTransaction.TRANS2_QUERY_FS_INFORMATION;
58     }
59
60     int writeSetupWireFormat( byte[] dst, int dstIndex ) {
61         return 0;
62     }
63     int writeParametersWireFormat( byte[] dst, int dstIndex ) {
64         return 0;
65     }
66     int writeDataWireFormat( byte[] dst, int dstIndex ) {
67         return 0;
68     }
69     int readSetupWireFormat( byte[] buffer, int bufferIndex, int len ) {
70         return 0;
71     }
72     int readParametersWireFormat( byte[] buffer, int bufferIndex, int len ) {
73         return 0;
74     }
75     int readDataWireFormat( byte[] buffer, int bufferIndex, int len ) {
76         switch( informationLevel ) {
77             case SMB_INFO_ALLOCATION:
78                 return readSmbInfoAllocationWireFormat( buffer, bufferIndex );
79             case SMB_QUERY_FS_SIZE_INFO:
80                 return readSmbQueryFSSizeInfoWireFormat( buffer, bufferIndex );
81             case SMB_FS_FULL_SIZE_INFORMATION:
82                 return readFsFullSizeInformationWireFormat( buffer, bufferIndex );
83             default:
84                 return 0;
85         }
86     }
87
88     int readSmbInfoAllocationWireFormat( byte[] buffer, int bufferIndex ) {
89         int start = bufferIndex;
90
91         SmbInfoAllocation info = new SmbInfoAllocation();
92
93         bufferIndex += 4; // skip idFileSystem
94

95         info.sectPerAlloc = readInt4( buffer, bufferIndex );
96         bufferIndex += 4;
97
98         info.alloc = readInt4( buffer, bufferIndex );
99         bufferIndex += 4;
100
101         info.free = readInt4( buffer, bufferIndex );
102         bufferIndex += 4;
103
104         info.bytesPerSect = readInt2( buffer, bufferIndex );
105         bufferIndex += 4;
106
107         this.info = info;
108
109         return bufferIndex - start;
110     }
111     int readSmbQueryFSSizeInfoWireFormat( byte[] buffer, int bufferIndex ) {
112         int start = bufferIndex;
113
114         SmbInfoAllocation info = new SmbInfoAllocation();
115
116         info.alloc = readInt8( buffer, bufferIndex );
117         bufferIndex += 8;
118
119         info.free = readInt8( buffer, bufferIndex );
120         bufferIndex += 8;
121
122         info.sectPerAlloc = readInt4( buffer, bufferIndex );
123         bufferIndex += 4;
124
125         info.bytesPerSect = readInt4( buffer, bufferIndex );
126         bufferIndex += 4;
127
128         this.info = info;
129
130         return bufferIndex - start;
131     }
132     int readFsFullSizeInformationWireFormat( byte[] buffer, int bufferIndex )
133     {
134         int start = bufferIndex;
135         
136         SmbInfoAllocation info = new SmbInfoAllocation();
137         
138         // Read total allocation units.
139
info.alloc = readInt8( buffer, bufferIndex );
140         bufferIndex += 8;
141         
142         // read caller available allocation units
143
info.free = readInt8( buffer, bufferIndex );
144         bufferIndex += 8;
145
146         // skip actual free units
147
bufferIndex += 8;
148         
149         info.sectPerAlloc = readInt4( buffer, bufferIndex );
150         bufferIndex += 4;
151         
152         info.bytesPerSect = readInt4( buffer, bufferIndex );
153         bufferIndex += 4;
154
155         this.info = info;
156
157         return bufferIndex - start;
158     }
159
160     public String JavaDoc toString() {
161         return new String JavaDoc( "Trans2QueryFSInformationResponse[" +
162             super.toString() + "]" );
163     }
164 }
165
Popular Tags