本文整理汇总了C++中read_block函数的典型用法代码示例。如果您正苦于以下问题:C++ read_block函数的具体用法?C++ read_block怎么用?C++ read_block使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read_block函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: read_bitmap
// Read and validate the file system bitmap.
//
// Read all the bitmap blocks into memory.
// Set the "bitmap" pointer to point at the beginning of the first
// bitmap block.
//
// Check that all reserved blocks -- 0, 1, and the bitmap blocks themselves --
// are all marked as in-use
// (for each block i, assert(!block_is_free(i))).
//
// Hint: Assume that the superblock has already been loaded into
// memory (in variable 'super'). Check out super->s_nblocks.
void
read_bitmap(void)
{
int r;
uint32_t i;
char *blk;
// Read the bitmap into memory.
// The bitmap consists of one or more blocks. A single bitmap block
// contains the in-use bits for BLKBITSIZE blocks. There are
// super->s_nblocks blocks in the disk altogether.
// Set 'bitmap' to point to the first address in the bitmap.
// Hint: Use read_block.
// LAB 5: Your code here.
uint32_t bitmap_blkno = super->s_nblocks / BLKBITSIZE;
if(super -> s_nblocks % BLKBITSIZE != 0)
bitmap_blkno++;
for(i=0;i<bitmap_blkno;i++){
if(read_block(2+i,&blk) < 0)
panic("read_bitmap: read_block fail!\n");
}
bitmap = (uint32_t *)diskaddr(2);
// Make sure the reserved and root blocks are marked in-use.
assert(!block_is_free(0));
assert(!block_is_free(1));
assert(bitmap);
// Make sure that the bitmap blocks are marked in-use.
// LAB 5: Your code here.
for(i=0;i<bitmap_blkno;i++)
assert(!block_is_free(2+i));
cprintf("read_bitmap is good\n");
}
开发者ID:mainboy,项目名称:xv6,代码行数:48,代码来源:fs.c
示例2: hdfsRead
boost::string_ref HDFSFileSplitter::fetch_block(bool is_next) {
int nbytes = 0;
if (is_next) {
// directly read the next block using the current file
nbytes = hdfsRead(fs_, file_, data_, hdfs_block_size);
if (nbytes == 0)
return "";
if (nbytes == -1) {
throw base::HuskyException("read next block error!");
}
} else {
// Ask the master for a new block
BinStream question;
question << url_ << husky::Context::get_param("hostname");
BinStream answer = husky::Context::get_coordinator()->ask_master(question, husky::TYPE_HDFS_BLK_REQ);
std::string fn;
answer >> fn;
answer >> offset_;
if (fn == "") {
// no more files
return "";
}
if (file_ != NULL) {
int rc = hdfsCloseFile(fs_, file_);
assert(rc == 0);
// Notice that "file" will be deleted inside hdfsCloseFile
file_ = NULL;
}
// read block
nbytes = read_block(fn);
}
return boost::string_ref(data_, nbytes);
}
开发者ID:WuZihao1,项目名称:husky,代码行数:36,代码来源:hdfs_file_splitter.cpp
示例3: main
main (int argc, char *argv[])
{
float block[GULP],copy[GULP];
int ixnc,kxnc,i,j,k,n,off,nadd,nread,headersize=0;
input=fopen(argv[1],"rb");
output=fopen(argv[2],"wb");
nadd=atoi(argv[3]);
for (i=0;i<4;i++) ifstream[i]='Y';
if (!(headersize=read_header(input)))
error_message("could not read header parameters!");
obits=32;
tsamp*=nadd;
filterbank_header(output);
for (i=0;i<GULP;i++) block[i]=copy[i]=0.0;
nread=GULP/nchans;
while(n=read_block(input,nbits,block,nread)) {
k=off=0;
for (i=0;i<n/nchans;i++) {
ixnc=i*nchans;
kxnc=k*nchans;
for (j=0;j<nchans;j++) copy[off+j]+=block[ixnc+j];
k++;
if (k==nadd) {
off+=nchans;
k=0;
}
}
for (j=0;j<n/nadd;j++) copy[j]/=(float)nadd;
fwrite(copy,sizeof(float),n/nadd,output);
for (j=0;j<n/nadd;j++) copy[j]=0.0;
}
}
开发者ID:SixByNine,项目名称:sigproc,代码行数:36,代码来源:downsample.c
示例4: dedup_calc_block_hash_crc
/*
* Update dedup structure with block's hash and crc
*/
void dedup_calc_block_hash_crc(sector_t block)
{
size_t block_size = dedup_get_block_size();
char *block_data;
if (block >= blocks_count)
// outside dedup range
return;
block_data = (char*)kmalloc(block_size, GFP_KERNEL);
if (block_data == NULL) {
printk(KERN_ERR "failed allocating block data buffer.\n");
return;
}
// Read block
read_block(block_data, block_size, start_block + block);
// Calc hash
calc_hash(block_data, block_size, blocksArray.hashes[block]);
// Calc crc32
blocksArray.hash_crc[block] = crc32_le(0, blocksArray.hashes[block], SHA256_DIGEST_SIZE);
kfree(block_data);
}
开发者ID:davidsaOpenu,项目名称:dedup,代码行数:27,代码来源:dedup_sysfs.c
示例5: ext2_read
size_t ext2_read(Ext2_file *file, uint8_t *buf, size_t count)
{
// Check if we would read past the end of the file
if (file->pos + count > file->inode.size)
count = file->inode.size - file->pos;
size_t bytes_left = count;
while (bytes_left > 0) {
size_t to_copy = bytes_left;
// Check if this read will go beyond the current buffer
bool new_block = file->curr_block_pos + to_copy >= block_size;
if (new_block)
to_copy = block_size - file->curr_block_pos;
// Copy across from the buffer in the *file and advance the position
memcpy(buf + (count - bytes_left),
file->buf + file->curr_block_pos, to_copy);
file->curr_block_pos += to_copy;
file->pos += to_copy;
bytes_left -= to_copy;
// If we read to the end of the buffer then read the next block
if (new_block) {
file->curr_block_pos = 0;
file->block_index++;
if (file->block_index >= 12)
PANIC("Indirect block pointers are currently unsupported");
read_block(file->inode.dbp[file->block_index], file->buf);
}
}
return count;
}
开发者ID:orodley,项目名称:studix,代码行数:36,代码来源:ext2.c
示例6: sba_reiserfs_find_journal_entries
int sba_reiserfs_find_journal_entries(void)
{
int i;
char *data;
if ((data = read_block(REISER_SUPER)) != NULL) {
struct reiserfs_super_block *rsb = (struct reiserfs_super_block *)data;
if (sba_reiserfs_is_any_reiserfs_magic_string (rsb)) {
sba_debug(1,"SUCCESS ! Found reiserfs superblock\n");
sba_debug(1,"Journal begin = %u Journal size = %u\n",
rsb->s_v1.s_journal.jp_journal_1st_block, rsb->s_v1.s_journal.jp_journal_size);
sba_debug(1,"Trans max = %u Max batch = %u\n",
rsb->s_v1.s_journal.jp_journal_trans_max, rsb->s_v1.s_journal.jp_journal_max_batch);
sba_debug(1,"Commit age = %u Trans age = %u\n",
rsb->s_v1.s_journal.jp_journal_max_commit_age, rsb->s_v1.s_journal.jp_journal_max_trans_age);
reiser_jour_start = rsb->s_v1.s_journal.jp_journal_1st_block;
reiser_jour_size = rsb->s_v1.s_journal.jp_journal_size;
}
free_page((int)data);
}
for (i = 0; i < reiser_jour_size; i ++) {
ht_add(h_sba_reiserfs_journal, reiser_jour_start + i);
}
sba_debug(1, "Begin = %d End = %d\n", reiser_jour_start, reiser_jour_start + reiser_jour_size - 1);
return 1;
}
开发者ID:codereview0,项目名称:fault-injection-driver,代码行数:36,代码来源:sba_reiserfs.c
示例7: comment_43_uncompress
static int comment_43_uncompress(FILE *infp, FILE *outfp, int skip_magic)
{
block_data_t *block_data = malloc(sizeof(block_data_t));
size_t work_len = snappy_max_compressed_length(UINT16_MAX); /* length of worst case */
char *work = malloc(work_len);
int err = 1;
stream_state_t state = skip_magic ? PROCESSING_STATE : INITIAL_STATE;
if (block_data == NULL || work == NULL) {
print_error("out of memory\n");
goto cleanup;
}
while (state != ERROR_STATE) {
switch (read_block(infp, block_data)) {
case EOF:
if (state == END_OF_STREAM_STATE) {
err = 0; /* success */
goto cleanup;
}
/* FALLTHROUGH */
case TOO_SHORT_DATA_BLOCK:
if (feof_unlocked(infp)) {
print_error("Unexpected end of file\n");
} else {
print_error("Failed to read a file: %s\n", strerror(errno));
}
goto cleanup;
}
state = process_block(outfp, state, block_data, work, work_len);
}
cleanup:
free(block_data);
free(work);
return err;
}
开发者ID:adfernandes,项目名称:snzip,代码行数:36,代码来源:comment-43-format.c
示例8: __attribute__
struct compressor *read_super(int fd, struct squashfs_super_block *sBlk, char *source)
{
int res, bytes = 0;
char buffer[SQUASHFS_METADATA_SIZE] __attribute__ ((aligned));
res = read_fs_bytes(fd, SQUASHFS_START, sizeof(struct squashfs_super_block),
sBlk);
if(res == 0) {
ERROR("Can't find a SQUASHFS superblock on %s\n",
source);
ERROR("Wrong filesystem or filesystem is corrupted!\n");
goto failed_mount;
}
SQUASHFS_INSWAP_SUPER_BLOCK(sBlk);
if(sBlk->s_magic != SQUASHFS_MAGIC) {
if(sBlk->s_magic == SQUASHFS_MAGIC_SWAP)
ERROR("Pre 4.0 big-endian filesystem on %s, appending"
" to this is unsupported\n", source);
else {
ERROR("Can't find a SQUASHFS superblock on %s\n",
source);
ERROR("Wrong filesystem or filesystem is corrupted!\n");
}
goto failed_mount;
}
/* Check the MAJOR & MINOR versions */
if(sBlk->s_major != SQUASHFS_MAJOR || sBlk->s_minor > SQUASHFS_MINOR) {
if(sBlk->s_major < 4)
ERROR("Filesystem on %s is a SQUASHFS %d.%d filesystem."
" Appending\nto SQUASHFS %d.%d filesystems is "
"not supported. Please convert it to a "
"SQUASHFS 4 filesystem\n", source,
sBlk->s_major,
sBlk->s_minor, sBlk->s_major, sBlk->s_minor);
else
ERROR("Filesystem on %s is %d.%d, which is a later "
"filesystem version than I support\n",
source, sBlk->s_major, sBlk->s_minor);
goto failed_mount;
}
/* Check the compression type */
comp = lookup_compressor_id(sBlk->compression);
if(!comp->supported) {
ERROR("Filesystem on %s uses %s compression, this is "
"unsupported by this version\n", source, comp->name);
ERROR("Compressors available:\n");
display_compressors("", "");
goto failed_mount;
}
/*
* Read extended superblock information from disk.
*
* Read compressor specific options from disk if present, and pass
* to compressor to set compressor options.
*
* Note, if there's no compressor options present, the compressor
* is still called to set the default options (the defaults may have
* been changed by the user specifying options on the command
* line which need to be over-ridden).
*
* Compressor_extract_options is also used to ensure that
* we know how decompress a filesystem compressed with these
* compression options.
*/
if(SQUASHFS_COMP_OPTS(sBlk->flags)) {
bytes = read_block(fd, sizeof(*sBlk), NULL, 0, buffer);
if(bytes == 0) {
ERROR("Failed to read compressor options from append "
"filesystem\n");
ERROR("Filesystem corrupted?\n");
goto failed_mount;
}
}
res = compressor_extract_options(comp, sBlk->block_size, buffer, bytes);
if(res == -1) {
ERROR("Compressor failed to set compressor options\n");
goto failed_mount;
}
printf("Found a valid %sSQUASHFS superblock on %s.\n",
SQUASHFS_EXPORTABLE(sBlk->flags) ? "exportable " : "", source);
printf("\tCompression used %s\n", comp->name);
printf("\tInodes are %scompressed\n",
SQUASHFS_UNCOMPRESSED_INODES(sBlk->flags) ? "un" : "");
printf("\tData is %scompressed\n",
SQUASHFS_UNCOMPRESSED_DATA(sBlk->flags) ? "un" : "");
printf("\tFragments are %scompressed\n",
SQUASHFS_UNCOMPRESSED_FRAGMENTS(sBlk->flags) ? "un" : "");
printf("\tXattrs are %scompressed\n",
SQUASHFS_UNCOMPRESSED_XATTRS(sBlk->flags) ? "un" : "");
printf("\tFragments are %spresent in the filesystem\n",
SQUASHFS_NO_FRAGMENTS(sBlk->flags) ? "not " : "");
printf("\tAlways-use-fragments option is %sspecified\n",
//.........这里部分代码省略.........
开发者ID:LucaBongiorni,项目名称:sasquatch,代码行数:101,代码来源:read_fs.c
示例9: decode_block
void decode_block(decoder_info_t *decoder_info,int size,int ypos,int xpos){
int width = decoder_info->width;
int height = decoder_info->height;
int xposY = xpos;
int yposY = ypos;
int xposC = xpos/2;
int yposC = ypos/2;
int sizeY = size;
int sizeC = size/2;
block_mode_t mode;
mv_t mv;
intra_mode_t intra_mode;
frame_type_t frame_type = decoder_info->frame_info.frame_type;
int bipred = decoder_info->bipred;
int qpY = decoder_info->frame_info.qpb;
int qpC = chroma_qp[qpY];
/* Intermediate block variables */
uint8_t *pblock_y = thor_alloc(MAX_BLOCK_SIZE*MAX_BLOCK_SIZE, 16);
uint8_t *pblock_u = thor_alloc(MAX_BLOCK_SIZE*MAX_BLOCK_SIZE, 16);
uint8_t *pblock_v = thor_alloc(MAX_BLOCK_SIZE*MAX_BLOCK_SIZE, 16);
int16_t *coeff_y = thor_alloc(2*MAX_TR_SIZE*MAX_TR_SIZE, 16);
int16_t *coeff_u = thor_alloc(2*MAX_TR_SIZE*MAX_TR_SIZE, 16);
int16_t *coeff_v = thor_alloc(2*MAX_TR_SIZE*MAX_TR_SIZE, 16);
/* Block variables for bipred */
uint8_t *pblock0_y = thor_alloc(MAX_BLOCK_SIZE*MAX_BLOCK_SIZE, 16);
uint8_t *pblock0_u = thor_alloc(MAX_BLOCK_SIZE*MAX_BLOCK_SIZE, 16);
uint8_t *pblock0_v = thor_alloc(MAX_BLOCK_SIZE*MAX_BLOCK_SIZE, 16);
uint8_t *pblock1_y = thor_alloc(MAX_BLOCK_SIZE*MAX_BLOCK_SIZE, 16);
uint8_t *pblock1_u = thor_alloc(MAX_BLOCK_SIZE*MAX_BLOCK_SIZE, 16);
uint8_t *pblock1_v = thor_alloc(MAX_BLOCK_SIZE*MAX_BLOCK_SIZE, 16);
yuv_frame_t *rec = decoder_info->rec;
yuv_frame_t *ref = decoder_info->ref[0];
/* Calculate position in padded reference frame */
int ref_posY = yposY*ref->stride_y+xposY;
int ref_posC = yposC*ref->stride_c+xposC;
/* Pointers to current position in reconstructed frame*/
uint8_t *rec_y = &rec->y[yposY*rec->stride_y+xposY];
uint8_t *rec_u = &rec->u[yposC*rec->stride_c+xposC];
uint8_t *rec_v = &rec->v[yposC*rec->stride_c+xposC];
/* Pointers to colocated block position in reference frame */
uint8_t *ref_y = ref->y + ref_posY;
uint8_t *ref_u = ref->u + ref_posC;
uint8_t *ref_v = ref->v + ref_posC;
stream_t *stream = decoder_info->stream;
/* Read data from bitstream */
block_info_dec_t block_info;
block_info.block_pos.size = size;
block_info.block_pos.ypos = ypos;
block_info.block_pos.xpos = xpos;
block_info.coeffq_y = coeff_y;
block_info.coeffq_u = coeff_u;
block_info.coeffq_v = coeff_v;
/* Used for rectangular skip blocks */
int bwidth = min(size,width - xpos);
int bheight = min(size,height - ypos);
block_info.block_pos.bwidth = bwidth;
block_info.block_pos.bheight = bheight;
read_block(decoder_info,stream,&block_info,frame_type);
mode = block_info.block_param.mode;
if (mode == MODE_INTRA){
/* Dequantize, inverse tranform, predict and reconstruct */
intra_mode = block_info.block_param.intra_mode;
int upright_available = get_upright_available(ypos,xpos,size,width);
int downleft_available = get_downleft_available(ypos,xpos,size,height);
int tb_split = block_info.block_param.tb_split;
decode_and_reconstruct_block_intra(rec_y,rec->stride_y,sizeY,qpY,pblock_y,coeff_y,tb_split,upright_available,downleft_available,intra_mode,yposY,xposY,width,0);
decode_and_reconstruct_block_intra(rec_u,rec->stride_c,sizeC,qpC,pblock_u,coeff_u,tb_split&&size>8,upright_available,downleft_available,intra_mode,yposC,xposC,width/2,1);
decode_and_reconstruct_block_intra(rec_v,rec->stride_c,sizeC,qpC,pblock_v,coeff_v,tb_split&&size>8,upright_available,downleft_available,intra_mode,yposC,xposC,width/2,2);
}
else
{
if (mode==MODE_SKIP){
if (block_info.block_param.dir==2){
uint8_t *ref0_y,*ref0_u,*ref0_v;
uint8_t *ref1_y,*ref1_u,*ref1_v;
int r0 = decoder_info->frame_info.ref_array[block_info.block_param.ref_idx0];
yuv_frame_t *ref0 = r0>=0 ? decoder_info->ref[r0] : decoder_info->interp_frames[0];
ref0_y = ref0->y + ref_posY;
ref0_u = ref0->u + ref_posC;
ref0_v = ref0->v + ref_posC;
int r1 = decoder_info->frame_info.ref_array[block_info.block_param.ref_idx1];
yuv_frame_t *ref1 = r1>=0 ? decoder_info->ref[r1] : decoder_info->interp_frames[0];
ref1_y = ref1->y + ref_posY;
ref1_u = ref1->u + ref_posC;
//.........这里部分代码省略.........
开发者ID:awakecoding,项目名称:thor,代码行数:101,代码来源:decode_block.c
示例10: write_tind_metadata
static int write_tind_metadata(struct defrag_ctx *c, struct data_extent *e,
__u32 tind_block, __u32 *cur_logical,
__u32 *cur_block)
{
struct inode *inode = c->inodes[e->inode_nr];
__u32 offset = *cur_logical;
__u32 ind_blocks = EXT2_ADDR_PER_BLOCK(&c->sb);
__u32 blocks_per_ind = 1 + ind_blocks;
__u32 blocks_per_dind = 1 + ind_blocks * blocks_per_ind;
__u32 blocks_per_tind = 1 + ind_blocks * blocks_per_dind;
__u32 buffer[EXT2_ADDR_PER_BLOCK(&c->sb)];
int ret;
char to_sync = 0;
if (tind_block == 0) {
*cur_logical += blocks_per_tind;
return 0;
}
ret = read_block(c, buffer, tind_block);
if (ret)
return -1;
offset -= EXT2_TIND_LBLOCK(&c->sb) + 1;
offset = offset % blocks_per_tind;
if (offset % blocks_per_dind) {
offset = offset / blocks_per_dind;
ret = write_dind_metadata(c, e, buffer[offset], cur_logical,
cur_block);
if (ret)
return ret;
offset++;
} else {
offset = offset / blocks_per_dind;
}
while (offset < EXT2_ADDR_PER_BLOCK(&c->sb)
&& *cur_block <= e->end_block) {
__u32 new_block;
if (is_sparse(inode, *cur_logical))
new_block = 0;
else
new_block = (*cur_block)++;
(*cur_logical)++;
if (new_block) {
ret = write_dind_metadata(c, e, new_block,
cur_logical, cur_block);
if (ret)
return ret;
} else {
*cur_logical += blocks_per_dind - 1;
}
if (buffer[offset] != new_block) {
to_sync = 1;
buffer[offset] = new_block;
}
offset++;
}
if (to_sync) {
ret = write_block(c, buffer, tind_block);
return ret;
}
return 0;
}
开发者ID:ennoruijters,项目名称:e2defrag,代码行数:61,代码来源:metadata_write.c
示例11: pcap_ng_next_packet
/*
* Read and return the next packet from the savefile. Return the header
* in hdr and a pointer to the contents in data. Return 0 on success, 1
* if there were no more packets, and -1 on an error.
*/
static int
pcap_ng_next_packet(pcap_t *p, struct pcap_pkthdr *hdr, u_char **data)
{
struct pcap_ng_sf *ps = p->priv;
struct block_cursor cursor;
int status;
struct enhanced_packet_block *epbp;
struct simple_packet_block *spbp;
struct packet_block *pbp;
bpf_u_int32 interface_id = 0xFFFFFFFF;
struct interface_description_block *idbp;
struct section_header_block *shbp;
FILE *fp = p->rfile;
u_int64_t t, sec, frac;
/*
* Look for an Enhanced Packet Block, a Simple Packet Block,
* or a Packet Block.
*/
for (;;) {
/*
* Read the block type and length; those are common
* to all blocks.
*/
status = read_block(fp, p, &cursor, p->errbuf);
if (status == 0)
return (1); /* EOF */
if (status == -1)
return (-1); /* error */
switch (cursor.block_type) {
case BT_EPB:
/*
* Get a pointer to the fixed-length portion of the
* EPB.
*/
epbp = get_from_block_data(&cursor, sizeof(*epbp),
p->errbuf);
if (epbp == NULL)
return (-1); /* error */
/*
* Byte-swap it if necessary.
*/
if (p->swapped) {
/* these were written in opposite byte order */
interface_id = SWAPLONG(epbp->interface_id);
hdr->caplen = SWAPLONG(epbp->caplen);
hdr->len = SWAPLONG(epbp->len);
t = ((u_int64_t)SWAPLONG(epbp->timestamp_high)) << 32 |
SWAPLONG(epbp->timestamp_low);
} else {
interface_id = epbp->interface_id;
hdr->caplen = epbp->caplen;
hdr->len = epbp->len;
t = ((u_int64_t)epbp->timestamp_high) << 32 |
epbp->timestamp_low;
}
goto found;
case BT_SPB:
/*
* Get a pointer to the fixed-length portion of the
* SPB.
*/
spbp = get_from_block_data(&cursor, sizeof(*spbp),
p->errbuf);
if (spbp == NULL)
return (-1); /* error */
/*
* SPB packets are assumed to have arrived on
* the first interface.
*/
interface_id = 0;
/*
* Byte-swap it if necessary.
*/
if (p->swapped) {
/* these were written in opposite byte order */
hdr->len = SWAPLONG(spbp->len);
} else
hdr->len = spbp->len;
/*
* The SPB doesn't give the captured length;
* it's the minimum of the snapshot length
* and the packet length.
*/
hdr->caplen = hdr->len;
if ((int)hdr->caplen > p->snapshot)
hdr->caplen = p->snapshot;
t = 0; /* no time stamps */
goto found;
//.........这里部分代码省略.........
开发者ID:Stichting-MINIX-Research-Foundation,项目名称:minix,代码行数:101,代码来源:sf-pcap-ng.c
示例12: DMESSAGE
void
Playback_DS::disk_thread ( void )
{
_thread.name( "Playback" );
DMESSAGE( "playback thread running" );
/* buffer to hold the interleaved data returned by the track reader */
sample_t *buf = buffer_alloc( _nframes * channels() * _disk_io_blocks );
sample_t *cbuf = buffer_alloc( _nframes );
const nframes_t nframes = _nframes;
nframes_t blocks_written;
while ( ! _terminate )
{
seek:
blocks_written = 0;
read_block( buf, nframes * _disk_io_blocks );
while ( blocks_written < _disk_io_blocks &&
wait_for_block() )
{
// lock(); // for seeking
if ( _pending_seek )
{
/* FIXME: non-RT-safe IO */
DMESSAGE( "performing seek to frame %lu", (unsigned long)_seek_frame );
_frame = _seek_frame;
_pending_seek = false;
flush();
goto seek;
}
/* might have received terminate signal while waiting for block */
if ( _terminate )
goto done;
// unlock(); // for seeking
/* deinterleave the buffer and stuff it into the per-channel ringbuffers */
const size_t block_size = nframes * sizeof( sample_t );
for ( int i = 0; i < channels(); i++ )
{
buffer_deinterleave_one_channel( cbuf,
buf + ( blocks_written * nframes * channels() ),
i,
channels(),
nframes );
while ( jack_ringbuffer_write_space( _rb[ i ] ) < block_size )
usleep( 100 * 1000 );
jack_ringbuffer_write( _rb[ i ], ((char*)cbuf), block_size );
}
blocks_written++;
}
}
done:
DMESSAGE( "playback thread terminating" );
free(buf);
free(cbuf);
// flush();
_terminate = false;
_thread.exit();
}
开发者ID:harryhaaren,项目名称:non,代码行数:81,代码来源:Playback_DS.C
示例13: do_readpage
static int do_readpage(struct ubifs_info *c, struct inode *inode,
struct page *page, int last_block_size)
{
void *addr;
int err = 0, i;
unsigned int block, beyond;
struct ubifs_data_node *dn;
loff_t i_size = inode->i_size;
dbg_gen("ino %lu, pg %lu, i_size %lld",
inode->i_ino, page->index, i_size);
addr = kmap(page);
block = page->index << UBIFS_BLOCKS_PER_PAGE_SHIFT;
beyond = (i_size + UBIFS_BLOCK_SIZE - 1) >> UBIFS_BLOCK_SHIFT;
if (block >= beyond) {
/* Reading beyond inode */
memset(addr, 0, PAGE_CACHE_SIZE);
goto out;
}
dn = kmalloc(UBIFS_MAX_DATA_NODE_SZ, GFP_NOFS);
if (!dn)
return -ENOMEM;
i = 0;
while (1) {
int ret;
if (block >= beyond) {
/* Reading beyond inode */
err = -ENOENT;
memset(addr, 0, UBIFS_BLOCK_SIZE);
} else {
/*
* Reading last block? Make sure to not write beyond
* the requested size in the destination buffer.
*/
if (((block + 1) == beyond) || last_block_size) {
void *buff;
int dlen;
/*
* We need to buffer the data locally for the
* last block. This is to not pad the
* destination area to a multiple of
* UBIFS_BLOCK_SIZE.
*/
buff = malloc(UBIFS_BLOCK_SIZE);
if (!buff) {
printf("%s: Error, malloc fails!\n",
__func__);
err = -ENOMEM;
break;
}
/* Read block-size into temp buffer */
ret = read_block(inode, buff, block, dn);
if (ret) {
err = ret;
if (err != -ENOENT) {
free(buff);
break;
}
}
if (last_block_size)
dlen = last_block_size;
else
dlen = le32_to_cpu(dn->size);
/* Now copy required size back to dest */
memcpy(addr, buff, dlen);
free(buff);
} else {
ret = read_block(inode, addr, block, dn);
if (ret) {
err = ret;
if (err != -ENOENT)
break;
}
}
}
if (++i >= UBIFS_BLOCKS_PER_PAGE)
break;
block += 1;
addr += UBIFS_BLOCK_SIZE;
}
if (err) {
if (err == -ENOENT) {
/* Not found, so it must be a hole */
dbg_gen("hole");
goto out_free;
}
ubifs_err("cannot read page %lu of inode %lu, error %d",
page->index, inode->i_ino, err);
goto error;
}
//.........这里部分代码省略.........
开发者ID:dhs-shine,项目名称:sprd_project,代码行数:101,代码来源:ubifs.c
示例14: fbcopy
int fbcopy( FILE *fout,
CIFBLK *cif,
DADSM *dadsm,
int tran,
int verbose) {
FORMAT1_DSCB *f1dscb = &dadsm->f1buf;
DSXTENT extent[MAX_EXTENTS];
int rc, trk = 0, trkconv = 999, rec = 1;
int cyl = 0, head = 0, rc_rb, len, offset;
int rc_copy = 0;
int recs_written = 0, lrecl, num_extents;
int lstartrack = 0, lstarrec = 0, lstarvalid = 0;
BYTE *buffer;
char *pascii = NULL;
char zdsn[sizeof(f1dscb->ds1dsnam) + 1]; // ascii dsn
// Kludge to avoid rewriting this code (for now):
memcpy(&extent, (void *)&(dadsm->f1ext), sizeof(extent));
num_extents = f1dscb->ds1noepv;
lrecl = (f1dscb->ds1lrecl[0] << 8) | (f1dscb->ds1lrecl[1]);
if (absvalid) {
strcpy(zdsn, argdsn);
if (debug) fprintf(stderr, "fbcopy absvalid\n");
} else {
make_asciiz(zdsn, sizeof(zdsn),
f1dscb->ds1dsnam, sizeof(f1dscb->ds1dsnam));
if ((f1dscb->ds1lstar[0] !=0) ||
(f1dscb->ds1lstar[1] != 0) ||
(f1dscb->ds1lstar[2] != 0)) {
lstartrack = (f1dscb->ds1lstar[0] << 8) | (f1dscb->ds1lstar[1]);
lstarrec = f1dscb->ds1lstar[2];
lstarvalid = 1; // DS1LSTAR valid
}
}
if (debug) {
fprintf(stderr, "fbcopy zdsn %s\n", zdsn);
fprintf(stderr, "fbcopy num_extents %d\n", num_extents);
fprintf(stderr, "fbcopy lrecl %d\n", lrecl);
fprintf(stderr, "fbcopy F1 DSCB\n");
data_dump(f1dscb, sizeof(FORMAT1_DSCB));
sayext(num_extents, (void *)&extent);
}
if (verbose) // DS1LSTAR = last block written TTR
fprintf(stderr,
"fbcopy DS1LSTAR %2.2X%2.2X%2.2X lstartrack %d "
"lstarrec %d lstarvalid %d\n",
f1dscb->ds1lstar[0], f1dscb->ds1lstar[1], f1dscb->ds1lstar[2],
lstartrack, lstarrec, lstarvalid);
if (tran) { // need ASCII translation buffer?
pascii = malloc(lrecl + 1);
if (pascii == NULL) {
fprintf(stderr, "fbcopy unable to allocate ascii buffer\n");
return -1;
}
}
while (1) { // output records until something stops us
// Honor DS1LSTAR when valid
if ((lstarvalid) && (trk == lstartrack) && (rec > lstarrec)) {
if (verbose)
fprintf(stderr, "fbcopy DS1LSTAR indicates EOF\n"
"fbcopy DS1LSTAR %2.2X%2.2X%2.2X "
"track %d record %d\n",
f1dscb->ds1lstar[0], f1dscb->ds1lstar[1],
f1dscb->ds1lstar[2], trk, rec);
rc_copy = recs_written;
break;
}
// Convert TT to CCHH for upcoming read_block call
if (trkconv != trk) { // avoid converting for each block
trkconv = trk; // current track converted
rc = convert_tt(trk, num_extents, extent, cif->heads, &cyl, &head);
if (rc < 0) {
fprintf(stderr,
"fbcopy convert_tt track %5.5d, rc %d\n", trk, rc);
if (absvalid)
rc_copy = recs_written;
else
rc_copy = -1;
break;
}
if (verbose > 1)
fprintf(stderr, "fbcopy convert TT %5.5d CCHH %4.4X %4.4X\n",
trk, cyl, head);
}
// Read block from dasd
if (verbose > 2)
fprintf(stderr, "fbcopy reading track %d "
"record %d CCHHR = %4.4X %4.4X %2.2X\n",
trk, rec, cyl, head, rec);
rc_rb = read_block(cif, cyl, head, rec, NULL, NULL, &buffer, &len);
//.........这里部分代码省略.........
开发者ID:CrashSerious,项目名称:Pi-hercules,代码行数:101,代码来源:dasdseq.c
示例15: assert
//.........这里部分代码省略.........
ASSERT(bp->lmfs_dev != NO_DEV);
ASSERT(bp->lmfs_flags & VMMC_BLOCK_LOCKED);
ASSERT(bp->data);
if(ino != VMC_NO_INODE) {
if(bp->lmfs_inode == VMC_NO_INODE
|| bp->lmfs_inode != ino
|| bp->lmfs_inode_offset != ino_off) {
bp->lmfs_inode = ino;
bp->lmfs_inode_offset = ino_off;
bp->lmfs_needsetcache = 1;
}
}
return(bp);
} else {
/* This block is not the one sought. */
bp = bp->lmfs_hash; /* move to next block on hash chain */
}
}
/* Desired block is not on available chain. Find a free block to use. */
if(bp) {
ASSERT(bp->lmfs_flags & VMMC_EVICTED);
} else {
if ((bp = front) == NULL) panic("all buffers in use: %d", nr_bufs);
}
assert(bp);
rm_lru(bp);
/* Remove the block that was just taken from its hash chain. */
b = BUFHASH(bp->lmfs_blocknr);
prev_ptr = buf_hash[b];
if (prev_ptr == bp) {
buf_hash[b] = bp->lmfs_hash;
} else {
/* The block just taken is not on the front of its hash chain. */
while (prev_ptr->lmfs_hash != NULL)
if (prev_ptr->lmfs_hash == bp) {
prev_ptr->lmfs_hash = bp->lmfs_hash; /* found it */
break;
} else {
prev_ptr = prev_ptr->lmfs_hash; /* keep looking */
}
}
freeblock(bp);
bp->lmfs_inode = ino;
bp->lmfs_inode_offset = ino_off;
bp->lmfs_flags = VMMC_BLOCK_LOCKED;
bp->lmfs_needsetcache = 0;
bp->lmfs_dev = dev; /* fill in device number */
bp->lmfs_blocknr = block; /* fill in block number */
ASSERT(bp->lmfs_count == 0);
raisecount(bp);
b = BUFHASH(bp->lmfs_blocknr);
bp->lmfs_hash = buf_hash[b];
buf_hash[b] = bp; /* add to hash list */
assert(dev != NO_DEV);
/* Block is not found in our cache, but we do want it
* if it's in the vm cache.
*/
assert(!bp->data);
assert(!bp->lmfs_bytes);
if(vmcache) {
if((bp->data = vm_map_cacheblock(dev, dev_off, ino, ino_off,
&bp->lmfs_flags, fs_block_size)) != MAP_FAILED) {
bp->lmfs_bytes = fs_block_size;
ASSERT(!bp->lmfs_needsetcache);
return bp;
}
}
bp->data = NULL;
/* Not in the cache; reserve memory for its contents. */
lmfs_alloc_block(bp);
assert(bp->data);
if(only_search == PREFETCH) {
/* PREFETCH: don't do i/o. */
bp->lmfs_dev = NO_DEV;
} else if (only_search == NORMAL) {
read_block(bp);
} else if(only_search == NO_READ) {
/* This block will be overwritten by new contents. */
} else
panic("unexpected only_search value: %d", only_search);
assert(bp->data);
return(bp); /* return the newly acquired block */
}
开发者ID:wieck,项目名称:minix,代码行数:101,代码来源:cache.c
示例16: make64
//.........这里部分代码省略.........
;
if(!bp) {
panic("no buffer available");
}
} else {
bp->b_bytes = fs_block_size;
}
}
ASSERT(bp);
ASSERT(bp->bp);
ASSERT(bp->b_bytes == fs_block_size);
ASSERT(bp->b_count == 0);
rm_lru(bp);
/* Remove the block that was just taken from its hash chain. */
b = BUFHASH(bp->b_blocknr);
prev_ptr = buf_hash[b];
if (prev_ptr == bp) {
buf_hash[b] = bp->b_hash;
} else {
/* The block just taken is not on the front of its hash chain. */
while (prev_ptr->b_hash != NULL)
if (prev_ptr->b_hash == bp) {
prev_ptr->b_hash = bp->b_hash; /* found it */
break;
} else {
prev_ptr = prev_ptr->b_hash; /* keep looking */
}
}
/* If the block taken is dirty, make it clean by writing it to the disk.
* Avoid hysteresis by flushing all other dirty blocks for the same device.
*/
if (bp->b_dev != NO_DEV) {
if (ISDIRTY(bp)) flushall(bp->b_dev);
/* Are we throwing out a block that contained something?
* Give it to VM for the second-layer cache.
*/
yieldid = make64(bp->b_dev, bp->b_blocknr);
assert(bp->b_bytes == fs_block_size);
BP_CLEARDEV(bp);
}
/* Fill in block's parameters and add it to the hash chain where it goes. */
if(dev == NO_DEV) BP_CLEARDEV(bp);
else BP_SETDEV(bp, dev);
bp->b_blocknr = block; /* fill in block number */
bp->b_count++; /* record that block is being used */
b = BUFHASH(bp->b_blocknr);
bp->b_hash = buf_hash[b];
buf_hash[b] = bp; /* add to hash list */
if(dev == NO_DEV) {
if(vmcache && cmp64(yieldid, VM_BLOCKID_NONE) != 0) {
vm_yield_block_get_block(yieldid, VM_BLOCKID_NONE,
bp->bp, fs_block_size);
}
return(bp); /* If the caller wanted a NO_DEV block, work is done. */
}
/* Go get the requested block unless searching or prefetching. */
if(only_search == PREFETCH || only_search == NORMAL) {
/* Block is not found in our cache, but we do want it
* if it's in the vm cache.
*/
if(vmcache) {
/* If we can satisfy the PREFETCH or NORMAL request
* from the vm cache, work is done.
*/
if(vm_yield_block_get_block(yieldid, getid,
bp->bp, fs_block_size) == OK) {
return bp;
}
}
}
if(only_search == PREFETCH) {
/* PREFETCH: don't do i/o. */
BP_CLEARDEV(bp);
} else if (only_search == NORMAL) {
read_block(bp);
} else if(only_search == NO_READ) {
/* we want this block, but its contents
* will be overwritten. VM has to forget
* about it.
*/
if(vmcache) {
vm_forgetblock(getid);
}
} else
panic("unexpected only_search value: %d", only_search);
assert(bp->bp);
return(bp); /* return the newly acquired block */
}
开发者ID:tizzybec,项目名称:minix,代码行数:101,代码来源:cache.c
示例17: getF4dscb
int getF4dscb(
CIFBLK *cif,
FORMAT4_DSCB *f4dscb,
DASD_VOL_LABEL *volrec,
DSXTENT *vtocx,
int verbose) {
char vtockey[sizeof(f4dscb->ds4keyid)];
void *f4key, *f4data;
int f4kl, f4dl;
int cyl, head, rec, rc;
// Extract VTOC's CCHHR from volume label
cyl = (volrec->volvtoc[0] << 8) | volrec->volvtoc[1];
head = (volrec->volvtoc[2] << 8) | volrec->volvtoc[3];
rec = volrec->volvtoc[4];
if (verbose > 1)
fprintf(stderr, "getF4dscb VTOC F4 at cyl %d head %d rec %d\n", cyl, head, rec);
// Read VTOC's Format 4 DSCB (VTOC self-descriptor)
if (verbose)
fprintf(stderr, "getF4dscb reading VTOC F4 DSCB\n");
rc = read_block(cif, cyl, head, rec, (void *) &f4key, &f4kl, (void *) &f4data, &f4dl);
if (rc) {
fprintf(stderr, "getF4dscb error reading F4 DSCB, rc %d\n", rc);
return 1;
}
// Verify correct key and data length
if ((f4kl != sizeof(f4dscb->ds4keyid)) ||
(f4dl != (sizeof(FORMAT4_DSCB) - sizeof(f4dscb->ds4keyid)))) {
fprintf(stderr, "getF4dscb erroneous key length %d or data length %d\n",
f4kl, f4dl);
return 2;
}
// Return data to caller
memcpy((void *) &f4dscb->ds4keyid, f4key, f4kl); // copy F4 key into buffer
memcpy((void *) &f4dscb->ds4fmtid, f4data, f4dl); // copy F4 data into buffer
memcpy((void *) vtocx, (void *)&f4dscb->ds4vtoce,
sizeof(f4dscb->ds4vtoce)); // copy VTOC extent entry
if (verbose > 1) {
fprintf(stderr, "getF4dscb F4 DSCB\n");
data_dump((void *) f4dscb, sizeof(FORMAT4_DSCB));
}
// Verify DS4FMTID byte = x'F4', DS4KEYID key = x'04', and DS4NOEXT = x'01'
// Do this after copying data to caller's buffer so we can use struct fields
// rather than having to calculate offset to verified data; little harm done
// if it doesn't verify since we're toast if they're bad.
memset(vtockey, 0x04, sizeof(vtockey));
if ((f4dscb->ds4fmtid != 0xf4) ||
(f4dscb->ds4noext != 0x01) ||
(memcmp(&f4dscb->ds4keyid, vtockey, sizeof(vtockey)))) {
fprintf(stderr, "getF4dscb "
"VTOC format id byte invalid (DS4IDFMT) %2.2X, \n"
"VTOC key invalid, or multi-extent VTOC\n",
f4dscb->ds4fmtid);
return 3;
}
// Display VTOC extent info (always one extent, never more)
if (verbose > 1) {
fprintf (stderr, "getF4dscb "
"VTOC start CCHH=%2.2X%2.2X %2.2X%2.2X "
"end CCHH=%2.2X%2.2X %2.2X%2.2X\n",
vtocx->xtbcyl[0], vtocx->xtbcyl[1],
vtocx->xtbtrk[0], vtocx->xtbtrk[1],
vtocx->xtecyl[0], vtocx->xtecyl[1],
vtocx->xtetrk[0], vtocx->xtetrk[1]);
}
return 0;
} /* getF4dscb */
开发者ID:CrashSerious,项目名称:Pi-hercules,代码行数:79,代码来源:dasdseq.c
示例18: printf
int iaea_header_type::read_header ()
{
char line[MAX_STR_LEN];
if(fheader==NULL)
{
printf("\n ERROR: Unable to open header file \n");
return(FAIL);
}
// ******************************************************************************
// 1. PHSP format
/*********************************************/
if ( read_block(line,"FILE_TYPE") == FAIL )
{
printf("\nMandatory keyword FILE_TYPE is not defined in input\n");
return FAIL;
}
else file_type = atoi(line);
/*********************************************/
if ( read_block(line,"CHECKSUM") == FAIL )
{
printf("\nMandatory keyword CHECKSUM is not defined in input\n");
return FAIL;
}
else checksum = atol(line);
/*********************************************/
if ( read_block(line,"RECORD_LENGTH") == FAIL )
{
printf("\nMandatory keyword RECORD_LENGTH is not defined in input\n");
return FAIL;
}
else record_length = atoi(line);
/*********************************************/
if ( read_block(line,"BYTE_ORDER") == FAIL )
{
printf("\nMandatory keyword BYTE_ORDER is not defined in input\n");
return FAIL;
}
else byte_order = atoi(line);
/*********************************************/
if( get_blockname(line,"RECORD_CONTENTS") == FAIL)
{
|
请发表评论