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


C++ write_inode函数代码示例

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


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

示例1: do_mkdir

void do_mkdir()
{
    struct inode cur_dir,new_dir;
    char dirname[256];
    struct dir_ent ent;
    scanf("%s",dirname);
    if(strcmp(dirname,".")==0 || strcmp(dirname,"..")==0)
    {
        printf("Error directory name.\n");        
        return ;
    }
    get_inode(pwd,&cur_dir);  
        /*分配一个inode给新的目录*/
    new_dir.i_num=alloc_inode();
    new_dir.i_start_sect=alloc_data();        /*分配一个数据扇区*/
    new_dir.i_nr_sects=1;
    
    new_dir.i_pnum=pwd;
    new_dir.i_mode=2;
    new_dir.i_size=0;

        //给新目录增加默认目录项
    ent.i_num=pwd;    strcpy(ent.name,"..");
    add_entry(&new_dir,&ent);
    ent.i_num=new_dir.i_num;  strcpy(ent.name,".");
    add_entry(&new_dir,&ent);  
 
    ent.i_num=new_dir.i_num;    strcpy(ent.name,dirname);     
    add_entry(&cur_dir,&ent);
    //写入inode数组中
    write_inode(pwd,&cur_dir);
    write_inode(new_dir.i_num,&new_dir); 
}
开发者ID:wizardcypress,项目名称:fake-shell,代码行数:33,代码来源:command_list.c

示例2: main

int main(int argc, char **argv) {
  int devfd;

  // get the device from argv
  if(argc != 2) {
    fprintf(stderr, "need to pass in a device\n");
    exit(1);
  }
  // open device
  devfd = open_device(argv[1], O_WRONLY);

  // find if there is enough space -- seek blocks * block size
  verify_device_space(devfd);

  // write the superblock
  write_superblock(devfd);

  // setup the inodes for /
  write_inode(devfd, 3, 1);

  // setup the inode for lost+found
  write_inode(devfd, 2, 2);

  // skip into file section
  // write directories for / ., ..
  struct rdfs_dirent *p = calloc(3, sizeof(struct rdfs_dirent));
  struct rdfs_dirent *dirent = p;
  p->d_inode = 1;
  strcpy(p->d_name, ".");
  p++;
  p->d_inode = 1;
  strcpy(p->d_name, "..");
  p++;
  p->d_inode = 2;
  strcpy(p->d_name, "lost+found");
  write_directory(devfd, dirent, 3, 0);
  free(dirent);

  // write directories for lost+found ., ..
  p = calloc(2, sizeof(struct rdfs_dirent));
  dirent = p;
  p->d_inode = 2;
  strcpy(p->d_name, ".");
  p++;
  p->d_inode = 1;
  strcpy(p->d_name, "..");
  write_directory(devfd, dirent, 2, 1);

  free(dirent);

  return 0;
}
开发者ID:fr0stbyte,项目名称:rdfs,代码行数:52,代码来源:mkfs.c

示例3: do_write

