1 /* $NetBSD: v7fs_inode_util.c,v 1.2 2011/07/18 21:51:49 apb Exp $ */
4 * Copyright (c) 2011 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #if HAVE_NBTOOL_CONFIG_H
33 #include "nbtool_config.h"
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: v7fs_inode_util.c,v 1.2 2011/07/18 21:51:49 apb Exp $");
38 #if defined _KERNEL_OPT
43 #include <sys/systm.h>
44 #include <sys/param.h>
51 #include "v7fs_impl.h"
52 #include "v7fs_inode.h"
54 #ifdef V7FS_INODE_DEBUG
55 #define DPRINTF(fmt, args...) printf("%s: " fmt, __func__, ##args)
57 #define DPRINTF(fmt, args...) ((void)0)
61 v7fs_inode_chmod(struct v7fs_inode
*inode
, v7fs_mode_t mode
)
63 #define V7FS_MODE_MASK 0xfff
64 DPRINTF("setattr %08o -> %08o\n", inode
->mode
, mode
);
66 inode
->mode
&= ~V7FS_MODE_MASK
;
67 inode
->mode
|= (mode
& V7FS_MODE_MASK
);
68 DPRINTF("setattr %08o -> %08o\n", inode
->mode
, mode
);
72 v7fs_inode_dump(const struct v7fs_inode
*p
)
74 printf("nlink %d mode %06o %d/%d %d bytes\n",
76 p
->uid
, p
->gid
, p
->filesize
);
78 printf("atime %d mtime %d ctime %d\n",
79 p
->atime
, p
->mtime
, p
->ctime
);
84 printf(" atime %s mtime %s ctime %s", ctime(&at
), ctime(&mt
),
87 if (v7fs_inode_iscdev(p
) || v7fs_inode_isbdev(p
)) {
88 printf("device:%d/%d\n", (p
->device
>> 8), p
->device
& 0xff);
96 (struct v7fs_self
*fs
,
97 int (*func
)(struct v7fs_self
*, void *, struct v7fs_inode
*, v7fs_ino_t
),
100 struct v7fs_superblock
*sb
= &fs
->superblock
;
104 /* Loop over ilist. */
105 for (k
= 1, i
= V7FS_ILIST_SECTOR
; i
< sb
->datablock_start_sector
;
107 struct v7fs_inode_diskimage
*di
;
108 struct v7fs_inode inode
;
111 if (!(buf
= scratch_read(fs
, i
))) {
112 DPRINTF("block %zu I/O error.\n", i
);
113 k
+= V7FS_INODE_PER_BLOCK
;
116 di
= (struct v7fs_inode_diskimage
*)buf
;
117 for (j
= 0; j
< V7FS_INODE_PER_BLOCK
; j
++, k
++) {
118 v7fs_inode_setup_memory_image(fs
, &inode
, di
+ j
);
119 inode
.inode_number
= k
;
120 if ((ret
= func(fs
, ctx
, &inode
, k
))) {
121 scratch_free(fs
, buf
);
125 scratch_free(fs
, buf
);