diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bf9ec21 --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +# Files generated by ./autogen.sh +Makefile.in +aclocal.m4 +autom4te.cache/ +build-aux/ +m4/ +config.h.in +configure +ar-lib +compile +config.guess +config.sub +depcomp +install-sh +ltmain.sh +missing +# Files generated by ./configure +config.h +config.log +config.status +libtool +stamp-h1 +.deps/ +Makefile +# Files generated by make +*.o +*.a +*.lo +*.la +.libs/ +.dirstamp +# Files for development +GPATH +GRTAGS +GTAGS +TAGS +tags +*~ diff --git a/Makefile.am b/Makefile.am index f7be12a..0a2bcb4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,14 +2,23 @@ ACLOCAL_AMFLAGS = -I m4 nobase_pkginclude_HEADERS = config.h +GEN_DRV = +PLAT_DRV = + if PLATFORM_LINUX -SUBDIRS = messages src/tape_drivers/linux/ltotape + PLAT_DRV += src/tape_drivers/linux/ltotape endif if PLATFORM_MAC -SUBDIRS = messages src/tape_drivers/osx/ltotape + PLAT_DRV += src/tape_drivers/osx/ltotape endif if PLATFORM_NETBSD -SUBDIRS = messages src/tape_drivers/netbsd/ltotape + PLAT_DRV += src/tape_drivers/netbsd/ltotape +endif + +if CHECKONLY + SUBDIRS = messages src/tape_drivers/generic/dummy +else + SUBDIRS = messages ${GEN_DRV} ${PLAT_DRV} endif diff --git a/configure.ac b/configure.ac index 73e8067..36c8454 100644 --- a/configure.ac +++ b/configure.ac @@ -5,14 +5,31 @@ AC_PREREQ([2.69]) AC_INIT([ltfs-plugins], [0.1], [manu@netbsd.org]) AC_CONFIG_SRCDIR([src/tape_drivers/netbsd/ltotape/ltotape.c]) AC_CONFIG_MACRO_DIRS([m4]) -AC_CONFIG_MACRO_DIR([m4]) +AC_CONFIG_MACRO_DIR([m4]) AC_CANONICAL_TARGET AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects]) AC_CONFIG_HEADERS([config.h]) AC_PROG_CC +AC_PROG_CC_C99 +AM_PROG_CC_C_O AM_PROG_AR AC_PROG_LIBTOOL +# Detecting target OS +case "${target_os}" in + linux*) + target_linux=yes + ;; + darwin*) + target_mac=yes + ;; + netbsd*) + target_netbsd=yes + ;; + *) + AC_MSG_ERROR(["OS $target_os is not supported"]) + ;; +esac # Checks for header files. AC_CHECK_HEADERS([fcntl.h inttypes.h stdlib.h string.h sys/file.h sys/ioctl.h unistd.h]) @@ -28,15 +45,15 @@ AC_TYPE_UINT8_T # Checks for library functions. AC_CHECK_FUNCS([memset strerror strstr]) -dnl +dnl dnl Check for pkg-config -dnl -if test -z "$PKG_CONFIG" +dnl +if test -z "$PKG_CONFIG" then - AC_PATH_PROG(PKG_CONFIG, pkg-config, [no]) -fi + AC_PATH_PROG(PKG_CONFIG, pkg-config, [no]) +fi if test "x${PKG_CONFIG}" = "xno" -then +then AC_MSG_ERROR([pkg-config was not found]) fi @@ -48,13 +65,13 @@ if test "x${GENRB}" = "xno" then AC_MSG_ERROR([genrb was not found]) fi - -dnl + +dnl dnl Check for pkgdata -dnl +dnl AC_PATH_PROG(PKGDATA, pkgdata, no) if test "x${PKGDATA}" = "xno" -then +then AC_MSG_ERROR([pkgdata was not found]) fi @@ -87,6 +104,17 @@ then AC_MSG_RESULT([$ICU_MODULE_VERSION]) fi +dnl +dnl interface checker +dnl +AC_MSG_CHECKING([No driver build, only check backend I/F]) +AC_ARG_ENABLE([checkonly], + [AS_HELP_STRING([--enable-checkonly],[No driver build, only check backend I/F])], + [checkonly=$enableval], + [checkonly=no] +) +AC_MSG_RESULT([$checkonly]) + dnl dnl test for ENOMEDIUM dnl @@ -95,39 +123,30 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include ],[ #error no ENOMEDIUM #endif])],[],[AM_CPPFLAGS="${AM_CPPFLAGS} -DENOMEDIUM=EAGAIN"]) +if test "x${target_linux}" = "xyes" +then + AM_CPPFLAGS="-D_GNU_SOURCE" +fi AM_CPPFLAGS="${AM_CPPFLAGS} `${PKG_CONFIG} --cflags ltfs`" AM_CPPFLAGS="${AM_CPPFLAGS} `${PKG_CONFIG} --cflags fuse`" AM_CPPFLAGS="${AM_CPPFLAGS} -DIBM_LTFS_BUILD -DGENERIC_OEM_BUILD" AM_CPPFLAGS="${AM_CPPFLAGS} ${ICU_MODULE_CFLAGS}" -case "${target_os}" in - linux*) - target_linux=yes - ;; - darwin*) - host_mac=yes - ;; - netbsd*) - target_netbsd=yes - ;; - *) - AC_MSG_ERROR(["OS $target_os is not supported"]) - ;; -esac - AM_CONDITIONAL([PLATFORM_LINUX], [test "x${target_linux}" = "xyes"]) AM_CONDITIONAL([PLATFORM_MAC], [test "x${target_mac}" = "xyes"]) AM_CONDITIONAL([PLATFORM_NETBSD], [test "x${target_netbsd}" = "xyes"]) +AM_CONDITIONAL([CHECKONLY], [test "x${checkonly}" = "xyes"]) AM_CONDITIONAL([CHK_MESSAGE], [test "x${use_msg_check}" = "xyes"]) AC_SUBST(CFLAGS) AC_SUBST(AM_CPPFLAGS) AC_SUBST(AM_EXTRA_CPPFLAGS) AC_SUBST(AM_CFLAGS) -AC_SUBST(AM_LDFLAGS) +AC_SUBST(AM_LDFLAGS) -AC_CONFIG_FILES([Makefile messages/Makefile +AC_CONFIG_FILES([Makefile messages/Makefile + src/tape_drivers/generic/dummy/Makefile src/tape_drivers/linux/ltotape/Makefile src/tape_drivers/osx/ltotape/Makefile src/tape_drivers/netbsd/ltotape/Makefile]) diff --git a/src/tape_drivers/generic/dummy/Makefile.am b/src/tape_drivers/generic/dummy/Makefile.am new file mode 100644 index 0000000..d2a4a2a --- /dev/null +++ b/src/tape_drivers/generic/dummy/Makefile.am @@ -0,0 +1,34 @@ +# +# +# Copyright (c) 2019 IBM Corp. +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of version 2.1 of the GNU Lesser General Public License +# as published by the Free Software Foundation. +# +# 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 Lesser 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: +# Free Software Foundation, Inc. +# 51 Franklin Street, Fifth Floor +# Boston, MA 02110-1301, USA. +# +# + +lib_LTLIBRARIES = libtape-dummy.la +libdir = @libdir@/ltfs + +AM_LIBTOOLFLAGS = --tag=disable-static + +libtape_dummy_la_SOURCES = dummy.c +libtape_dummy_la_DEPENDENCIES = +libtape_dummy_la_LIBADD = +libtape_dummy_la_CPPFLAGS = @AM_CPPFLAGS@ -I$(top_srcdir)/src +libtape_dummy_la_LDFLAGS = -avoid-version -module + +install-exec-hook: + for f in $(lib_LTLIBRARIES); do rm -f $(libdir)/$$f; done diff --git a/src/tape_drivers/generic/dummy/dummy.c b/src/tape_drivers/generic/dummy/dummy.c new file mode 100644 index 0000000..6533bd5 --- /dev/null +++ b/src/tape_drivers/generic/dummy/dummy.c @@ -0,0 +1,429 @@ +/* +** +** Copyright (c) 2019 IBM Corp. +** +** This program is free software; you can redistribute it and/or modify it +** under the terms of version 2.1 of the GNU Lesser General Public License +** as published by the Free Software Foundation. +** +** 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 Lesser 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: +** Free Software Foundation, Inc. +** 51 Franklin Street, Fifth Floor +** Boston, MA 02110-1301, USA. +** +************************************************************************************* +** +** COMPONENT NAME: LTFS 3rd party backend project +** +** FILE NAME: dummy,c +** +** DESCRIPTION: Dummy backend to check the compatibility with LTFS's backend I/F +** +** AUTHOR: Atsushi Abe +** IBM Tokyo Lab., Japan +** piste@jp.ibm.com +** +************************************************************************************* +*/ + +#include + +#include + +#include "libltfs/tape_ops.h" +#include "libltfs/ltfs_error.h" + +#include "tape_drivers/tape_drivers.h" + +/** + * Emulator-specific data structures, used in lieu of a file descriptor + */ +struct dummy_data { + int drive_type; /**< drive type defined by ltfs */ + char *serial_number; /**< Serial number of this dummy tape device */ + char *product_id; /**< Product ID of this dummy tape device */ +}; + +static struct fuse_opt dummy_opts[] = { + FUSE_OPT_END +}; + +int null_parser(void *state, const char *arg, int key, struct fuse_args *outargs) +{ + return 1; +} + +int dummy_parse_opts(void *device, void *opt_args) +{ + struct dummy_data *state = (struct dummy_data *) device; + struct fuse_args *args = (struct fuse_args *) opt_args; + int ret; + + /* fuse_opt_parse can handle a NULL device parameter just fine */ + ret = fuse_opt_parse(args, state, dummy_opts, null_parser); + if (ret < 0) + return ret; + + return DEVICE_GOOD; +} + +void dummy_help_message(const char *progname) +{ + return; +} + +int dummy_open(const char *name, void **handle) +{ + struct dummy_data *state; + + state = (struct dummy_data *)calloc(1,sizeof(struct dummy_data)); + if (!state) { + return -EDEV_NO_MEMORY; + } + + *handle = (void *) state; + return DEVICE_GOOD; +} + +int dummy_reopen(const char *name, void *device) +{ + /* Do nothing */ + return DEVICE_GOOD; +} + +int dummy_close(void *device) +{ + struct dummy_data *state = (struct dummy_data *)device; + + if (state) + free(state); + + return DEVICE_GOOD; +} + +int dummy_close_raw(void *device) +{ + return DEVICE_GOOD; +} + +int dummy_is_connected(const char *devname) +{ + return DEVICE_GOOD; +} + +int dummy_inquiry(void *device, struct tc_inq *inq) +{ + return DEVICE_GOOD; +} + +int dummy_inquiry_page(void *device, unsigned char page, struct tc_inq_page *inq) +{ + return DEVICE_GOOD; +} + +int dummy_test_unit_ready(void *device) +{ + return DEVICE_GOOD; +} + +int dummy_read(void *device, char *buf, size_t count, struct tc_position *pos, + const bool unusual_size) +{ + return DEVICE_GOOD; +} + +int dummy_write(void *device, const char *buf, size_t count, struct tc_position *pos) +{ + return DEVICE_GOOD; +} + +int dummy_writefm(void *device, size_t count, struct tc_position *pos, bool immed) +{ + return DEVICE_GOOD; +} + +int dummy_rewind(void *device, struct tc_position *pos) +{ + return DEVICE_GOOD; +} + +int dummy_locate(void *device, struct tc_position dest, struct tc_position *pos) +{ + return DEVICE_GOOD; +} + +int dummy_space(void *device, size_t count, TC_SPACE_TYPE type, struct tc_position *pos) +{ + return DEVICE_GOOD; +} + +int dummy_erase(void *device, struct tc_position *pos, bool long_erase) +{ + return DEVICE_GOOD; +} + +int dummy_load(void *device, struct tc_position *pos) +{ + return DEVICE_GOOD; +} + +int dummy_unload(void *device, struct tc_position *pos) +{ + return DEVICE_GOOD; +} + +int dummy_readpos(void *device, struct tc_position *pos) +{ + return DEVICE_GOOD; +} + +int dummy_setcap(void *device, uint16_t proportion) +{ + return DEVICE_GOOD; +} + +int dummy_format(void *device, TC_FORMAT_TYPE format, const char *vol_name, const char *barcode_name, const char *vol_mam_uuid) +{ + return DEVICE_GOOD; +} + +int dummy_remaining_capacity(void *device, struct tc_remaining_cap *cap) +{ + return DEVICE_GOOD; +} + +int dummy_get_cartridge_health(void *device, struct tc_cartridge_health *cart_health) +{ + return DEVICE_GOOD; +} + +int dummy_get_tape_alert(void *device, uint64_t *tape_alert) +{ + return DEVICE_GOOD; +} + +int dummy_clear_tape_alert(void *device, uint64_t tape_alert) +{ + return DEVICE_GOOD; +} + +int dummy_get_xattr(void *device, const char *name, char **buf) +{ + return DEVICE_GOOD; +} + +int dummy_set_xattr(void *device, const char *name, const char *buf, size_t size) +{ + return DEVICE_GOOD; +} + +int dummy_logsense(void *device, const uint8_t page, unsigned char *buf, const size_t size) +{ + return DEVICE_GOOD; +} + +int dummy_modesense(void *device, const uint8_t page, const TC_MP_PC_TYPE pc, const uint8_t subpage, unsigned char *buf, const size_t size) +{ + return DEVICE_GOOD; +} + +int dummy_modeselect(void *device, unsigned char *buf, const size_t size) +{ + return DEVICE_GOOD; +} + +int dummy_reserve_unit(void *device) +{ + return DEVICE_GOOD; +} + +int dummy_release_unit(void *device) +{ + return DEVICE_GOOD; +} + +int dummy_prevent_medium_removal(void *device) +{ + return DEVICE_GOOD; +} + +int dummy_allow_medium_removal(void *device) +{ + return DEVICE_GOOD; +} + +int dummy_read_attribute(void *device, const tape_partition_t part, const uint16_t id + , unsigned char *buf, const size_t size) +{ + return DEVICE_GOOD; +} + +int dummy_write_attribute(void *device, const tape_partition_t part + , const unsigned char *buf, const size_t size) +{ + return DEVICE_GOOD; +} + +int dummy_allow_overwrite(void *device, const struct tc_position pos) +{ + return DEVICE_GOOD; +} + +int dummy_get_eod_status(void *device, int partition) +{ + return EOD_GOOD; +} + +int dummy_set_compression(void *device, bool enable_compression, struct tc_position *pos) +{ + return DEVICE_GOOD; +} + +int dummy_set_default(void *device) +{ + return DEVICE_GOOD; +} + +int dummy_get_parameters(void *device, struct tc_drive_param *params) +{ + return DEVICE_GOOD; +} + +const char *dummy_default_device_name(void) +{ + return "DUMMY000"; +} + +int dummy_get_device_list(struct tc_drive_info *buf, int count) +{ + return DEVICE_GOOD; +} + +int dummy_set_key(void *device, const unsigned char *keyalias, const unsigned char *key) +{ + return -EDEV_UNSUPPORTED_FUNCTION; +} + +int dummy_get_keyalias(void *device, unsigned char **keyalias) +{ + return -EDEV_UNSUPPORTED_FUNCTION; +} + +int dummy_takedump_drive(void *device, bool nonforced_dump) +{ + /* Do nothing */ + return DEVICE_GOOD; +} + +int dummy_is_mountable(void *device, const char *barcode, const unsigned char cart_type, + const unsigned char density) +{ + return MEDIUM_CANNOT_ACCESS; +} + +bool dummy_is_readonly(void *device) +{ + return false; +} + +int dummy_get_worm_status(void *device, bool *is_worm) +{ + return DEVICE_GOOD; +} + +int dummy_get_serialnumber(void *device, char **result) +{ + return DEVICE_GOOD; +} + +int dummy_set_profiler(void *device, char *work_dir, bool enable) +{ + /* Do nohting: file backend does not support profiler */ + return DEVICE_GOOD; +} + +int dummy_get_block_in_buffer(void *device, unsigned int *block) +{ + return DEVICE_GOOD; +} + +struct tape_ops dummy_handler = { + .open = dummy_open, + .reopen = dummy_reopen, + .close = dummy_close, + .close_raw = dummy_close_raw, + .is_connected = dummy_is_connected, + .inquiry = dummy_inquiry, + .inquiry_page = dummy_inquiry_page, + .test_unit_ready = dummy_test_unit_ready, + .read = dummy_read, + .write = dummy_write, + .writefm = dummy_writefm, + .rewind = dummy_rewind, + .locate = dummy_locate, + .space = dummy_space, + .erase = dummy_erase, + .load = dummy_load, + .unload = dummy_unload, + .readpos = dummy_readpos, + .setcap = dummy_setcap, + .format = dummy_format, + .remaining_capacity = dummy_remaining_capacity, + .logsense = dummy_logsense, + .modesense = dummy_modesense, + .modeselect = dummy_modeselect, + .reserve_unit = dummy_reserve_unit, + .release_unit = dummy_release_unit, + .prevent_medium_removal = dummy_prevent_medium_removal, + .allow_medium_removal = dummy_allow_medium_removal, + .write_attribute = dummy_write_attribute, + .read_attribute = dummy_read_attribute, + .allow_overwrite = dummy_allow_overwrite, + .set_compression = dummy_set_compression, + .set_default = dummy_set_default, + .get_cartridge_health = dummy_get_cartridge_health, + .get_tape_alert = dummy_get_tape_alert, + .clear_tape_alert = dummy_clear_tape_alert, + .get_xattr = dummy_get_xattr, + .set_xattr = dummy_set_xattr, + .get_parameters = dummy_get_parameters, + .get_eod_status = dummy_get_eod_status, + .get_device_list = dummy_get_device_list, + .help_message = dummy_help_message, + .parse_opts = dummy_parse_opts, + .default_device_name = dummy_default_device_name, + .set_key = dummy_set_key, + .get_keyalias = dummy_get_keyalias, + .takedump_drive = dummy_takedump_drive, + .is_mountable = dummy_is_mountable, + .get_worm_status = dummy_get_worm_status, + .get_serialnumber = dummy_get_serialnumber, + .set_profiler = dummy_set_profiler, + .get_block_in_buffer = dummy_get_block_in_buffer, + .is_readonly = dummy_is_readonly, +}; + +struct tape_ops *tape_dev_get_ops(void) +{ + return &dummy_handler; +} + +#ifndef mingw_PLATFORM +extern char tape_generic_dummy_dat[]; +#endif + +const char *tape_dev_get_message_bundle_name(void **message_data) +{ +#ifndef mingw_PLATFORM + *message_data = tape_generic_dummy_dat; +#else + *message_data = NULL; +#endif + return "tape_generic_dummy"; +} diff --git a/src/tape_drivers/linux/ltotape/Makefile.am b/src/tape_drivers/linux/ltotape/Makefile.am index 055d255..0e4e63d 100755 --- a/src/tape_drivers/linux/ltotape/Makefile.am +++ b/src/tape_drivers/linux/ltotape/Makefile.am @@ -11,7 +11,7 @@ # under the terms of version 2.1 of the GNU Lesser General Public License # as published by the Free Software Foundation. # -# This program is distributed in the hope that it will be useful, but +# 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 Lesser General Public # License for more details. @@ -31,8 +31,8 @@ libdir = @libdir@/ltfs AM_LIBTOOLFLAGS = --tag=disable-static libdriver_ltotape_la_SOURCES = ltotape.c ltotape_diag.c ltotape_platform.c -libdriver_ltotape_la_DEPENDENCIES = $(top_srcdir)/messages/libdriver_ltotape_dat.la -libdriver_ltotape_la_LIBADD = $(top_srcdir)/messages/libdriver_ltotape_dat.la +libdriver_ltotape_la_DEPENDENCIES = $(top_srcdir)/messages/libdriver_ltotape_dat.a +libdriver_ltotape_la_LIBADD = $(top_srcdir)/messages/libdriver_ltotape_dat.a libdriver_ltotape_la_CPPFLAGS = @AM_CPPFLAGS@ -I$(top_srcdir)/src libdriver_ltotape_la_LDFLAGS = -avoid-version -module diff --git a/src/tape_drivers/linux/ltotape/ltotape_platform.c b/src/tape_drivers/linux/ltotape/ltotape_platform.c index f1bc806..6d542c9 100755 --- a/src/tape_drivers/linux/ltotape/ltotape_platform.c +++ b/src/tape_drivers/linux/ltotape/ltotape_platform.c @@ -35,7 +35,6 @@ #include #include #include -#include #include #include #include @@ -43,10 +42,13 @@ #include "../../../libltfs/ltfs_error.h" #include "../../../ltfsprintf.h" #include "../../../libltfs/ltfslogging.h" + #include "ltotape.h" #include "ltotape_diag.h" #include "ltotape_supdevs.h" +#include + /* * Max transfer size to ask the SG driver to handle (1MB): */ @@ -114,7 +116,7 @@ int ltotape_scsiexec (ltotape_scsi_io_type *scsi_io) memset ((void *)&sg_io, 0, sizeof (sg_io)); - /* + /* * Set up required fields */ sg_io.interface_id = (int) 'S'; @@ -138,12 +140,12 @@ int ltotape_scsiexec (ltotape_scsi_io_type *scsi_io) free (sense_string); } - /* - * Here's the actual command execution + /* + * Here's the actual command execution */ status = ioctl (scsi_io->fd, SG_IO, &sg_io); - /* + /* * Now determine the outcome: */ scsi_status = S_NO_STATUS; /* Until proven otherwise... */ @@ -152,34 +154,34 @@ int ltotape_scsiexec (ltotape_scsi_io_type *scsi_io) if ((status < 0) || ((sg_io.driver_status & 0xF) == SG_ERR_DRIVER_INVALID)) { driver_status = DS_ILLEGAL; - /* + /* * Unit didn't respond to selection */ } else if (sg_io.host_status == SG_ERR_DID_NO_CONNECT) { driver_status = DS_SELECTION_TIMEOUT; - /* + /* * Unit timed out */ } else if (sg_io.host_status == SG_ERR_DID_TIME_OUT) { driver_status = DS_TIMEOUT; errno = ETIMEDOUT; - /* + /* * Bus (link, whatever) was reset */ } else if (sg_io.host_status == SG_ERR_DID_RESET) { driver_status = DS_RESET; if (errno == 0) errno = EIO; /* ensure it doesn't go unnoticed */ - /* - * Good driver status + /* + * Good driver status */ } else if (sg_io.host_status == SG_ERR_DID_OK) { driver_status = DS_GOOD; scsi_status = sg_io.status; - /* + /* * For anything else, create a composite value of "driver status" to help with debug */ } else @@ -188,7 +190,7 @@ int ltotape_scsiexec (ltotape_scsi_io_type *scsi_io) scsi_io->actual_data_length = sg_io.dxfer_len - sg_io.resid; scsi_io->sense_length = sg_io.sb_len_wr; - /* + /* * A driver error is always bad news */ if (driver_status != DS_GOOD) { @@ -316,28 +318,28 @@ int ltotape_map_st2sg (const char *devname, char *sgdevname) int host_unique_id; } devinfo; - /* + /* * First check for a valid device name: */ if (devname == (const char *)NULL) { ltfsmsg (LTFS_ERR, "20032E", devname, "Null device name"); return -EDEV_INVALID_ARG; - - /* + + /* * If the given device is already a 'sg' device, nothing to be done. */ } else if (strstr (devname, "/dev/sg") != (char*)NULL) { strcpy (sgdevname, devname); return DEVICE_GOOD; - - /* + + /* * If the given device is a 'st' device, change it to an 'nst' device to ensure that * on close the driver doesn't issue a rewind command to the tape. */ } else if (strstr (devname, "/dev/st") != (char *)NULL) { length = strlen (devname) + 2; /* +1 for 'n' and +1 for '\0' */ outcome = asprintf (&temp, "%s", devname + strlen ("/dev/st")); - + if ((outcome == -1) || (!temp)) { /* Low on memory or other error. Return failure. */ ltfsmsg (LTFS_ERR, "20100E"); sgdevname = NULL; @@ -348,7 +350,7 @@ int ltotape_map_st2sg (const char *devname, char *sgdevname) if (!nstdevname) { /* Low on memory. Return failure. */ ltfsmsg (LTFS_ERR, "20100E"); if (temp) { - free (temp); + free (temp); temp = NULL; } sgdevname = NULL; @@ -366,9 +368,9 @@ int ltotape_map_st2sg (const char *devname, char *sgdevname) temp = NULL; } - /* + /* * Given device name is already a 'nst' device; or if 'something else' (/dev/something) is - * passed by the user, 'open' should handle that below. + * passed by the user, 'open' should handle that below. */ } else { nstdevname = (char *)devname; @@ -391,7 +393,7 @@ int ltotape_map_st2sg (const char *devname, char *sgdevname) if (outcome < 0) { ltfsmsg (LTFS_ERR, "20032E", devname, "SCSI_IOCTL_GET_IDLUN failed"); if (allocated) { - free (nstdevname); + free (nstdevname); nstdevname = NULL; } return -EDEV_DRIVER_ERROR; @@ -399,7 +401,7 @@ int ltotape_map_st2sg (const char *devname, char *sgdevname) } else if ((fp = fopen ("/proc/scsi/sg/devices", "rb")) == (FILE *)NULL) { ltfsmsg (LTFS_ERR, "20032E", devname, "Unable to open /proc/scsi/sg/devices"); if (allocated) { - free (nstdevname); + free (nstdevname); nstdevname = NULL; } return -EDEV_INTERNAL_ERROR; @@ -424,7 +426,7 @@ int ltotape_map_st2sg (const char *devname, char *sgdevname) if (!found) { if (allocated) { - free (nstdevname); + free (nstdevname); nstdevname = NULL; } return -EDEV_DEVICE_UNSUPPORTABLE; @@ -433,7 +435,7 @@ int ltotape_map_st2sg (const char *devname, char *sgdevname) sprintf (sgdevname, "/dev/sg%d", i); ltfsmsg (LTFS_DEBUG, "20034D", nstdevname, sgdevname, dev_host_no, dev_channel, dev_scsi_id, dev_lun); if (allocated) { - free (nstdevname); + free (nstdevname); nstdevname = NULL; } return DEVICE_GOOD; @@ -463,7 +465,7 @@ int ltotape_open (const char *devname, void **handle) memset (&inq_data, 0, sizeof (struct tc_inq)); - /* + /* * We use the SCSI generic driver for ioctls. Here we attempt to map a given 'st' device * to a corresponding 'sg' device... */ @@ -479,7 +481,7 @@ int ltotape_open (const char *devname, void **handle) return -EDEV_NO_MEMORY; } - /* + /* * Open the device: */ device->fd = open (sgdevname, O_RDWR | O_NDELAY); @@ -489,7 +491,7 @@ int ltotape_open (const char *devname, void **handle) if (errno == EAGAIN) { ltfsmsg (LTFS_ERR, "20086E", devname); ret = -EDEV_DEVICE_BUSY; - + } else { ltfsmsg (LTFS_ERR, "20087E", devname, errno); ret = -EDEV_DEVICE_UNOPENABLE; @@ -500,7 +502,7 @@ int ltotape_open (const char *devname, void **handle) ltfsmsg (LTFS_WARN, "20088W", devname); } - /* + /* * Lock the opened device. */ if (flock (device->fd, LOCK_EX | LOCK_NB) != 0) { @@ -518,17 +520,17 @@ int ltotape_open (const char *devname, void **handle) ioctl (device->fd, SG_GET_RESERVED_SIZE, &res_sz); ltfsmsg (LTFS_DEBUG, "20020D", res_sz); - /* + /* * Set up the default timeout, should be overwritten by each backend function: */ device->timeout_ms = LTO_DEFAULT_TIMEOUT; - /* + /* * Default Early Warning EOM state is that we're not yet at the warning point: */ device->eweomstate = before_eweom; - /* + /* * Default logfile directory - initially NULL; will get set if/when we parse FUSE options.. */ device->logdir = NULL;