本文整理汇总了C++中put_block函数的典型用法代码示例。如果您正苦于以下问题:C++ put_block函数的具体用法?C++ put_block怎么用?C++ put_block使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了put_block函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: minix_dir_empty
static int minix_dir_empty(struct inode *dir)
{
struct block *block;
struct minix_dentry *de;
int entries, i, k, n;
/* Assert that @dir is directory inode. */
entries = dir->i_size / MINIX_DENTRY_SIZE;
for (i = 0; i < entries; i += n) {
n = min(entries - i, MINIX_DENTRIES_PER_BLOCK);
block = bmap_block(dir, i / MINIX_DENTRIES_PER_BLOCK, 0);
if (!block)
continue;
de = (struct minix_dentry *)block->b_data;
for (k = 0; k < n; k++, de++) {
if (de->d_ino == 0)
continue;
if (de->d_name[0] != '.')
goto not_empty;
if (de->d_name[1] == '\0') {
if (de->d_ino != dir->i_ino)
panic("The inode number of . corrupts");
continue;
}
if (de->d_name[1] != '.' || de->d_name[2] != '\0')
goto not_empty;
}
put_block(block);
}
return 1;
not_empty:
put_block(block);
return 0;
}
示例2: bmap_block
struct minix_dentry *minix_lookup_dentry(struct inode *dir, char *base, int len, struct block **b)
{
struct minix_dentry *de;
struct block *block;
int entries, i, k, n;
if (len > MINIX_NAME_LEN)
return NULL;
entries = dir->i_size / MINIX_DENTRY_SIZE;
for (i = 0; i < entries; i += n) {
block = bmap_block(dir, i / MINIX_DENTRIES_PER_BLOCK, 0);
de = (struct minix_dentry *)block->b_data;
n = min(entries - i, MINIX_DENTRIES_PER_BLOCK);
for (k = 0; k < n; k++, de++) {
if (de->d_ino == 0)
continue;
/* strncmp skips deleted entry automatically. */
if (strlen(de->d_name) == len &&
!strncmp(de->d_name, base, len))
goto found;
}
put_block(block);
}
return NULL;
found:
if (b)
*b = block;
else
put_block(block);
return de;
}
示例3: dir_search
/**
* Looks for entry 'file' in the given directory contents. The inode is
* assumed to be of directory type.
*
* If the file is found it's inode number is returned, otherwise NO_INODE is
* returned.
*/
inode_nr dir_search(struct minix_inode *inode, const char *file)
{
struct minix_block *blk; /* block belonging to inode */
zone_nr z;
int c_pos = 0; /* current position in scan of directory */
int i; /* current position in directory block */
inode_nr retval;
debug("dir_search(%d, \"%s\"): searching...", inode->i_num,
file);
while((z = read_map(inode, c_pos)) != NO_ZONE) {
blk = get_block(z, TRUE);
/* TODO: fix bug. shouldn't use BLOCK_SIZE */
for(i = 0; i < BLOCK_SIZE; i+= DENTRY_SIZE) {
if(strcmp((char *)(blk->blk_data + i + 2), file) == 0) {
retval = *((inode_nr *)(blk->blk_data + i));
put_block(blk, DIR_BLOCK);
debug("dir_search(): found \"%s\" at ix=%d",
file, i);
return retval;
}
}
put_block(blk, DIR_BLOCK);
c_pos += BLOCK_SIZE;
}
/* couldn't find directory entry */
debug("dir_search(%d, \"%s\"): couldn't find entry", inode->i_num,
file);
return NO_INODE;
}
示例4: block_test
void block_test(void)
{
struct block *block;
unsigned char *p;
int i;
block = get_block(&hd_bdev, 0);
if (!block)
panic("Cannot get block");
if (block != get_block(&hd_bdev, 0))
panic("Cannot get hash block");
put_block(block);
p = (unsigned char *)block->b_data;
if (p[510] != 0x55 || p[511] != 0xaa)
panic("ERROR 0x55aa");
p[0] = 'h';
p[1] = 'k';
block->b_dirty = 1;
put_block(block);
block = get_block(&hd_bdev, 0);
p = (unsigned char *)block->b_data;
if (p[0] != 'h' || p[1] != 'k')
panic("block WRITE or READ error");
for (i = 0; i < 512; i++)
p[i] = 0xff;
block->b_dirty = 1;
put_block(block);
printk("flush buffer\n");
flush_block_buffer();
block = get_block(&hd_bdev, 0);
printk("test block ok\n");
}
示例5: sfs_write
int sfs_write(int fd, int start, int length, char *mem_pointer){
int size;
int i;
/* if(sscanf(fd, "%i", &intvar)!=1)
return -1;
if(sscanf(start, "%i" , &intvar)!=1)
return -1;
if(sscanf(length, "%i", &intvar)!=1)
return -1;
*/
if(strlen(mem_pointer)!=length){
printf("too many characters entered!");
return -1;
}
if(inode[fd][1]==1)
return -1;
if(OpenFileTable[fd][0]==0)
return -1;
if(OpenFileTable[fd][0]>1)
return -1;
printf("%d", strlen(mem_pointer));
char tmp_buffer[MAX_IO_LENGTH+1];
printf("%d", inode[fd][2]);
size=inode[fd][2];
memcpy(tmp_buffer, RAM[OpenFileTable[fd][1]], sizeof(RAM[OpenFileTable[fd][1]]));
if(!(inode[fd][3]==NULL)){
if(start==-1){
if(size!=0){
strcat(tmp_buffer, mem_pointer);
//memcpy(mem_pointer, tmp_buffer, sizeof(tmp_buffer));
}
inode[fd][2]=size+length;
memcpy(RAM[OpenFileTable[fd][1]], tmp_buffer, sizeof(tmp_buffer));
put_block(inode[fd][3],mem_pointer);
return 1;
//char tmp_buffer2[size + length+1];
//get_block(inode[fd][3], tmp_buffer);
}else if((start + length)> size){
printf("size issue");
return -1;
}else{
memcpy(tmp_buffer, RAM[OpenFileTable[fd][1]], sizeof(RAM[OpenFileTable[fd][1]]));
for(i=start;i<start+length;i++){
tmp_buffer[i]=mem_pointer[i-start];
}
//memcpy(tmp_buffer+start, mem_pointer, sizeof(mem_pointer));
memcpy(RAM[OpenFileTable[fd][1]], tmp_buffer, sizeof(tmp_buffer));
put_block(inode[fd][3],mem_pointer);
return 1;
}
}
return -1;
}
示例6: decFreeInodes
int decFreeInodes(int fd) {
char buf[BLOCK_SIZE];
// dec free inodes count in Super and GroupDesc
_get_block(fd, 1, buf);
Super * super = (Super *) buf;
super->s_free_inodes_count--;
put_block(fd, 1, buf);
_get_block(fd, 2, buf);
GroupDesc * gp = (GroupDesc *) buf;
gp->bg_free_inodes_count--;
put_block(fd, 2, buf);
return 0;
}
示例7: minix_lookup_dentry
struct inode *minix_inode_create(struct inode *dir, char *base, int len)
{
struct minix_dentry *de;
struct inode *inode;
struct block *block;
int entries, i, k, n;
if (len > MINIX_NAME_LEN)
return NULL;
/* exist? */
de = minix_lookup_dentry(dir, base, len, NULL);
if (de)
return NULL;
/* find an empty dir entry */
entries = dir->i_size / MINIX_DENTRY_SIZE;
for (i = 0; i < entries; i += n) {
block = bmap_block(dir, i / MINIX_DENTRIES_PER_BLOCK, 0);
de = (struct minix_dentry *)block->b_data;
n = min(entries - i, MINIX_DENTRIES_PER_BLOCK);
for (k = 0; k < n; k++, de++) {
if (de->d_ino == 0)
goto found;
}
if (i + n < entries || !(entries % MINIX_DENTRIES_PER_BLOCK)) {
put_block(block);
block = NULL;
}
}
/* create a new data block and get dir entry from it */
if (!block) {
block = bmap_block(dir, entries / MINIX_DENTRIES_PER_BLOCK, 1);
if (!block)
return NULL;
if (block->b_refcnt != 1)
panic("Not new block(ref:%d)", block->b_refcnt);
de = (struct minix_dentry *)block->b_data;
}
inode_update_size(dir, dir->i_size + MINIX_DENTRY_SIZE);
found:
inode = minix_new_inode(dir->i_sb);
if (!inode)
goto out;
/* fill dir entry */
strncpy(de->d_name, base, len);
de->d_name[len] = '\0';
de->d_ino = inode->i_ino;
minix_inode_dirty_block(dir, block);
out:
put_block(block);
return inode;
}
示例8: updateFreeInodes
int updateFreeInodes(int devId, int delta) {
char buf[BLKSIZE];
// dec free inodes count in SUPER and GD
get_block(devId, 1, buf);
sp = (SUPER *)buf;
sp->s_free_inodes_count + delta;
put_block(devId, 1, buf);
get_block(devId, 2, buf);
gp = (GD *)buf;
gp->bg_free_inodes_count + delta;
put_block(devId, 2, buf);
}
示例9: updateFreeBlocks
//Pass 1 to increase by 1, -1 to decrease by 1, etc
int updateFreeBlocks(int devId, int delta) {
char buf[BLKSIZE];
// update free block count in SUPER and GD
get_block(devId, 1, buf);
sp = (SUPER *)buf;
sp->s_free_blocks_count + delta;
put_block(devId, 1, buf);
get_block(devId, 2, buf);
gp = (GD *)buf;
gp->bg_free_blocks_count + delta;
put_block(devId, 2, buf);
}
示例10: decFreeInodes
void decFreeInodes(int dev)
{
char buf[BLKSIZE];
//dec free inodes count in SUPER and gd
get_block(dev, 1, buf);
sp = (SUPER *)buf;
sp->s_free_inodes_count--;
put_block(dev, 1, buf);
get_block(dev, 2, buf);
gp = (GD *)buf;
gp->bg_free_inodes_count--;
put_block(dev, 2, buf);
}
示例11: split_index_node
/* splits the index node at the given level of the given path */
PRIVATE int split_index_node(struct root *r, struct path *p, int level) {
int slot = p->slots[level];
struct cache *left = p->nodes[level];
int nritems = left->u.node.header.nritems;
int nrstaying = nritems/2; /* smaller half stays on the left */
int nrmoving = nritems - nrstaying; /* larger half moves to the right */
struct cache *right;
blocknr_t rightnr;
assert(left->will_write); /* was ensured on tree descent */
rightnr = alloc_block(r->fs_info, left, left->u.node.header.type);
if (!rightnr) return -ENOSPC;
right = init_node(rightnr, left->u.node.header.type, level);
if (!right) return -errno;
if(is_root_level(level, p)) { /* no node above, so need to grow tree */
blocknr_t new_rootnr;
struct cache *c;
assert(level < MAX_LEVEL - 1); /* has room to add another level */
new_rootnr = alloc_block(r->fs_info, right, right->u.node.header.type);
if (!new_rootnr) return -ENOSPC;
c = init_node(new_rootnr, right->u.node.header.type, level + 1);
if (!c) return -errno;
p->nodes[level + 1] = c;
p->slots[level + 1] = 0; /* path on the left node */
insert_key_ptr(r, p, level + 1,
key_for(left, 0), left->write_blocknr);
r->blocknr = new_rootnr;
}
memmove(&right->u.node.u.key_ptrs[0], /* move larger half to right node */
&left->u.node.u.key_ptrs[nrstaying],
nrmoving * sizeof(struct key_ptr));
right->u.node.header.nritems = nrmoving;
memset(&left->u.node.u.key_ptrs[nrstaying], 0, /* clear moved in left */
nrmoving * sizeof(struct key_ptr));
left->u.node.header.nritems = nrstaying;
p->slots[level + 1]++; /* temporarily, for inserting in parent node */
insert_key_ptr(r, p, level + 1, key_for(right, 0), rightnr);
if (slot >= nrstaying) { /* need to change path to the right */
p->nodes[level] = right;
p->slots[level] = slot - nrstaying;
put_block(left); /* free left since it's now off the path */
} else {
p->slots[level + 1]--; /* path back to left node in parent node */
put_block(right); /* free right since it's not on the path */
}
return SUCCESS;
}
示例12: dir_try_enter
int
dir_try_enter(zone_t z, ino_t child, char const *name)
{
struct direct *dir_entry = alloc_block();
int r = 0;
block_t b;
int i, l;
b = z << zone_shift;
for (l = 0; l < zone_per_block; l++, b++) {
get_block(b, dir_entry);
for (i = 0; i < NR_DIR_ENTRIES(block_size); i++)
if (!dir_entry[i].d_ino)
break;
if(i < NR_DIR_ENTRIES(block_size)) {
r = 1;
dir_entry[i].d_ino = child;
assert(sizeof(dir_entry[i].d_name) == MFS_DIRSIZ);
if (verbose && strlen(name) > MFS_DIRSIZ)
fprintf(stderr, "File name %s is too long, truncated\n", name);
strncpy(dir_entry[i].d_name, name, MFS_DIRSIZ);
put_block(b, dir_entry);
break;
}
}
free(dir_entry);
return r;
}
示例13: insert_bit
/* Insert one bit into the bitmap */
void
insert_bit(block_t map, bit_t bit)
{
int boff, w, s;
unsigned int bits_per_block;
block_t map_block;
bitchunk_t *buf;
buf = alloc_block();
bits_per_block = FS_BITS_PER_BLOCK(block_size);
map_block = map + bit / bits_per_block;
if (map_block >= inode_offset)
pexit("insertbit invades inodes area - this cannot happen");
boff = bit % bits_per_block;
assert(boff >=0);
assert(boff < FS_BITS_PER_BLOCK(block_size));
get_block(map_block, buf);
w = boff / FS_BITCHUNK_BITS;
s = boff % FS_BITCHUNK_BITS;
buf[w] |= (1 << s);
put_block(map_block, buf);
free(buf);
}
示例14: incr_size
/* Increment the file-size in inode n */
void
incr_size(ino_t n, size_t count)
{
block_t b;
int off;
b = ((n - 1) / inodes_per_block) + inode_offset;
off = (n - 1) % inodes_per_block;
{
struct inode *inodes;
assert(inodes_per_block * sizeof(*inodes) == block_size);
if(!(inodes = alloc_block()))
err(1, "couldn't allocate a block of inodes");
get_block(b, inodes);
/* Check overflow; avoid compiler spurious warnings */
if (inodes[off].i_size+(int)count < inodes[off].i_size ||
inodes[off].i_size > MAX_MAX_SIZE-(int)count)
pexit("File has become too big to be handled by MFS");
inodes[off].i_size += count;
put_block(b, inodes);
free(inodes);
}
}
示例15: incr_link
/* Increment the link count to inode n */
void
incr_link(ino_t n)
{
int off;
static int enter = 0;
static struct inode *inodes = NULL;
block_t b;
if (enter++) pexit("internal error: recursive call to incr_link()");
b = ((n - 1) / inodes_per_block) + inode_offset;
off = (n - 1) % inodes_per_block;
{
assert(sizeof(*inodes) * inodes_per_block == block_size);
if(!inodes && !(inodes = alloc_block()))
err(1, "couldn't allocate a block of inodes");
get_block(b, inodes);
inodes[off].i_nlinks++;
/* Check overflow (particularly on V1)... */
if (inodes[off].i_nlinks <= 0)
pexit("Too many links to a directory");
put_block(b, inodes);
}
enter = 0;
}