示例#1
0
文件: bs_paio.c 项目: wtnb75/tgt
static int bs_paio_open(struct scsi_lu *lu, char *path, int *fd, uint64_t *size)
{
	*fd = backed_file_open(path, O_RDWR|O_LARGEFILE|O_DIRECT, size);
	/* If we get access denied, try opening the file in readonly mode */
	if (*fd == -1 && (errno == EACCES || errno == EROFS)) {
		*fd = backed_file_open(path, O_RDONLY|O_LARGEFILE|O_DIRECT,
				       size);
		lu->attrs.readonly = 1;
	}
	if (*fd < 0)
		return *fd;
	return 0;
}
示例#2
0
文件: bs_rdwr.c 项目: YankunLi/tgt
static int bs_rdwr_open(struct scsi_lu *lu, char *path, int *fd, uint64_t *size)
{
	uint32_t blksize = 0;

	*fd = backed_file_open(path, O_RDWR|O_LARGEFILE|lu->bsoflags, size,
				&blksize);
	/* If we get access denied, try opening the file in readonly mode */
	if (*fd == -1 && (errno == EACCES || errno == EROFS)) {
		*fd = backed_file_open(path, O_RDONLY|O_LARGEFILE|lu->bsoflags,
				       size, &blksize);
		lu->attrs.readonly = 1;
	}
	if (*fd < 0)
		return *fd;

	if (!lu->attrs.no_auto_lbppbe)
		update_lbppbe(lu, blksize);

	return 0;
}
示例#3
0
static struct tgt_device *bd_mmap_open(char *path, int *fd, uint64_t *size)
{
	struct tgt_device *dev;

	dev = zalloc(sizeof(*dev));
	if (!dev)
		return NULL;

	*fd = backed_file_open(path, O_RDWR| O_LARGEFILE, size);
	if (*fd < 0) {
		free(dev);
		dev = NULL;
	}

	return dev;
}
示例#4
0
static int bs_ssc_open(struct scsi_lu *lu, char *path, int *fd, uint64_t *size)
{
	struct ssc_info *ssc;
	char *cart = NULL;
	ssize_t rd;
	int ret;
	struct blk_header_info *h;

	ssc = dtype_priv(lu);

	*fd = backed_file_open(path, O_RDWR | O_LARGEFILE, size, NULL);
	if (*fd < 0) {
		eprintf("Could not open %s %m\n", path);
		return *fd;
	}
	eprintf("Backing store %s, %d\n", path, *fd);

	if (*size < SSC_BLK_HDR_SIZE + sizeof(struct MAM)) {
		eprintf("backing file too small - not correct media format\n");
		return -1;
	}

	h = &ssc->c_blk;
	/* Can't call 'resp_rewind() at this point as lu data not
	 * setup */
	rd = ssc_read_blkhdr(*fd, h, 0);
	if (rd) {
		eprintf("Failed to read complete blk header: %d %m\n", (int)rd);
		return -1;
	}

	ret = ssc_read_mam_info(*fd, &ssc->mam);
	if (ret) {
		eprintf("Failed to read MAM: %d %m\n", (int)rd);
		return -1;
	}

	rd = ssc_read_blkhdr(*fd, h, h->next);
	if (rd) {
		eprintf("Failed to read complete blk header: %d %m\n", (int)rd);
		return -1;
	}

	switch (ssc->mam.medium_type) {
	case CART_CLEAN:
		cart = "Cleaning cartridge";
		break;
	case CART_DATA:
		cart = "data cartridge";
		break;
	case CART_WORM:
		cart = "WORM cartridge";
		break;
	default:
		cart = "Unknown cartridge type";
		break;
	}

	dprintf("Media size: %d, media type: %s\n", h->blk_sz, cart);
	return 0;
}