v7fs_inode_util.c revision 1.1 1 1.1 uch /* $NetBSD: v7fs_inode_util.c,v 1.1 2011/06/27 11:52:25 uch Exp $ */
2 1.1 uch
3 1.1 uch /*-
4 1.1 uch * Copyright (c) 2011 The NetBSD Foundation, Inc.
5 1.1 uch * All rights reserved.
6 1.1 uch *
7 1.1 uch * This code is derived from software contributed to The NetBSD Foundation
8 1.1 uch * by UCHIYAMA Yasushi.
9 1.1 uch *
10 1.1 uch * Redistribution and use in source and binary forms, with or without
11 1.1 uch * modification, are permitted provided that the following conditions
12 1.1 uch * are met:
13 1.1 uch * 1. Redistributions of source code must retain the above copyright
14 1.1 uch * notice, this list of conditions and the following disclaimer.
15 1.1 uch * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 uch * notice, this list of conditions and the following disclaimer in the
17 1.1 uch * documentation and/or other materials provided with the distribution.
18 1.1 uch *
19 1.1 uch * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 uch * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 uch * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 uch * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 uch * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 uch * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 uch * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 uch * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 uch * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 uch * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 uch * POSSIBILITY OF SUCH DAMAGE.
30 1.1 uch */
31 1.1 uch
32 1.1 uch #include <sys/cdefs.h>
33 1.1 uch __KERNEL_RCSID(0, "$NetBSD: v7fs_inode_util.c,v 1.1 2011/06/27 11:52:25 uch Exp $");
34 1.1 uch #if defined _KERNEL_OPT
35 1.1 uch #include "opt_v7fs.h"
36 1.1 uch #endif
37 1.1 uch
38 1.1 uch #ifdef _KERNEL
39 1.1 uch #include <sys/systm.h>
40 1.1 uch #include <sys/param.h>
41 1.1 uch #else
42 1.1 uch #include <stdio.h>
43 1.1 uch #include <time.h>
44 1.1 uch #endif
45 1.1 uch
46 1.1 uch #include "v7fs.h"
47 1.1 uch #include "v7fs_impl.h"
48 1.1 uch #include "v7fs_inode.h"
49 1.1 uch
50 1.1 uch #ifdef V7FS_INODE_DEBUG
51 1.1 uch #define DPRINTF(fmt, args...) printf("%s: " fmt, __func__, ##args)
52 1.1 uch #else
53 1.1 uch #define DPRINTF(fmt, args...) ((void)0)
54 1.1 uch #endif
55 1.1 uch
56 1.1 uch void
57 1.1 uch v7fs_inode_chmod(struct v7fs_inode *inode, v7fs_mode_t mode)
58 1.1 uch {
59 1.1 uch #define V7FS_MODE_MASK 0xfff
60 1.1 uch DPRINTF("setattr %08o -> %08o\n", inode->mode, mode);
61 1.1 uch
62 1.1 uch inode->mode &= ~V7FS_MODE_MASK;
63 1.1 uch inode->mode |= (mode & V7FS_MODE_MASK);
64 1.1 uch DPRINTF("setattr %08o -> %08o\n", inode->mode, mode);
65 1.1 uch }
66 1.1 uch
67 1.1 uch void
68 1.1 uch v7fs_inode_dump(const struct v7fs_inode *p)
69 1.1 uch {
70 1.1 uch printf("nlink %d mode %06o %d/%d %d bytes\n",
71 1.1 uch p->nlink, p->mode,
72 1.1 uch p->uid, p->gid, p->filesize);
73 1.1 uch
74 1.1 uch printf("atime %d mtime %d ctime %d\n",
75 1.1 uch p->atime, p->mtime, p->ctime);
76 1.1 uch #ifndef _KERNEL
77 1.1 uch time_t at = p->atime;
78 1.1 uch time_t mt = p->mtime;
79 1.1 uch time_t ct = p->ctime;
80 1.1 uch printf(" atime %s mtime %s ctime %s", ctime(&at), ctime(&mt),
81 1.1 uch ctime(&ct));
82 1.1 uch #endif
83 1.1 uch if (v7fs_inode_iscdev(p) || v7fs_inode_isbdev(p)) {
84 1.1 uch printf("device:%d/%d\n", (p->device >> 8), p->device & 0xff);
85 1.1 uch }
86 1.1 uch printf("\n");
87 1.1 uch }
88 1.1 uch
89 1.1 uch
90 1.1 uch int
91 1.1 uch v7fs_ilist_foreach
92 1.1 uch (struct v7fs_self *fs,
93 1.1 uch int (*func)(struct v7fs_self *, void *, struct v7fs_inode *, v7fs_ino_t),
94 1.1 uch void *ctx)
95 1.1 uch {
96 1.1 uch struct v7fs_superblock *sb = &fs->superblock;
97 1.1 uch size_t i, j, k;
98 1.1 uch int ret;
99 1.1 uch
100 1.1 uch /* Loop over ilist. */
101 1.1 uch for (k = 1, i = V7FS_ILIST_SECTOR; i < sb->datablock_start_sector;
102 1.1 uch i++) {
103 1.1 uch struct v7fs_inode_diskimage *di;
104 1.1 uch struct v7fs_inode inode;
105 1.1 uch void *buf;
106 1.1 uch
107 1.1 uch if (!(buf = scratch_read(fs, i))) {
108 1.1 uch DPRINTF("block %zu I/O error.\n", i);
109 1.1 uch k += V7FS_INODE_PER_BLOCK;
110 1.1 uch continue;
111 1.1 uch }
112 1.1 uch di = (struct v7fs_inode_diskimage *)buf;
113 1.1 uch for (j = 0; j < V7FS_INODE_PER_BLOCK; j++, k++) {
114 1.1 uch v7fs_inode_setup_memory_image(fs, &inode, di + j);
115 1.1 uch inode.inode_number = k;
116 1.1 uch if ((ret = func(fs, ctx, &inode, k))) {
117 1.1 uch scratch_free(fs, buf);
118 1.1 uch return ret;
119 1.1 uch }
120 1.1 uch }
121 1.1 uch scratch_free(fs, buf);
122 1.1 uch }
123 1.1 uch return 0;
124 1.1 uch }
125