001: /* jcifs smb client library in Java
002: * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package com.knowgate.jcifs.smb;
020:
021: import java.io.UnsupportedEncodingException;
022:
023: class Trans2QueryFSInformationResponse extends
024: SmbComTransactionResponse {
025:
026: // information levels
027: static final int SMB_INFO_ALLOCATION = 1;
028: static final int SMB_QUERY_FS_SIZE_INFO = 0x103;
029:
030: class SmbInfoAllocation implements AllocInfo {
031: long alloc; // Also handles SmbQueryFSSizeInfo
032: long free;
033: int sectPerAlloc;
034: int bytesPerSect;
035:
036: public long getCapacity() {
037: return alloc * sectPerAlloc * bytesPerSect;
038: }
039:
040: public long getFree() {
041: return free * sectPerAlloc * bytesPerSect;
042: }
043:
044: public String toString() {
045: return new String("SmbInfoAllocation[" + "alloc=" + alloc
046: + ",free=" + free + ",sectPerAlloc=" + sectPerAlloc
047: + ",bytesPerSect=" + bytesPerSect + "]");
048: }
049: }
050:
051: private int informationLevel;
052:
053: AllocInfo info;
054:
055: Trans2QueryFSInformationResponse(int informationLevel) {
056: this .informationLevel = informationLevel;
057: command = SMB_COM_TRANSACTION2;
058: subCommand = SmbComTransaction.TRANS2_QUERY_FS_INFORMATION;
059: }
060:
061: int writeSetupWireFormat(byte[] dst, int dstIndex) {
062: return 0;
063: }
064:
065: int writeParametersWireFormat(byte[] dst, int dstIndex) {
066: return 0;
067: }
068:
069: int writeDataWireFormat(byte[] dst, int dstIndex) {
070: return 0;
071: }
072:
073: int readSetupWireFormat(byte[] buffer, int bufferIndex, int len) {
074: return 0;
075: }
076:
077: int readParametersWireFormat(byte[] buffer, int bufferIndex, int len) {
078: return 0;
079: }
080:
081: int readDataWireFormat(byte[] buffer, int bufferIndex, int len) {
082: switch (informationLevel) {
083: case SMB_INFO_ALLOCATION:
084: return readSmbInfoAllocationWireFormat(buffer, bufferIndex);
085: case SMB_QUERY_FS_SIZE_INFO:
086: return readSmbQueryFSSizeInfoWireFormat(buffer, bufferIndex);
087: default:
088: return 0;
089: }
090: }
091:
092: int readSmbInfoAllocationWireFormat(byte[] buffer, int bufferIndex) {
093: int start = bufferIndex;
094:
095: SmbInfoAllocation info = new SmbInfoAllocation();
096:
097: bufferIndex += 4; // skip idFileSystem
098:
099: info.sectPerAlloc = readInt4(buffer, bufferIndex);
100: bufferIndex += 4;
101:
102: info.alloc = readInt4(buffer, bufferIndex);
103: bufferIndex += 4;
104:
105: info.free = readInt4(buffer, bufferIndex);
106: bufferIndex += 4;
107:
108: info.bytesPerSect = readInt2(buffer, bufferIndex);
109: bufferIndex += 4;
110:
111: this .info = info;
112:
113: return bufferIndex - start;
114: }
115:
116: int readSmbQueryFSSizeInfoWireFormat(byte[] buffer, int bufferIndex) {
117: int start = bufferIndex;
118:
119: SmbInfoAllocation info = new SmbInfoAllocation();
120:
121: info.alloc = readInt4(buffer, bufferIndex);
122: bufferIndex += 4;
123: info.alloc |= readInt4(buffer, bufferIndex) << 32L;
124: bufferIndex += 4;
125:
126: info.free = readInt4(buffer, bufferIndex);
127: bufferIndex += 4;
128: info.free |= readInt4(buffer, bufferIndex) << 32L;
129: bufferIndex += 4;
130:
131: info.sectPerAlloc = readInt4(buffer, bufferIndex);
132: bufferIndex += 4;
133:
134: info.bytesPerSect = readInt4(buffer, bufferIndex);
135: bufferIndex += 4;
136:
137: this .info = info;
138:
139: return bufferIndex - start;
140: }
141:
142: public String toString() {
143: return new String("Trans2QueryFSInformationResponse["
144: + super .toString() + "]");
145: }
146: }
|