1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #define LOG_TAG "MtpStorageInfo" 18 19 #include "MtpDebug.h" 20 #include "MtpDataPacket.h" 21 #include "MtpStorageInfo.h" 22 #include "MtpStringBuffer.h" 23 24 namespace android { 25 26 MtpStorageInfo::MtpStorageInfo(MtpStorageID id) 27 : mStorageID(id), 28 mStorageType(0), 29 mFileSystemType(0), 30 mAccessCapability(0), 31 mMaxCapacity(0), 32 mFreeSpaceBytes(0), 33 mFreeSpaceObjects(0), 34 mStorageDescription(NULL), 35 mVolumeIdentifier(NULL) 36 { 37 } 38 39 MtpStorageInfo::~MtpStorageInfo() { 40 if (mStorageDescription) 41 free(mStorageDescription); 42 if (mVolumeIdentifier) 43 free(mVolumeIdentifier); 44 } 45 46 void MtpStorageInfo::read(MtpDataPacket& packet) { 47 MtpStringBuffer string; 48 49 // read the device info 50 mStorageType = packet.getUInt16(); 51 mFileSystemType = packet.getUInt16(); 52 mAccessCapability = packet.getUInt16(); 53 mMaxCapacity = packet.getUInt64(); 54 mFreeSpaceBytes = packet.getUInt64(); 55 mFreeSpaceObjects = packet.getUInt32(); 56 57 packet.getString(string); 58 mStorageDescription = strdup((const char *)string); 59 packet.getString(string); 60 mVolumeIdentifier = strdup((const char *)string); 61 } 62 63 void MtpStorageInfo::print() { 64 ALOGD("Storage Info %08X:\n\tmStorageType: %d\n\tmFileSystemType: %d\n\tmAccessCapability: %d\n", 65 mStorageID, mStorageType, mFileSystemType, mAccessCapability); 66 ALOGD("\tmMaxCapacity: %lld\n\tmFreeSpaceBytes: %lld\n\tmFreeSpaceObjects: %d\n", 67 mMaxCapacity, mFreeSpaceBytes, mFreeSpaceObjects); 68 ALOGD("\tmStorageDescription: %s\n\tmVolumeIdentifier: %s\n", 69 mStorageDescription, mVolumeIdentifier); 70 } 71 72 } // namespace android 73