1*9f988b79SJean-Baptiste Boric /* $NetBSD: v7fs_superblock_util.c,v 1.2 2011/07/18 21:51:49 apb Exp $ */
2*9f988b79SJean-Baptiste Boric
3*9f988b79SJean-Baptiste Boric /*-
4*9f988b79SJean-Baptiste Boric * Copyright (c) 2011 The NetBSD Foundation, Inc.
5*9f988b79SJean-Baptiste Boric * All rights reserved.
6*9f988b79SJean-Baptiste Boric *
7*9f988b79SJean-Baptiste Boric * This code is derived from software contributed to The NetBSD Foundation
8*9f988b79SJean-Baptiste Boric * by UCHIYAMA Yasushi.
9*9f988b79SJean-Baptiste Boric *
10*9f988b79SJean-Baptiste Boric * Redistribution and use in source and binary forms, with or without
11*9f988b79SJean-Baptiste Boric * modification, are permitted provided that the following conditions
12*9f988b79SJean-Baptiste Boric * are met:
13*9f988b79SJean-Baptiste Boric * 1. Redistributions of source code must retain the above copyright
14*9f988b79SJean-Baptiste Boric * notice, this list of conditions and the following disclaimer.
15*9f988b79SJean-Baptiste Boric * 2. Redistributions in binary form must reproduce the above copyright
16*9f988b79SJean-Baptiste Boric * notice, this list of conditions and the following disclaimer in the
17*9f988b79SJean-Baptiste Boric * documentation and/or other materials provided with the distribution.
18*9f988b79SJean-Baptiste Boric *
19*9f988b79SJean-Baptiste Boric * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20*9f988b79SJean-Baptiste Boric * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21*9f988b79SJean-Baptiste Boric * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22*9f988b79SJean-Baptiste Boric * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23*9f988b79SJean-Baptiste Boric * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*9f988b79SJean-Baptiste Boric * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*9f988b79SJean-Baptiste Boric * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*9f988b79SJean-Baptiste Boric * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*9f988b79SJean-Baptiste Boric * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*9f988b79SJean-Baptiste Boric * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*9f988b79SJean-Baptiste Boric * POSSIBILITY OF SUCH DAMAGE.
30*9f988b79SJean-Baptiste Boric */
31*9f988b79SJean-Baptiste Boric
32*9f988b79SJean-Baptiste Boric #if HAVE_NBTOOL_CONFIG_H
33*9f988b79SJean-Baptiste Boric #include "nbtool_config.h"
34*9f988b79SJean-Baptiste Boric #endif
35*9f988b79SJean-Baptiste Boric
36*9f988b79SJean-Baptiste Boric #include <sys/cdefs.h>
37*9f988b79SJean-Baptiste Boric __KERNEL_RCSID(0, "$NetBSD: v7fs_superblock_util.c,v 1.2 2011/07/18 21:51:49 apb Exp $");
38*9f988b79SJean-Baptiste Boric #if defined _KERNEL_OPT
39*9f988b79SJean-Baptiste Boric #include "opt_v7fs.h"
40*9f988b79SJean-Baptiste Boric #endif
41*9f988b79SJean-Baptiste Boric
42*9f988b79SJean-Baptiste Boric #ifdef _KERNEL
43*9f988b79SJean-Baptiste Boric #include <sys/systm.h>
44*9f988b79SJean-Baptiste Boric #include <sys/param.h> /* errno */
45*9f988b79SJean-Baptiste Boric #else
46*9f988b79SJean-Baptiste Boric #include <stdio.h>
47*9f988b79SJean-Baptiste Boric #include <time.h>
48*9f988b79SJean-Baptiste Boric #endif
49*9f988b79SJean-Baptiste Boric
50*9f988b79SJean-Baptiste Boric #include "v7fs.h"
51*9f988b79SJean-Baptiste Boric #include "v7fs_impl.h"
52*9f988b79SJean-Baptiste Boric #include "v7fs_superblock.h"
53*9f988b79SJean-Baptiste Boric #include "v7fs_inode.h"
54*9f988b79SJean-Baptiste Boric
55*9f988b79SJean-Baptiste Boric #ifdef V7FS_SUPERBLOCK_DEBUG
56*9f988b79SJean-Baptiste Boric #define DPRINTF(fmt, args...) printf("%s: " fmt, __func__, ##args)
57*9f988b79SJean-Baptiste Boric #define DPRINTF_(fmt, args...) printf(fmt, ##args)
58*9f988b79SJean-Baptiste Boric #else
59*9f988b79SJean-Baptiste Boric #define DPRINTF(fmt, args...) ((void)0)
60*9f988b79SJean-Baptiste Boric #define DPRINTF_(fmt, args...) ((void)0)
61*9f988b79SJean-Baptiste Boric #endif
62*9f988b79SJean-Baptiste Boric
63*9f988b79SJean-Baptiste Boric void
v7fs_superblock_status(struct v7fs_self * fs)64*9f988b79SJean-Baptiste Boric v7fs_superblock_status(struct v7fs_self *fs)
65*9f988b79SJean-Baptiste Boric {
66*9f988b79SJean-Baptiste Boric struct v7fs_superblock *sb = &fs->superblock;
67*9f988b79SJean-Baptiste Boric struct v7fs_stat *stat = &fs->stat;
68*9f988b79SJean-Baptiste Boric
69*9f988b79SJean-Baptiste Boric stat->total_blocks = sb->volume_size - sb->datablock_start_sector;
70*9f988b79SJean-Baptiste Boric stat->total_inode = V7FS_MAX_INODE(sb);
71*9f988b79SJean-Baptiste Boric stat->free_inode = sb->total_freeinode;
72*9f988b79SJean-Baptiste Boric stat->free_blocks = sb->total_freeblock;
73*9f988b79SJean-Baptiste Boric stat->total_files = stat->total_inode - sb->total_freeinode - 1;
74*9f988b79SJean-Baptiste Boric
75*9f988b79SJean-Baptiste Boric DPRINTF("block %d/%d, inode %d/%d\n", stat->free_blocks,
76*9f988b79SJean-Baptiste Boric stat->total_blocks, stat->free_inode, stat->total_inode);
77*9f988b79SJean-Baptiste Boric }
78*9f988b79SJean-Baptiste Boric
79*9f988b79SJean-Baptiste Boric void
v7fs_superblock_dump(const struct v7fs_self * fs)80*9f988b79SJean-Baptiste Boric v7fs_superblock_dump(const struct v7fs_self *fs)
81*9f988b79SJean-Baptiste Boric {
82*9f988b79SJean-Baptiste Boric const struct v7fs_superblock *sb = &fs->superblock;
83*9f988b79SJean-Baptiste Boric
84*9f988b79SJean-Baptiste Boric #define print(x) printf("%s: %d\n", #x, sb->x)
85*9f988b79SJean-Baptiste Boric print(datablock_start_sector);
86*9f988b79SJean-Baptiste Boric print(volume_size);
87*9f988b79SJean-Baptiste Boric print(nfreeblock);
88*9f988b79SJean-Baptiste Boric print(nfreeinode);
89*9f988b79SJean-Baptiste Boric print(update_time);
90*9f988b79SJean-Baptiste Boric print(lock_freeblock);
91*9f988b79SJean-Baptiste Boric print(lock_freeinode);
92*9f988b79SJean-Baptiste Boric print(modified);
93*9f988b79SJean-Baptiste Boric print(readonly);
94*9f988b79SJean-Baptiste Boric #if !defined _KERNEL
95*9f988b79SJean-Baptiste Boric time_t t = sb->update_time;
96*9f988b79SJean-Baptiste Boric printf("%s", ctime(&t));
97*9f988b79SJean-Baptiste Boric #endif
98*9f988b79SJean-Baptiste Boric print(total_freeblock);
99*9f988b79SJean-Baptiste Boric print(total_freeinode);
100*9f988b79SJean-Baptiste Boric #undef print
101*9f988b79SJean-Baptiste Boric }
102