1335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood/*
2335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood * Copyright (C) 2010 The Android Open Source Project
3335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood *
4335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood * Licensed under the Apache License, Version 2.0 (the "License");
5335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood * you may not use this file except in compliance with the License.
6335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood * You may obtain a copy of the License at
7335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood *
8335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood *      http://www.apache.org/licenses/LICENSE-2.0
9335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood *
10335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood * Unless required by applicable law or agreed to in writing, software
11335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood * distributed under the License is distributed on an "AS IS" BASIS,
12335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood * See the License for the specific language governing permissions and
14335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood * limitations under the License.
15335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood */
16335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood
17a6c490b8b2d96ebaab632286029463f932ae3b6bMike Lockwood#define LOG_TAG "MtpStorageInfo"
18335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood
19d239cb6e6898bdf2300e9038111727a9056c58eeMark Salyzyn#include <inttypes.h>
20d239cb6e6898bdf2300e9038111727a9056c58eeMark Salyzyn
21b14e588bec4d5e39e61b020b5b575f2ce555d316Mike Lockwood#include "MtpDebug.h"
22335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood#include "MtpDataPacket.h"
23335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood#include "MtpStorageInfo.h"
24335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood#include "MtpStringBuffer.h"
25335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood
26335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwoodnamespace android {
27335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood
28335dd2be955607f2632eabc25045857f2cc8b674Mike LockwoodMtpStorageInfo::MtpStorageInfo(MtpStorageID id)
29335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood    :   mStorageID(id),
30335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood        mStorageType(0),
31335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood        mFileSystemType(0),
32335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood        mAccessCapability(0),
33335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood        mMaxCapacity(0),
34335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood        mFreeSpaceBytes(0),
35335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood        mFreeSpaceObjects(0),
36335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood        mStorageDescription(NULL),
37335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood        mVolumeIdentifier(NULL)
38335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood{
39335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood}
40335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood
41335dd2be955607f2632eabc25045857f2cc8b674Mike LockwoodMtpStorageInfo::~MtpStorageInfo() {
42335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood    if (mStorageDescription)
43335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood        free(mStorageDescription);
44335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood    if (mVolumeIdentifier)
45335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood        free(mVolumeIdentifier);
46335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood}
47335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood
48335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwoodvoid MtpStorageInfo::read(MtpDataPacket& packet) {
49335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood    MtpStringBuffer string;
50335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood
51335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood    // read the device info
52335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood    mStorageType = packet.getUInt16();
53335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood    mFileSystemType = packet.getUInt16();
54335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood    mAccessCapability = packet.getUInt16();
55335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood    mMaxCapacity = packet.getUInt64();
56335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood    mFreeSpaceBytes = packet.getUInt64();
57335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood    mFreeSpaceObjects = packet.getUInt32();
58335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood
59335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood    packet.getString(string);
60335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood    mStorageDescription = strdup((const char *)string);
61335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood    packet.getString(string);
62335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood    mVolumeIdentifier = strdup((const char *)string);
63335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood}
64335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood
65335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwoodvoid MtpStorageInfo::print() {
66b8a805261bf0282e992d3608035e47d05a898710Steve Block    ALOGD("Storage Info %08X:\n\tmStorageType: %d\n\tmFileSystemType: %d\n\tmAccessCapability: %d\n",
67335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood            mStorageID, mStorageType, mFileSystemType, mAccessCapability);
68d239cb6e6898bdf2300e9038111727a9056c58eeMark Salyzyn    ALOGD("\tmMaxCapacity: %" PRIu64 "\n\tmFreeSpaceBytes: %" PRIu64 "\n\tmFreeSpaceObjects: %d\n",
69335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood            mMaxCapacity, mFreeSpaceBytes, mFreeSpaceObjects);
70b8a805261bf0282e992d3608035e47d05a898710Steve Block    ALOGD("\tmStorageDescription: %s\n\tmVolumeIdentifier: %s\n",
71335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood            mStorageDescription, mVolumeIdentifier);
72335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood}
73335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood
74335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood}  // namespace android
75