当前位置: 首页>>代码示例>>C++>>正文


C++ read_inode函数代码示例

本文整理汇总了C++中read_inode函数的典型用法代码示例。如果您正苦于以下问题:C++ read_inode函数的具体用法?C++ read_inode怎么用?C++ read_inode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了read_inode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: stat_file

/** Obte la informacio d'un inode. 
 * @inode: nombre del fitxer.
 * @stat: el punter de sortida de les dades.
 * @return: 0 si exit.
 */
int stat_file(int inode, emofs_inode_stat *stat) {
	emofs_inode tmp;
	int error;
	
	error = read_inode(inode, &tmp);
	if (error > -1) {
		memcpy(stat, &tmp, sizeof(emofs_inode_stat));
	}
	return error;
}
开发者ID:bmiro,项目名称:EmoFS,代码行数:15,代码来源:file.c

示例2: mkdir_handler

//handling mkdir request
void mkdir_handler(Msg *msg, int sender_pid)
{
    char pathname[MAXPATHNAMELEN];
    CopyFrom(sender_pid,pathname,msg->ptr1,msg->num1+1);
    char* dir_name = pathname+msg->num1;
    int direct_len = msg->num1;
    while ((*dir_name)!='/' && dir_name!=pathname) {
        dir_name--;
        direct_len--;
    }
    if ((*dir_name)=='/') {
        direct_len++;
        dir_name++;
    }
    if (strlen(dir_name)==0) {
        perror("invalid pathname when creating file!");
        msg->type = ERROR;
        return;
    }
    int direct_inum = path_to_inum(pathname,direct_len,msg->num2,0);
    if (direct_inum<=0) {
        perror("invalid pathname when creating file!");
        msg->type = ERROR;
        return;
    }
    int new_inum = check_dir(direct_inum,dir_name);
    if (new_inum<0) {
        perror("invalid pathname when creating file!");
        msg->type = ERROR;
        return;
    }

    //exist same file name in the directory
    else if (new_inum>0) {
        perror("exist a directory with same name");
        msg->type = ERROR;
        return;
    }
    else if (new_inum==0) {
        new_inum = alloc_inode(INODE_DIRECTORY,direct_inum);
        struct dir_entry *d = empty_dir(direct_inum);
        if (d==NULL) {
            perror("no empty space for new directory");
            msg->type = ERROR;
            return;
        }
        d->inum = new_inum;
        memcpy(d->name,dir_name,strlen(dir_name));
        inode_cache *n = read_inode(direct_inum);
        n->data.nlink++;
        n->data.size+=sizeof(struct dir_entry);
        n->dirty = 1;
        msg->num1 = 0;
    }
}
开发者ID:liujun77,项目名称:Yalnix-File-System,代码行数:56,代码来源:yfs.c

示例3: ext2_read

ssize_t ext2_read(open_file_descriptor * ofd, void * buf, size_t size) {
	if ((ofd->flags & O_ACCMODE) == O_WRONLY) {
		return 0;
	}
	int inode = ofd->inode->i_ino;
	if (inode >= 0) {
		ext2_fs_instance_t *instance = (ext2_fs_instance_t*) ofd->fs_instance;
		off_t offset = ofd->current_octet;
		int count = 0;
		struct ext2_inode *einode = read_inode(instance, inode);
		
		if (offset >= einode->i_size) {
			return 0;
		}

		if (size + offset > einode->i_size) {
			size = einode->i_size - offset;
		}
		
		int n_blk = 0;
		while (offset >= (unsigned int)(1024 << instance->superblock.s_log_block_size)) {
			n_blk++;
			offset -= (1024 << instance->superblock.s_log_block_size);
		}
		//int n_blk = offset / (1024 << instance->superblock.s_log_block_size);
		//offset %= (1024 << instance->superblock.s_log_block_size);
		//
		while (size > 0) {
			int addr = addr_inode_data2(instance, einode, n_blk);
			if (addr == 0) break;
			n_blk++;

			size_t size2 = (1024 << instance->superblock.s_log_block_size) - offset;
			if (size2 > size) {
				size2 = size;
			}

			instance->read_data(instance->super.device, ((char*)buf) + count, size2, addr + offset);

			size -= size2;
			count += size2;
			offset = 0;
		}

		// Commenté pour des raisons évidentes de perf.
		//	struct timeval tv;
		//	gettimeofday(&tv, NULL);
		//	einode.i_atime = tv.tv_sec;
		//	write_inode(inode, &einode);
		ofd->current_octet += count;
		return count;
	} else {
		return inode;
	}
}
开发者ID:TacOS-team,项目名称:tacos,代码行数:55,代码来源:ext2_functions.c

示例4: output_files

