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 <inttypes.h> 20 21#include "MtpDebug.h" 22#include "MtpDataPacket.h" 23#include "MtpStorageInfo.h" 24#include "MtpStringBuffer.h" 25 26namespace android { 27 28MtpStorageInfo::MtpStorageInfo(MtpStorageID id) 29 : mStorageID(id), 30 mStorageType(0), 31 mFileSystemType(0), 32 mAccessCapability(0), 33 mMaxCapacity(0), 34 mFreeSpaceBytes(0), 35 mFreeSpaceObjects(0), 36 mStorageDescription(NULL), 37 mVolumeIdentifier(NULL) 38{ 39} 40 41MtpStorageInfo::~MtpStorageInfo() { 42 if (mStorageDescription) 43 free(mStorageDescription); 44 if (mVolumeIdentifier) 45 free(mVolumeIdentifier); 46} 47 48void MtpStorageInfo::read(MtpDataPacket& packet) { 49 MtpStringBuffer string; 50 51 // read the device info 52 mStorageType = packet.getUInt16(); 53 mFileSystemType = packet.getUInt16(); 54 mAccessCapability = packet.getUInt16(); 55 mMaxCapacity = packet.getUInt64(); 56 mFreeSpaceBytes = packet.getUInt64(); 57 mFreeSpaceObjects = packet.getUInt32(); 58 59 packet.getString(string); 60 mStorageDescription = strdup((const char *)string); 61 packet.getString(string); 62 mVolumeIdentifier = strdup((const char *)string); 63} 64 65void MtpStorageInfo::print() { 66 ALOGD("Storage Info %08X:\n\tmStorageType: %d\n\tmFileSystemType: %d\n\tmAccessCapability: %d\n", 67 mStorageID, mStorageType, mFileSystemType, mAccessCapability); 68 ALOGD("\tmMaxCapacity: %" PRIu64 "\n\tmFreeSpaceBytes: %" PRIu64 "\n\tmFreeSpaceObjects: %d\n", 69 mMaxCapacity, mFreeSpaceBytes, mFreeSpaceObjects); 70 ALOGD("\tmStorageDescription: %s\n\tmVolumeIdentifier: %s\n", 71 mStorageDescription, mVolumeIdentifier); 72} 73 74} // namespace android 75