diff --git a/.gitignore b/.gitignore index d96d064043299cf1005d91ea1c2d03da81acc894..710a8d72aca1479b247bd0decac75a06b475cc63 100644 --- a/.gitignore +++ b/.gitignore @@ -38,6 +38,7 @@ castor/tape/rechandler/rechandlerd castor/tape/rmc/castor-tape-acs-dismount castor/tape/rmc/castor-tape-acs-mount castor/tape/rmc/castor-tape-acs-queryvolume +castor/tape/rmc/castor-tape-mount castor/tape/tapebridge/tapebridged castor/tape/tapegateway/tapegatewayd castor/tape/tpcp/dumptp diff --git a/castor/tape/rmc/AcsCmd.cpp b/castor/tape/rmc/AcsCmd.cpp index c70d9f64aa1eb3797a29fb358ed147fb71bb9c5a..1559c061d7ca3462eac8d1547476c24cc4e018da 100644 --- a/castor/tape/rmc/AcsCmd.cpp +++ b/castor/tape/rmc/AcsCmd.cpp @@ -32,8 +32,7 @@ //------------------------------------------------------------------------------ castor::tape::rmc::AcsCmd::AcsCmd(std::istream &inStream, std::ostream &outStream, std::ostream &errStream, Acs &acs) throw(): - m_in(inStream), m_out(outStream), m_err(errStream), m_acs(acs), - m_debugBuf(outStream), m_dbg(&m_debugBuf) { + Cmd(inStream, outStream, errStream), m_acs(acs) { } //------------------------------------------------------------------------------ @@ -45,25 +44,9 @@ castor::tape::rmc::AcsCmd::~AcsCmd() throw() { //------------------------------------------------------------------------------ // bool2Str //------------------------------------------------------------------------------ -std::string castor::tape::rmc::AcsCmd::bool2Str(bool &value) const +std::string castor::tape::rmc::AcsCmd::bool2Str(const BOOLEAN value) const throw() { - if(value) { - return "TRUE"; - } else { - return "FALSE"; - } -} - -//------------------------------------------------------------------------------ -// bool2Str -//------------------------------------------------------------------------------ -std::string castor::tape::rmc::AcsCmd::bool2Str(BOOLEAN &value) const - throw() { - if(value) { - return "TRUE"; - } else { - return "FALSE"; - } + return value ? "TRUE" : "FALSE"; } //------------------------------------------------------------------------------ diff --git a/castor/tape/rmc/AcsCmd.hpp b/castor/tape/rmc/AcsCmd.hpp index 0dfceeba22fc9e1ffcfa337c7dc20a84c39f4e07..f7673d8538dd5b225144f2f2bacfa5be74d07794 100644 --- a/castor/tape/rmc/AcsCmd.hpp +++ b/castor/tape/rmc/AcsCmd.hpp @@ -29,7 +29,7 @@ #include "castor/exception/Mismatch.hpp" #include "castor/exception/RequestFailed.hpp" #include "castor/tape/rmc/Acs.hpp" -#include "castor/tape/rmc/DebugBuf.hpp" +#include "castor/tape/rmc/Cmd.hpp" #include <istream> #include <ostream> @@ -48,7 +48,7 @@ namespace rmc { * Abstract class implementing common code and data structures for command-line * tools that interact with ACLS compatible tape libraries. */ -class AcsCmd { +class AcsCmd: public Cmd { public: /** * Constructor. @@ -68,49 +68,17 @@ public: protected: - /** - * Standard input stream. - */ - std::istream &m_in; - - /** - * Standard output stream. - */ - std::ostream &m_out; - - /** - * Standard error stream. - */ - std::ostream &m_err; - /** * Wrapper around the ACSLS C-API. */ Acs &m_acs; - /** - * Debug stream buffer that inserts a standard debug preamble before each - * message-line written to it. - */ - DebugBuf m_debugBuf; - - /** - * Stream used to write debug messages. - * - * This stream will insert a standard debug preamble before each message-line - * written to it. - */ - std::ostream m_dbg; - - /** - * Returns the string representation of the specfied boolean value. - */ - std::string bool2Str(bool &value) const throw(); - /** * Returns the string representation of the specfied boolean value. + * + * @param value The boolean value. */ - std::string bool2Str(BOOLEAN &value) const throw(); + std::string bool2Str(const BOOLEAN value) const throw(); /** * Requests responses from ACSLS in a loop until the RT_FINAL response is diff --git a/castor/tape/rmc/Cmd.cpp b/castor/tape/rmc/Cmd.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ff3cbb9f3db0156cabe6cab0978897e4c1453700 --- /dev/null +++ b/castor/tape/rmc/Cmd.cpp @@ -0,0 +1,47 @@ +/****************************************************************************** + * castor/tape/rmc/Cmd.cpp + * + * 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 + *****************************************************************************/ + +#include "castor/tape/rmc/Cmd.hpp" + +//------------------------------------------------------------------------------ +// constructor +//------------------------------------------------------------------------------ +castor::tape::rmc::Cmd::Cmd(std::istream &inStream, + std::ostream &outStream, std::ostream &errStream) throw(): + m_in(inStream), m_out(outStream), m_err(errStream), m_debugBuf(outStream), + m_dbg(&m_debugBuf) { +} + +//------------------------------------------------------------------------------ +// destructor +//------------------------------------------------------------------------------ +castor::tape::rmc::Cmd::~Cmd() throw() { +} + +//------------------------------------------------------------------------------ +// bool2Str +//------------------------------------------------------------------------------ +std::string castor::tape::rmc::Cmd::bool2Str(const bool value) const throw() { + return value ? "TRUE" : "FALSE"; +} diff --git a/castor/tape/rmc/Cmd.hpp b/castor/tape/rmc/Cmd.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8082d5cd54e43dc124eaca26df06034afce042d5 --- /dev/null +++ b/castor/tape/rmc/Cmd.hpp @@ -0,0 +1,103 @@ +/****************************************************************************** + * castor/tape/rmc/Cmd.hpp + * + * 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 + *****************************************************************************/ + +#ifndef CASTOR_TAPE_RMC_CMD_HPP +#define CASTOR_TAPE_RMC_CMD_HPP 1 + +#include "castor/tape/rmc/DebugBuf.hpp" + +#include <istream> +#include <ostream> +#include <string> + +namespace castor { +namespace tape { +namespace rmc { + +/** + * Abstract class implementing common code and data structures for a + * command-line tool. + */ +class Cmd { +public: + /** + * Constructor. + * + * @param inStream Standard input stream. + * @param outStream Standard output stream. + * @param errStream Standard error stream. + */ + Cmd(std::istream &inStream, std::ostream &outStream, std::ostream &errStream) + throw(); + + /** + * Pure-virtual destructor to guarantee this class is abstract. + */ + virtual ~Cmd() throw() = 0; + +protected: + + /** + * Standard input stream. + */ + std::istream &m_in; + + /** + * Standard output stream. + */ + std::ostream &m_out; + + /** + * Standard error stream. + */ + std::ostream &m_err; + + /** + * Debug stream buffer that inserts a standard debug preamble before each + * message-line written to it. + */ + DebugBuf m_debugBuf; + + /** + * Stream used to write debug messages. + * + * This stream will insert a standard debug preamble before each message-line + * written to it. + */ + std::ostream m_dbg; + + /** + * Returns the string representation of the specfied boolean value. + * + * @param value The boolean value. + */ + std::string bool2Str(const bool value) const throw(); + +}; // class Cmd + +} // namespace rmc +} // namespace tape +} // namespace castor + +#endif // CASTOR_TAPE_RMC_CMD_HPP diff --git a/castor/tape/rmc/MountCmd.cpp b/castor/tape/rmc/MountCmd.cpp index 9d6e7ad57cdc44de988523d14d837287cdf5814d..02f3063783d756a1327ec544804f597a9e146385 100644 --- a/castor/tape/rmc/MountCmd.cpp +++ b/castor/tape/rmc/MountCmd.cpp @@ -33,7 +33,7 @@ //------------------------------------------------------------------------------ castor::tape::rmc::MountCmd::MountCmd(std::istream &inStream, std::ostream &outStream, std::ostream &errStream) throw(): - m_defaultTimeout(600) { + Cmd(inStream, outStream, errStream), m_defaultTimeout(600) { } //------------------------------------------------------------------------------ @@ -106,9 +106,6 @@ castor::tape::rmc::MountCmdLine castor::tape::rmc::MountCmd::parseCmdLine( MountCmdLine cmdLine; char c; - // Set the query option to the default value - cmdLine.queryInterval = m_defaultQueryInterval; - // Set timeout option to the default value cmdLine.timeout = m_defaultTimeout; @@ -125,7 +122,7 @@ castor::tape::rmc::MountCmdLine castor::tape::rmc::MountCmd::parseCmdLine( cmdLine.help = true; break; case 'r': - cmdLine.readOnly = TRUE; + cmdLine.readOnly = true; break; case 't': cmdLine.timeout = atoi(optarg); diff --git a/castor/tape/rmc/MountCmd.hpp b/castor/tape/rmc/MountCmd.hpp index 93c5f9eecfd797c96eb5ba1a20217371b78ad248..aee13f4415715fad8805b59f0829bf8198e160e2 100644 --- a/castor/tape/rmc/MountCmd.hpp +++ b/castor/tape/rmc/MountCmd.hpp @@ -28,7 +28,7 @@ #include "castor/exception/Internal.hpp" #include "castor/exception/InvalidArgument.hpp" #include "castor/exception/MissingOperand.hpp" -#include "castor/exception/MountFailed.hpp" +#include "castor/tape/rmc/Cmd.hpp" #include "castor/tape/rmc/MountCmdLine.hpp" #include <stdint.h> @@ -40,7 +40,7 @@ namespace rmc { /** * The class implementing the mount command. */ -class MountCmd { +class MountCmd: public Cmd { public: /** @@ -101,6 +101,7 @@ private: * success or failure. */ const int m_defaultTimeout; + }; // class MountCmd } // namespace rmc diff --git a/castor/tape/rmc/MountCmdLine.cpp b/castor/tape/rmc/MountCmdLine.cpp new file mode 100644 index 0000000000000000000000000000000000000000..baf75d8128a127238b995f6ec3337702480ed224 --- /dev/null +++ b/castor/tape/rmc/MountCmdLine.cpp @@ -0,0 +1,35 @@ +/****************************************************************************** + * castor/tape/rmc/MountCmdLine.hpp + * + * 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 + *****************************************************************************/ + +#include "castor/tape/rmc/MountCmdLine.hpp" + +//----------------------------------------------------------------------------- +// constructor +//----------------------------------------------------------------------------- +castor::tape::rmc::MountCmdLine::MountCmdLine() throw(): + debug(false), + help(false), + readOnly(false), + timeout(0) { +} diff --git a/castor/tape/rmc/MountCmdLine.hpp b/castor/tape/rmc/MountCmdLine.hpp index e93afd81edbd11919a92776647a0512164c2dba1..b2bcd06a49ffe09216355d6e34c87a1a84908ed6 100644 --- a/castor/tape/rmc/MountCmdLine.hpp +++ b/castor/tape/rmc/MountCmdLine.hpp @@ -38,7 +38,7 @@ struct MountCmdLine { /** * Constructor. * - * Initialises all BOOLEAN member-variables to FALSE, all integer + * Initialises all bool member-variables to false, all integer * member-variables to 0 and the volume identifier to an empty string. */ MountCmdLine() throw(); @@ -56,7 +56,7 @@ struct MountCmdLine { /** * True if the tape is to be mount for read-only access. */ - BOOLEAN readOnly; + bool readOnly; /** * Time in seconds to wait for the mount to conclude. diff --git a/castor/tape/rmc/MountMain.cpp b/castor/tape/rmc/MountMain.cpp index 1c11680b76c3a8d058391c3e06726a51158fd4ef..f35c8c04a393fbaf263df87e54e5a98eb29dac77 100644 --- a/castor/tape/rmc/MountMain.cpp +++ b/castor/tape/rmc/MountMain.cpp @@ -31,7 +31,6 @@ //------------------------------------------------------------------------------ int main(const int argc, char *const *const argv) { - castor::tape::rmc::AcsImpl acs; castor::tape::rmc::MountCmd cmd(std::cin, std::cout, std::cerr); return cmd.main(argc, argv); diff --git a/debian/castor-devel.manpages b/debian/castor-devel.manpages index a40a247d8ef1f816ecfc0141760280e0dbfdea98..316b111ed259c43c7fcafaa4757ddb4d66ec90b2 100644 --- a/debian/castor-devel.manpages +++ b/debian/castor-devel.manpages @@ -154,6 +154,7 @@ debian/castor/usr/share/man/man3/rmc_find_cartridge.3castor.gz debian/castor/usr/share/man/man3/rmc_get_geometry.3castor.gz debian/castor/usr/share/man/man3/rmc_import.3castor.gz debian/castor/usr/share/man/man3/rmc_mount.3castor.gz +debian/castor/usr/share/man/man3/rmc_mnt.3castor.gz debian/castor/usr/share/man/man3/rmc_read_elem_status.3castor.gz debian/castor/usr/share/man/man3/rmc_seterrbuf.3castor.gz debian/castor/usr/share/man/man3/rwndtape.3castor.gz diff --git a/debian/castor-rmc-client.install.perm b/debian/castor-rmc-client.install.perm index 9f75a26f3b31374e2f9acf3355d7b22a5984b809..8a828c51d0726f97748657dc8dfe55377dacd3f7 100644 --- a/debian/castor-rmc-client.install.perm +++ b/debian/castor-rmc-client.install.perm @@ -1 +1,2 @@ +%attr(6755,root,root) usr/bin/castor-tape-mount %attr(6755,root,root) usr/bin/smc diff --git a/debian/castor-rmc-client.manpages b/debian/castor-rmc-client.manpages index 1babb322ab6a65e388fc7f022afb6e523e90dcda..b3c3d3b4b2f5a2b899646ee5f1301fbcac35801d 100644 --- a/debian/castor-rmc-client.manpages +++ b/debian/castor-rmc-client.manpages @@ -1 +1,2 @@ +debian/castor/usr/share/man/man1/castor-tape-mount.1castor.gz debian/castor/usr/share/man/man1/smc.1castor.gz diff --git a/rmc/rmc_mnt.c b/rmc/rmc_mnt.c index 8a3c63e34bf5e9efcdc5500e262fdf70e0526037..e6a78013e522ce13bd2bd834b5e5cf1fabf37192 100644 --- a/rmc/rmc_mnt.c +++ b/rmc/rmc_mnt.c @@ -61,7 +61,7 @@ int rmc_mnt( case RMC_LOADER_TYPE_SMC: return rmc_smc_mnt(server, vid, drive); default: - errno = ERMCUNREC; + errno = ERMCUKNLDRTYPE; /* Unknown loader type */ serrno = errno; return -1; } @@ -88,25 +88,29 @@ static int rmc_acs_mnt( char rmc_host[CA_MAXHOSTNAMELEN+1]; struct rmc_acs_drive_id drive_id = {0, 0, 0, 0}; - /* 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; + if(CA_MAXVIDLEN < strlen(vid)) { + errno = ERMCVIDTOOLONG; /* VID is too long */ serrno = errno; return -1; } - if(CA_MAXVIDLEN < strlen(vid)) { - errno = ERMCUNREC; + if(rmc_get_rmc_host_of_drive(drive, rmc_host, sizeof(rmc_host))) { + errno = ERMCPARSERMCHOST; /* Failed to parse RMC host */ serrno = errno; return -1; } - if(rmc_get_rmc_host_of_drive(drive, rmc_host, sizeof(rmc_host))) { + if(rmc_get_acs_drive_id(drive, &drive_id)) { + errno = ERMCPARSEACSDRV; /* Failed to parse ACS drive id */ + serrno = errno; return -1; } - if(rmc_get_acs_drive_id(drive, &drive_id)) { + /* It is an internal error if the total size of the request message */ + /* would be greater than RMC_REQBUFSZ */ + if(msglen > RMC_REQBUFSZ) { + errno = SEINTERNAL; + serrno = errno; return -1; } diff --git a/rmc/rmc_mnt.man b/rmc/rmc_mnt.man index 0017c2ef3a83f3c120e275da3cebd1b1d35aa136..a44ffa77714035d8c712358558ea56a6e3d0c2db 100644 --- a/rmc/rmc_mnt.man +++ b/rmc/rmc_mnt.man @@ -48,12 +48,12 @@ mount, or -1 if the operation failed. In the latter case, .B serrno is set appropriately. .SH ERRORS -.TP 1.2i +.TP 1.8i .B SECOMERR Communication error. .TP .B ERMCUNREC -Unknown host or invalid drive or vid too long or requester does not have +Unknown host or invalid drive or requester does not have TP_SYSTEM privilege in the Cupv database. .TP .B ERMCFASTR @@ -61,6 +61,21 @@ Unit attention. .TP .B ERMCOMSGR Hardware error or Medium Removal Prevented. +.TP +.B ERMCUKNLDRTYPE +Unknown loader type. +.TP +.B ERMCVIDTOOLONG +VID is too long. +.TP +.B ERMCPARSERMCHOST +Failed to parse RMC host. +.TP +.B ERMCPARSEACSDRV +Failed to parse ACS drive id. +.TP +.B SEINTERNAL +Internal error. .SH SEE ALSO .BR Cupvlist(1) , .SH AUTHOR