/**
 * @brief 输出文件 
 * @param[in] absolute_path 文件的绝对路径
 * @param[in] all           是否输出全部文件,包括隐藏文件,以及.和..
 * @param[in] almost_all    是否“几乎全部”输出,包括隐藏文件,不包括.和..
 * @param[in] long_list     是否按长列表方式输出
 */
void output_files( const char * absolute_path, bool all, bool almost_all, bool long_list )  // ls
{
	struct ext2_group_desc group;
	struct ext2_inode inode;
	void * block = NULL;

	int inode_no = get_file_inode_no(absolute_path);
	if ( inode_no == -1 )
	{
		fprintf(stderr, "Current directory does not exist.\n");
		return;
	}
	read_group_descriptor(&group);
	read_inode(&group, &inode, inode_no);

	if (S_ISDIR(inode.i_mode))
	{
		struct ext2_dir_entry_2 * entry = NULL;
		unsigned int size = 0;
		if ((block = malloc(block_size)) == NULL)
		{
			fprintf(stderr, "Insufficient memory.\n");
			exit(EXIT_FAILURE);
		}

		lseek(fd_ext2, BLOCK_OFFSET(inode.i_block[0]), SEEK_SET);
		read(fd_ext2, block, block_size);                // read block from disk

		entry = (struct ext2_dir_entry_2 *) block;  // first entry in the directory
		// Notice that the list may be terminated with a NULL entry (entry->inode == NULL)
		while((size < inode.i_size) && entry->inode)
		{
			if ( entry->name[0] == '.' )
			{
				if ( all )
					output_entry(entry, long_list, entry->inode);
				else if ( almost_all )
				{
					if ( strcmp(entry->name, ".") && strcmp(entry->name, "..") )
						output_entry(entry, long_list, entry->inode);
				}
			}
			else
				output_entry(entry, long_list, entry->inode);
			entry = (struct ext2_dir_entry_2 *)((void *)entry + entry->rec_len);
			size += entry->rec_len;
		}
		puts("");

		free(block);
		block = entry = NULL;
	}
	else
		fprintf(stderr, "Current directory does not exist.\n");
}
开发者ID:freshpassport,项目名称:hnust_2012_operating_system_course_design,代码行数:62,代码来源:ext2.c

示例5: ext2_open_inode

void ext2_open_inode(uint32_t inode_num, Ext2_file *file)
{
	read_inode(&file->inode, inode_num);
	file->pos            = 0;
	file->block_index    = 0;
	file->buf            = kmalloc(block_size);
	file->curr_block_pos = 0;

	// Read in the first block immediately
	read_block(file->inode.dbp[0], file->buf);
}
开发者ID:orodley,项目名称:studix,代码行数:11,代码来源:ext2.c

示例6: msfs_readdir

static int msfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, fuse_file_info *fi) {
	reset_error();
	printf("msfs_readdir(%s) inode %lu\n", path, fi->fh);
	inode_t entry_inode, inode = read_inode((addr_t)fi->fh);
	if(msfs_error != 0) return msfs_error;

	bump_atime(&inode);

	addr_t addr = 0;
	file_entry_t * entry;

	entry = next_file_entry(&inode, &addr);

	while(entry != NULL) {
		entry_inode = read_inode(entry->address);
		filler(buf, entry->name, &entry_inode.attributes, 0);
		free_file_entry(entry);
		entry = next_file_entry(&inode, &addr);
	}
	return msfs_error;
}
开发者ID:torandi,项目名称:craftfs,代码行数:21,代码来源:msfs.cpp

示例7: msfs_read

static int msfs_read(const char *path, char *buf, size_t size, off_t offset, fuse_file_info *fi) {
	printf("msfs_read(%s)\n", path);
	reset_error();
	inode_t inode = read_inode((addr_t)fi->fh);
	if(msfs_error != 0) return msfs_error;

	bump_atime(&inode);

	int bytes = read_inode_data(&inode, offset, size, buf);
	if(msfs_error != 0) return msfs_error;
	return bytes;
}
开发者ID:torandi,项目名称:craftfs,代码行数:12,代码来源:msfs.cpp

示例8: ext2_symlink

int ext2_symlink(inode_t *dir, dentry_t *dentry, const char* target) {
	int ret = ext2_mknod(dir, dentry, 0777 | EXT2_S_IFLNK, 0);
	if (ret) {
		return ret;
	}

	int inode = dentry->d_inode->i_ino;
	ext2_fs_instance_t* instance = (ext2_fs_instance_t*)dir->i_instance;
	struct ext2_inode *einode = read_inode(instance, inode);
	ext2_write2inode(instance, inode, einode, 0, target, strlen(target));
	return 0;
}
开发者ID:TacOS-team,项目名称:tacos,代码行数:12,代码来源:ext2_functions.c

