diff --git a/messages/internal_error/root.txt b/messages/internal_error/root.txt index 685b26dc..4ca96eec 100644 --- a/messages/internal_error/root.txt +++ b/messages/internal_error/root.txt @@ -251,6 +251,7 @@ root:table { I1198E:string{ "The tape is already removed." } I1199E:string{ "You need to move tape to a storage slot first before the operation." } I1200E:string{ "The operation needs to be started again." } + I1201E:string{ "Locate returns write-perm error." } // Special error codes I9997E:string{ "Child process error (ltfsck/mkltfs): %s (%d)." } diff --git a/messages/libltfs/root.txt b/messages/libltfs/root.txt index eb867875..dfe74acc 100644 --- a/messages/libltfs/root.txt +++ b/messages/libltfs/root.txt @@ -808,6 +808,7 @@ v 17264I:string { "The index on %s is newer, but MAM shows a permanent write error happened on %s." } 17265I:string { "Skip writing the index because of %s." } 17266I:string { "Skip setting the append only mode because the drive doesn't seem to support it." } + 17267E:string { "Locate command returns write-perm error (%d). Replace a return code to %d." } // For Debug 19999I:string { "%s %s %d." } diff --git a/src/libltfs/arch/errormap.c b/src/libltfs/arch/errormap.c index 748f1bd1..f3ad3d52 100644 --- a/src/libltfs/arch/errormap.c +++ b/src/libltfs/arch/errormap.c @@ -286,6 +286,7 @@ static struct error_map fuse_error_list[] = { { LTFS_TAPE_REMOVED, "I1198E", EIDRM}, { LTFS_NEED_MOVE, "I1199E", EINVAL}, { LTFS_NEED_START_OVER, "I1200E", EINVAL}, + { LTFS_LOCATE_ERROR, "I1201E", EIO}, { EDEV_NO_SENSE, "D0000E", EIO}, { EDEV_OVERRUN, "D0002E", EIO}, diff --git a/src/libltfs/ltfs_error.h b/src/libltfs/ltfs_error.h index a7abe8ce..d7aa6034 100644 --- a/src/libltfs/ltfs_error.h +++ b/src/libltfs/ltfs_error.h @@ -257,6 +257,7 @@ #define LTFS_TAPE_REMOVED 1198 /* The tape is already removed */ #define LTFS_NEED_MOVE 1199 /* Need to move tape to a storage slot first before the operation */ #define LTFS_NEED_START_OVER 1200 /* Need operation needs to be started again */ +#define LTFS_LOCATE_ERROR 1201 /* Locate returns write-perm error */ #define LTFS_ERR_MAX 19999 diff --git a/src/libltfs/tape.c b/src/libltfs/tape.c index f23c9f2a..d6ae97c9 100644 --- a/src/libltfs/tape.c +++ b/src/libltfs/tape.c @@ -851,6 +851,7 @@ int tape_seek_append_position(struct device_data *dev, tape_partition_t prt, boo if (ret < 0) { ltfsmsg(LTFS_ERR, 12033E, ret); dev->write_error = true; + return ret; } @@ -996,7 +997,7 @@ int tape_rewind(struct device_data *dev) */ int tape_seek(struct device_data *dev, struct tc_position *pos) { - int ret; + int ret = 0; CHECK_ARG_NULL(dev, -LTFS_NULL_ARG); CHECK_ARG_NULL(pos, -LTFS_NULL_ARG); @@ -1016,8 +1017,14 @@ int tape_seek(struct device_data *dev, struct tc_position *pos) ltfs_mutex_unlock(&dev->read_only_flag_mutex); } } - else { - ret = 0; + + if (IS_WRITE_PERM(-ret)) { + /* + * LOCATE command must not return a WRITE_PERM related error. + * LOCATE is actually read operation, it doesn't make sense to return a WRITE_PERM at all. + */ + ltfsmsg(LTFS_ERR, 17267E, ret, -LTFS_LOCATE_ERROR); + ret = -LTFS_LOCATE_ERROR; } if (ret == 0 && (dev->position.partition != pos->partition || @@ -1051,6 +1058,14 @@ int tape_seek_eod(struct device_data *dev, tape_partition_t partition) ret = dev->backend->locate(dev->backend_data, seekpos, &dev->position); if (ret < 0) { ltfsmsg(LTFS_ERR, 12039E, ret); + if (IS_WRITE_PERM(-ret)) { + /* + * LOCATE command must not return a WRITE_PERM related error. + * LOCATE is actually read operation, it doesn't make sense to return a WRITE_PERM at all. + */ + ltfsmsg(LTFS_ERR, 17267E, ret, -LTFS_LOCATE_ERROR); + ret = -LTFS_LOCATE_ERROR; + } return ret; } @@ -1547,6 +1562,14 @@ int tape_unformat(struct device_data *dev) ret = dev->backend->locate(dev->backend_data, bom, &dev->position); if (ret < 0) { ltfsmsg(LTFS_ERR, 12054E, ret); + if (IS_WRITE_PERM(-ret)) { + /* + * LOCATE command must not return a WRITE_PERM related error. + * LOCATE is actually read operation, it doesn't make sense to return a WRITE_PERM at all. + */ + ltfsmsg(LTFS_ERR, 17267E, ret, -LTFS_LOCATE_ERROR); + ret = -LTFS_LOCATE_ERROR; + } return ret; }