[stgt] [PATCH 5/8] ssc: make the on-disk blk_header strcutre big endian
FUJITA Tomonori
fujita.tomonori at lab.ntt.co.jp
Sun Oct 12 06:38:50 CEST 2008
The on-disk blk_header structure was stored in machine endian so the
ssc image file has no compatibility among big and little endian
architecutres. This patch makes the on-disk blk_header structure big
endian.
Signed-off-by: FUJITA Tomonori <fujita.tomonori at lab.ntt.co.jp>
---
usr/bs_ssc.c | 139 +++++++++++++++++++++++--------------------------------
usr/bs_ssc.h | 5 +-
usr/dump_tape.c | 12 ++---
usr/libssc.c | 38 +++++++++++----
usr/libssc.h | 4 +-
usr/mktape.c | 42 ++++++++---------
usr/ssc.h | 12 ++++-
7 files changed, 126 insertions(+), 126 deletions(-)
diff --git a/usr/bs_ssc.c b/usr/bs_ssc.c
index 1adc02f..6d81318 100644
--- a/usr/bs_ssc.c
+++ b/usr/bs_ssc.c
@@ -70,7 +70,7 @@ static int32_t be24_to_2comp(uint8_t *c)
static int skip_next_header(struct scsi_lu *lu)
{
struct ssc_info *ssc = dtype_priv(lu);
- struct blk_header *h = ssc->c_blk;
+ struct blk_header_info *h = &ssc->c_blk;
return ssc_read_blkhdr(lu->fd, h, h->next);
}
@@ -79,7 +79,7 @@ static int skip_prev_header(struct scsi_lu *lu)
{
ssize_t rd;
struct ssc_info *ssc = dtype_priv(lu);
- struct blk_header *h = ssc->c_blk;
+ struct blk_header_info *h = &ssc->c_blk;
rd = ssc_read_blkhdr(lu->fd, h, h->prev);
if (rd)
@@ -94,16 +94,15 @@ static int resp_rewind(struct scsi_lu *lu)
int fd;
ssize_t rd;
struct ssc_info *ssc = dtype_priv(lu);
- struct blk_header *h;
+ struct blk_header_info *h = &ssc->c_blk;
- h = ssc->c_blk;
fd = lu->fd;
eprintf("*** Backing store fd: %s %d %d ***\n", lu->path, lu->fd, fd);
rd = ssc_read_blkhdr(fd, h, 0);
if (rd) {
- eprintf("Could not read %Zd bytes:%m\n", sizeof(*h));
+ eprintf("fail to read the first block header\n");
return 1;
}
@@ -111,33 +110,25 @@ static int resp_rewind(struct scsi_lu *lu)
}
static int append_blk(struct scsi_cmd *cmd, uint8_t *data,
- int size, int orig_sz, int type)
+ int size, int orig_sz, int type)
{
int fd;
- struct blk_header *curr;
- struct blk_header *eod;
- struct ssc_info *ssc;
+ struct ssc_info *ssc = dtype_priv(cmd->dev);
+ struct blk_header_info c, *curr = &c;
+ struct blk_header_info e, *eod = &e;
ssize_t ret;
- ssc = dtype_priv(cmd->dev);
fd = cmd->dev->fd;
-
- eod = zalloc(sizeof(struct blk_header));
- if (!eod) {
- eprintf("Failed to malloc %" PRId64 " bytes\n",
- (uint64_t)sizeof(eod));
- return -ENOMEM;
- }
+ *curr = ssc->c_blk;
eprintf("B4 update : prev/curr/next"
" <%" PRId64 "/%" PRId64 "/%" PRId64 "> type: %d,"
" num: %" PRIx64 ", ondisk sz: %d, about to write %d\n",
- ssc->c_blk->prev, ssc->c_blk->curr, ssc->c_blk->next,
- ssc->c_blk->blk_type, ssc->c_blk->blk_num,
- ssc->c_blk->ondisk_sz, size);
+ curr->prev, curr->curr, curr->next,
+ curr->blk_type, curr->blk_num,
+ curr->ondisk_sz, size);
- curr = ssc->c_blk;
- curr->next = curr->curr + size + sizeof(struct blk_header);
+ curr->next = curr->curr + size + SSC_BLK_HDR_SIZE;
curr->blk_type = type;
curr->ondisk_sz = size;
curr->blk_sz = orig_sz;
@@ -148,9 +139,8 @@ static int append_blk(struct scsi_cmd *cmd, uint8_t *data,
eod->blk_sz = 0;
eod->blk_type = BLK_EOD;
eod->blk_num = curr->blk_num + 1;
- eod->a = 'A';
- eod->z = 'Z';
- ssc->c_blk = eod;
+
+ memcpy(&ssc->c_blk, eod, sizeof(*eod));
eprintf("After update : prev/curr/next"
" <%" PRId64 "/%" PRId64 "/%" PRId64 "> type: %d,"
@@ -171,36 +161,31 @@ static int append_blk(struct scsi_cmd *cmd, uint8_t *data,
if (ret) {
eprintf("Rewrite of blk header failed: %m\n");
sense_data_build(cmd, MEDIUM_ERROR, ASC_WRITE_ERROR);
- goto failed_write;
+ return SAM_STAT_CHECK_CONDITION;
}
/* Write new EOD blk header */
ret = ssc_write_blkhdr(fd, eod, eod->curr);
if (ret) {
eprintf("Write of EOD blk header failed: %m\n");
sense_data_build(cmd, MEDIUM_ERROR, ASC_WRITE_ERROR);
- goto failed_write;
+ return SAM_STAT_CHECK_CONDITION;
}
/* Write any data */
if (size) {
ret = pwrite(fd, data, size,
- (off_t)curr->curr + sizeof(struct blk_header));
+ (off_t)curr->curr + SSC_BLK_HDR_SIZE);
if (ret != size) {
eprintf("Write of data failed: %m\n");
sense_data_build(cmd, MEDIUM_ERROR, ASC_WRITE_ERROR);
- goto failed_write;
+ return SAM_STAT_CHECK_CONDITION;
}
}
/* Write new EOD blk header */
fsync(fd);
- free(curr);
return SAM_STAT_GOOD;
-
-failed_write:
- free(curr);
- return SAM_STAT_CHECK_CONDITION;
}
#define SENSE_FILEMARK 0x80
@@ -208,16 +193,17 @@ failed_write:
static int space_filemark_reverse(struct scsi_cmd *cmd, int32_t count)
{
struct ssc_info *ssc = dtype_priv(cmd->dev);
+ struct blk_header_info *h = &ssc->c_blk;
count *= -1;
again:
- if (!ssc->c_blk->prev) {
+ if (!h->prev) {
sense_data_build(cmd, NO_SENSE, ASC_BOM);
return SAM_STAT_CHECK_CONDITION;
}
- if (ssc->c_blk->blk_type == BLK_FILEMARK)
+ if (h->blk_type == BLK_FILEMARK)
count--;
if (skip_prev_header(cmd->dev)) {
@@ -235,14 +221,15 @@ again:
static int space_filemark_forward(struct scsi_cmd *cmd, int32_t count)
{
struct ssc_info *ssc = dtype_priv(cmd->dev);
+ struct blk_header_info *h = &ssc->c_blk;
again:
- if (ssc->c_blk->blk_type == BLK_EOD) {
+ if (h->blk_type == BLK_EOD) {
sense_data_build(cmd, NO_SENSE, ASC_END_OF_DATA);
return SAM_STAT_CHECK_CONDITION;
}
- if (ssc->c_blk->blk_type == BLK_FILEMARK)
+ if (h->blk_type == BLK_FILEMARK)
count--;
if (skip_next_header(cmd->dev)) {
@@ -260,9 +247,10 @@ again:
static int space_filemark(struct scsi_cmd *cmd, int32_t count)
{
struct ssc_info *ssc = dtype_priv(cmd->dev);
+ struct blk_header_info *h = &ssc->c_blk;
int result;
- eprintf("*** space %d filemarks, %llu\n", count, ssc->c_blk->curr);
+ eprintf("*** space %d filemarks, %llu\n", count, h->curr);
if (count > 0)
result = space_filemark_forward(cmd, count);
@@ -271,7 +259,7 @@ static int space_filemark(struct scsi_cmd *cmd, int32_t count)
else
result = SAM_STAT_GOOD;
- eprintf("%llu\n", ssc->c_blk->curr);
+ eprintf("%llu\n", h->curr);
return result;
}
@@ -279,8 +267,9 @@ static int space_filemark(struct scsi_cmd *cmd, int32_t count)
static int space_blocks(struct scsi_cmd *cmd, int32_t count)
{
struct ssc_info *ssc = dtype_priv(cmd->dev);
+ struct blk_header_info *h = &ssc->c_blk;
- eprintf("*** space %d blocks, %llu\n", count, ssc->c_blk->curr);
+ eprintf("*** space %d blocks, %llu\n", count, h->curr);
while (count != 0) {
if (count > 0) {
@@ -289,7 +278,7 @@ static int space_blocks(struct scsi_cmd *cmd, int32_t count)
ASC_MEDIUM_FORMAT_CORRUPT);
return SAM_STAT_CHECK_CONDITION;
}
- if (ssc->c_blk->blk_type == BLK_EOD) {
+ if (h->blk_type == BLK_EOD) {
sense_data_build(cmd, NO_SENSE,
ASC_END_OF_DATA);
return SAM_STAT_CHECK_CONDITION;
@@ -301,7 +290,7 @@ static int space_blocks(struct scsi_cmd *cmd, int32_t count)
ASC_MEDIUM_FORMAT_CORRUPT);
return SAM_STAT_CHECK_CONDITION;
}
- if (ssc->c_blk->blk_type == BLK_BOT) {
+ if (h->blk_type == BLK_BOT) {
/* Can't leave at BOT */
skip_next_header(cmd->dev);
@@ -311,7 +300,7 @@ static int space_blocks(struct scsi_cmd *cmd, int32_t count)
count++;
}
}
- eprintf("%llu\n", ssc->c_blk->curr);
+ eprintf("%llu\n", h->curr);
return SAM_STAT_GOOD;
}
@@ -319,19 +308,20 @@ static int resp_var_read(struct scsi_cmd *cmd, uint8_t *buf, uint32_t length,
int *transferred)
{
struct ssc_info *ssc = dtype_priv(cmd->dev);
+ struct blk_header_info *h = &ssc->c_blk;
int ret = 0, result = SAM_STAT_GOOD;
length = min(length, get_unaligned_be24(&cmd->scb[2]));
*transferred = 0;
- if (length != ssc->c_blk->blk_sz) {
- if (ssc->c_blk->blk_type == BLK_EOD)
+ if (length != h->blk_sz) {
+ if (h->blk_type == BLK_EOD)
sense_data_build(cmd, 0x40 | BLANK_CHECK,
NO_ADDITIONAL_SENSE);
else
sense_data_build(cmd, NO_SENSE, NO_ADDITIONAL_SENSE);
- length = min(length, ssc->c_blk->blk_sz);
+ length = min(length, h->blk_sz);
result = SAM_STAT_CHECK_CONDITION;
scsi_set_in_resid_by_actual(cmd, length);
@@ -339,8 +329,7 @@ static int resp_var_read(struct scsi_cmd *cmd, uint8_t *buf, uint32_t length,
goto out;
}
- ret = pread(cmd->dev->fd, buf, length,
- ssc->c_blk->curr + sizeof(struct blk_header));
+ ret = pread(cmd->dev->fd, buf, length, h->curr + SSC_BLK_HDR_SIZE);
if (ret != length) {
sense_data_build(cmd, MEDIUM_ERROR, ASC_READ_ERROR);
result = SAM_STAT_CHECK_CONDITION;
@@ -360,7 +349,8 @@ out:
static int resp_fixed_read(struct scsi_cmd *cmd, uint8_t *buf, uint32_t length,
int *transferred)
{
- struct ssc_info *ssc;
+ struct ssc_info *ssc = dtype_priv(cmd->dev);
+ struct blk_header_info *h = &ssc->c_blk;
int i, ret, result = SAM_STAT_GOOD;
int count;
ssize_t residue;
@@ -368,12 +358,11 @@ static int resp_fixed_read(struct scsi_cmd *cmd, uint8_t *buf, uint32_t length,
uint32_t block_length = ssc_get_block_length(cmd->dev);
count = get_unaligned_be24(&cmd->scb[2]);
- ssc = dtype_priv(cmd->dev);
fd = cmd->dev->fd;
ret = 0;
for (i = 0; i < count; i++) {
- if (ssc->c_blk->blk_type == BLK_FILEMARK) {
+ if (h->blk_type == BLK_FILEMARK) {
uint8_t info[4];
eprintf("Oops - found filemark\n");
@@ -385,9 +374,9 @@ static int resp_fixed_read(struct scsi_cmd *cmd, uint8_t *buf, uint32_t length,
goto out;
}
- if (block_length != ssc->c_blk->blk_sz) {
+ if (block_length != h->blk_sz) {
eprintf("block size mismatch %d vs %d\n",
- block_length, ssc->c_blk->blk_sz);
+ block_length, h->blk_sz);
sense_data_build(cmd, MEDIUM_ERROR,
ASC_MEDIUM_FORMAT_CORRUPT);
result = SAM_STAT_CHECK_CONDITION;
@@ -395,7 +384,7 @@ static int resp_fixed_read(struct scsi_cmd *cmd, uint8_t *buf, uint32_t length,
}
residue = pread(fd, buf, block_length,
- ssc->c_blk->curr + sizeof(struct blk_header));
+ h->curr + SSC_BLK_HDR_SIZE);
if (block_length != residue) {
eprintf("Could only read %d bytes, not %d\n",
(int)residue, block_length);
@@ -422,7 +411,8 @@ out:
static void tape_rdwr_request(struct scsi_cmd *cmd)
{
- struct ssc_info *ssc;
+ struct ssc_info *ssc = dtype_priv(cmd->dev);
+ struct blk_header_info *h = &ssc->c_blk;
int ret, code;
uint32_t length, i, transfer_length, residue;
int result = SAM_STAT_GOOD;
@@ -477,14 +467,13 @@ static void tape_rdwr_request(struct scsi_cmd *cmd)
buf = scsi_get_in_buffer(cmd);
eprintf("*** READ_6: length %d, count %d, fixed block %s, %llu, %d\n",
- length, count, (fixed) ? "Yes" : "No", ssc->c_blk->curr, sti);
+ length, count, (fixed) ? "Yes" : "No", h->curr, sti);
if (fixed)
result = resp_fixed_read(cmd, buf, length, &ret);
else
result = resp_var_read(cmd, buf, length, &ret);
- eprintf("Executed READ_6, Read %d bytes, %llu\n", ret,
- ssc->c_blk->curr);
+ eprintf("Executed READ_6, Read %d bytes, %llu\n", ret, h->curr);
break;
case WRITE_6:
@@ -533,7 +522,7 @@ static void tape_rdwr_request(struct scsi_cmd *cmd)
result = space_filemark(cmd, count);
break;
} else if (code == 3) { /* End of data */
- while (ssc->c_blk->blk_type != BLK_EOD)
+ while (h->blk_type != BLK_EOD)
if (skip_next_header(cmd->dev)) {
sense_data_build(cmd, MEDIUM_ERROR,
ASC_MEDIUM_FORMAT_CORRUPT);
@@ -601,6 +590,7 @@ static int bs_tape_open(struct scsi_lu *lu, char *path, int *fd, uint64_t *size)
char *cart = NULL;
ssize_t rd;
int ret;
+ struct blk_header_info *h;
ssc = dtype_priv(lu);
@@ -612,35 +602,30 @@ static int bs_tape_open(struct scsi_lu *lu, char *path, int *fd, uint64_t *size)
}
eprintf("*** Backing store fd: %d ***\n", *fd);
- if (*size < (sizeof(struct blk_header) + sizeof(struct MAM))) {
+ if (*size < SSC_BLK_HDR_SIZE + sizeof(struct MAM)) {
eprintf("backing file too small - not correct media format\n");
return -1;
}
- if (!ssc->c_blk)
- ssc->c_blk = zalloc(sizeof(struct blk_header));
- if (!ssc->c_blk) {
- eprintf("malloc(%d) failed\n", (int)sizeof(struct blk_header));
- goto read_failed;
- }
+ h = &ssc->c_blk;
/* Can't call 'resp_rewind() at this point as lu data not
* setup */
- rd = ssc_read_blkhdr(*fd, ssc->c_blk, 0);
+ rd = ssc_read_blkhdr(*fd, h, 0);
if (rd) {
eprintf("Failed to read complete blk header: %d %m\n", (int)rd);
- goto read_failed;
+ return -1;
}
ret = ssc_read_mam_info(*fd, &ssc->mam);
if (ret) {
eprintf("Failed to read MAM: %d %m\n", (int)rd);
- goto read_failed;
+ return -1;
}
- rd = ssc_read_blkhdr(*fd, ssc->c_blk, ssc->c_blk->next);
+ rd = ssc_read_blkhdr(*fd, h, h->next);
if (rd) {
eprintf("Failed to read complete blk header: %d %m\n", (int)rd);
- goto read_failed;
+ return -1;
}
switch (ssc->mam.medium_type) {
@@ -658,14 +643,8 @@ static int bs_tape_open(struct scsi_lu *lu, char *path, int *fd, uint64_t *size)
break;
}
- eprintf("Media size: %d, media type: %s\n",
- ssc->c_blk->blk_sz, cart);
+ eprintf("Media size: %d, media type: %s\n", h->blk_sz, cart);
return 0;
-
-read_failed:
- free(ssc->c_blk);
- ssc->c_blk = NULL;
- return -1;
}
static void bs_tape_exit(struct scsi_lu *lu)
@@ -678,8 +657,6 @@ static void bs_tape_close(struct scsi_lu *lu)
{
struct ssc_info *ssc;
ssc = dtype_priv(lu);
- free(ssc->c_blk);
- ssc->c_blk = NULL;
dprintf("##### Close #####\n");
close(lu->fd);
}
diff --git a/usr/bs_ssc.h b/usr/bs_ssc.h
index 85cf25f..b226330 100644
--- a/usr/bs_ssc.h
+++ b/usr/bs_ssc.h
@@ -29,8 +29,10 @@
#define TGT_TAPE_VERSION 2
+#define SSC_BLK_HDR_SIZE (sizeof(struct blk_header))
+
struct blk_header {
- uint8_t a;
+ uint8_t h_csum[4];
uint32_t ondisk_sz;
uint32_t blk_sz;
uint32_t blk_type;
@@ -38,7 +40,6 @@ struct blk_header {
uint64_t prev;
uint64_t curr;
uint64_t next;
- uint8_t z;
};
/*
diff --git a/usr/dump_tape.c b/usr/dump_tape.c
index 1816f8d..7b16925 100644
--- a/usr/dump_tape.c
+++ b/usr/dump_tape.c
@@ -35,13 +35,8 @@
#include "bs_ssc.h"
#include "libssc.h"
-void print_current_header(struct blk_header *pos)
+void print_current_header(struct blk_header_info *pos)
{
- if (pos->a != 'A')
- printf("head sanity check failed\n");
- if (pos->z != 'Z')
- printf("tail sanity check failed\n");
-
switch (pos->blk_type) {
case BLK_UNCOMPRESS_DATA:
printf(" Uncompressed data");
@@ -82,7 +77,7 @@ void print_current_header(struct blk_header *pos)
pos->ondisk_sz);
}
-int skip_to_next_header(int fd, struct blk_header *pos)
+int skip_to_next_header(int fd, struct blk_header_info *pos)
{
int ret;
@@ -100,7 +95,7 @@ int main(int argc, char *argv[])
char datafile[1024] = "";
loff_t nread;
struct MAM_info mam;
- struct blk_header current_position;
+ struct blk_header_info current_position;
time_t t;
int a;
unsigned char *p;
@@ -153,6 +148,7 @@ int main(int argc, char *argv[])
perror("Could not read MAM");
exit(1);
}
+
if (mam.tape_fmt_version != TGT_TAPE_VERSION) {
printf("Unknown media format version %x\n",
mam.tape_fmt_version);
diff --git a/usr/libssc.c b/usr/libssc.c
index eba7b74..6ef9517 100644
--- a/usr/libssc.c
+++ b/usr/libssc.c
@@ -26,7 +26,7 @@
#include "ssc.h"
#include "be_byteshift.h"
-#define SSC_1ST_HDR_OFFSET (sizeof(struct MAM) + sizeof(struct blk_header))
+#define SSC_1ST_HDR_OFFSET (sizeof(struct MAM) + SSC_BLK_HDR_SIZE)
#define SSC_GET_MAM_INFO_VAL(member, bits)\
{\
@@ -50,7 +50,7 @@ int ssc_read_mam_info(int fd, struct MAM_info *i)
m = &mam;
- ret = pread(fd, m, sizeof(struct MAM), sizeof(struct blk_header));
+ ret = pread(fd, m, sizeof(struct MAM), SSC_BLK_HDR_SIZE);
if (ret != sizeof(struct MAM))
return 1;
@@ -169,7 +169,7 @@ int ssc_write_mam_info(int fd, struct MAM_info *i)
SSC_PUT_MAM_INFO_VAL(dirty, 8);
- ret = pwrite(fd, m, sizeof(struct MAM), sizeof(struct blk_header));
+ ret = pwrite(fd, m, sizeof(struct MAM), SSC_BLK_HDR_SIZE);
if (ret != sizeof(struct MAM))
return 1;
@@ -179,23 +179,41 @@ int ssc_write_mam_info(int fd, struct MAM_info *i)
return 0;
}
-int ssc_read_blkhdr(int fd, struct blk_header *h, off_t offset)
+int ssc_read_blkhdr(int fd, struct blk_header_info *i, off_t offset)
{
size_t count;
+ struct blk_header h, *m = &h;
- count = pread(fd, h, sizeof(*h), offset);
- if (count != sizeof(*h))
+ count = pread(fd, m, SSC_BLK_HDR_SIZE, offset);
+ if (count != SSC_BLK_HDR_SIZE)
return 1;
+ SSC_GET_MAM_INFO_VAL(ondisk_sz, 32);
+ SSC_GET_MAM_INFO_VAL(blk_sz, 32);
+ SSC_GET_MAM_INFO_VAL(blk_type, 32);
+ SSC_GET_MAM_INFO_VAL(blk_num, 64);
+ SSC_GET_MAM_INFO_VAL(prev, 64);
+ SSC_GET_MAM_INFO_VAL(curr, 64);
+ SSC_GET_MAM_INFO_VAL(next, 64);
+
return 0;
}
-int ssc_write_blkhdr(int fd, struct blk_header *h, off_t offset)
+int ssc_write_blkhdr(int fd, struct blk_header_info *i, off_t offset)
{
size_t count;
-
- count = pwrite(fd, h, sizeof(*h), offset);
- if (count != sizeof(*h))
+ struct blk_header h, *m = &h;
+
+ SSC_PUT_MAM_INFO_VAL(ondisk_sz, 32);
+ SSC_PUT_MAM_INFO_VAL(blk_sz, 32);
+ SSC_PUT_MAM_INFO_VAL(blk_type, 32);
+ SSC_PUT_MAM_INFO_VAL(blk_num, 64);
+ SSC_PUT_MAM_INFO_VAL(prev, 64);
+ SSC_PUT_MAM_INFO_VAL(curr, 64);
+ SSC_PUT_MAM_INFO_VAL(next, 64);
+
+ count = pwrite(fd, m, SSC_BLK_HDR_SIZE, offset);
+ if (count != SSC_BLK_HDR_SIZE)
return 1;
return 0;
diff --git a/usr/libssc.h b/usr/libssc.h
index b278509..ace2037 100644
--- a/usr/libssc.h
+++ b/usr/libssc.h
@@ -3,7 +3,7 @@
extern int ssc_read_mam_info(int fd, struct MAM_info *i);
extern int ssc_write_mam_info(int fd, struct MAM_info *i);
-extern int ssc_read_blkhdr(int fd, struct blk_header *h, off_t offset);
-extern int ssc_write_blkhdr(int fd, struct blk_header *h, off_t offset);
+extern int ssc_read_blkhdr(int fd, struct blk_header_info *h, off_t offset);
+extern int ssc_write_blkhdr(int fd, struct blk_header_info *h, off_t offset);
#endif
diff --git a/usr/mktape.c b/usr/mktape.c
index 20cb709..ca6c826 100644
--- a/usr/mktape.c
+++ b/usr/mktape.c
@@ -49,7 +49,7 @@ void usage(char *progname)
int main(int argc, char *argv[])
{
int file;
- struct blk_header h;
+ struct blk_header_info hdr, *h = &hdr;
struct MAM_info mi;
uint8_t current_media[1024];
char *progname = argv[0];
@@ -118,19 +118,18 @@ int main(int argc, char *argv[])
if (size == 0)
size = 8000;
- h.a = 'A';
- h.z = 'Z';
- h.blk_type = BLK_BOT;
- h.blk_num = 0;
- h.blk_sz = size;
- h.prev = 0;
- h.curr = 0;
- h.next = sizeof(struct MAM) + sizeof(h);
+ memset(h, 0, sizeof(h));
+ h->blk_type = BLK_BOT;
+ h->blk_num = 0;
+ h->blk_sz = size;
+ h->prev = 0;
+ h->curr = 0;
+ h->next = sizeof(struct MAM) + SSC_BLK_HDR_SIZE;
printf("blk_sz: %d, next %" PRId64 ", %" PRId64 "\n",
- h.blk_sz, h.next, h.next);
+ h->blk_sz, h->next, h->next);
printf("Sizeof(mam): %" PRId64 ", sizeof(h): %" PRId64 "\n",
- (uint64_t)sizeof(struct MAM), (uint64_t)sizeof(h));
+ (uint64_t)sizeof(struct MAM), (uint64_t)SSC_BLK_HDR_SIZE);
memset(&mi, 0, sizeof(mi));
@@ -165,7 +164,7 @@ int main(int argc, char *argv[])
exit(2);
}
- ret = ssc_write_blkhdr(file, &h, 0);
+ ret = ssc_write_blkhdr(file, h, 0);
if (ret) {
perror("Unable to write header");
exit(1);
@@ -176,16 +175,15 @@ int main(int argc, char *argv[])
perror("Unable to write MAM");
exit(1);
}
- memset(&h, 0, sizeof(h));
- h.a = 'A';
- h.z = 'Z';
- h.blk_type = BLK_EOD;
- h.blk_num = 1;
- h.prev = 0;
- h.next = lseek64(file, 0, SEEK_CUR);
- h.curr = h.next;
-
- ret = ssc_write_blkhdr(file, &h, h.next);
+
+ memset(h, 0, sizeof(h));
+ h->blk_type = BLK_EOD;
+ h->blk_num = 1;
+ h->prev = 0;
+ h->next = lseek64(file, 0, SEEK_CUR);
+ h->curr = h->next;
+
+ ret = ssc_write_blkhdr(file, h, h->next);
if (ret) {
perror("Unable to write header");
exit(1);
diff --git a/usr/ssc.h b/usr/ssc.h
index dcd1337..b72f2bc 100644
--- a/usr/ssc.h
+++ b/usr/ssc.h
@@ -5,6 +5,16 @@
#ifndef _SSC_H_
#define _SSC_H_
+struct blk_header_info {
+ uint32_t ondisk_sz;
+ uint32_t blk_sz;
+ uint32_t blk_type;
+ uint64_t blk_num;
+ uint64_t prev;
+ uint64_t curr;
+ uint64_t next;
+};
+
/*
* MAM structure based from IBM Ultrium SCSI Reference WB1109-02
*/
@@ -59,7 +69,7 @@ struct ssc_info {
struct MAM_info mam;
- struct blk_header *c_blk; /* Current block header */
+ struct blk_header_info c_blk; /* Current block header */
};
#endif
--
1.5.6.5
--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
More information about the stgt
mailing list