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