/* 将外部文件写入到镜像中 */
void do_write()
{
    struct stat st;
    struct inode cur_dir,new_file;
    struct dir_ent ent;
    char buf[SECTOR_SIZE+10];
    int i;
    FILE *fin;
    char filename[16];
    scanf("%s",filename);
    if(stat(filename,&st)<0) {
        printf("No such file.\n");
        return ;
    }
    fin=fopen(filename,"rb");
    get_inode(pwd,&cur_dir);
    new_file.i_num=alloc_inode();
    new_file.i_pnum=pwd;
    new_file.i_size=st.st_size; 
    new_file.i_mode=1; //标示为文件
    ent.i_num=new_file.i_num;   strcpy(ent.name,filename);    
    add_entry(&cur_dir,&ent);
    
    u32 last_sector=0,cur_sector;
    u32 need=st.st_size/(SECTOR_SIZE-sizeof(u32))+1;
    new_file.i_nr_sects=need;
        //根据文件大小,逐个分配扇区来写入数据,并采用单链表方式连接各个扇区
    for(i=0;i<need;i++)
    {
        cur_sector=alloc_data();
        if(last_sector==0)  {
            new_file.i_start_sect=cur_sector;
        }else{ //上一个扇区到这个扇区的指针
            fseek(fimg,last_sector*SECTOR_SIZE+SECTOR_SIZE-sizeof(u32),SEEK_SET);
            fwrite(&cur_sector,sizeof(u32),1,fimg);
        }
        int nread=fread(buf,sizeof(char),SECTOR_SIZE-sizeof(u32),fin);
        if(nread<0)  {
            printf("Read file %s error.\n",filename );
            return ;
        }
        fseek(fimg,cur_sector*SECTOR_SIZE,SEEK_SET);
        fwrite(buf,sizeof(char),nread,fimg);
        last_sector=cur_sector;
    }
    fseek(fimg,last_sector*SECTOR_SIZE+SECTOR_SIZE-sizeof(u32),SEEK_SET);
    u32 tmp=0;
    fwrite(&tmp,sizeof(u32),1,fimg);
    write_inode(new_file.i_num,&new_file);
    write_inode(cur_dir.i_num,&cur_dir);
}
开发者ID:wizardcypress,项目名称:fake-shell,代码行数:52,代码来源:command_list.c

示例4: delete_file

long
delete_file(ext2_filsys fs, ext2_ino_t inode)
{
  struct ext2_inode inode_buf;
  long retval;

  if ((retval = read_inode(fs, inode, &inode_buf)))
    {
      fprintf(stderr, "%s\n", error_message(retval));
      return(retval);
    }

  inode_buf.i_dtime = time(NULL);
  if ((retval = write_inode(fs, inode, &inode_buf)))
    {
      fprintf(stderr, "%s\n", error_message(retval));
      return(retval);
    }

  if ((retval = ext2fs_block_iterate(fs, inode, 0, NULL,
                                     release_blocks_proc, NULL)))
    {
      fprintf(stderr, "%s\n", error_message(retval));
      return(retval);
    }

  ext2fs_inode_alloc_stats(fs, inode, -1);

  return(0);
}
开发者ID:er13,项目名称:e2tools,代码行数:30,代码来源:util.c

示例5: emofs_link

/** Crea l'enllaç de una entrada de directori del src_path a l'inode espeificic
 * per la altre entrada de directori link_path. Actualitza la quatitat
 * d'enllaços d'entrades en el directori de l'inode. Té control de
 * concurrència.
 * @src_path: ruta del fitxer a enllaçar
 * @link_path: ruta de l'enllaç
 * @return: 0 si correctament.
 *	    -1 en cas d'error.
 */
int emofs_link(const char *src_path, const char *link_path) {
	int p_dir_src_inode = 0;
	int p_src_inode = 0;
	int p_dir_dst_inode = 0;
	int p_dst_inode = 0;
	int p_entry = 0;

	emofs_inode inode;
	emofs_dir_entry dir_entry;
		
	char link_name[MAX_FILENAME_LEN];
	char partial_link_path[MAX_PATH_LEN];

	if (!mutex){
		emofs_sem_get(&mutex);
	}
	emofs_sem_wait(mutex);
	
	emofs_get_partial_path(link_path, partial_link_path, link_name);
	/* Comprovam i obtenim informació del primer path */
	p_dir_src_inode = 0;
	if (emofs_find_entry(src_path, \
			     &p_dir_src_inode, &p_src_inode, &p_entry) == -1) {
		puts("EmoFS_Link: El fitxer o directori font no existeix");
		emofs_sem_signal(mutex);
		return -1;
	}
	
	/* Comprovam que no estiqui ja creat el fitxer */
	p_dir_dst_inode = 0;
	if (emofs_find_entry(link_path, \
			     &p_dir_dst_inode, &p_dst_inode, &p_entry) == 0) {
		puts("EmoFS_Link: El fitxer ja existeix");
		emofs_sem_signal(mutex);
		return -1;
	}
	
	/* Incrementam el numero d'enllaços de l'inode font */
	read_inode(p_src_inode, &inode);
	inode.link_count++;
	write_inode(p_src_inode, &inode);
	
	/* Cream l'entrada de directori de l'enllaç */
	dir_entry.inode = p_src_inode;
	strcpy(dir_entry.name, link_name);
	
	/* Anam a escriure l'entrada de directori al direcotri desti */
	read_inode(p_dir_dst_inode, &inode); /* Per saber el tamany de fitxer */
	if (write_file(p_dir_dst_inode, &dir_entry, \
		       inode.size, sizeof(emofs_dir_entry)) == -1) {
		puts("EmoFS_Link: Error d'escriptura");
		emofs_sem_signal(mutex);
		return -1;
	}
	emofs_sem_signal(mutex);
	return 0;	
}
开发者ID:bmiro,项目名称:EmoFS,代码行数:66,代码来源:dir.c

