added rmindex to the build
improve style following our guidelines removed dependency on libbe.so git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15928 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
55f6067fcd
commit
17a014aaf7
|
@ -38,6 +38,7 @@ StdBinCommands
|
||||||
renice.c
|
renice.c
|
||||||
rescan.c
|
rescan.c
|
||||||
rmattr.cpp
|
rmattr.cpp
|
||||||
|
rmindex.cpp
|
||||||
safemode.c
|
safemode.c
|
||||||
sysinfo.c
|
sysinfo.c
|
||||||
unchop.c
|
unchop.c
|
||||||
|
|
|
@ -1,15 +1,11 @@
|
||||||
// Copyright (c) 2003, OpenBeOS
|
/*
|
||||||
//
|
* Copyright 2003-2006 Haiku Inc.
|
||||||
// This software is part of the OpenBeOS distribution and is covered
|
* Distributed under the terms of the MIT license
|
||||||
// by the OpenBeOS license.
|
*
|
||||||
//
|
* Authors:
|
||||||
// File: rmindex.cpp
|
* Scott Dellinger (dellinsd@myrealbox.com)
|
||||||
// Author: Scott Dellinger (dellinsd@myrealbox.com)
|
* Jérôme Duval
|
||||||
// Description: Removes an index from a volume.
|
*/
|
||||||
//
|
|
||||||
// Changelog:
|
|
||||||
// 2003-03-09 initial version
|
|
||||||
//
|
|
||||||
|
|
||||||
// std C includes
|
// std C includes
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -20,9 +16,6 @@
|
||||||
#include <fs_info.h>
|
#include <fs_info.h>
|
||||||
#include <fs_index.h>
|
#include <fs_index.h>
|
||||||
#include <TypeConstants.h>
|
#include <TypeConstants.h>
|
||||||
#include <Directory.h>
|
|
||||||
#include <Path.h>
|
|
||||||
#include <Volume.h>
|
|
||||||
|
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
|
||||||
|
@ -55,7 +48,8 @@ static struct option const longopts[] =
|
||||||
void usage(int);
|
void usage(int);
|
||||||
const char* lookup_index_type(uint32);
|
const char* lookup_index_type(uint32);
|
||||||
|
|
||||||
int main (int32 argc, char **argv)
|
int
|
||||||
|
main (int32 argc, char **argv)
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
int verbose = 0;
|
int verbose = 0;
|
||||||
|
@ -63,93 +57,75 @@ int main (int32 argc, char **argv)
|
||||||
char *index_name = NULL;
|
char *index_name = NULL;
|
||||||
int retval;
|
int retval;
|
||||||
char *error_message;
|
char *error_message;
|
||||||
|
char *path = NULL;
|
||||||
|
|
||||||
while ((c = getopt_long(argc, argv, "d:ht:v", longopts, NULL)) != -1)
|
while ((c = getopt_long(argc, argv, "d:ht:v", longopts, NULL)) != -1) {
|
||||||
{
|
switch (c) {
|
||||||
switch (c)
|
|
||||||
{
|
|
||||||
case 0:
|
case 0:
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
vol_device = dev_for_path(optarg);
|
path = optarg;
|
||||||
if (vol_device < 0)
|
break;
|
||||||
{
|
|
||||||
fprintf(stderr, "%s: can't get information about volume: %s\n", argv[0], optarg);
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case GETOPT_HELP_CHAR:
|
case GETOPT_HELP_CHAR:
|
||||||
usage(0);
|
usage(0);
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
verbose = 1;
|
verbose = 1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
usage(1);
|
usage(1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Remove the index from the volume of the current
|
/* Remove the index from the volume of the current
|
||||||
directory if no volume was specified. */
|
directory if no volume was specified. */
|
||||||
if (vol_device == 0)
|
if (path == NULL) {
|
||||||
{
|
path = ".";
|
||||||
vol_device = dev_for_path(".");
|
|
||||||
if (vol_device < 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "%s: can't get information about current volume\n", argv[0]);
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc - optind == 1) // last argument
|
vol_device = dev_for_path(path);
|
||||||
{
|
if (vol_device < 0) {
|
||||||
|
fprintf(stderr, "%s: can't get information about current volume\n", argv[0]);
|
||||||
|
return B_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argc - optind == 1) { // last argument
|
||||||
index_name = argv[optind];
|
index_name = argv[optind];
|
||||||
} else
|
} else {
|
||||||
{
|
|
||||||
usage(1);
|
usage(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (verbose)
|
if (verbose) {
|
||||||
{
|
|
||||||
/* Get the mount point of the specified volume. */
|
|
||||||
BVolume volume(vol_device);
|
|
||||||
BDirectory dir;
|
|
||||||
volume.GetRootDirectory(&dir);
|
|
||||||
BPath path(&dir, NULL);
|
|
||||||
|
|
||||||
/* Get the index type. */
|
/* Get the index type. */
|
||||||
index_info i_info;
|
index_info i_info;
|
||||||
status_t status = fs_stat_index(vol_device, index_name, &i_info);
|
status_t status = fs_stat_index(vol_device, index_name, &i_info);
|
||||||
if (status != B_OK)
|
if (status != B_OK) {
|
||||||
{
|
fprintf(stderr, "%s: fs_stat_index(): (%d) %s\n", argv[0], errno, strerror(errno));
|
||||||
printf("%s: fs_stat_index(): (%d) %s\n", argv[0], errno, strerror(errno));
|
|
||||||
return (errno);
|
return (errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Look up the string name equivalent of the index type. */
|
/* Look up the string name equivalent of the index type. */
|
||||||
const char* index_type_str = lookup_index_type(i_info.type);
|
const char* index_type_str = lookup_index_type(i_info.type);
|
||||||
|
|
||||||
fprintf(stdout, "Removing index \"%s\" of type %s from volume mounted at %s.\n", index_name, index_type_str, path.Path());
|
fprintf(stdout, "Removing index \"%s\" of type %s from volume containing %s\n", index_name, index_type_str, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((retval = fs_remove_index(vol_device, index_name)) != 0)
|
if ((retval = fs_remove_index(vol_device, index_name)) != 0) {
|
||||||
{
|
switch (errno) {
|
||||||
switch (errno)
|
case B_FILE_ERROR:
|
||||||
{
|
|
||||||
B_FILE_ERROR:
|
|
||||||
error_message = "A filesystem error prevented the operation.";
|
error_message = "A filesystem error prevented the operation.";
|
||||||
break;
|
break;
|
||||||
B_BAD_VALUE:
|
case B_BAD_VALUE:
|
||||||
error_message = "Invalid device specified.";
|
error_message = "Invalid device specified.";
|
||||||
break;
|
break;
|
||||||
B_NOT_ALLOWED:
|
case B_NOT_ALLOWED:
|
||||||
error_message = "Can't remove a system-reserved index, or the device is read-only.";
|
error_message = "Can't remove a system-reserved index, or the device is read-only.";
|
||||||
break;
|
break;
|
||||||
B_NO_MEMORY:
|
case B_NO_MEMORY:
|
||||||
error_message = "Insufficient memory to complete the operation.";
|
error_message = "Insufficient memory to complete the operation.";
|
||||||
break;
|
break;
|
||||||
B_ENTRY_NOT_FOUND:
|
case B_ENTRY_NOT_FOUND:
|
||||||
error_message = "The specified index does not exist.";
|
error_message = "The specified index does not exist.";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -160,10 +136,12 @@ int main (int32 argc, char **argv)
|
||||||
fprintf(stderr, "%s\n", error_message);
|
fprintf(stderr, "%s\n", error_message);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (0);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void usage (int status)
|
|
||||||
|
void
|
||||||
|
usage (int status)
|
||||||
{
|
{
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
"Usage: rmindex [OPTION]... INDEX_NAME\n"
|
"Usage: rmindex [OPTION]... INDEX_NAME\n"
|
||||||
|
@ -184,10 +162,11 @@ void usage (int status)
|
||||||
exit(status);
|
exit(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* lookup_index_type(uint32 device_type)
|
|
||||||
|
const char*
|
||||||
|
lookup_index_type(uint32 device_type)
|
||||||
{
|
{
|
||||||
switch (device_type)
|
switch (device_type) {
|
||||||
{
|
|
||||||
case B_DOUBLE_TYPE:
|
case B_DOUBLE_TYPE:
|
||||||
return "double";
|
return "double";
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue