xref: /netbsd-src/sys/fs/v7fs/v7fs_superblock_util.c (revision 1b9578b8c2c1f848eeb16dabbfd7d1f0d9fdefbd)
1 /*	$NetBSD: v7fs_superblock_util.c,v 1.1 2011/06/27 11:52:25 uch Exp $	*/
2 
3 /*-
4  * Copyright (c) 2011 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by UCHIYAMA Yasushi.
9  *
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.
18  *
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.
30  */
31 
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: v7fs_superblock_util.c,v 1.1 2011/06/27 11:52:25 uch Exp $");
34 #if defined _KERNEL_OPT
35 #include "opt_v7fs.h"
36 #endif
37 
38 #ifdef _KERNEL
39 #include <sys/systm.h>
40 #include <sys/param.h>	/* errno */
41 #else
42 #include <stdio.h>
43 #include <time.h>
44 #endif
45 
46 #include "v7fs.h"
47 #include "v7fs_impl.h"
48 #include "v7fs_superblock.h"
49 #include "v7fs_inode.h"
50 
51 #ifdef V7FS_SUPERBLOCK_DEBUG
52 #define	DPRINTF(fmt, args...)	printf("%s: " fmt, __func__, ##args)
53 #define	DPRINTF_(fmt, args...)	printf(fmt, ##args)
54 #else
55 #define	DPRINTF(fmt, args...)	((void)0)
56 #define	DPRINTF_(fmt, args...)	((void)0)
57 #endif
58 
59 void
60 v7fs_superblock_status(struct v7fs_self *fs)
61 {
62 	struct v7fs_superblock *sb = &fs->superblock;
63 	struct v7fs_stat *stat = &fs->stat;
64 
65 	stat->total_blocks = sb->volume_size - sb->datablock_start_sector;
66 	stat->total_inode = V7FS_MAX_INODE(sb);
67 	stat->free_inode = sb->total_freeinode;
68 	stat->free_blocks = sb->total_freeblock;
69 	stat->total_files = stat->total_inode - sb->total_freeinode - 1;
70 
71 	DPRINTF("block %d/%d, inode %d/%d\n", stat->free_blocks,
72 	    stat->total_blocks, stat->free_inode, stat->total_inode);
73 }
74 
75 void
76 v7fs_superblock_dump(const struct v7fs_self *fs)
77 {
78 	const struct v7fs_superblock *sb = &fs->superblock;
79 
80 #define	print(x)	printf("%s: %d\n", #x, sb->x)
81 	print(datablock_start_sector);
82 	print(volume_size);
83 	print(nfreeblock);
84 	print(nfreeinode);
85 	print(update_time);
86 	print(lock_freeblock);
87 	print(lock_freeinode);
88 	print(modified);
89 	print(readonly);
90 #if !defined _KERNEL
91 	time_t t = sb->update_time;
92 	printf("%s", ctime(&t));
93 #endif
94 	print(total_freeblock);
95 	print(total_freeinode);
96 #undef print
97 }
98