blob: 21a8322da77ae633487e5c00b1ee7be6e5cbec97 [file] [log] [blame]
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -04001/*
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 bigbiffaf32bb92018-12-18 18:39:53 -05008 * http://www.apache.org/licenses/LICENSE-2.0
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -04009 *
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 bigbiffc7eee6f2014-09-02 18:59:01 -040015 */
16
bigbiff bigbiffaf32bb92018-12-18 18:39:53 -050017#define LOG_TAG "MtpStorageInfo"
18
19#include <inttypes.h>
20
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040021#include "MtpDebug.h"
22#include "MtpDataPacket.h"
23#include "MtpStorageInfo.h"
24#include "MtpStringBuffer.h"
25
26MtpStorageInfo::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
39MtpStorageInfo::~MtpStorageInfo() {
40 if (mStorageDescription)
41 free(mStorageDescription);
42 if (mVolumeIdentifier)
43 free(mVolumeIdentifier);
44}
45
bigbiff bigbiffaf32bb92018-12-18 18:39:53 -050046bool MtpStorageInfo::read(MtpDataPacket& packet) {
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040047 MtpStringBuffer string;
48
49 // read the device info
bigbiff bigbiffaf32bb92018-12-18 18:39:53 -050050 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 bigbiffc7eee6f2014-09-02 18:59:01 -040056
bigbiff bigbiffaf32bb92018-12-18 18:39:53 -050057 if (!packet.getString(string)) return false;
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040058 mStorageDescription = strdup((const char *)string);
bigbiff bigbiffaf32bb92018-12-18 18:39:53 -050059 if (!mStorageDescription) return false;
60 if (!packet.getString(string)) return false;
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040061 mVolumeIdentifier = strdup((const char *)string);
bigbiff bigbiffaf32bb92018-12-18 18:39:53 -050062 if (!mVolumeIdentifier) return false;
63
64 return true;
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040065}
66
67void MtpStorageInfo::print() {
bigbiff bigbiffaf32bb92018-12-18 18:39:53 -050068 MTPD("Storage Info %08X:\n\tmStorageType: %d\n\tmFileSystemType: %d\n\tmAccessCapability: %d\n",
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040069 mStorageID, mStorageType, mFileSystemType, mAccessCapability);
bigbiff bigbiffaf32bb92018-12-18 18:39:53 -050070 MTPD("\tmMaxCapacity: %" PRIu64 "\n\tmFreeSpaceBytes: %" PRIu64 "\n\tmFreeSpaceObjects: %d\n",
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040071 mMaxCapacity, mFreeSpaceBytes, mFreeSpaceObjects);
bigbiff bigbiffaf32bb92018-12-18 18:39:53 -050072 MTPD("\tmStorageDescription: %s\n\tmVolumeIdentifier: %s\n",
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040073 mStorageDescription, mVolumeIdentifier);
74}