From 84bf9059ffaa1b36cdbbceff4cff7c2d8ea7e2a2 Mon Sep 17 00:00:00 2001 From: Steven Murray <steven.murray@cern.ch> Date: Mon, 18 Nov 2013 17:46:31 +0100 Subject: [PATCH] Added the client function name rmc_unmnt(). --- mediachanger/castorrmc/rmc/rmc_unmnt.c | 92 ++++++++++++++++++++++++ mediachanger/castorrmc/rmc/rmc_unmnt.man | 66 +++++++++++++++++ 2 files changed, 158 insertions(+) create mode 100644 mediachanger/castorrmc/rmc/rmc_unmnt.c create mode 100644 mediachanger/castorrmc/rmc/rmc_unmnt.man diff --git a/mediachanger/castorrmc/rmc/rmc_unmnt.c b/mediachanger/castorrmc/rmc/rmc_unmnt.c new file mode 100644 index 0000000000..7e7d869f00 --- /dev/null +++ b/mediachanger/castorrmc/rmc/rmc_unmnt.c @@ -0,0 +1,92 @@ +/****************************************************************************** + * rmc/rmc_unmnt.c + * + * This file is part of the Castor project. + * See http://castor.web.cern.ch/castor + * + * Copyright (C) 2003 CERN + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * + * + * @author Steven.Murray@cern.ch + *****************************************************************************/ + +/* rmc_unmnt - unmount a cartridge from a drive that maybe in either */ +/* a SCSI compatible or an ACS compatible tape library */ + +#include <stdlib.h> +#include <sys/types.h> +#include <unistd.h> +#include <netinet/in.h> +#include "h/marshall.h" +#include "h/rmc_api.h" +#include "h/rmc_constants.h" +#include "h/serrno.h" + +#include <errno.h> +#include <string.h> + +int rmc_unmnt( + const char *const server, + const char *const vid, + const char *const loader) +{ + const gid_t gid = getgid(); + const uid_t uid = getuid(); + + /* The total length of the fixed size members of the request message */ + /* is Magic (4 bytes) + request ID (4 bytes) + length (4 bytes) + */ + /* uid (4 bytes) + gid (4 bytes) = 20 bytes */ + const int msglen = 20 + strlen(vid) + 1 + strlen(loader) + 1; + + char repbuf[1]; + char *sbp = NULL; + char sendbuf[RMC_REQBUFSZ]; + + /* Consider the function arguments invalid if the total size of the */ + /* request message would be greater than RMC_REQBUFSZ */ + if(msglen > RMC_REQBUFSZ) { + errno = ERMCUNREC; + serrno = errno; + return -1; + } + + if(CA_MAXVIDLEN < strlen(vid)) { + errno = ERMCUNREC; + serrno = errno; + return -1; + } + + /* Build request header */ + sbp = sendbuf; + marshall_LONG (sbp, RMC_MAGIC); + marshall_LONG (sbp, RMC_GENERICUNMOUNT); + marshall_LONG (sbp, msglen); + + /* Build request body */ + marshall_LONG (sbp, uid); + marshall_LONG (sbp, gid); + marshall_STRING (sbp, vid); + marshall_STRING (sbp, loader); + + /* Being paranoid; checking the calculated message length against */ + /* the number of bytes marshalled */ + if(sbp - sendbuf != msglen) { + errno = SEINTERNAL; + serrno = errno; + return -1; + } + + return send2rmc (server, sendbuf, msglen, repbuf, sizeof(repbuf)); +} diff --git a/mediachanger/castorrmc/rmc/rmc_unmnt.man b/mediachanger/castorrmc/rmc/rmc_unmnt.man new file mode 100644 index 0000000000..c33dc3b199 --- /dev/null +++ b/mediachanger/castorrmc/rmc/rmc_unmnt.man @@ -0,0 +1,66 @@ +.\" Copyright (C) 2002 by CERN/IT/PDP/DM +.\" All rights reserved +.\" +.TH RMC_UNMNT 3 "$Date: 2013/11/18 16:21:00 $" CASTOR "rmc Library Functions" +.SH NAME +rmc_unmnt \- send a request to the Remote Media Changer daemon to have a volume unmounted +.SH SYNOPSIS +.B #include <sys/types.h> +.br +\fB#include "rmc_api.h"\fR +.sp +.BI "int rmc_unmnt (char *" server , +.BI "char *" vid , +.BI "char *" loader ); +.SH DESCRIPTION +.B rmc_unmnt +asks the Remote Media Changer server running on +.I server +to unmount the volume +.I vid +from the drive specified by +.IR loader . +.TP +.I server +specifies the Remote Media Changer to be contacted. +.TP +.I vid +is the volume visual identifier. +It must be at most six characters long. +.TP +.I loader +specifies the drive in the robot in one of the following forms: +.RS +.TP +acsACS_NUMBER,LSM_NUMBER,PANEL_NUMBER,TRANSPORT_NUMBER +.TP +manual +.TP +smc@hostname,drive_ordinal +.RE + +.LP +This function requires TP_SYSTEM privilege in the Cupv database. +.SH RETURN VALUE +This routine returns 0 if the operation was successful or -1 if the operation +failed. In the latter case, +.B serrno +is set appropriately. +.SH ERRORS +.TP 1.2i +.B SECOMERR +Communication error. +.TP +.B ERMCUNREC +Unknown host or invalid loader or vid too long or requester does not have +TP_SYSTEM privilege in the Cupv database. +.TP +.B ERMCFASTR +Unit attention. +.TP +.B ERMCOMSGR +Hardware error or Medium Removal Prevented. +.SH SEE ALSO +.BR Cupvlist(1) , +.SH AUTHOR +\fBCASTOR\fP Team <castor.support@cern.ch> -- GitLab