示例9: lfs_write

ssize_t lfs_write(int filedes, const void *buf, size_t count) {
	int err, write = 0;
	struct inode* node;

	unsigned int* block = malloc(BLOCK_SIZE);
	if (!block) {
		return -ENOMEM;
	} else {
		node = malloc(INODE_SIZE);
		if (!node) {
			err = -ENOMEM;
		} else {
			err = read_inode(log_system, filedes, node);
			if (node->file_size % BLOCK_SIZE == 0) {
				/*All blocks started on are filled*/
				write = count;
				if (node->number_of_blocks >= BLOCKS_PR_INODE) {
					return -ENOMEM;
				}
				if (count > BLOCK_SIZE) {
					write = BLOCK_SIZE;
				}
				memcpy(block, buf, write);
				node->blocks_changed[node->number_of_blocks] = 1;
				node->number_of_blocks++;
				node->file_size += write;
				err = buff_write_inode_with_changes(log_system, node, block);
				if (!err) {
					int start = (node->file_size % BLOCK_SIZE);
					write = BLOCK_SIZE - start;
					if (write > count) {
						write = count;
					}
					err = read_block(log_system, block,
							node->block_placements[node->number_of_blocks - 1]);
					if (!err) {
						node->blocks_changed[node->number_of_blocks - 1] = 1;
						memcpy(&block[start], buf, write);
						node->file_size += write;
						err = buff_write_inode_with_changes(log_system, node, block);
					}
				}
			}
			free(node);
		}
		free(block);
	}
	if (err < 0) {
		return err;
	}
	return write;
}
开发者ID:kitalda,项目名称:lfs,代码行数:52,代码来源:lfs.c

示例10: close_ifile

void
close_ifile(file_desc_t *fd)
{
    struct inode_s inode;
    
    /* if the buffer is dirty, flush the file */
    flush_ifile(fd);
    
    /* update the inode information (size) */
    read_inode(fd->fds_inumber, &inode);
    inode.ind_size = fd->fds_size;
    write_inode(fd->fds_inumber, &inode);
}
开发者ID:ErwanDouaille,项目名称:Lille1-Master-Info,代码行数:13,代码来源:ifile.c

示例11: ext2_mknod

int ext2_mknod(inode_t *dir, dentry_t *dentry, mode_t mode, dev_t dev) {
        int ino =  mknod_inode((ext2_fs_instance_t*)dir->i_instance, dir->i_ino, dentry->d_name, mode, dev);
        if (ino == 0) {
                return -ENOTDIR; //XXX
        }
        struct ext2_inode *einode = read_inode((ext2_fs_instance_t*)dir->i_instance, ino);

        dentry->d_inode = (inode_t*)kmalloc(sizeof(inode_t),0);
        ext2inode_2_inode(dentry->d_inode, dir->i_instance, ino, einode);
        dentry->d_inode->i_count = 0;

        return 0;
}
开发者ID:desiros777,项目名称:desiros,代码行数:13,代码来源:ext2_functions.c

示例12: debug3

struct inode *__iget(register struct super_block *sb,
		     ino_t inr /*,int crossmntp */ )
{
    register struct inode *inode;

    debug3("iget called(%x, %d, %d)\n", sb, inr, 0 /* crossmntp */ );
    if (!sb)
	panic("VFS: iget with sb==NULL");

  repeat:
    do {
	inode = first_inode;
	do {
	    if (inode->i_dev == sb->s_dev && inode->i_ino == inr)
		goto found_it;
	} while ((inode = inode->i_prev) != first_inode);
	debug("iget: getting an empty inode...\n");
    } while (!(inode = get_empty_inode()));
    debug1("iget: got one... (%x)!\n", empty);

    inode->i_sb = sb;
    inode->i_dev = sb->s_dev;
    inode->i_flags = ((unsigned short int) sb->s_flags);
    inode->i_ino = inr;
    put_last_lru(inode);
    debug("iget: Reading inode\n");
    read_inode(inode);
    debug("iget: Read it\n");
    goto return_it;

  found_it:
    if (!inode->i_count)
	nr_free_inodes--;
    inode->i_count++;
    wait_on_inode(inode);
    if (inode->i_dev != sb->s_dev || inode->i_ino != inr) {
	printk("Whee.. inode changed from under us. Tell _.\n");
	iput(inode);
	goto repeat;
    }
    if ( /* crossmntp && */ inode->i_mount) {
	struct inode *tmp = inode->i_mount;
	tmp->i_count++;
	iput(inode);
	inode = tmp;
	wait_on_inode(inode);
    }

  return_it:
    return inode;
}
开发者ID:lithoxs,项目名称:elks,代码行数:51,代码来源:inode.c

示例13: main

