etc/protocols - sync with NetBSD-8
[minix.git] / sys / fs / v7fs / v7fs_inode_util.c
blob94dfd7a3baf717516d73908a1a1284551b314d64
1 /* $NetBSD: v7fs_inode_util.c,v 1.2 2011/07/18 21:51:49 apb Exp $ */
3 /*-
4 * Copyright (c) 2011 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by UCHIYAMA Yasushi.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
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"
34 #endif
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
39 #include "opt_v7fs.h"
40 #endif
42 #ifdef _KERNEL
43 #include <sys/systm.h>
44 #include <sys/param.h>
45 #else
46 #include <stdio.h>
47 #include <time.h>
48 #endif
50 #include "v7fs.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)
56 #else
57 #define DPRINTF(fmt, args...) ((void)0)
58 #endif
60 void
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);
71 void
72 v7fs_inode_dump(const struct v7fs_inode *p)
74 printf("nlink %d mode %06o %d/%d %d bytes\n",
75 p->nlink, p->mode,
76 p->uid, p->gid, p->filesize);
78 printf("atime %d mtime %d ctime %d\n",
79 p->atime, p->mtime, p->ctime);
80 #ifndef _KERNEL
81 time_t at = p->atime;
82 time_t mt = p->mtime;
83 time_t ct = p->ctime;
84 printf(" atime %s mtime %s ctime %s", ctime(&at), ctime(&mt),
85 ctime(&ct));
86 #endif
87 if (v7fs_inode_iscdev(p) || v7fs_inode_isbdev(p)) {
88 printf("device:%d/%d\n", (p->device >> 8), p->device & 0xff);
90 printf("\n");
94 int
95 v7fs_ilist_foreach
96 (struct v7fs_self *fs,
97 int (*func)(struct v7fs_self *, void *, struct v7fs_inode *, v7fs_ino_t),
98 void *ctx)
100 struct v7fs_superblock *sb = &fs->superblock;
101 size_t i, j, k;
102 int ret;
104 /* Loop over ilist. */
105 for (k = 1, i = V7FS_ILIST_SECTOR; i < sb->datablock_start_sector;
106 i++) {
107 struct v7fs_inode_diskimage *di;
108 struct v7fs_inode inode;
109 void *buf;
111 if (!(buf = scratch_read(fs, i))) {
112 DPRINTF("block %zu I/O error.\n", i);
113 k += V7FS_INODE_PER_BLOCK;
114 continue;
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);
122 return ret;
125 scratch_free(fs, buf);
127 return 0;