Add an extra option to isvolume to check if the underlaying partition is
perhaps read-only, while the volume appears to be writable because of the filesystem overlays. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30327 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
acc632c7ec
commit
2d294045c7
|
@ -32,7 +32,6 @@ StdBinCommands
|
||||||
finddir.c
|
finddir.c
|
||||||
hd.c
|
hd.c
|
||||||
idestatus.c
|
idestatus.c
|
||||||
isvolume.cpp
|
|
||||||
listarea.c
|
listarea.c
|
||||||
listimage.c
|
listimage.c
|
||||||
listport.c
|
listport.c
|
||||||
|
@ -110,6 +109,7 @@ StdBinCommands
|
||||||
# Haiku-specific apps which need libbe.so
|
# Haiku-specific apps which need libbe.so
|
||||||
if $(TARGET_PLATFORM) = haiku {
|
if $(TARGET_PLATFORM) = haiku {
|
||||||
StdBinCommands
|
StdBinCommands
|
||||||
|
isvolume.cpp
|
||||||
shutdown.cpp
|
shutdown.cpp
|
||||||
: be : $(haiku-utils_rsrc) ;
|
: be : $(haiku-utils_rsrc) ;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,21 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2006, Haiku Inc. All rights reserved.
|
* Copyright 2002-2009, Haiku Inc. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Jonas Sundstrom, jonas.sundstrom@kirilla.com
|
* Jonas Sundstrom, jonas.sundstrom@kirilla.com
|
||||||
|
* Stephan Aßmus <superstippi@gmx.de>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <fs_info.h>
|
#include <fs_info.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <DiskDevice.h>
|
||||||
|
#include <DiskDeviceRoster.h>
|
||||||
|
#include <Volume.h>
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
usage()
|
usage()
|
||||||
|
@ -19,17 +23,19 @@ usage()
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Usage: isvolume {-OPTION} [volumename]\n"
|
"Usage: isvolume {-OPTION} [volumename]\n"
|
||||||
" Where OPTION is one of:\n"
|
" Where OPTION is one of:\n"
|
||||||
" -readonly - volume is read-only\n"
|
" -readonly - volume is read-only\n"
|
||||||
" -query - volume supports queries\n"
|
" -readonly-partion - partition for the volume is read-only\n"
|
||||||
" -attribute - volume supports attributes\n"
|
" -query - volume supports queries\n"
|
||||||
" -mime - volume supports MIME information\n"
|
" -attribute - volume supports attributes\n"
|
||||||
" -shared - volume is shared\n"
|
" -mime - volume supports MIME information\n"
|
||||||
" -persistent - volume is backed on permanent storage\n"
|
" -shared - volume is shared\n"
|
||||||
" -removable - volume is on removable media\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"
|
" 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"
|
" 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"
|
" 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");
|
" If no volume is specified, the volume of the current directory is "
|
||||||
|
"assumed.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,7 +45,8 @@ main(int argc, char** argv)
|
||||||
dev_t volumeDevice = dev_for_path(".");
|
dev_t volumeDevice = dev_for_path(".");
|
||||||
uint32 isVolumeFlags = 0;
|
uint32 isVolumeFlags = 0;
|
||||||
fs_info volumeInfo;
|
fs_info volumeInfo;
|
||||||
|
bool doPartitionReadOnlyCheck = false;
|
||||||
|
|
||||||
for (int i = 1; i < argc; i++) {
|
for (int i = 1; i < argc; i++) {
|
||||||
if (!strcmp(argv[i], "--help")) {
|
if (!strcmp(argv[i], "--help")) {
|
||||||
usage();
|
usage();
|
||||||
|
@ -47,35 +54,67 @@ main(int argc, char** argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argv[i][0] == '-') {
|
if (argv[i][0] == '-') {
|
||||||
if (! strcmp(argv[i], "-readonly"))
|
if (strcmp(argv[i], "-readonly") == 0)
|
||||||
isVolumeFlags |= B_FS_IS_READONLY;
|
isVolumeFlags |= B_FS_IS_READONLY;
|
||||||
else if (! strcmp(argv[i], "-query"))
|
else if (strcmp(argv[i], "-query") == 0)
|
||||||
isVolumeFlags |= B_FS_HAS_QUERY;
|
isVolumeFlags |= B_FS_HAS_QUERY;
|
||||||
else if (! strcmp(argv[i], "-attribute"))
|
else if (strcmp(argv[i], "-attribute") == 0)
|
||||||
isVolumeFlags |= B_FS_HAS_ATTR;
|
isVolumeFlags |= B_FS_HAS_ATTR;
|
||||||
else if (! strcmp(argv[i], "-mime"))
|
else if (strcmp(argv[i], "-mime") == 0)
|
||||||
isVolumeFlags |= B_FS_HAS_MIME;
|
isVolumeFlags |= B_FS_HAS_MIME;
|
||||||
else if (! strcmp(argv[i], "-shared"))
|
else if (strcmp(argv[i], "-shared") == 0)
|
||||||
isVolumeFlags |= B_FS_IS_SHARED;
|
isVolumeFlags |= B_FS_IS_SHARED;
|
||||||
else if (! strcmp(argv[i], "-persistent"))
|
else if (strcmp(argv[i], "-persistent") == 0)
|
||||||
isVolumeFlags |= B_FS_IS_PERSISTENT;
|
isVolumeFlags |= B_FS_IS_PERSISTENT;
|
||||||
else if (! strcmp(argv[i], "-removable"))
|
else if (strcmp(argv[i], "-removable") == 0)
|
||||||
isVolumeFlags |= B_FS_IS_REMOVABLE;
|
isVolumeFlags |= B_FS_IS_REMOVABLE;
|
||||||
|
else if (strcmp(argv[i], "-readonly-partion"))
|
||||||
|
doPartitionReadOnlyCheck = true;
|
||||||
else {
|
else {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"%s: option %s is not understood (use --help for help)\n", argv[0], argv[i]);
|
"%s: option %s is not understood (use --help for help)\n",
|
||||||
|
argv[0], argv[i]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
volumeDevice = dev_for_path(argv[i]);
|
volumeDevice = dev_for_path(argv[i]);
|
||||||
|
|
||||||
if (volumeDevice < 0) {
|
if (volumeDevice < 0) {
|
||||||
fprintf(stderr, "%s: can't get information about volume: %s\n", argv[0], argv[i]);
|
fprintf(stderr, "%s: can't get information about volume: %s\n",
|
||||||
|
argv[0], argv[i]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (doPartitionReadOnlyCheck) {
|
||||||
|
// This requires an extra code-path, because volumes may now appear
|
||||||
|
// writable, but only because of the "write" file-system overlay.
|
||||||
|
BVolume volume(volumeDevice);
|
||||||
|
status_t ret = volume.InitCheck();
|
||||||
|
if (ret != B_OK) {
|
||||||
|
fprintf(stderr, "%s: failed to get BVolume for device %ld: %s\n",
|
||||||
|
argv[0], volumeDevice, strerror(ret));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
BDiskDeviceRoster roster;
|
||||||
|
BDiskDevice diskDevice;
|
||||||
|
BPartition* partition;
|
||||||
|
ret = roster.FindPartitionByVolume(volume, &diskDevice,
|
||||||
|
&partition);
|
||||||
|
if (ret != B_OK) {
|
||||||
|
fprintf(stderr, "%s: failed to get partition for device %ld: %s\n",
|
||||||
|
argv[0], volumeDevice, strerror(ret));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
// check this option directly and not via fs_stat_dev()
|
||||||
|
if (partition->IsReadOnly()) {
|
||||||
|
printf("yes\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (fs_stat_dev(volumeDevice, &volumeInfo) == B_OK) {
|
if (fs_stat_dev(volumeDevice, &volumeInfo) == B_OK) {
|
||||||
if (volumeInfo.flags & isVolumeFlags)
|
if (volumeInfo.flags & isVolumeFlags)
|
||||||
printf("yes\n");
|
printf("yes\n");
|
||||||
|
@ -84,7 +123,8 @@ main(int argc, char** argv)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "%s: can't get information about dev_t: %ld\n", argv[0], volumeDevice);
|
fprintf(stderr, "%s: can't get information about dev_t: %ld\n",
|
||||||
|
argv[0], volumeDevice);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue