/[hurd]/hurd/ext2fs/inode.c
ViewVC logotype

Diff of /hurd/ext2fs/inode.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.62 by roland, Tue Oct 8 23:10:09 2002 UTC revision 1.62.2.1 by ams, Thu Aug 25 18:34:18 2005 UTC
# Line 1  Line 1 
1  /* Inode management routines  /* Inode management routines
2    
3     Copyright (C) 1994,95,96,97,98,99,2000,01,02 Free Software Foundation, Inc.     Copyright (C) 1994,95,96,97,98,99,2000,01,02,05 Free Software Foundation, Inc.
4    
5     Converted for ext2fs by Miles Bader <miles@gnu.org>     Converted for ext2fs by Miles Bader <miles@gnu.org>
6    
# Line 91  diskfs_cached_lookup (ino_t inum, struct Line 91  diskfs_cached_lookup (ino_t inum, struct
91    dn->dir_idx = 0;    dn->dir_idx = 0;
92    dn->pager = 0;    dn->pager = 0;
93    rwlock_init (&dn->alloc_lock);    rwlock_init (&dn->alloc_lock);
94    pokel_init (&dn->indir_pokel, diskfs_disk_pager, disk_image);    pokel_init (&dn->indir_pokel, diskfs_disk_pager, disk_cache);
95    
96    /* Create the new node.  */    /* Create the new node.  */
97    np = diskfs_make_node (dn);    np = diskfs_make_node (dn);
# Line 200  read_node (struct node *np) Line 200  read_node (struct node *np)
200    error_t err;    error_t err;
201    struct stat *st = &np->dn_stat;    struct stat *st = &np->dn_stat;
202    struct disknode *dn = np->dn;    struct disknode *dn = np->dn;
203    struct ext2_inode *di = dino (np->cache_id);    struct ext2_inode *di;
204    struct ext2_inode_info *info = &dn->info;    struct ext2_inode_info *info = &dn->info;
205    
206      ext2_debug ("(%d)", np->cache_id);
207    
208    err = diskfs_catch_exception ();    err = diskfs_catch_exception ();
209    if (err)    if (err)
210      return err;      return err;
211    
212      di = dino_lookup (np->cache_id);
213    
214    st->st_fstype = FSTYPE_EXT2FS;    st->st_fstype = FSTYPE_EXT2FS;
215    st->st_fsid = getpid ();      /* This call is very cheap.  */    st->st_fsid = getpid ();      /* This call is very cheap.  */
216    st->st_ino = np->cache_id;    st->st_ino = np->cache_id;
# Line 275  read_node (struct node *np) Line 279  read_node (struct node *np)
279        info->i_high_size = di->i_size_high;        info->i_high_size = di->i_size_high;
280        if (info->i_high_size)    /* XXX */        if (info->i_high_size)    /* XXX */
281          {          {
282              dino_put (di);
283            ext2_warning ("cannot handle large file inode %Ld", np->cache_id);            ext2_warning ("cannot handle large file inode %Ld", np->cache_id);
284              diskfs_end_catch_exception ();
285            return EFBIG;            return EFBIG;
286          }          }
287      }      }
# Line 297  read_node (struct node *np) Line 303  read_node (struct node *np)
303      }      }
304    dn->info_i_translator = di->i_translator;    dn->info_i_translator = di->i_translator;
305    
306      dino_put (di);
307    diskfs_end_catch_exception ();    diskfs_end_catch_exception ();
308    
309    if (S_ISREG (st->st_mode) || S_ISDIR (st->st_mode)    if (S_ISREG (st->st_mode) || S_ISDIR (st->st_mode)
310        || (S_ISLNK (st->st_mode) && st->st_blocks))        || (S_ISLNK (st->st_mode) && st->st_blocks))
311      {      np->allocsize = round_block (np->dn_stat.st_size);
       unsigned offset;  
   
       np->allocsize = np->dn_stat.st_size;  
   
       /* Round up to a block multiple.  */  
       offset = np->allocsize & ((1 << log2_block_size) - 1);  
       if (offset > 0)  
         np->allocsize += block_size - offset;  
     }  