示例6: msfs_ftruncate

static int msfs_ftruncate(const char * path, off_t off, struct fuse_file_info * fi) {
	printf("msfs_ftruncate(%s)\n", path);
	reset_error();
	inode_t inode = read_inode((addr_t)fi->fh);
	if(msfs_error != 0) return msfs_error;
	if(!check_access(&inode, O_TRUNC)) return -EPERM;
	inode.attributes.st_size = (addr_t) off;
	write_inode(&inode);
	return msfs_error;
}
开发者ID:torandi,项目名称:craftfs,代码行数:10,代码来源:msfs.cpp

示例7: main

int main ( int argc, char * argv [] )
{
	struct gfs_super *super;
	struct conf conf;
	int super_len, i;
	
	prase_cmdLine(&conf, argv, argc);
	init_conf(&conf);	
	super_len = init_super(&conf, &super);
	
	write_inode(&conf, 0, super, super_len, S_IFREG | 0777);
	write_inode(&conf, 1, NULL, 0, S_IFDIR | 0777);
	for( i = 0;i < conf.nblocks; i++)
		write_inode(&conf, i+2, NULL, 0, 0);
		
	printf("Created fs in file %s.\n%ld blocks with bs %d.\nTotal size %ld bytes.\n",
			conf.fname, conf.nblocks, conf.block_size, conf.nblocks*conf.block_size);	
	return 0;
}
开发者ID:Arseny-N,项目名称:fgfs,代码行数:19,代码来源:mkgfs.c

示例8: Server_UnLink

int Server_UnLink(int inum,char *name)
{	int inode_num,i;
	int dir_inum=inum;
	int last_slash=-1;
	struct inode curr_inode;
	char dir_path[MAXPATHNAMELEN];
	
	if(inum<1||inum>max_inode_num||name==NULL)
		return ERROR;

	inode_num=LookUp(name,inum,0);
	if((inode_num==ERROR)||(inode_num==0))
	{	printf("\nERROR: Path Not Found!");
		return ERROR;
	}

	GetInode(inode_num,&curr_inode);
	if(curr_inode.type==INODE_DIRECTORY)
	{	printf("\nERROR: Cannot Unlink a Directory!");
		return ERROR;
	}

	for(i=0;i<strlen(name);i++)
		if(name[i]=='/')
			last_slash=i;
	if(last_slash==-1)
		dir_inum=inum;
	else if (last_slash==0)
		dir_inum=ROOTINODE;
	else
	{
		strncpy(dir_path,name,last_slash);
		dir_path[last_slash]='\0';
		dir_inum=LookUp(dir_path,inum,0);
	}

	if(curr_inode.nlink>1)
	{
		curr_inode.nlink=curr_inode.nlink-1;
		
	}
	/*Else Delete the file inode and all the blocks allocated to it*/
	else 
	{
		truncate_file(&curr_inode);
		curr_inode.type=INODE_FREE;
		Add_free_inode(inode_num);
		
	}
	Delete_from_dir(dir_inum,inode_num);
	write_inode(inode_num,&curr_inode);
	return 0;

}
开发者ID:rishika23,项目名称:lab3,代码行数:54,代码来源:yfs_04_25_3.c

示例9: sync_inodes

