netinet{,6}: Assert in{,6}_inithead() are only used for system routing tables.
[dragonfly.git] / sys / gnu / vfs / ext2fs / ext2_inode_cnv.c
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  */
24
25 /*
26  * routines to convert on disk ext2 inodes in dinodes 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 <machine/inttypes.h>
35
36 #include "quota.h"
37
38 #define NO_I_DEFINES
39 #include "inode.h"
40 #include "ext2_fs.h"
41 #include "ext2_extern.h"
42
43 void
44 ext2_print_dinode(struct ext2_dinode *di)
45 {
46         int i;
47         kprintf( /* "Inode: %5d" */
48                 " Type: %10s Mode: 0x%o Flags: 0x%x  Version: %d\n",
49                 "n/a", di->di_mode, di->di_flags, di->di_gen);
50         kprintf( "User: %5lu Group: %5lu  Size: %lu\n",
51                 (unsigned long)di->di_uid, (unsigned long)di->di_gid,
52                 (unsigned long)di->di_size);
53         kprintf( "Links: %3d Blockcount: %d\n",
54                 di->di_nlink, di->di_blocks);
55         kprintf( "ctime: 0x%x", di->di_ctime);
56         kprintf( "atime: 0x%x", di->di_atime);
57         kprintf( "mtime: 0x%x", di->di_mtime);
58         kprintf( "BLOCKS: ");
59         for(i=0; i < (di->di_blocks <= 24 ? ((di->di_blocks+1)/2): 12); i++)
60                 kprintf("%d ", di->di_db[i]);
61         kprintf("\n");
62 }
63
64 void
65 ext2_print_inode(struct inode *in)
66 {
67         kprintf( "Inode: %"PRId64, in->i_number);
68         ext2_print_dinode(&in->i_din);
69 }
70
71 /*
72  *      raw ext2 inode to dinode
73  */
74 void
75 ext2_ei2di(struct ext2_inode *ei, struct ext2_dinode *di)
76 {
77         int     i;
78
79         di->di_nlink    = ei->i_links_count;
80         /* Godmar thinks - if the link count is zero, then the inode is
81            unused - according to ext2 standards. Ufs marks this fact
82            by setting i_mode to zero - why ?
83            I can see that this might lead to problems in an undelete.
84         */
85         di->di_mode     = ei->i_links_count ? ei->i_mode : 0;
86         di->di_size     = ei->i_size;
87         di->di_atime    = ei->i_atime;
88         di->di_mtime    = ei->i_mtime;
89         di->di_ctime    = ei->i_ctime;
90         di->di_flags    = 0;
91         di->di_flags    |= (ei->i_flags & EXT2_APPEND_FL) ? APPEND : 0;
92         di->di_flags    |= (ei->i_flags & EXT2_IMMUTABLE_FL) ? IMMUTABLE : 0;
93         di->di_blocks   = ei->i_blocks;
94         di->di_gen      = ei->i_generation;
95         di->di_uid      = ei->i_uid;
96         di->di_gid      = ei->i_gid;
97         /* XXX use memcpy */
98         for(i = 0; i < NDADDR; i++)
99                 di->di_db[i] = ei->i_block[i];
100         for(i = 0; i < NIADDR; i++)
101                 di->di_ib[i] = ei->i_block[EXT2_NDIR_BLOCKS + i];
102 }
103
104 /*
105  *      dinode to raw ext2 inode
106  */
107 void
108 ext2_di2ei(struct ext2_dinode *di, struct ext2_inode *ei)
109 {
110         int     i;
111
112         ei->i_mode              = di->di_mode;
113         ei->i_links_count       = di->di_nlink;
114         /*
115            Godmar thinks: if dtime is nonzero, ext2 says this inode
116            has been deleted, this would correspond to a zero link count
117          */
118         ei->i_dtime             = ei->i_links_count ? 0 : di->di_mtime;
119         ei->i_size              = di->di_size;
120         ei->i_atime             = di->di_atime;
121         ei->i_mtime             = di->di_mtime;
122         ei->i_ctime             = di->di_ctime;
123         ei->i_flags             = di->di_flags;
124         ei->i_flags             = 0;
125         ei->i_flags             |= (di->di_flags & APPEND) ? EXT2_APPEND_FL: 0;
126         ei->i_flags             |= (di->di_flags & IMMUTABLE)
127                                                         ? EXT2_IMMUTABLE_FL: 0;
128         ei->i_blocks            = di->di_blocks;
129         ei->i_generation        = di->di_gen;
130         ei->i_uid               = di->di_uid;
131         ei->i_gid               = di->di_gid;
132         /* XXX use memcpy */
133         for(i = 0; i < NDADDR; i++)
134                 ei->i_block[i] = di->di_db[i];
135         for(i = 0; i < NIADDR; i++)
136                 ei->i_block[EXT2_NDIR_BLOCKS + i] = di->di_ib[i];
137 }