312    else    else
313      /* Allocsize should be zero for anything except directories, files, and      /* Allocsize should be zero for anything except directories, files, and
314         long symlinks.  These are the only things allowed to have any blocks         long symlinks.  These are the only things allowed to have any blocks
# Line 398  write_node (struct node *np) Line 396  write_node (struct node *np)
396  {  {
397    error_t err;    error_t err;
398    struct stat *st = &np->dn_stat;    struct stat *st = &np->dn_stat;
399    struct ext2_inode *di = dino (np->cache_id);    struct ext2_inode *di;
400    
401      ext2_debug ("(%d)", np->cache_id);
402    
403    if (np->dn->info.i_prealloc_count)    if (np->dn->info.i_prealloc_count)
404      ext2_discard_prealloc (np);      ext2_discard_prealloc (np);
# Line 409  write_node (struct node *np) Line 409  write_node (struct node *np)
409    
410        assert (!diskfs_readonly);        assert (!diskfs_readonly);
411    
412        ext2_debug ("writing inode %d to disk", np->cache_id);        ext2_debug ("writing inode %Ld to disk", np->cache_id);
413    
414        err = diskfs_catch_exception ();        err = diskfs_catch_exception ();
415        if (err)        if (err)
416          return NULL;          return NULL;
417    
418          di = dino_lookup (np->cache_id);
419    
420        di->i_generation = st->st_gen;        di->i_generation = st->st_gen;
421    
422        /* We happen to know that the stat mode bits are the same        /* We happen to know that the stat mode bits are the same
# Line 490  write_node (struct node *np) Line 492  write_node (struct node *np)
492        diskfs_end_catch_exception ();        diskfs_end_catch_exception ();
493        np->dn_stat_dirty = 0;        np->dn_stat_dirty = 0;
494    
495          /* Leave invoking dino_put (di) to the caller.  */
496        return di;        return di;
497      }      }
498    else    else
# Line 649  diskfs_set_translator (struct node *np, Line 652  diskfs_set_translator (struct node *np,
652    if (err)    if (err)
653      return err;      return err;
654    
655    di = dino (np->cache_id);    di = dino_lookup (np->cache_id);
656    blkno = di->i_translator;    blkno = di->i_translator;
657    
658    if (namelen && !blkno)    if (namelen && !blkno)
# Line 662  diskfs_set_translator (struct node *np, Line 665  diskfs_set_translator (struct node *np,
665                          0, 0, 0);                          0, 0, 0);
666        if (blkno == 0)        if (blkno == 0)
667          {          {
668              dino_put (di);
669            diskfs_end_catch_exception ();            diskfs_end_catch_exception ();
670            return ENOSPC;            return ENOSPC;
671          }          }
# Line 685  diskfs_set_translator (struct node *np, Line 689  diskfs_set_translator (struct node *np,
689        np->dn_stat.st_mode &= ~S_IPTRANS;        np->dn_stat.st_mode &= ~S_IPTRANS;
690        np->dn_set_ctime = 1;        np->dn_set_ctime = 1;
691      }      }
692      else
693        dino_put (di);
694    
695    if (namelen)    if (namelen)
696      {      {
697          void *blkptr;
698    
699        buf[0] = namelen & 0xFF;        buf[0] = namelen & 0xFF;
700        buf[1] = (namelen >> 8) & 0xFF;        buf[1] = (namelen >> 8) & 0xFF;
701        bcopy (name, buf + 2, namelen);        memcpy (buf + 2, name, namelen);
702    
703        bcopy (buf, bptr (blkno), block_size);        blkptr = buffer_lookup (blkno);
704        record_global_poke (bptr (blkno));        memcpy (blkptr, buf, block_size);
705          record_global_poke (blkptr);
706    
707        np->dn_stat.st_mode |= S_IPTRANS;        np->dn_stat.st_mode |= S_IPTRANS;
708        np->dn_set_ctime = 1;        np->dn_set_ctime = 1;
# Line 711  diskfs_get_translator (struct node *np, Line 720  diskfs_get_translator (struct node *np,
720    error_t err = 0;    error_t err = 0;
721    daddr_t blkno;    daddr_t blkno;
722    unsigned datalen;    unsigned datalen;
723    const void *transloc;    void *transloc;
724    
725    assert (sblock->s_creator_os == EXT2_OS_HURD);    assert (sblock->s_creator_os == EXT2_OS_HURD);
726    
# Line 719  diskfs_get_translator (struct node *np, Line 728  diskfs_get_translator (struct node *np,
728    if (err)    if (err)
729      return err;      return err;
730    
731    blkno = (dino (np->cache_id))->i_translator;    struct ext2_inode *di = dino_lookup (np->cache_id);
732      blkno = di->i_translator;
733      dino_put (di);
734    assert (blkno);    assert (blkno);
735    transloc = bptr (blkno);    transloc = buffer_lookup (blkno);
736    
737    datalen =    datalen =
738      ((unsigned char *)transloc)[0] + (((unsigned char *)transloc)[1] << 8);      ((unsigned char *)transloc)[0] + (((unsigned char *)transloc)[1] << 8);
# Line 736  diskfs_get_translator (struct node *np, Line 747  diskfs_get_translator (struct node *np,
747          memcpy (*namep, transloc + 2, datalen);          memcpy (*namep, transloc + 2, datalen);
748      }      }
749    
750      buffer_put (transloc);
751    diskfs_end_catch_exception ();    diskfs_end_catch_exception ();
752    
753    *namelen = datalen;    *namelen = datalen;
# Line 757  write_symlink (struct node *node, const Line 769  write_symlink (struct node *node, const
769    
770    assert (node->dn_stat.st_blocks == 0);    assert (node->dn_stat.st_blocks == 0);
771    
772    bcopy (target, node->dn->info.i_data, len);    memcpy (node->dn->info.i_data, target, len);
773    node->dn_stat.st_size = len - 1;    node->dn_stat.st_size = len - 1;
774    node->dn_set_ctime = 1;    node->dn_set_ctime = 1;
775    node->dn_set_mtime = 1;    node->dn_set_mtime = 1;
# Line 774  read_symlink (struct node *node, char *t Line 786  read_symlink (struct node *node, char *t
786    
787    assert (node->dn_stat.st_size < MAX_INODE_SYMLINK);    assert (node->dn_stat.st_size < MAX_INODE_SYMLINK);
788    
789    bcopy (node->dn->info.i_data, target, node->dn_stat.st_size);    memcpy (target, node->dn->info.i_data, node->dn_stat.st_size);
790    return 0;    return 0;
791  }  }
792    

Legend:
Removed from v.1.62  
changed lines
  Added in v.1.62.2.1

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26