| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 Intel Corporation |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the test suite of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
| 21 | ** included in the packaging of this file. Please review the following |
| 22 | ** information to ensure the GNU General Public License requirements will |
| 23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 24 | ** |
| 25 | ** $QT_END_LICENSE$ |
| 26 | ** |
| 27 | ****************************************************************************/ |
| 28 | |
| 29 | #include <QtCore/QStorageInfo> |
| 30 | |
| 31 | void printVolumes(const QList<QStorageInfo> &volumes, int (*printer)(const char *, ...)) |
| 32 | { |
| 33 | // Sample output: |
| 34 | // Filesystem (Type) Size Available BSize Label Mounted on |
| 35 | // /dev/sda2 (ext4) RO 388480 171218 1024 /boot |
| 36 | // /dev/mapper/system-root (btrfs) RW |
| 37 | // 214958080 39088272 4096 / |
| 38 | // /dev/disk1s2 (hfs) RW 488050672 419909696 4096 Macintosh HD2 /Volumes/Macintosh HD2 |
| 39 | |
| 40 | printer("Filesystem (Type) Size Available BSize Label Mounted on\n" ); |
| 41 | foreach (const QStorageInfo &info, volumes) { |
| 42 | QByteArray fsAndType = info.device(); |
| 43 | if (info.fileSystemType() != fsAndType) |
| 44 | fsAndType += " (" + info.fileSystemType() + ')'; |
| 45 | |
| 46 | printer("%-19s R%c " , fsAndType.constData(), info.isReadOnly() ? 'O' : 'W'); |
| 47 | if (fsAndType.size() > 19) |
| 48 | printer("\n%23s" , "" ); |
| 49 | |
| 50 | printer("%10llu %10llu %5u " , info.bytesTotal() / 1024, info.bytesFree() / 1024, info.blockSize()); |
| 51 | if (!info.subvolume().isEmpty()) |
| 52 | printer("subvol=%-18s " , qPrintable(info.subvolume())); |
| 53 | else |
| 54 | printer("%-25s " , qPrintable(info.name())); |
| 55 | printer("%s\n" , qPrintable(info.rootPath())); |
| 56 | } |
| 57 | } |
| 58 | |