Files
haiku-beta6/src/bin/isvolume.cpp
T

91 lines
2.4 KiB
C++
Raw Normal View History

2006-12-22 08:17:16 +00:00
/*
* Copyright 2002-2006, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Jonas Sundstrom, [email protected]
*/
2002-10-06 11:31:44 +00:00
#include <fs_info.h>
2006-12-22 08:17:16 +00:00
#include <stdio.h>
#include <string.h>
static void
usage()
{
fprintf(stderr,
"Usage: isvolume {-OPTION} [volumename]\n"
" Where OPTION is one of:\n"
" -readonly - volume is read-only\n"
" -query - volume supports queries\n"
" -attribute - volume supports attributes\n"
" -mime - volume supports MIME information\n"
" -shared - volume is shared\n"
" -persistent - volume is backed on permanent storage\n"
" -removable - volume is on removable media\n"
" If the option is true for the named volume, 'yes' is printed\n"
" and if the option is false, 'no' is printed. Multiple options\n"
" can be specified in which case all of them must be true.\n\n"
" If no volume is specified, the volume of the current directory is assumed.\n");
}
2002-10-06 11:31:44 +00:00
2006-12-22 08:17:16 +00:00
int
main(int32 argc, char** argv)
2002-10-06 11:31:44 +00:00
{
2006-12-22 08:17:16 +00:00
dev_t volumeDevice = dev_for_path(".");
uint32 isVolumeFlags = 0;
fs_info volumeInfo;
2002-10-06 11:31:44 +00:00
2006-12-22 08:17:16 +00:00
for (int i = 1; i < argc; i++) {
if (!strcmp(argv[i], "--help")) {
usage();
2006-12-22 08:17:16 +00:00
return 0;
2002-10-06 11:31:44 +00:00
}
2006-12-22 08:17:16 +00:00
if (argv[i][0] == '-') {
if (! strcmp(argv[i], "-readonly"))
isVolumeFlags |= B_FS_IS_READONLY;
else if (! strcmp(argv[i], "-query"))
isVolumeFlags |= B_FS_HAS_QUERY;
else if (! strcmp(argv[i], "-attribute"))
isVolumeFlags |= B_FS_HAS_ATTR;
else if (! strcmp(argv[i], "-mime"))
isVolumeFlags |= B_FS_HAS_MIME;
else if (! strcmp(argv[i], "-shared"))
isVolumeFlags |= B_FS_IS_SHARED;
else if (! strcmp(argv[i], "-persistent"))
isVolumeFlags |= B_FS_IS_PERSISTENT;
else if (! strcmp(argv[i], "-removable"))
isVolumeFlags |= B_FS_IS_REMOVABLE;
else {
fprintf(stderr,
"%s: option %s is not understood (use --help for help)\n", argv[0], argv[i]);
return 1;
2002-10-06 11:31:44 +00:00
}
2006-12-22 08:17:16 +00:00
} else {
volumeDevice = dev_for_path(argv[i]);
2002-10-06 11:31:44 +00:00
2006-12-22 08:17:16 +00:00
if (volumeDevice < 0) {
2002-10-06 11:31:44 +00:00
fprintf(stderr, "%s: can't get information about volume: %s\n", argv[0], argv[i]);
return 1;
2002-10-06 11:31:44 +00:00
}
}
}
2006-12-22 08:17:16 +00:00
if (fs_stat_dev(volumeDevice, &volumeInfo) == B_OK) {
if (volumeInfo.flags & isVolumeFlags)
2002-10-06 11:31:44 +00:00
printf("yes\n");
else
printf("no\n");
2006-12-22 08:17:16 +00:00
return 0;
} else {
fprintf(stderr, "%s: can't get information about dev_t: %ld\n", argv[0], volumeDevice);
return 1;
2002-10-06 11:31:44 +00:00
}
}