亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? block-qcow.c

?? xen 3.2.2 源碼
?? C
?? 第 1 頁 / 共 3 頁
字號:
/* block-qcow.c * * Asynchronous Qemu copy-on-write disk implementation. * Code based on the Qemu implementation * (see copyright notice below) * * (c) 2006 Andrew Warfield and Julian Chesterfield * *//* * Block driver for the QCOW format *  * Copyright (c) 2004 Fabrice Bellard *  * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files(the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: */#include <errno.h>#include <fcntl.h>#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <sys/statvfs.h>#include <sys/stat.h>#include <sys/ioctl.h>#include <linux/fs.h>#include <string.h>#include <zlib.h>#include <inttypes.h>#include <libaio.h>#include <openssl/md5.h>#include "bswap.h"#include "aes.h"#include "tapdisk.h"#include "tapaio.h"#if 1#define ASSERT(_p) \    if ( !(_p) ) { DPRINTF("Assertion '%s' failed, line %d, file %s", #_p , \    __LINE__, __FILE__); *(int*)0=0; }#else#define ASSERT(_p) ((void)0)#endif#define ROUNDUP(l, s) \({ \    (uint64_t)( \        (l + (s - 1)) - ((l + (s - 1)) % s)); \})struct pending_aio {        td_callback_t cb;        int id;        void *private;	int nb_sectors;	char *buf;	uint64_t sector;};#define IOCB_IDX(_s, _io) ((_io) - (_s)->iocb_list)#define ZERO_TEST(_b) (_b | 0x00)/**************************************************************//* QEMU COW block driver with compression and encryption support */#define QCOW_MAGIC (('Q' << 24) | ('F' << 16) | ('I' << 8) | 0xfb)#define XEN_MAGIC  (('X' << 24) | ('E' << 16) | ('N' << 8) | 0xfb)#define QCOW_VERSION 1#define QCOW_CRYPT_NONE 0x00#define QCOW_CRYPT_AES  0x01#define QCOW_OFLAG_COMPRESSED (1LL << 63)#define SPARSE_FILE 0x01#ifndef O_BINARY#define O_BINARY 0#endiftypedef struct QCowHeader {	uint32_t magic;	uint32_t version;	uint64_t backing_file_offset;	uint32_t backing_file_size;	uint32_t mtime;	uint64_t size; /* in bytes */	uint8_t cluster_bits;	uint8_t l2_bits;	uint32_t crypt_method;	uint64_t l1_table_offset;} QCowHeader;/*Extended header for Xen enhancements*/typedef struct QCowHeader_ext {        uint32_t xmagic;        uint32_t cksum;        uint32_t min_cluster_alloc;        uint32_t flags;} QCowHeader_ext;#define L2_CACHE_SIZE 16  /*Fixed allocation in Qemu*/struct tdqcow_state {        int fd;                        /*Main Qcow file descriptor */	uint64_t fd_end;               /*Store a local record of file length */	char *name;                    /*Record of the filename*/	uint32_t backing_file_size;	uint64_t backing_file_offset;	int encrypted;                 /*File contents are encrypted or plain*/	int cluster_bits;              /*Determines length of cluster as 					*indicated by file hdr*/	int cluster_size;              /*Length of cluster*/	int cluster_sectors;           /*Number of sectors per cluster*/	int cluster_alloc;             /*Blktap fix for allocating full 					*extents*/	int min_cluster_alloc;         /*Blktap historical extent alloc*/	int sparse;                    /*Indicates whether to preserve sparseness*/	int l2_bits;                   /*Size of L2 table entry*/	int l2_size;                   /*Full table size*/	int l1_size;                   /*L1 table size*/	uint64_t cluster_offset_mask;    	uint64_t l1_table_offset;      /*L1 table offset from beginning of 					*file*/	uint64_t *l1_table;            /*L1 table entries*/	uint64_t *l2_cache;            /*We maintain a cache of size 					*L2_CACHE_SIZE of most read entries*/	uint64_t l2_cache_offsets[L2_CACHE_SIZE];     /*L2 cache entries*/	uint32_t l2_cache_counts[L2_CACHE_SIZE];      /*Cache access record*/	uint8_t *cluster_cache;          	uint8_t *cluster_data;	uint8_t *sector_lock;          /*Locking bitmap for AIO reads/writes*/	uint64_t cluster_cache_offset; /**/	uint32_t crypt_method;         /*current crypt method, 0 if no 					*key yet */	uint32_t crypt_method_header;  /**/	AES_KEY aes_encrypt_key;       /*AES key*/	AES_KEY aes_decrypt_key;       /*AES key*/        /* libaio state */        tap_aio_context_t   aio_ctx;        int                 max_aio_reqs;        struct iocb        *iocb_list;        struct iocb       **iocb_free;        struct pending_aio *pending_aio;        int                 iocb_free_count;        struct iocb       **iocb_queue;        int                 iocb_queued;        struct io_event    *aio_events;};static int decompress_cluster(struct tdqcow_state *s, uint64_t cluster_offset);static void free_aio_state(struct disk_driver *dd){        struct tdqcow_state *s = (struct tdqcow_state *)dd->private;        if (s->sector_lock)                free(s->sector_lock);        if (s->iocb_list)                free(s->iocb_list);        if (s->pending_aio)                free(s->pending_aio);        if (s->aio_events)                free(s->aio_events);        if (s->iocb_free)                free(s->iocb_free);        if (s->iocb_queue)                free(s->iocb_queue);}static int init_aio_state(struct disk_driver *dd){	int i, ret;	struct td_state     *bs = dd->td_state;	struct tdqcow_state  *s = (struct tdqcow_state *)dd->private;        long     ioidx;        s->iocb_list = NULL;        s->pending_aio = NULL;        s->aio_events = NULL;        s->iocb_free = NULL;        s->iocb_queue = NULL;        /*Initialize Locking bitmap*/	s->sector_lock = calloc(1, bs->size);		if (!s->sector_lock) {		DPRINTF("Failed to allocate sector lock\n");		goto fail;	}        /* A segment (i.e. a page) can span multiple clusters */        s->max_aio_reqs = ((getpagesize() / s->cluster_size) + 1) *            MAX_SEGMENTS_PER_REQ * MAX_REQUESTS;        /* Initialize AIO */        s->iocb_free_count = s->max_aio_reqs;        s->iocb_queued     = 0;        if (!(s->iocb_list = malloc(sizeof(struct iocb) * s->max_aio_reqs)) ||            !(s->pending_aio = malloc(sizeof(struct pending_aio) * s->max_aio_reqs)) ||            !(s->aio_events = malloc(sizeof(struct io_event) * s->max_aio_reqs)) ||            !(s->iocb_free = malloc(sizeof(struct iocb *) * s->max_aio_reqs)) ||            !(s->iocb_queue = malloc(sizeof(struct iocb *) * s->max_aio_reqs))) {                DPRINTF("Failed to allocate AIO structs (max_aio_reqs = %d)\n",                        s->max_aio_reqs);                goto fail;        }	ret = tap_aio_setup(&s->aio_ctx, s->aio_events, s->max_aio_reqs);	if (ret < 0) {                if (ret == -EAGAIN) {                        DPRINTF("Couldn't setup AIO context.  If you are "                                "trying to concurrently use a large number "                                "of blktap-based disks, you may need to "                                "increase the system-wide aio request limit. "                                "(e.g. 'echo echo 1048576 > /proc/sys/fs/"                                "aio-max-nr')\n");                } else {                        DPRINTF("Couldn't setup AIO context.\n");                }		goto fail;	}        for (i=0;i<s->max_aio_reqs;i++)                s->iocb_free[i] = &s->iocb_list[i];        DPRINTF("AIO state initialised\n");        return 0; fail:	return -1;}static uint32_t gen_cksum(char *ptr, int len){	unsigned char *md;	uint32_t ret;	md = malloc(MD5_DIGEST_LENGTH);	if(!md) return 0;	if (MD5((unsigned char *)ptr, len, md) != md) {		free(md);		return 0;	}	memcpy(&ret, md, sizeof(uint32_t));	free(md);	return ret;}static int get_filesize(char *filename, uint64_t *size, struct stat *st){	int fd;	QCowHeader header;	/*Set to the backing file size*/	fd = open(filename, O_RDONLY);	if (fd < 0)		return -1;	if (read(fd, &header, sizeof(header)) < sizeof(header)) {		close(fd);		return -1;	}	close(fd);		be32_to_cpus(&header.magic);	be64_to_cpus(&header.size);	if (header.magic == QCOW_MAGIC) {		*size = header.size >> SECTOR_SHIFT;		return 0;	}	if(S_ISBLK(st->st_mode)) {		fd = open(filename, O_RDONLY);		if (fd < 0)			return -1;		if (ioctl(fd,BLKGETSIZE,size)!=0) {			printf("Unable to get Block device size\n");			close(fd);			return -1;		}		close(fd);	} else *size = (st->st_size >> SECTOR_SHIFT);		return 0;}static int qcow_set_key(struct tdqcow_state *s, const char *key){	uint8_t keybuf[16];	int len, i;		memset(keybuf, 0, 16);	len = strlen(key);	if (len > 16)		len = 16;	/* XXX: we could compress the chars to 7 bits to increase	   entropy */	for (i = 0; i < len; i++) {		keybuf[i] = key[i];	}	s->crypt_method = s->crypt_method_header;		if (AES_set_encrypt_key(keybuf, 128, &s->aes_encrypt_key) != 0)		return -1;	if (AES_set_decrypt_key(keybuf, 128, &s->aes_decrypt_key) != 0)		return -1;#if 0	/* test */	{		uint8_t in[16];		uint8_t out[16];		uint8_t tmp[16];		for (i=0; i<16; i++)			in[i] = i;		AES_encrypt(in, tmp, &s->aes_encrypt_key);		AES_decrypt(tmp, out, &s->aes_decrypt_key);		for (i = 0; i < 16; i++)			DPRINTF(" %02x", tmp[i]);		DPRINTF("\n");		for (i = 0; i < 16; i++)			DPRINTF(" %02x", out[i]);		DPRINTF("\n");	}#endif	return 0;}static int async_read(struct tdqcow_state *s, int size, 		      uint64_t offset, char *buf, td_callback_t cb,		      int id, uint64_t sector, void *private){        struct   iocb *io;        struct   pending_aio *pio;	long     ioidx;        io = s->iocb_free[--s->iocb_free_count];        ioidx = IOCB_IDX(s, io);        pio = &s->pending_aio[ioidx];        pio->cb = cb;        pio->id = id;        pio->private = private;	pio->nb_sectors = size/512;	pio->buf = buf;	pio->sector = sector;        io_prep_pread(io, s->fd, buf, size, offset);        io->data = (void *)ioidx;        s->iocb_queue[s->iocb_queued++] = io;        return 1;}static int async_write(struct tdqcow_state *s, int size,		       uint64_t offset, char *buf, td_callback_t cb,		       int id, uint64_t sector, void *private){        struct   iocb *io;        struct   pending_aio *pio;	long     ioidx;        io = s->iocb_free[--s->iocb_free_count];        ioidx = IOCB_IDX(s, io);        pio = &s->pending_aio[ioidx];        pio->cb = cb;        pio->id = id;        pio->private = private;	pio->nb_sectors = size/512;	pio->buf = buf;	pio->sector = sector;        io_prep_pwrite(io, s->fd, buf, size, offset);        io->data = (void *)ioidx;        s->iocb_queue[s->iocb_queued++] = io;        return 1;}/*TODO: Fix sector span!*/static int aio_can_lock(struct tdqcow_state *s, uint64_t sector){	return (s->sector_lock[sector] ? 0 : 1);}static int aio_lock(struct tdqcow_state *s, uint64_t sector){	return ++s->sector_lock[sector];}static void aio_unlock(struct tdqcow_state *s, uint64_t sector){	if (!s->sector_lock[sector]) return;	--s->sector_lock[sector];	return;}/*  * The crypt function is compatible with the linux cryptoloop * algorithm for < 4 GB images. NOTE: out_buf == in_buf is * supported . */static void encrypt_sectors(struct tdqcow_state *s, int64_t sector_num,                            uint8_t *out_buf, const uint8_t *in_buf,                            int nb_sectors, int enc,                            const AES_KEY *key){	union {		uint64_t ll[2];		uint8_t b[16];	} ivec;	int i;		for (i = 0; i < nb_sectors; i++) {		ivec.ll[0] = cpu_to_le64(sector_num);		ivec.ll[1] = 0;		AES_cbc_encrypt(in_buf, out_buf, 512, key, 				ivec.b, enc);		sector_num++;		in_buf += 512;		out_buf += 512;	}}static int qtruncate(int fd, off_t length, int sparse){	int ret, i; 	int current = 0, rem = 0;	uint64_t sectors;	struct stat st;	char *buf;	/* If length is greater than the current file len	 * we synchronously write zeroes to the end of the 	 * file, otherwise we truncate the length down	 */	ret = fstat(fd, &st);	if (ret == -1) 		return -1;	if (S_ISBLK(st.st_mode))		return 0;	sectors = (length + DEFAULT_SECTOR_SIZE - 1)/DEFAULT_SECTOR_SIZE;	current = (st.st_size + DEFAULT_SECTOR_SIZE - 1)/DEFAULT_SECTOR_SIZE;	rem     = st.st_size % DEFAULT_SECTOR_SIZE;	/* If we are extending this file, we write zeros to the end --	 * this tries to ensure that the extents allocated wind up being	 * contiguous on disk.	 */	if(st.st_size < sectors * DEFAULT_SECTOR_SIZE) {		/*We are extending the file*/		if ((ret = posix_memalign((void **)&buf, 					  512, DEFAULT_SECTOR_SIZE))) {			DPRINTF("posix_memalign failed: %d\n", ret);			return -1;		}		memset(buf, 0x00, DEFAULT_SECTOR_SIZE);		if (lseek(fd, 0, SEEK_END)==-1) {			DPRINTF("Lseek EOF failed (%d), internal error\n",				errno);			free(buf);			return -1;		}		if (rem) {			ret = write(fd, buf, rem);			if (ret != rem) {				DPRINTF("write failed: ret = %d, err = %s\n",					ret, strerror(errno));				free(buf);				return -1;			}		}		for (i = current; i < sectors; i++ ) {			ret = write(fd, buf, DEFAULT_SECTOR_SIZE);			if (ret != DEFAULT_SECTOR_SIZE) {				DPRINTF("write failed: ret = %d, err = %s\n",					ret, strerror(errno));				free(buf);				return -1;			}		}		free(buf);	} else if(sparse && (st.st_size > sectors * DEFAULT_SECTOR_SIZE))		if (ftruncate(fd, (off_t)sectors * DEFAULT_SECTOR_SIZE)==-1) {			DPRINTF("Ftruncate failed (%s)\n", strerror(errno));			return -1;		}	return 0;}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产成人一区在线| 国产精品狼人久久影院观看方式| 一区二区三区欧美激情| 成人av手机在线观看| 国产精品天天摸av网| 不卡区在线中文字幕| 精品国产免费久久| 成人动漫一区二区三区| 椎名由奈av一区二区三区| 在线观看国产精品网站| 亚洲成人一区在线| 精品欧美乱码久久久久久 | 国产精品久久久久久久蜜臀 | 亚洲综合色噜噜狠狠| 91国偷自产一区二区三区成为亚洲经典| 亚洲欧洲日产国码二区| 在线免费精品视频| 久久精品国产99国产精品| 国产嫩草影院久久久久| 一本色道久久综合狠狠躁的推荐| 午夜精品免费在线观看| 精品少妇一区二区三区在线视频| 成人综合婷婷国产精品久久| 亚洲日本va在线观看| 91精品国产综合久久久蜜臀粉嫩| 九九国产精品视频| 国产精品超碰97尤物18| 3d成人h动漫网站入口| 国产麻豆精品久久一二三| 亚洲免费在线看| 欧美一区三区二区| 9久草视频在线视频精品| 日本在线不卡视频| 国产精品无圣光一区二区| 欧美亚洲国产bt| 国产福利91精品一区二区三区| 亚洲欧美成人一区二区三区| 欧美一区二区美女| 成人黄色av网站在线| 午夜精品123| 中文字幕在线播放不卡一区| 欧美一区午夜精品| 色成年激情久久综合| 精品一区二区三区在线播放视频| 亚洲免费视频中文字幕| 精品av久久707| 欧美性一二三区| 成人免费视频caoporn| 日韩国产欧美三级| 亚洲免费在线观看| 欧美激情在线观看视频免费| 欧美军同video69gay| 成人免费黄色在线| 久久99深爱久久99精品| 亚洲国产精品影院| 亚洲丝袜制服诱惑| 中文字幕 久热精品 视频在线| 欧美一区二区三区性视频| 在线亚洲+欧美+日本专区| 国产成人丝袜美腿| 久久激情综合网| 午夜久久久影院| 亚洲制服丝袜av| 国产精品久久久久久久久久久免费看 | 日韩精品乱码av一区二区| 欧美激情综合网| 精品美女被调教视频大全网站| 欧美日韩二区三区| 在线视频你懂得一区| 99久久精品情趣| 成人一区二区三区| 大桥未久av一区二区三区中文| 久久97超碰色| 精品无码三级在线观看视频| 蜜芽一区二区三区| 日本成人在线看| 日本女优在线视频一区二区| 亚洲一区二区美女| 亚洲午夜羞羞片| 婷婷开心激情综合| 午夜精品123| 蜜桃视频在线观看一区| 理论片日本一区| 精品一区二区日韩| 国产一区二区在线电影| 国产毛片精品一区| 国产精品一线二线三线精华| 国产激情一区二区三区桃花岛亚洲| 国产精品99久久久久| 国产精品中文欧美| 播五月开心婷婷综合| 91老师片黄在线观看| 在线视频国内一区二区| 制服视频三区第一页精品| 欧美一区二区视频在线观看| 日韩精品一区二| 精品成人一区二区三区四区| 久久久精品天堂| 国产精品久久久久久久浪潮网站| 中文字幕第一页久久| 亚洲伦理在线免费看| 偷拍与自拍一区| 精品一区二区久久| 菠萝蜜视频在线观看一区| 欧美色图一区二区三区| 欧美一级精品大片| 日本一区二区视频在线| 一区二区三区 在线观看视频| 天天做天天摸天天爽国产一区| 青青青伊人色综合久久| 国产suv精品一区二区6| 色天使色偷偷av一区二区| 欧美一区国产二区| 亚洲精品一区二区三区99| 国产精品久久久久9999吃药| 亚洲国产va精品久久久不卡综合| 麻豆国产精品官网| eeuss鲁片一区二区三区| 欧美日韩一区二区电影| 国产欧美精品一区二区色综合朱莉| 亚洲精品免费播放| 久久99精品久久久久久动态图| 成人一区二区三区在线观看| 538在线一区二区精品国产| 久久久久国色av免费看影院| 亚洲午夜久久久久久久久电影院 | 中文字幕一区免费在线观看 | 九一久久久久久| 国产成人精品影视| 色就色 综合激情| 精品成人a区在线观看| 亚洲自拍偷拍图区| 国产精品一区二区在线观看不卡| 欧美在线你懂的| 国产亚洲人成网站| 日韩在线播放一区二区| 99精品国产热久久91蜜凸| 欧美成va人片在线观看| 亚洲综合一二三区| 国产一级精品在线| 欧美高清hd18日本| 亚洲色图另类专区| 国产一区二区成人久久免费影院| 欧美人牲a欧美精品| 亚洲三级电影网站| 黑人巨大精品欧美黑白配亚洲| 欧美日韩综合在线| 亚洲欧美在线高清| 国产精品自拍一区| 精品国产伦一区二区三区观看体验 | 91精品国产手机| 亚洲综合在线电影| heyzo一本久久综合| 久久久久久久综合日本| 日韩在线一二三区| 欧美性xxxxxxxx| 一区二区三区产品免费精品久久75| 成人av在线一区二区| 国产色产综合色产在线视频| 久久精品999| 日韩欧美中文一区| 日韩成人免费电影| 欧美美女网站色| 丝袜美腿一区二区三区| 欧美日韩一区二区三区高清| 亚洲视频一二三区| 99国产精品99久久久久久| 国产精品久久久久一区二区三区 | 91网站视频在线观看| 国产精品护士白丝一区av| 国产精品一二三区在线| 久久精品在这里| 国产成人综合自拍| 久久综合狠狠综合| 久久99精品国产| 欧美成人一级视频| 激情综合色播激情啊| 久久久天堂av| 岛国一区二区三区| 国产精品久久久久久久第一福利| 成人免费福利片| 欧美激情一区二区三区在线| 成人深夜在线观看| 国产亚洲精品7777| 99久久久免费精品国产一区二区| 夜夜爽夜夜爽精品视频| 欧美另类变人与禽xxxxx| 日本系列欧美系列| 久久综合九色综合97婷婷女人| 国产成人久久精品77777最新版本| 国产精品精品国产色婷婷| 色婷婷久久99综合精品jk白丝| 亚洲成人www| 日韩精品在线看片z| 成人激情动漫在线观看| 亚洲激情校园春色| 91精选在线观看| 国产.精品.日韩.另类.中文.在线.播放| 国产欧美日韩不卡免费| 91理论电影在线观看|