Example #1
0
int
bc_DeleteHostCmd(struct cmd_syndesc *as, void *arock)
{
    struct cmd_item *ti;
    afs_int32 port = 0;
    udbClientTextP ctPtr;
    afs_int32 code = 0;

    ctPtr = &bc_globalConfig->configText[TB_TAPEHOSTS];
    code = bc_LockText(ctPtr);
    if (code)
	ERROR(code);

    code = bc_UpdateHosts();
    if (code) {
	afs_com_err(whoami, code, "; Can't retrieve tape hosts");
	return (code);
    }

    /* delete tape hosts first */
    ti = as->parms[0].items;
    if (ti) {
	if (as->parms[1].items) {
	    port = bc_SafeATOI(as->parms[1].items->data);
	    if (port < 0)
		return (BC_BADARG);
	}

	printf("Deleting host %s offset %u to tape list...", ti->data, port);
	fflush(stdout);
	code = bc_DeleteTapeHost(bc_globalConfig, ti->data, port);
	if (code) {
	    if (code == ENOENT)
		printf("failed: no such host entry\n");
	    else
		printf("failed with code %d\n", code);
	    ERROR(code);
	}

	code = bc_SaveHosts();
	if (code) {
	    afs_com_err(whoami, code, "Cannot save tape hosts");
	    afs_com_err(whoami, 0,
		    "Changes are temporary - for this session only");
	    ERROR(code);
	}
    }

    /* done */
    printf("done\n");
    fflush(stdout);

  error_exit:
    if (ctPtr->lockHandle != 0)
	bc_UnlockText(ctPtr);
    return (code);
}
Example #2
0
/* get partition id from a name */
afs_int32
bc_GetPartitionID(char *aname, afs_int32 *aval)
{

    /*bc_GetPartitionID */

    char tc;
    char ascii[3];

    /* special-case "anything" */
    if (strcmp(aname, ".*") == 0) {
	*aval = -1;
	return 0;
    }
    tc = *aname;
    if (tc == 0)
	return -1;		/* unknown */
    /* numbers go straight through */
    if (tc >= '0' && tc <= '9') {
	*aval = bc_SafeATOI(aname);
	return 0;
    }
    /* otherwise check for vicepa or /vicepa, or just plain "a" */
    ascii[2] = 0;
    if (strlen(aname) <= 2) {
	strcpy(ascii, aname);
    } else if (!strncmp(aname, "/vicep", 6)) {
	strncpy(ascii, aname + 6, 2);
    } else if (!strncmp(aname, "vicep", 5)) {
	strncpy(ascii, aname + 5, 2);
    } else
	return (BC_NOPARTITION);	/* bad partition name */
    /* now partitions are named /vicepa ... /vicepz, /vicepaa, /vicepab, .../vicepzz, and are numbered
     * from 0.  Do the appropriate conversion */
    if (ascii[1] == 0) {
	/* one char name, 0..25 */
	if (ascii[0] < 'a' || ascii[0] > 'z')
	    return -1;		/* wrongo */
	*aval = ascii[0] - 'a';
	return 0;
    } else {
	/* two char name, 26 .. <whatever> */
	if (ascii[0] < 'a' || ascii[0] > 'z')
	    return -1;		/* wrongo */
	if (ascii[1] < 'a' || ascii[1] > 'z')
	    return -1;		/* just as bad */
	*aval = (ascii[0] - 'a') * 26 + (ascii[1] - 'a') + 26;
	return 0;
    }
}				/*bc_GetPartitionID */