From 3bc5f4d5d9c76e31107b592e3fd95ac0d8639675 Mon Sep 17 00:00:00 2001 From: Mauricio <68037616+madjesc@users.noreply.github.com> Date: Tue, 10 Nov 2026 17:17:51 -0600 Subject: [PATCH 1/2] fix: disable SavePage bit in other vendors (#664) --- src/libltfs/tape.c | 28 +++++++++++++++---- src/libltfs/tape_ops.h | 2 +- src/tape_drivers/freebsd/cam/cam_tc.c | 12 ++++---- src/tape_drivers/generic/file/filedebug_tc.c | 4 +-- src/tape_drivers/generic/itdtimg/itdtimg_tc.c | 2 +- .../linux/lin_tape/lin_tape_ibmtape.c | 8 +++--- src/tape_drivers/linux/sg/sg_tape.c | 15 +++++----- .../netbsd/scsipi-ibmtape/scsipi_ibmtape.c | 8 +++--- src/tape_drivers/osx/iokit/iokit_tape.c | 12 ++++---- 9 files changed, 54 insertions(+), 37 deletions(-) diff --git a/src/libltfs/tape.c b/src/libltfs/tape.c index 05068c00..3ac80318 100644 --- a/src/libltfs/tape.c +++ b/src/libltfs/tape.c @@ -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" @@ -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, ¤t_position); @@ -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); } @@ -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) */ @@ -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); @@ -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; @@ -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); @@ -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); @@ -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 */ diff --git a/src/libltfs/tape_ops.h b/src/libltfs/tape_ops.h index 34c7a128..14b129fb 100644 --- a/src/libltfs/tape_ops.h +++ b/src/libltfs/tape_ops.h @@ -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. diff --git a/src/tape_drivers/freebsd/cam/cam_tc.c b/src/tape_drivers/freebsd/cam/cam_tc.c index 7c7f82bd..6d708855 100644 --- a/src/tape_drivers/freebsd/cam/cam_tc.c +++ b/src/tape_drivers/freebsd/cam/cam_tc.c @@ -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; @@ -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; @@ -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; } @@ -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; @@ -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) @@ -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) diff --git a/src/tape_drivers/generic/file/filedebug_tc.c b/src/tape_drivers/generic/file/filedebug_tc.c index 2d486ebb..9bf4acf9 100644 --- a/src/tape_drivers/generic/file/filedebug_tc.c +++ b/src/tape_drivers/generic/file/filedebug_tc.c @@ -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: @@ -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; diff --git a/src/tape_drivers/generic/itdtimg/itdtimg_tc.c b/src/tape_drivers/generic/itdtimg/itdtimg_tc.c index 7a5d768f..14eab2a0 100644 --- a/src/tape_drivers/generic/itdtimg/itdtimg_tc.c +++ b/src/tape_drivers/generic/itdtimg/itdtimg_tc.c @@ -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; diff --git a/src/tape_drivers/linux/lin_tape/lin_tape_ibmtape.c b/src/tape_drivers/linux/lin_tape/lin_tape_ibmtape.c index f67e54e9..84add631 100644 --- a/src/tape_drivers/linux/lin_tape/lin_tape_ibmtape.c +++ b/src/tape_drivers/linux/lin_tape/lin_tape_ibmtape.c @@ -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; @@ -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; @@ -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; @@ -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)); diff --git a/src/tape_drivers/linux/sg/sg_tape.c b/src/tape_drivers/linux/sg/sg_tape.c index a47eab89..6ec9ee66 100644 --- a/src/tape_drivers/linux/sg/sg_tape.c +++ b/src/tape_drivers/linux/sg/sg_tape.c @@ -52,6 +52,7 @@ #include #include #include +#include #include #include "libltfs/ltfs_error.h" @@ -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 */ @@ -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) { @@ -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); @@ -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; @@ -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]); @@ -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)); @@ -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; diff --git a/src/tape_drivers/netbsd/scsipi-ibmtape/scsipi_ibmtape.c b/src/tape_drivers/netbsd/scsipi-ibmtape/scsipi_ibmtape.c index 0ea8df55..b339cc25 100644 --- a/src/tape_drivers/netbsd/scsipi-ibmtape/scsipi_ibmtape.c +++ b/src/tape_drivers/netbsd/scsipi-ibmtape/scsipi_ibmtape.c @@ -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) { @@ -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); @@ -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)); @@ -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; diff --git a/src/tape_drivers/osx/iokit/iokit_tape.c b/src/tape_drivers/osx/iokit/iokit_tape.c index 7b72d2ff..e93ba1fa 100644 --- a/src/tape_drivers/osx/iokit/iokit_tape.c +++ b/src/tape_drivers/osx/iokit/iokit_tape.c @@ -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 */ @@ -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) { @@ -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)); @@ -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; @@ -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)); @@ -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; From 44e2da21af6d710d0718a0369e38a4c1742dfb59 Mon Sep 17 00:00:00 2001 From: Alexandra Rangel Date: Wed, 11 Nov 2026 14:45:06 -0600 Subject: [PATCH 2/2] update: set release version to 2.4.9.1 (#667) --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index fa2235d4..db91859f 100644 --- a/VERSION +++ b/VERSION @@ -1,2 +1,2 @@ -2.4.9.0 +2.4.9.1 (Prelim)