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: releng/9.0/sys/fs/ext2fs/ext2_inode_cnv.c 202283 2010-01-14 14:30:54Z lulf $
23 */
24
25 /*
26 * routines to convert on disk ext2 inodes into inodes and back
27 */
28 #include <sys/param.h>
29 #include <sys/systm.h>
30 #include <sys/lock.h>
31 #include <sys/stat.h>
32 #include <sys/vnode.h>
33
34 #include <fs/ext2fs/inode.h>
35 #include <fs/ext2fs/ext2fs.h>
36 #include <fs/ext2fs/ext2_extern.h>
37 #include <fs/ext2fs/ext2_dinode.h>
38
39 void
40 ext2_print_inode( in )
41 struct inode *in;
42 {
43 int i;
44
45 printf( "Inode: %5d", in->i_number);
46 printf( /* "Inode: %5d" */
47 " Type: %10s Mode: 0x%o Flags: 0x%x Version: %d\n",
48 "n/a", in->i_mode, in->i_flags, in->i_gen);
49 printf( "User: %5lu Group: %5lu Size: %lu\n",
50 (unsigned long)in->i_uid, (unsigned long)in->i_gid,
51 (unsigned long)in->i_size);
52 printf( "Links: %3d Blockcount: %d\n",
53 in->i_nlink, in->i_blocks);
54 printf( "ctime: 0x%x", in->i_ctime);
55 printf( "atime: 0x%x", in->i_atime);
56 printf( "mtime: 0x%x", in->i_mtime);
57 printf( "BLOCKS: ");
58 for(i=0; i < (in->i_blocks <= 24 ? ((in->i_blocks+1)/2): 12); i++)
59 printf("%d ", in->i_db[i]);
60 printf("\n");
61 }
62
63 /*
64 * raw ext2 inode to inode
65 */
66 void
67 ext2_ei2i(ei, ip)
68 struct ext2fs_dinode *ei;
69 struct inode *ip;
70 {
71 int i;
72
73 ip->i_nlink = ei->e2di_nlink;
74 /* Godmar thinks - if the link count is zero, then the inode is
75 unused - according to ext2 standards. Ufs marks this fact
76 by setting i_mode to zero - why ?
77 I can see that this might lead to problems in an undelete.
78 */
79 ip->i_mode = ei->e2di_nlink ? ei->e2di_mode : 0;
80 ip->i_size = ei->e2di_size;
81 if (S_ISREG(ip->i_mode))
82 ip->i_size |= ((u_int64_t)ei->e2di_size_high) << 32;
83 ip->i_atime = ei->e2di_atime;
84 ip->i_mtime = ei->e2di_mtime;
85 ip->i_ctime = ei->e2di_ctime;
86 ip->i_flags = 0;
87 ip->i_flags |= (ei->e2di_flags & EXT2_APPEND) ? SF_APPEND : 0;
88 ip->i_flags |= (ei->e2di_flags & EXT2_IMMUTABLE) ? SF_IMMUTABLE : 0;
89 ip->i_flags |= (ei->e2di_flags & EXT2_NODUMP) ? UF_NODUMP : 0;
90 ip->i_blocks = ei->e2di_nblock;
91 ip->i_gen = ei->e2di_gen;
92 ip->i_uid = ei->e2di_uid;
93 ip->i_gid = ei->e2di_gid;
94 /* XXX use memcpy */
95 for(i = 0; i < NDADDR; i++)
96 ip->i_db[i] = ei->e2di_blocks[i];
97 for(i = 0; i < NIADDR; i++)
98 ip->i_ib[i] = ei->e2di_blocks[EXT2_NDIR_BLOCKS + i];
99 }
100
101 /*
102 * inode to raw ext2 inode
103 */
104 void
105 ext2_i2ei(ip, ei)
106 struct inode *ip;
107 struct ext2fs_dinode *ei;
108 {
109 int i;
110
111 ei->e2di_mode = ip->i_mode;
112 ei->e2di_nlink = ip->i_nlink;
113 /*
114 Godmar thinks: if dtime is nonzero, ext2 says this inode
115 has been deleted, this would correspond to a zero link count
116 */
117 ei->e2di_dtime = ei->e2di_nlink ? 0 : ip->i_mtime;
118 ei->e2di_size = ip->i_size;
119 if (S_ISREG(ip->i_mode))
120 ei->e2di_size_high = ip->i_size >> 32;
121 ei->e2di_atime = ip->i_atime;
122 ei->e2di_mtime = ip->i_mtime;
123 ei->e2di_ctime = ip->i_ctime;
124 ei->e2di_flags = ip->i_flags;
125 ei->e2di_flags = 0;
126 ei->e2di_flags |= (ip->i_flags & SF_APPEND) ? EXT2_APPEND: 0;
127 ei->e2di_flags |= (ip->i_flags & SF_IMMUTABLE) ? EXT2_IMMUTABLE: 0;
128 ei->e2di_flags |= (ip->i_flags & UF_NODUMP) ? EXT2_NODUMP: 0;
129 ei->e2di_nblock = ip->i_blocks;
130 ei->e2di_gen = ip->i_gen;
131 ei->e2di_uid = ip->i_uid;
132 ei->e2di_gid = ip->i_gid;
133 /* XXX use memcpy */
134 for(i = 0; i < NDADDR; i++)
135 ei->e2di_blocks[i] = ip->i_db[i];
136 for(i = 0; i < NIADDR; i++)
137 ei->e2di_blocks[EXT2_NDIR_BLOCKS + i] = ip->i_ib[i];
138 }
Cache object: 4472540469582499aed28bdc998f04ff
|