8000 minix/minix/fs/ext2/inode.c at master · hakan-akan/minix · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
420 lines (351 loc) · 13.4 KB

inode.c

File metadata and controls

420 lines (351 loc) · 13.4 KB
/*===========================================================================*
* rw_inode *
*===========================================================================*/
void rw_inode(
register struct inode *rip, /* pointer to inode to be read/written */
int rw_flag /* READING or WRITING */
)
{
/* An entry in the inode table is to be copied to or from the disk. */
register struct buf *bp;
register struct super_block *sp;
register struct group_desc *gd;
register d_inode *dip;
u32_t block_group_number;
block_t b, offset;
/* Get the block where the inode resides. */
sp = get_super(rip->i_dev); /* get pointer to super block */
rip->i_sp = sp; /* inode must contain super block pointer */
block_group_number = (rip->i_num - 1) / sp->s_inodes_per_group;
gd = get_group_desc(block_group_number);
if (gd == NULL)
panic("can't get group_desc to read/write inode");
offset = ((rip->i_num - 1) % sp->s_inodes_per_group) * EXT2_INODE_SIZE(sp);
/* offset requires shifting, since each block contains several inodes,
* e.g. inode 2 is stored in bklock 0.
*/
b = (block_t) gd->inode_table + (offset >> sp->s_blocksize_bits);
bp = get_block(rip->i_dev, b, NORMAL);
offset &= (sp->s_block_size - 1);
dip = (d_inode*) (b_data(bp) + offset);
/* Do the read or write. */
if (rw_flag == WRITING) {
if (rip->i_update)
update_times(rip); /* times need updating */
if (sp->s_rd_only == FALSE)
lmfs_markdirty(bp);
}
icopy(rip, dip, rw_flag, TRUE);
put_block(bp, INODE_BLOCK);
rip->i_dirt = IN_CLEAN;
}
/*===========================================================================*
* icopy *
*===========================================================================*/
static void icopy(
register struct inode *rip, /* pointer to the in-core inode struct */
register d_inode *dip, /* pointer to the on-disk struct */
int direction, /* READING (from disk) or WRITING (to disk) */
int norm /* TRUE = do not swap bytes; FALSE = swap */
)
{
int i;
if (direction == READING) {
/* Copy inode to the in-core table, swapping bytes if need be. */
rip->i_mode = conv2(norm,dip->i_mode);
rip->i_uid = conv2(norm,dip->i_uid);
rip->i_size = conv4(norm,dip->i_size);
rip->i_atime = conv4(norm,dip->i_atime);
rip->i_ctime = conv4(norm,dip->i_ctime);
rip->i_mtime = conv4(norm,dip->i_mtime);
rip->i_dtime = conv4(norm,dip->i_dtime);
rip->i_gid = conv2(norm,dip->i_gid);
rip->i_links_count = conv2(norm,dip->i_links_count);
rip->i_blocks = conv4(norm,dip->i_blocks);
rip->i_flags = conv4(norm,dip->i_flags);
/* Minix doesn't touch osd1 and osd2 either, so just copy. */
memcpy(&rip->osd1, &dip->osd1, sizeof(rip->osd1));
for (i = 0; i < EXT2_N_BLOCKS; i++)
rip->i_block[i] = conv4(norm, dip->i_block[i]);
rip->i_generation = conv4(norm,dip->i_generation);
rip->i_file_acl = conv4(norm,dip->i_file_acl);
rip->i_dir_acl = conv4(norm,dip->i_dir_acl);
rip->i_faddr = conv4(norm,dip->i_faddr);
memcpy(&rip->osd2, &dip->osd2, sizeof(rip->osd2));
} else {
/* Copying inode to disk from the in-core table. */
dip->i_mode = conv2(norm,rip->i_mode);
dip->i_uid = conv2(norm,rip->i_uid);
dip->i_size = conv4(norm,rip->i_size);
dip->i_atime = conv4(norm,rip->i_atime);
dip->i_ctime = conv4(norm,rip->i_ctime);
dip->i_mtime = conv4(norm,rip->i_mtime);
dip->i_dtime = conv4(norm,rip->i_dtime);
dip->i_gid = conv2(norm,rip->i_gid);
dip->i_links_count = conv2(norm,rip->i_links_count);
dip->i_blocks = conv4(norm,rip->i_blocks);
dip->i_flags = conv4(norm,rip->i_flags);
/* Minix doesn't touch osd1 and osd2 either, so just copy. */
memcpy(&dip->osd1, &rip->osd1, sizeof(dip->osd1));
for (i = 0; i < EXT2_N_BLOCKS; i++)
dip->i_block[i] = conv4(norm, rip->i_block[i]);
dip->i_generation = conv4(norm,rip->i_generation);
dip->i_file_acl = conv4(norm,rip->i_file_acl);
dip->i_dir_acl = conv4(norm,rip->i_dir_acl);
dip->i_faddr = conv4(norm,rip->i_faddr);
memcpy(&dip->osd2, &rip->osd2, sizeof(dip->osd2));
}
}
/*===========================================================================*
* dup_inode *
*===========================================================================*/
void dup_inode(
struct inode *ip /* The inode to be duplicated. */
)
{
/* This routine is a simplified form of get_inode() for the case where
* the inode pointer is already known.
*/
ip->i_count++;
}
0