void sync_inodes(kdev_t dev)
{
    register struct inode *inode = first_inode;

    do {
	if (dev && inode->i_dev != dev)
	    continue;
	wait_on_inode(inode);
	if (inode->i_dirt)
	    write_inode(inode);
    } while ((inode = inode->i_prev) != first_inode);
}
开发者ID:lithoxs,项目名称:elks,代码行数:12,代码来源:inode.c

示例10: create_inode

/* alloue et initialise un bloc et range l'inoeud dedans retourne l'inode correspondant*/
unsigned int create_inode(enum file_type_e type) {
	int i,inumber;
	struct inode_s inode;
	inode.type = type;
	inode.ind_size = 0; /* inode size */
	for(i = 0 ; i < NDIRECT; i++) {
		inode.direct[i] = 0;
	}
	inumber = new_bloc();
	if(inumber == 0) { return 0;} /* volume plein */
	write_inode(inumber,&inode); /*on alloue le bloc pour y ranger l'inoeud */
	return inumber;
}
开发者ID:Levrifon,项目名称:ASE,代码行数:14,代码来源:inode.c

示例11: 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

示例12: do_write

int do_write(int fd, char * buf, int n) {

	//_Cli();
	int inode_number = search_for_fd(fd); //search fd in inode;
	if (inode_number == -1) {
		return -1;
	}
	iNode * inode = fs_get_inode(inode_number);
	return write_inode(inode, buf, n);
	//_Sti();	
	//return 1;

}
开发者ID:joseignaciosg,项目名称:SO--TP3-2011,代码行数:13,代码来源:newFs2.c

示例13: create_inode

unsigned int create_inode(enum file_type_e type) {
	int i,inumber;
	struct inode_s inode;
	inode.type = type;
	inode.ind_size = 0;
	inode.taille = 0;
	for(i = 0 ; i < n ; i++) {
		inode.inode_direct[i] = 0;
	}
	inumber = new_bloc();
	if(inumber == 0) { return 0;} /* volume plein */
	write_inode(inumber,&inode);
	return inumber;
}
开发者ID:Levrifon,项目名称:ASE,代码行数:14,代码来源:inode.c

示例14: sync_inodes

void sync_inodes(kdev_t dev)
{
    register struct inode *inode;
    register char *pi;

    inode = first_inode;
    for (pi = 0; ((int) pi) < nr_inodes * 2; pi++, inode = inode->i_next) {
	if (dev && inode->i_dev != dev)
	    continue;
	wait_on_inode(inode);
	if (inode->i_dirt)
	    write_inode(inode);
    }
}
开发者ID:lkundrak,项目名称:elks,代码行数:14,代码来源:inode.c

示例15: printk

struct inode *get_empty_inode(void)
{
    static ino_t ino = 0;
    register struct inode *inode, *best;
    int i;

  repeat:
    inode = first_inode;
    best = 0;
    for (inode = inode_block, i = 0; i < nr_inodes; inode++, i++) {
	if (!inode->i_count && !inode->i_lock && !inode->i_dirt) {
	    best = inode;
	    break;
	}
    }
    if (!best) {
	printk("VFS: No free inodes - contact somebody other than Linus\n");
	list_inode_status();
	sleep_on(&inode_wait);
	goto repeat;
    }
/* Here we are doing the same checks again. There cannot be a significant *
 * race condition here - no time has passed */
#if 0
    if (inode->i_lock) {
	wait_on_inode(inode);
	goto repeat;
    }
    if (inode->i_dirt) {
	write_inode(inode);
	goto repeat;
    }
    if (inode->i_count)
	goto repeat;
#endif
    clear_inode(inode);
    inode->i_count = inode->i_nlink = 1;
#ifdef BLOAT_FS
    inode->i_version = ++event;
#endif
    inode->i_sem = 0;
    inode->i_ino = ++ino;
    inode->i_dev = 0;
    nr_free_inodes--;
    if (nr_free_inodes < 0) {
	printk("VFS: get_empty_inode: bad free inode count.\n");
	nr_free_inodes = 0;
    }
    return inode;
}
开发者ID:lkundrak,项目名称:elks,代码行数:50,代码来源:inode.c


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