int main(int argc, char **argv)
{
	FILE *boot, *img;
	char boot_buf[512];
	short buf2[512];
	short blocks[256];
	struct inode inode;
	int i = 0;

	if (argc != 3) {
		fprintf(stderr, "install-boot boot.bin dev_name\n");
		exit(0);
	}

	boot = fopen(argv[1], "rb");
	if (boot == NULL) {
		fprintf(stderr, "File Open Error:%s", argv[3]);
		exit(0);
	}

	img = fopen(argv[2], "r+");
	if (img == NULL) {
		fprintf(stderr, "File Open Error:%s", argv[1]);
		exit(0);
	}

	fread(boot_buf, 512, 1, boot);
	fclose(boot);

	read_super(img);

	read_inode(img, 1, &inode);

	look_up(img, &inode, "boot");
	look_up(img, &inode, "kernel");

	memset(blocks, 0, 512);
	for (i = 0; i < 7; i++)
		blocks[i] = inode.i_zone[i];

	read_block(img, inode.i_zone[7], (char*) buf2);
	while (i * 1024 < inode.i_size) {
		blocks[i] = buf2[i - 7];
		i++;
	}

	fseek(img, 0, 0);
	fwrite(boot_buf, 1, 512, img);
	fwrite(blocks, 1, 512, img);
	fclose(img);
}
开发者ID:kenanconan,项目名称:firekylin,代码行数:51,代码来源:install-boot.c

示例14: read_inode

//search for dir_entry from parent dir
struct dir_entry *search_dir_entry(int direct_inum, char* filename)
{
    inode_cache *dir = read_inode(direct_inum);
    
    if (dir->data.type!=INODE_DIRECTORY) return NULL;
    int i,block_num;

    //check direct blocks
    for (i=0; i<NUM_DIRECT; i++) {
        if (dir->data.direct[i]<=0) break;
        block_num = dir->data.direct[i];
        block_cache *b = read_block(block_num);
        struct dir_entry *d = (struct dir_entry*)(b->data);
        int j;
        for (j=0; j<DIRS_PER_BLOCK; j++) {
            if (d[j].inum<=0) continue;
            if (isEqual(d[j].name,filename)){
                dir->dirty=1;
                b->dirty=1;
                return &d[j];
            }
        }
    }

    //check indirect bloc
    if (dir->data.indirect!=0) {
        block_num = dir->data.indirect;
        block_cache *b = read_block(block_num);
        int j;
        block_cache *tmp;
        for (j=0; j<BLOCKSIZE; j+=4) {
            block_num = *(int*)(b->data+j);
            if (block_num!=0) {
                tmp = read_block(block_num);
                struct dir_entry *d = (struct dir_entry*)(tmp->data);
                int k;
                for (k=0; k<DIRS_PER_BLOCK; k++) {
                    if (d[j].inum<=0) continue;
                    if (isEqual(d[j].name,filename)){
			dir->dirty=1;
                        tmp->dirty=1;
                        return &d[j];
                    }
                }
            }
            else break;
        }
    }

    return NULL;
}
开发者ID:liujun77,项目名称:Yalnix-File-System,代码行数:52,代码来源:yfs.c

示例15: find_file

static u_int16_t find_file(struct minix_superblock *sb, unsigned long address, const char *fname)
{
	unsigned long offset = 0;
	struct minix_dentry dentry;
	struct minix_inode inode;
	unsigned long inode_tbl_bass = get_inode_table_address(*sb);
	const char *tmp;
	u_int16_t ret = 0;

	int len = 0;
	int ftype;
	while (1) {
		// read first entry.
		read_dentry(&dentry, address, offset);

		if (dentry.inode == 0)
			break;

		read_inode(dentry.inode, &inode, inode_tbl_bass);

		tmp = fname;
		if (tmp[0] == '/') 
			tmp = tmp + 1;

		ftype = get_file_type(&inode); 
		if (ftype == I_FT_DIR) {
			len = count_delimita_length(tmp, '/');
			if (len == -1) {
				if (!strcmp(tmp, dentry.name))
					return dentry.inode;
			} else if (!strncmp(tmp, dentry.name, len)) {
				ret = find_file(sb, get_data_zone(inode.i_zone[0]), tmp + len);
			} else {
				// if final character is '/', finish searching.
				if (!strcmp(tmp + len, "/"))
					return dentry.inode;
			}
		} else if (ftype == I_FT_REGULAR) {
			if (!strcmp(dentry.name, tmp))
				return dentry.inode;
		}
		if (ret)
			return ret;

		offset += sizeof(dentry) - 1;
	}

	return 0;

}
开发者ID:masami256,项目名称:ext2test,代码行数:50,代码来源:test.c


注:本文中的read_inode函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。