bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 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 | * |
bigbiff bigbiff | af32bb9 | 2018-12-18 18:39:53 -0500 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 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. |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 15 | */ |
| 16 | |
bigbiff bigbiff | af32bb9 | 2018-12-18 18:39:53 -0500 | [diff] [blame] | 17 | #define LOG_TAG "MtpStorageInfo" |
| 18 | |
| 19 | #include <inttypes.h> |
| 20 | |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 21 | #include "MtpDebug.h" |
| 22 | #include "MtpDataPacket.h" |
| 23 | #include "MtpStorageInfo.h" |
| 24 | #include "MtpStringBuffer.h" |
| 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 | |
bigbiff bigbiff | af32bb9 | 2018-12-18 18:39:53 -0500 | [diff] [blame] | 46 | bool MtpStorageInfo::read(MtpDataPacket& packet) { |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 47 | MtpStringBuffer string; |
| 48 | |
| 49 | // read the device info |
bigbiff bigbiff | af32bb9 | 2018-12-18 18:39:53 -0500 | [diff] [blame] | 50 | if (!packet.getUInt16(mStorageType)) return false; |
| 51 | if (!packet.getUInt16(mFileSystemType)) return false; |
| 52 | if (!packet.getUInt16(mAccessCapability)) return false; |
| 53 | if (!packet.getUInt64(mMaxCapacity)) return false; |
| 54 | if (!packet.getUInt64(mFreeSpaceBytes)) return false; |
| 55 | if (!packet.getUInt32(mFreeSpaceObjects)) return false; |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 56 | |
bigbiff bigbiff | af32bb9 | 2018-12-18 18:39:53 -0500 | [diff] [blame] | 57 | if (!packet.getString(string)) return false; |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 58 | mStorageDescription = strdup((const char *)string); |
bigbiff bigbiff | af32bb9 | 2018-12-18 18:39:53 -0500 | [diff] [blame] | 59 | if (!mStorageDescription) return false; |
| 60 | if (!packet.getString(string)) return false; |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 61 | mVolumeIdentifier = strdup((const char *)string); |
bigbiff bigbiff | af32bb9 | 2018-12-18 18:39:53 -0500 | [diff] [blame] | 62 | if (!mVolumeIdentifier) return false; |
| 63 | |
| 64 | return true; |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | void MtpStorageInfo::print() { |
bigbiff bigbiff | af32bb9 | 2018-12-18 18:39:53 -0500 | [diff] [blame] | 68 | MTPD("Storage Info %08X:\n\tmStorageType: %d\n\tmFileSystemType: %d\n\tmAccessCapability: %d\n", |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 69 | mStorageID, mStorageType, mFileSystemType, mAccessCapability); |
bigbiff bigbiff | af32bb9 | 2018-12-18 18:39:53 -0500 | [diff] [blame] | 70 | MTPD("\tmMaxCapacity: %" PRIu64 "\n\tmFreeSpaceBytes: %" PRIu64 "\n\tmFreeSpaceObjects: %d\n", |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 71 | mMaxCapacity, mFreeSpaceBytes, mFreeSpaceObjects); |
bigbiff bigbiff | af32bb9 | 2018-12-18 18:39:53 -0500 | [diff] [blame] | 72 | MTPD("\tmStorageDescription: %s\n\tmVolumeIdentifier: %s\n", |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 73 | mStorageDescription, mVolumeIdentifier); |
| 74 | } |