Add support for COMPARE_AND_WRITE command

This commit is contained in:
Ronnie Sahlberg
2012-07-14 11:34:40 +10:00
parent f6705d4691
commit bdd6e6bb11
7 changed files with 126 additions and 0 deletions

View File

@@ -981,6 +981,53 @@ scsi_cdb_write16(uint64_t lba, uint32_t xferlen, int blocksize, int wrprotect, i
return task;
}
/*
* COMPAREANDWRITE
*/
struct scsi_task *
scsi_cdb_compareandwrite(uint64_t lba, uint8_t xferlen, int blocksize, int wrprotect, int dpo, int fua, int fua_nv, int group_number)
{
struct scsi_task *task;
task = malloc(sizeof(struct scsi_task));
if (task == NULL) {
return NULL;
}
memset(task, 0, sizeof(struct scsi_task));
task->cdb[0] = SCSI_OPCODE_COMPARE_AND_WRITE;
task->cdb[1] |= ((wrprotect & 0x07) << 5);
if (dpo) {
task->cdb[1] |= 0x10;
}
if (fua) {
task->cdb[1] |= 0x08;
}
if (fua_nv) {
task->cdb[1] |= 0x02;
}
*(uint32_t *)&task->cdb[2] = htonl(lba >> 32);
*(uint32_t *)&task->cdb[6] = htonl(lba & 0xffffffff);
task->cdb[13] = xferlen/blocksize;
task->cdb[14] |= (group_number & 0x1f);
task->cdb_size = 16;
if (xferlen != 0) {
task->xfer_dir = SCSI_XFER_WRITE;
} else {
task->xfer_dir = SCSI_XFER_NONE;
}
task->expxferlen = xferlen;
task->params.compareandwrite.lba = lba;
task->params.compareandwrite.num_blocks = xferlen/blocksize;
return task;
}
/*
* VERIFY10
*/