MtpStorageInfo.cpp revision 335dd2be955607f2632eabc25045857f2cc8b674
15460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao/* 25460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao * Copyright (C) 2010 The Android Open Source Project 35460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao * 45460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao * Licensed under the Apache License, Version 2.0 (the "License"); 55460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao * you may not use this file except in compliance with the License. 65460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao * You may obtain a copy of the License at 75460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao * 85460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao * http://www.apache.org/licenses/LICENSE-2.0 95460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao * 105460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao * Unless required by applicable law or agreed to in writing, software 115460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao * distributed under the License is distributed on an "AS IS" BASIS, 125460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 135460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao * See the License for the specific language governing permissions and 145460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao * limitations under the License. 155460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao */ 165460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 175460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#include <stdlib.h> 185460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 195460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#include "MtpDataPacket.h" 205460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#include "MtpStorageInfo.h" 215460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#include "MtpStringBuffer.h" 225460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 235460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaonamespace android { 245460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 255460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei LiaoMtpStorageInfo::MtpStorageInfo(MtpStorageID id) 265460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao : mStorageID(id), 275460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao mStorageType(0), 285460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao mFileSystemType(0), 295460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao mAccessCapability(0), 305460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao mMaxCapacity(0), 315460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao mFreeSpaceBytes(0), 325460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao mFreeSpaceObjects(0), 335460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao mStorageDescription(NULL), 345460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao mVolumeIdentifier(NULL) 355460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao{ 365460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao} 375460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 385460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei LiaoMtpStorageInfo::~MtpStorageInfo() { 395460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao if (mStorageDescription) 405460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao free(mStorageDescription); 415460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao if (mVolumeIdentifier) 425460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao free(mVolumeIdentifier); 435460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao} 445460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 455460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaovoid MtpStorageInfo::read(MtpDataPacket& packet) { 465460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao MtpStringBuffer string; 475460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 485460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao // read the device info 495460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao mStorageType = packet.getUInt16(); 505460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao mFileSystemType = packet.getUInt16(); 515460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao mAccessCapability = packet.getUInt16(); 525460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao mMaxCapacity = packet.getUInt64(); 53 mFreeSpaceBytes = packet.getUInt64(); 54 mFreeSpaceObjects = packet.getUInt32(); 55 56 packet.getString(string); 57 mStorageDescription = strdup((const char *)string); 58 packet.getString(string); 59 mVolumeIdentifier = strdup((const char *)string); 60} 61 62void MtpStorageInfo::print() { 63 printf("Storage Info %08X:\n\tmStorageType: %d\n\tmFileSystemType: %d\n\tmAccessCapability: %d\n", 64 mStorageID, mStorageType, mFileSystemType, mAccessCapability); 65 printf("\tmMaxCapacity: %lld\n\tmFreeSpaceBytes: %lld\n\tmFreeSpaceObjects: %d\n", 66 mMaxCapacity, mFreeSpaceBytes, mFreeSpaceObjects); 67 printf("\tmStorageDescription: %s\n\tmVolumeIdentifier: %s\n", 68 mStorageDescription, mVolumeIdentifier); 69} 70 71} // namespace android 72