Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions src/libltfs/tape.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@


#include "ltfs_error.h"
#include "tape_drivers/ibm_tape.h"
#include "tape.h"
#include "tape_ops.h"
#include "ltfs_endian.h"
Expand Down Expand Up @@ -1245,7 +1246,7 @@ ssize_t tape_write(struct device_data *dev, const char *buf, size_t count, bool
}

if (ltfs_caught_sigcont()) {
// Unset flag to avoid checking it again if it is not needed
// Unset flag to avoid checking it again if it is not needed
ltfs_sigcont_set(false);

ret_for_current_position = tape_get_position_from_drive(dev, &current_position);
Expand Down Expand Up @@ -1470,7 +1471,7 @@ static int tape_update_density(struct device_data *dev, int density_code)
mp_read_write_ctrl[1] = 0x00;
mp_read_write_ctrl[26] = density_code;

ret = dev->backend->modeselect(dev->backend_data, mp_read_write_ctrl, TC_MP_READ_WRITE_CTRL_SIZE);
ret = dev->backend->modeselect(dev->backend_data, mp_read_write_ctrl, TC_MP_READ_WRITE_CTRL_SIZE, false);
if (ret < 0) {
ltfsmsg(LTFS_ERR, 17239E, "modeselect", ret);
}
Expand Down Expand Up @@ -1577,7 +1578,8 @@ int tape_format(struct device_data *dev, tape_partition_t index_part, int densit
ret = dev->backend->modeselect(
dev->backend_data,
mp_medium_partition,
page_length
page_length,
false
);

/* Issue Format Medium (Make partitioned medium) */
Expand Down Expand Up @@ -2426,9 +2428,11 @@ int tape_set_pews(struct device_data *dev, bool set_value)
int ret;
unsigned char mp_dev_config_ext[TC_MP_DEV_CONFIG_EXT_SIZE];
struct tc_remaining_cap cap;
struct tc_drive_info tcinfo;
uint64_t half_of_max_p0 = 0;
static const uint16_t max_pews = 0xFFFF;
uint16_t pews;
bool savable = false;

CHECK_ARG_NULL(dev, -LTFS_NULL_ARG);
CHECK_ARG_NULL(dev->backend, -LTFS_NULL_ARG);
Expand Down Expand Up @@ -2472,7 +2476,12 @@ int tape_set_pews(struct device_data *dev, bool set_value)
mp_dev_config_ext[22] = (uint8_t)(pews >> 8 & 0xFF);
mp_dev_config_ext[23] = (uint8_t)(pews & 0xFF);

ret = dev->backend->modeselect(dev->backend_data, mp_dev_config_ext, TC_MP_DEV_CONFIG_EXT_SIZE);
if (tape_get_info(dev, &tcinfo) == 0) {
if (!strcmp(IBM_VENDOR_ID, tcinfo.vendor)) {
savable = true;
}
}
ret = dev->backend->modeselect(dev->backend_data, mp_dev_config_ext, TC_MP_DEV_CONFIG_EXT_SIZE, savable);
if (ret < 0)
ltfsmsg(LTFS_ERR, 17103E, ret);
return 0;
Expand Down Expand Up @@ -2530,6 +2539,8 @@ int tape_enable_append_only_mode(struct device_data *dev, bool enable)
bool loaded = false;
bool supported = true;
unsigned char mp_dev_config_ext[TC_MP_DEV_CONFIG_EXT_SIZE];
struct tc_drive_info tcinfo;
bool savable = false;

CHECK_ARG_NULL(dev, -LTFS_NULL_ARG);
CHECK_ARG_NULL(dev->backend, -LTFS_NULL_ARG);
Expand Down Expand Up @@ -2588,7 +2599,12 @@ int tape_enable_append_only_mode(struct device_data *dev, bool enable)
mp_dev_config_ext[21] &= 0x0F;
mp_dev_config_ext[21] |= enable ? 0x10 : 0x00;

ret = dev->backend->modeselect(dev->backend_data, mp_dev_config_ext, TC_MP_DEV_CONFIG_EXT_SIZE);
if (tape_get_info(dev, &tcinfo) == 0) {
if (!strcmp(IBM_VENDOR_ID, tcinfo.vendor)) {
savable = true;
}
}
ret = dev->backend->modeselect(dev->backend_data, mp_dev_config_ext, TC_MP_DEV_CONFIG_EXT_SIZE, savable);
if (ret < 0) {
if (ret == -EDEV_ILLEGAL_REQUEST) {
ltfsmsg(LTFS_INFO, 17266I);
Expand Down Expand Up @@ -3137,7 +3153,7 @@ int tape_set_attribute_to_cm(struct device_data* dev,
if (!attr_data) {
return -LTFS_NO_MEMORY;
}

/* fill the MAM header information */
ltfs_u16tobe(attr_data, type); /* set attribute type */
attr_data[2] = format; /* set data format type */
Expand Down
2 changes: 1 addition & 1 deletion src/libltfs/tape_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ struct tape_ops {
* @return 0 on success or a negative value on error. Backends for which Mode Select is
* meaningless should return 0.
*/
int (*modeselect)(void *device, unsigned char *buf, const size_t size);
int (*modeselect)(void *device, unsigned char *buf, const size_t size, bool save);

/**
* Send a SCSI Reserve Unit command to a device.
Expand Down
12 changes: 6 additions & 6 deletions src/tape_drivers/freebsd/cam/cam_tc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1955,7 +1955,7 @@ int camtape_modesense(void *device, const uint8_t page, const TC_MP_PC_TYPE pc,
* @param size length of buf
* @return 0 on success or a negative value on error
*/
int camtape_modeselect(void *device, unsigned char *buf, const size_t size)
int camtape_modeselect(void *device, unsigned char *buf, const size_t size, bool save)
{
int rc;
char *msg = NULL;
Expand Down Expand Up @@ -2351,7 +2351,7 @@ int camtape_set_compression(void *device, const bool enable_compression, struct
else
buf[18] &= 0x7F; /* Unset DCE field*/

rc = camtape_modeselect(device, buf, sizeof(buf));
rc = camtape_modeselect(device, buf, sizeof(buf), false);

ltfs_profiler_add_entry(softc->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_SETCOMPRS));
return rc;
Expand Down Expand Up @@ -2385,7 +2385,7 @@ int camtape_set_default(void *device)
buf[1] = 0x00;
buf[24] = 0x0C;

rc = camtape_modeselect(device, buf, sizeof(buf));
rc = camtape_modeselect(device, buf, sizeof(buf), false);
if (rc != DEVICE_GOOD)
goto bailout;
}
Expand Down Expand Up @@ -3031,7 +3031,7 @@ int camtape_setcap(void *device, uint16_t proportion)
buf[27] |= 0x01;
buf[28] = 0x00;

rc = camtape_modeselect(device, buf, sizeof(buf));
rc = camtape_modeselect(device, buf, sizeof(buf), false);
} else {
int timeout;

Expand Down Expand Up @@ -3510,7 +3510,7 @@ static int camtape_set_encryption_state(struct camtape_data *softc,
*/
rwc_page->encryption_state |= encryption_state;

rc = camtape_modeselect(softc, buf, buf_fill_len);
rc = camtape_modeselect(softc, buf, buf_fill_len, false);

bailout:
if (rc != DEVICE_GOOD)
Expand Down Expand Up @@ -3696,7 +3696,7 @@ int camtape_set_key(void *device, const unsigned char * const keyalias, const un

scsi_ulto2b(0, mode_hdr->data_length);

rc = camtape_modeselect(device, buf, bufsize);
rc = camtape_modeselect(device, buf, bufsize, false);

bailout:
if (rc != DEVICE_GOOD)
Expand Down
4 changes: 2 additions & 2 deletions src/tape_drivers/generic/file/filedebug_tc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1426,7 +1426,7 @@ static inline int _sanitize_tape(struct filedebug_data *state)
ret = -EDEV_MEDIUM_FORMAT_ERROR;
break;
}
}
}
else if (gen == DRIVE_GEN_JAG4) {
switch (state->conf.cart_type) {
case TC_MP_JB:
Expand Down Expand Up @@ -2036,7 +2036,7 @@ int filedebug_modesense(void *device, const uint8_t page, const TC_MP_PC_TYPE pc
return DEVICE_GOOD;
}

int filedebug_modeselect(void *device, unsigned char *buf, const size_t size)
int filedebug_modeselect(void *device, unsigned char *buf, const size_t size, bool save)
{
int ret = 0;
struct filedebug_data *state = (struct filedebug_data *)device;
Expand Down
2 changes: 1 addition & 1 deletion src/tape_drivers/generic/itdtimg/itdtimg_tc.c
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ int itdtimage_modesense(void *device, const uint8_t page, const TC_MP_PC_TYPE pc
return DEVICE_GOOD;
}

int itdtimage_modeselect(void *device, unsigned char *buf, const size_t size)
int itdtimage_modeselect(void *device, unsigned char *buf, const size_t size, bool save)
{
/* Do nothing */
return DEVICE_GOOD;
Expand Down
8 changes: 4 additions & 4 deletions src/tape_drivers/linux/lin_tape/lin_tape_ibmtape.c
Original file line number Diff line number Diff line change
Expand Up @@ -2432,7 +2432,7 @@ int lin_tape_ibmtape_modesense(void *device, const uint8_t page, const TC_MP_PC_
* @param size length of buf
* @return 0 on success or a negative value on error
*/
int lin_tape_ibmtape_modeselect(void *device, unsigned char *buf, const size_t size)
int lin_tape_ibmtape_modeselect(void *device, unsigned char *buf, const size_t size, bool save)
{
struct sioc_pass_through spt;
int rc;
Expand Down Expand Up @@ -2765,7 +2765,7 @@ int lin_tape_ibmtape_set_compression(void *device, const bool enable_compression
else
buf[18] &= 0x7F; /* Unset DCE field*/

rc = lin_tape_ibmtape_modeselect(device, buf, sizeof(buf));
rc = lin_tape_ibmtape_modeselect(device, buf, sizeof(buf), false);

ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_SETCOMPRS));
return rc;
Expand Down Expand Up @@ -2800,7 +2800,7 @@ int lin_tape_ibmtape_set_default(void *device)
buf[1] = 0x00;
buf[24] = 0x0C;

rc = lin_tape_ibmtape_modeselect(device, buf, sizeof(buf));
rc = lin_tape_ibmtape_modeselect(device, buf, sizeof(buf), false);
if (rc != DEVICE_GOOD) {
ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_SETDEFAULT));
return rc;
Expand Down Expand Up @@ -3360,7 +3360,7 @@ int lin_tape_ibmtape_setcap(void *device, uint16_t proportion)
buf[27] |= 0x01;
buf[28] = 0x00;

rc = lin_tape_ibmtape_modeselect(device, buf, sizeof(buf));
rc = lin_tape_ibmtape_modeselect(device, buf, sizeof(buf), false);
} else {

memset(&spt, 0, sizeof(spt));
Expand Down
15 changes: 8 additions & 7 deletions src/tape_drivers/linux/sg/sg_tape.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include <string.h>
#include <unistd.h>
#include <dirent.h>
#include <stdbool.h>
#include <sys/ioctl.h>

#include "libltfs/ltfs_error.h"
Expand Down Expand Up @@ -114,7 +115,7 @@ int sg_space(void *device, size_t count, TC_SPACE_TYPE type, struct tc_position
int sg_logsense(void *device, const uint8_t page, const uint8_t subpage, unsigned char *buf, const size_t size);
int sg_modesense(void *device, const unsigned char page, const TC_MP_PC_TYPE pc,
const unsigned char subpage, unsigned char *buf, const size_t size);
int sg_modeselect(void *device, unsigned char *buf, const size_t size);
int sg_modeselect(void *device, unsigned char *buf, const size_t size, bool save);
static const char *_generate_product_name(const char *product_id);

/* Local functions */
Expand Down Expand Up @@ -234,7 +235,7 @@ static int _set_lbp(void *device, bool enable)
buf[22] = 0;
}

ret = sg_modeselect(device, buf, sizeof(buf));
ret = sg_modeselect(device, buf, sizeof(buf), false);

if (ret == DEVICE_GOOD) {
if (enable) {
Expand Down Expand Up @@ -2965,7 +2966,7 @@ int sg_setcap(void *device, uint16_t proportion)
buf[27] |= 0x01;
buf[28] = 0x00;

ret = sg_modeselect(device, buf, sizeof(buf));
ret = sg_modeselect(device, buf, sizeof(buf), false);
} else {
/* Zero out the CDB and the result buffer */
ret = init_sg_io_header(&req);
Expand Down Expand Up @@ -3350,7 +3351,7 @@ int sg_modesense(void *device, const unsigned char page, const TC_MP_PC_TYPE pc,
return ret;
}

int sg_modeselect(void *device, unsigned char *buf, const size_t size)
int sg_modeselect(void *device, unsigned char *buf, const size_t size, bool save)
{
int ret = -EDEV_UNKNOWN;
int ret_ep = DEVICE_GOOD;
Expand Down Expand Up @@ -3384,7 +3385,7 @@ int sg_modeselect(void *device, unsigned char *buf, const size_t size)
* specific mode page
* Right now SDE and LE does not set any non savable pages, but this could change.
* */
cdb[1] = 0x11;
cdb[1] = 0x10 | (save? 1 : 0);
ltfs_u16tobe(cdb + 7, size);

timeout = get_timeout(priv->timeouts, cdb[0]);
Expand Down Expand Up @@ -3800,7 +3801,7 @@ int sg_set_compression(void *device, const bool enable_compression, struct tc_po
else
buf[18] = buf[18] & 0x7E;

ret = sg_modeselect(device, buf, sizeof(buf));
ret = sg_modeselect(device, buf, sizeof(buf), false);

ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_SETCOMPRS));

Expand Down Expand Up @@ -3830,7 +3831,7 @@ int sg_set_default(void *device)
buf[1] = 0x00;
buf[24] = 0x0C;

ret = sg_modeselect(device, buf, sizeof(buf));
ret = sg_modeselect(device, buf, sizeof(buf), false);
if (ret < 0) {
ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_SETDEFAULT));
return ret;
Expand Down
8 changes: 4 additions & 4 deletions src/tape_drivers/netbsd/scsipi-ibmtape/scsipi_ibmtape.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ static int _set_lbp(void *device, bool enable)
buf[22] = 0;
}

ret = scsipi_ibmtape_modeselect(device, buf, sizeof(buf));
ret = scsipi_ibmtape_modeselect(device, buf, sizeof(buf), false);

if (ret == DEVICE_GOOD) {
if (enable) {
Expand Down Expand Up @@ -2466,7 +2466,7 @@ int scsipi_ibmtape_setcap(void *device, uint16_t proportion)
buf[27] |= 0x01;
buf[28] = 0x00;

ret = scsipi_ibmtape_modeselect(device, buf, sizeof(buf));
ret = scsipi_ibmtape_modeselect(device, buf, sizeof(buf), false);
} else {
/* Zero out the CDB and the result buffer */
ret = init_scsireq(&req);
Expand Down Expand Up @@ -3258,7 +3258,7 @@ int scsipi_ibmtape_set_compression(void *device, const bool enable_compression,
else
buf[18] = buf[18] & 0x7E;

ret = scsipi_ibmtape_modeselect(device, buf, sizeof(buf));
ret = scsipi_ibmtape_modeselect(device, buf, sizeof(buf), false);

ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_SETCOMPRS));

Expand Down Expand Up @@ -3288,7 +3288,7 @@ int scsipi_ibmtape_set_default(void *device)
buf[1] = 0x00;
buf[24] = 0x0C;

ret = scsipi_ibmtape_modeselect(device, buf, sizeof(buf));
ret = scsipi_ibmtape_modeselect(device, buf, sizeof(buf), false);
if (ret < 0) {
ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_SETDEFAULT));
return ret;
Expand Down
12 changes: 6 additions & 6 deletions src/tape_drivers/osx/iokit/iokit_tape.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ int iokit_logsense(void *device, const uint8_t page, const uint8_t subpage,
unsigned char *buf, const size_t size);
int iokit_modesense(void *device, const unsigned char page, const TC_MP_PC_TYPE pc,
const unsigned char subpage, unsigned char *buf, const size_t size);
int iokit_modeselect(void *device, unsigned char *buf, const size_t size);
int iokit_modeselect(void *device, unsigned char *buf, const size_t size, bool save);
static const char *_generate_product_name(const char *product_id);

/* Local functions */
Expand Down Expand Up @@ -229,7 +229,7 @@ static int _set_lbp(void *device, bool enable)
buf[22] = 0;
}

ret = iokit_modeselect(device, buf, sizeof(buf));
ret = iokit_modeselect(device, buf, sizeof(buf), false);

if (ret == DEVICE_GOOD) {
if (enable) {
Expand Down Expand Up @@ -2198,7 +2198,7 @@ int iokit_setcap(void *device, uint16_t proportion)
buf[27] |= 0x01;
buf[28] = 0x00;

ret = iokit_modeselect(device, buf, sizeof(buf));
ret = iokit_modeselect(device, buf, sizeof(buf), false);
} else {
/* Zero out the CDB and the result buffer */
memset(cdb, 0, sizeof(cdb));
Expand Down Expand Up @@ -2524,7 +2524,7 @@ int iokit_modesense(void *device, const unsigned char page, const TC_MP_PC_TYPE
return ret;
}

int iokit_modeselect(void *device, unsigned char *buf, const size_t size)
int iokit_modeselect(void *device, unsigned char *buf, const size_t size, bool save)
{
int ret = -EDEV_UNKNOWN;
struct iokit_data *priv = (struct iokit_data*)device;
Expand Down Expand Up @@ -3011,7 +3011,7 @@ int iokit_set_compression(void *device, const bool enable_compression, struct tc
else
buf[18] = buf[18] & 0x7E;

ret = iokit_modeselect(device, buf, sizeof(buf));
ret = iokit_modeselect(device, buf, sizeof(buf), false);

ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_SETCOMPRS));

Expand Down Expand Up @@ -3041,7 +3041,7 @@ int iokit_set_default(void *device)
buf[1] = 0x00;
buf[24] = 0x0C;

ret = iokit_modeselect(device, buf, sizeof(buf));
ret = iokit_modeselect(device, buf, sizeof(buf), false);
if (ret < 0) {
ltfs_profiler_add_entry(priv->profiler, NULL, TAPEBEND_REQ_EXIT(REQ_TC_SETDEFAULT));
return ret;
Expand Down
Loading