KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > knowgate > 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 com.knowgate.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
29     class SmbInfoAllocation implements AllocInfo {
30         long alloc; // Also handles SmbQueryFSSizeInfo
31
long free;
32         int sectPerAlloc;
33         int bytesPerSect;
34
35         public long getCapacity() {
36             return alloc * sectPerAlloc * bytesPerSect;
37         }
38         public long getFree() {
39             return free * sectPerAlloc * bytesPerSect;
40         }
41         public String JavaDoc toString() {
42             return new String JavaDoc( "SmbInfoAllocation[" +
43                 "alloc=" + alloc + ",free=" + free +
44                 ",sectPerAlloc=" + sectPerAlloc +
45                 ",bytesPerSect=" + bytesPerSect + "]" );
46         }
47     }
48
49     private int informationLevel;
50
51     AllocInfo info;
52
53     Trans2QueryFSInformationResponse( int informationLevel ) {
54         this.informationLevel = informationLevel;
55         command = SMB_COM_TRANSACTION2;
56         subCommand = SmbComTransaction.TRANS2_QUERY_FS_INFORMATION;
57     }
58
59     int writeSetupWireFormat( byte[] dst, int dstIndex ) {
60         return 0;
61     }
62     int writeParametersWireFormat( byte[] dst, int dstIndex ) {
63         return 0;
64     }
65     int writeDataWireFormat( byte[] dst, int dstIndex ) {
66         return 0;
67     }
68     int readSetupWireFormat( byte[] buffer, int bufferIndex, int len ) {
69         return 0;
70     }
71     int readParametersWireFormat( byte[] buffer, int bufferIndex, int len ) {
72         return 0;
73     }
74     int readDataWireFormat( byte[] buffer, int bufferIndex, int len ) {
75         switch( informationLevel ) {
76             case SMB_INFO_ALLOCATION:
77                 return readSmbInfoAllocationWireFormat( buffer, bufferIndex );
78             case SMB_QUERY_FS_SIZE_INFO:
79                 return readSmbQueryFSSizeInfoWireFormat( buffer, bufferIndex );
80             default:
81                 return 0;
82         }
83     }
84
85     int readSmbInfoAllocationWireFormat( byte[] buffer, int bufferIndex ) {
86         int start = bufferIndex;
87
88         SmbInfoAllocation info = new SmbInfoAllocation();
89
90         bufferIndex += 4; // skip idFileSystem
91

92         info.sectPerAlloc = readInt4( buffer, bufferIndex );
93         bufferIndex += 4;
94
95         info.alloc = readInt4( buffer, bufferIndex );
96         bufferIndex += 4;
97
98         info.free = readInt4( buffer, bufferIndex );
99         bufferIndex += 4;
100
101         info.bytesPerSect = readInt2( buffer, bufferIndex );
102         bufferIndex += 4;
103
104         this.info = info;
105
106         return bufferIndex - start;
107     }
108     int readSmbQueryFSSizeInfoWireFormat( byte[] buffer, int bufferIndex ) {
109         int start = bufferIndex;
110
111         SmbInfoAllocation info = new SmbInfoAllocation();
112
113         info.alloc = readInt4( buffer, bufferIndex );
114         bufferIndex += 4;
115         info.alloc |= readInt4( buffer, bufferIndex ) << 32L;
116         bufferIndex += 4;
117
118         info.free = readInt4( buffer, bufferIndex );
119         bufferIndex += 4;
120         info.free |= readInt4( buffer, bufferIndex ) << 32L;
121         bufferIndex += 4;
122
123         info.sectPerAlloc = readInt4( buffer, bufferIndex );
124         bufferIndex += 4;
125
126         info.bytesPerSect = readInt4( buffer, bufferIndex );
127         bufferIndex += 4;
128
129         this.info = info;
130
131         return bufferIndex - start;
132     }
133     public String JavaDoc toString() {
134         return new String JavaDoc( "Trans2QueryFSInformationResponse[" +
135             super.toString() + "]" );
136     }
137 }
138
Popular Tags