File:  [DragonFly] / src / sys / vfs / gnu / ext2fs / ext2_inode_cnv.c
Revision 1.3: download - view: text, annotated - select for diffs
Thu Aug 7 21:17:41 2003 UTC (11 years, 4 months ago) by dillon
Branches: MAIN
CVS tags: HEAD
kernel tree reorganization stage 1: Major cvs repository work (not logged as
commits) plus a major reworking of the #include's to accomodate the
relocations.

    * CVS repository files manually moved.  Old directories left intact
      and empty (temporary).

    * Reorganize all filesystems into vfs/, most devices into dev/,
      sub-divide devices by function.

    * Begin to move device-specific architecture files to the device
      subdirs rather then throwing them all into, e.g. i386/include

    * Reorganize files related to system busses, placing the related code
      in a new bus/ directory.  Also move cam to bus/cam though this may
      not have been the best idea in retrospect.

    * Reorganize emulation code and place it in a new emulation/ directory.

    * Remove the -I- compiler option in order to allow #include file
      localization, rename all config generated X.h files to use_X.h to
      clean up the conflicts.

    * Remove /usr/src/include (or /usr/include) dependancies during the
      kernel build, beyond what is normally needed to compile helper
      programs.

    * Make config create 'machine' softlinks for architecture specific
      directories outside of the standard <arch>/include.

    * Bump the config rev.

    WARNING! after this commit /usr/include and /usr/src/sys/compile/*
    should be regenerated from scratch.

    1: /*
    2:  * Copyright (c) 1995 The University of Utah and
    3:  * the Computer Systems Laboratory at the University of Utah (CSL).
    4:  * All rights reserved.
    5:  *
    6:  * Permission to use, copy, modify and distribute this software is hereby
    7:  * granted provided that (1) source code retains these copyright, permission,
    8:  * and disclaimer notices, and (2) redistributions including binaries
    9:  * reproduce the notices in supporting documentation, and (3) all advertising
   10:  * materials mentioning features or use of this software display the following
   11:  * acknowledgement: ``This product includes software developed by the
   12:  * Computer Systems Laboratory at the University of Utah.''
   13:  *
   14:  * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
   15:  * IS" CONDITION.  THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
   16:  * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
   17:  *
   18:  * CSL requests users of this software to return to csl-dist@cs.utah.edu any
   19:  * improvements that they make and grant CSL redistribution rights.
   20:  *
   21:  *      Utah $Hdr$
   22:  * $FreeBSD: src/sys/gnu/ext2fs/ext2_inode_cnv.c,v 1.11 2000/01/01 17:39:21 bde Exp $
   23:  * $DragonFly: src/sys/vfs/gnu/ext2fs/ext2_inode_cnv.c,v 1.3 2003/08/07 21:17:41 dillon Exp $
   24:  */
   25: 
   26: /*
   27:  * routines to convert on disk ext2 inodes in dinodes and back
   28:  */
   29: #include <sys/param.h>
   30: #include <sys/systm.h>
   31: #include <sys/lock.h>
   32: #include <sys/stat.h>
   33: #include <sys/vnode.h>
   34: 
   35: #include <vfs/ufs/quota.h>
   36: #include <vfs/ufs/inode.h>
   37: 
   38: /*
   39:  * Undo the definitions in <ufs/ufs/inode.h> that would destroy the include
   40:  * of <gnu/ext2fs/ext2_fs.h>.
   41:  */
   42: #undef i_atime
   43: #undef i_blocks
   44: #undef i_ctime
   45: #undef i_db
   46: #undef i_flags
   47: #undef i_gen
   48: #undef i_gid
   49: #undef i_ib
   50: #undef i_mode
   51: #undef i_mtime
   52: #undef i_nlink
   53: #undef i_rdev
   54: #undef i_shortlink
   55: #undef i_size
   56: #undef i_uid
   57: 
   58: #include "ext2_fs.h"
   59: #include "ext2_extern.h"
   60: 
   61: void
   62: ext2_print_dinode( di )
   63: 	struct dinode *di;
   64: {
   65: 	int i;
   66: 	printf( /* "Inode: %5d" */
   67: 		" Type: %10s Mode: 0x%o Flags: 0x%x  Version: %d\n",
   68: 		"n/a", di->di_mode, di->di_flags, di->di_gen);
   69: 	printf( "User: %5lu Group: %5lu  Size: %lu\n",
   70: 		(unsigned long)di->di_uid, (unsigned long)di->di_gid,
   71: 		(unsigned long)di->di_size);
   72: 	printf( "Links: %3d Blockcount: %d\n",
   73: 		di->di_nlink, di->di_blocks);
   74: 	printf( "ctime: 0x%x", di->di_ctime); 
   75: 	printf( "atime: 0x%x", di->di_atime); 
   76: 	printf( "mtime: 0x%x", di->di_mtime); 
   77: 	printf( "BLOCKS: ");
   78: 	for(i=0; i < (di->di_blocks <= 24 ? ((di->di_blocks+1)/2): 12); i++)
   79: 		printf("%d ", di->di_db[i]);
   80: 	printf("\n");
   81: }
   82: 
   83: void
   84: ext2_print_inode( in )
   85: 	struct inode *in;
   86: {
   87: 	printf( "Inode: %5d", in->i_number);
   88: 	ext2_print_dinode(&in->i_din);
   89: }
   90: 
   91: /*
   92:  *	raw ext2 inode to dinode
   93:  */
   94: void
   95: ext2_ei2di(ei, di)
   96:         struct ext2_inode *ei;
   97:         struct dinode *di;
   98: {
   99:         int     i;
  100: 
  101:         di->di_nlink    = ei->i_links_count;
  102: 	/* Godmar thinks - if the link count is zero, then the inode is
  103: 	   unused - according to ext2 standards. Ufs marks this fact
  104: 	   by setting i_mode to zero - why ?
  105: 	   I can see that this might lead to problems in an undelete.
  106: 	*/
  107: 	di->di_mode     = ei->i_links_count ? ei->i_mode : 0;
  108:         di->di_size     = ei->i_size;
  109:         di->di_atime	= ei->i_atime;
  110:         di->di_mtime	= ei->i_mtime;
  111:         di->di_ctime	= ei->i_ctime;
  112:         di->di_flags    = 0;
  113:         di->di_flags    |= (ei->i_flags & EXT2_APPEND_FL) ? APPEND : 0;
  114:         di->di_flags    |= (ei->i_flags & EXT2_IMMUTABLE_FL) ? IMMUTABLE : 0;
  115:         di->di_blocks   = ei->i_blocks;
  116:         di->di_gen      = ei->i_generation;
  117:         di->di_uid      = ei->i_uid;
  118:         di->di_gid      = ei->i_gid;
  119: 	/* XXX use memcpy */
  120:         for(i = 0; i < NDADDR; i++)
  121:                 di->di_db[i] = ei->i_block[i];
  122:         for(i = 0; i < NIADDR; i++)
  123:                 di->di_ib[i] = ei->i_block[EXT2_NDIR_BLOCKS + i];
  124: }
  125: 
  126: /*
  127:  *	dinode to raw ext2 inode
  128:  */
  129: void
  130: ext2_di2ei(di, ei)
  131:         struct dinode *di;
  132:         struct ext2_inode *ei;
  133: {
  134:         int     i;
  135: 
  136:         ei->i_mode              = di->di_mode;
  137:         ei->i_links_count       = di->di_nlink;
  138: 	/* 
  139: 	   Godmar thinks: if dtime is nonzero, ext2 says this inode
  140: 	   has been deleted, this would correspond to a zero link count
  141: 	 */
  142:         ei->i_dtime             = ei->i_links_count ? 0 : di->di_mtime;
  143:         ei->i_size              = di->di_size;
  144:         ei->i_atime             = di->di_atime;
  145:         ei->i_mtime             = di->di_mtime;
  146:         ei->i_ctime             = di->di_ctime;
  147:         ei->i_flags             = di->di_flags;
  148:         ei->i_flags    		= 0;
  149:         ei->i_flags    		|= (di->di_flags & APPEND) ? EXT2_APPEND_FL: 0;
  150:         ei->i_flags    		|= (di->di_flags & IMMUTABLE) 
  151: 							? EXT2_IMMUTABLE_FL: 0;
  152:         ei->i_blocks            = di->di_blocks;
  153:         ei->i_generation        = di->di_gen;
  154:         ei->i_uid               = di->di_uid;
  155:         ei->i_gid               = di->di_gid;
  156: 	/* XXX use memcpy */
  157:         for(i = 0; i < NDADDR; i++)
  158:                 ei->i_block[i] = di->di_db[i];
  159:         for(i = 0; i < NIADDR; i++)
  160:                 ei->i_block[EXT2_NDIR_BLOCKS + i] = di->di_ib[i];
  161: }