Deleted Added
full compact
ext2_inode_cnv.c (96749) ext2_inode_cnv.c (125962)
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$
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: head/sys/gnu/fs/ext2fs/ext2_inode_cnv.c 96749 2002-05-16 19:08:03Z iedowse $
22 * $FreeBSD: head/sys/gnu/fs/ext2fs/ext2_inode_cnv.c 125962 2004-02-18 14:08:25Z tjr $
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 <gnu/ext2fs/inode.h>
35#include <gnu/ext2fs/ext2_fs.h>
36#include <gnu/ext2fs/ext2_extern.h>
37
38void
39ext2_print_inode( in )
40 struct inode *in;
41{
42 int i;
43
44 printf( "Inode: %5d", in->i_number);
45 printf( /* "Inode: %5d" */
46 " Type: %10s Mode: 0x%o Flags: 0x%x Version: %d\n",
47 "n/a", in->i_mode, in->i_flags, in->i_gen);
48 printf( "User: %5lu Group: %5lu Size: %lu\n",
49 (unsigned long)in->i_uid, (unsigned long)in->i_gid,
50 (unsigned long)in->i_size);
51 printf( "Links: %3d Blockcount: %d\n",
52 in->i_nlink, in->i_blocks);
53 printf( "ctime: 0x%x", in->i_ctime);
54 printf( "atime: 0x%x", in->i_atime);
55 printf( "mtime: 0x%x", in->i_mtime);
56 printf( "BLOCKS: ");
57 for(i=0; i < (in->i_blocks <= 24 ? ((in->i_blocks+1)/2): 12); i++)
58 printf("%d ", in->i_db[i]);
59 printf("\n");
60}
61
62/*
63 * raw ext2 inode to inode
64 */
65void
66ext2_ei2i(ei, ip)
67 struct ext2_inode *ei;
68 struct inode *ip;
69{
70 int i;
71
72 ip->i_nlink = ei->i_links_count;
73 /* Godmar thinks - if the link count is zero, then the inode is
74 unused - according to ext2 standards. Ufs marks this fact
75 by setting i_mode to zero - why ?
76 I can see that this might lead to problems in an undelete.
77 */
78 ip->i_mode = ei->i_links_count ? ei->i_mode : 0;
79 ip->i_size = ei->i_size;
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 <gnu/ext2fs/inode.h>
35#include <gnu/ext2fs/ext2_fs.h>
36#include <gnu/ext2fs/ext2_extern.h>
37
38void
39ext2_print_inode( in )
40 struct inode *in;
41{
42 int i;
43
44 printf( "Inode: %5d", in->i_number);
45 printf( /* "Inode: %5d" */
46 " Type: %10s Mode: 0x%o Flags: 0x%x Version: %d\n",
47 "n/a", in->i_mode, in->i_flags, in->i_gen);
48 printf( "User: %5lu Group: %5lu Size: %lu\n",
49 (unsigned long)in->i_uid, (unsigned long)in->i_gid,
50 (unsigned long)in->i_size);
51 printf( "Links: %3d Blockcount: %d\n",
52 in->i_nlink, in->i_blocks);
53 printf( "ctime: 0x%x", in->i_ctime);
54 printf( "atime: 0x%x", in->i_atime);
55 printf( "mtime: 0x%x", in->i_mtime);
56 printf( "BLOCKS: ");
57 for(i=0; i < (in->i_blocks <= 24 ? ((in->i_blocks+1)/2): 12); i++)
58 printf("%d ", in->i_db[i]);
59 printf("\n");
60}
61
62/*
63 * raw ext2 inode to inode
64 */
65void
66ext2_ei2i(ei, ip)
67 struct ext2_inode *ei;
68 struct inode *ip;
69{
70 int i;
71
72 ip->i_nlink = ei->i_links_count;
73 /* Godmar thinks - if the link count is zero, then the inode is
74 unused - according to ext2 standards. Ufs marks this fact
75 by setting i_mode to zero - why ?
76 I can see that this might lead to problems in an undelete.
77 */
78 ip->i_mode = ei->i_links_count ? ei->i_mode : 0;
79 ip->i_size = ei->i_size;
80 if (S_ISREG(ip->i_mode))
81 ip->i_size |= ((u_int64_t)ei->i_size_high) << 32;
80 ip->i_atime = ei->i_atime;
81 ip->i_mtime = ei->i_mtime;
82 ip->i_ctime = ei->i_ctime;
83 ip->i_flags = 0;
84 ip->i_flags |= (ei->i_flags & EXT2_APPEND_FL) ? APPEND : 0;
85 ip->i_flags |= (ei->i_flags & EXT2_IMMUTABLE_FL) ? IMMUTABLE : 0;
86 ip->i_blocks = ei->i_blocks;
87 ip->i_gen = ei->i_generation;
88 ip->i_uid = ei->i_uid;
89 ip->i_gid = ei->i_gid;
90 /* XXX use memcpy */
91 for(i = 0; i < NDADDR; i++)
92 ip->i_db[i] = ei->i_block[i];
93 for(i = 0; i < NIADDR; i++)
94 ip->i_ib[i] = ei->i_block[EXT2_NDIR_BLOCKS + i];
95}
96
97/*
98 * inode to raw ext2 inode
99 */
100void
101ext2_i2ei(ip, ei)
102 struct inode *ip;
103 struct ext2_inode *ei;
104{
105 int i;
106
107 ei->i_mode = ip->i_mode;
108 ei->i_links_count = ip->i_nlink;
109 /*
110 Godmar thinks: if dtime is nonzero, ext2 says this inode
111 has been deleted, this would correspond to a zero link count
112 */
113 ei->i_dtime = ei->i_links_count ? 0 : ip->i_mtime;
114 ei->i_size = ip->i_size;
82 ip->i_atime = ei->i_atime;
83 ip->i_mtime = ei->i_mtime;
84 ip->i_ctime = ei->i_ctime;
85 ip->i_flags = 0;
86 ip->i_flags |= (ei->i_flags & EXT2_APPEND_FL) ? APPEND : 0;
87 ip->i_flags |= (ei->i_flags & EXT2_IMMUTABLE_FL) ? IMMUTABLE : 0;
88 ip->i_blocks = ei->i_blocks;
89 ip->i_gen = ei->i_generation;
90 ip->i_uid = ei->i_uid;
91 ip->i_gid = ei->i_gid;
92 /* XXX use memcpy */
93 for(i = 0; i < NDADDR; i++)
94 ip->i_db[i] = ei->i_block[i];
95 for(i = 0; i < NIADDR; i++)
96 ip->i_ib[i] = ei->i_block[EXT2_NDIR_BLOCKS + i];
97}
98
99/*
100 * inode to raw ext2 inode
101 */
102void
103ext2_i2ei(ip, ei)
104 struct inode *ip;
105 struct ext2_inode *ei;
106{
107 int i;
108
109 ei->i_mode = ip->i_mode;
110 ei->i_links_count = ip->i_nlink;
111 /*
112 Godmar thinks: if dtime is nonzero, ext2 says this inode
113 has been deleted, this would correspond to a zero link count
114 */
115 ei->i_dtime = ei->i_links_count ? 0 : ip->i_mtime;
116 ei->i_size = ip->i_size;
117 if (S_ISREG(ip->i_mode))
118 ei->i_size_high = ip->i_size >> 32;
115 ei->i_atime = ip->i_atime;
116 ei->i_mtime = ip->i_mtime;
117 ei->i_ctime = ip->i_ctime;
118 ei->i_flags = ip->i_flags;
119 ei->i_flags = 0;
120 ei->i_flags |= (ip->i_flags & APPEND) ? EXT2_APPEND_FL: 0;
121 ei->i_flags |= (ip->i_flags & IMMUTABLE) ? EXT2_IMMUTABLE_FL: 0;
122 ei->i_blocks = ip->i_blocks;
123 ei->i_generation = ip->i_gen;
124 ei->i_uid = ip->i_uid;
125 ei->i_gid = ip->i_gid;
126 /* XXX use memcpy */
127 for(i = 0; i < NDADDR; i++)
128 ei->i_block[i] = ip->i_db[i];
129 for(i = 0; i < NIADDR; i++)
130 ei->i_block[EXT2_NDIR_BLOCKS + i] = ip->i_ib[i];
131}
119 ei->i_atime = ip->i_atime;
120 ei->i_mtime = ip->i_mtime;
121 ei->i_ctime = ip->i_ctime;
122 ei->i_flags = ip->i_flags;
123 ei->i_flags = 0;
124 ei->i_flags |= (ip->i_flags & APPEND) ? EXT2_APPEND_FL: 0;
125 ei->i_flags |= (ip->i_flags & IMMUTABLE) ? EXT2_IMMUTABLE_FL: 0;
126 ei->i_blocks = ip->i_blocks;
127 ei->i_generation = ip->i_gen;
128 ei->i_uid = ip->i_uid;
129 ei->i_gid = ip->i_gid;
130 /* XXX use memcpy */
131 for(i = 0; i < NDADDR; i++)
132 ei->i_block[i] = ip->i_db[i];
133 for(i = 0; i < NIADDR; i++)
134 ei->i_block[EXT2_NDIR_BLOCKS + i] = ip->i_ib[i];
135}