xref: /netbsd-src/sys/fs/v7fs/v7fs_superblock_util.c (revision f1ca1ce2bf561c65d8d08b5a57f1979f43f5aa7f)
1*f1ca1ce2Sapb /*	$NetBSD: v7fs_superblock_util.c,v 1.2 2011/07/18 21:51:49 apb Exp $	*/
29255b46fSuch 
39255b46fSuch /*-
49255b46fSuch  * Copyright (c) 2011 The NetBSD Foundation, Inc.
59255b46fSuch  * All rights reserved.
69255b46fSuch  *
79255b46fSuch  * This code is derived from software contributed to The NetBSD Foundation
89255b46fSuch  * by UCHIYAMA Yasushi.
99255b46fSuch  *
109255b46fSuch  * Redistribution and use in source and binary forms, with or without
119255b46fSuch  * modification, are permitted provided that the following conditions
129255b46fSuch  * are met:
139255b46fSuch  * 1. Redistributions of source code must retain the above copyright
149255b46fSuch  *    notice, this list of conditions and the following disclaimer.
159255b46fSuch  * 2. Redistributions in binary form must reproduce the above copyright
169255b46fSuch  *    notice, this list of conditions and the following disclaimer in the
179255b46fSuch  *    documentation and/or other materials provided with the distribution.
189255b46fSuch  *
199255b46fSuch  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
209255b46fSuch  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
219255b46fSuch  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
229255b46fSuch  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
239255b46fSuch  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
249255b46fSuch  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
259255b46fSuch  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
269255b46fSuch  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
279255b46fSuch  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
289255b46fSuch  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
299255b46fSuch  * POSSIBILITY OF SUCH DAMAGE.
309255b46fSuch  */
319255b46fSuch 
32*f1ca1ce2Sapb #if HAVE_NBTOOL_CONFIG_H
33*f1ca1ce2Sapb #include "nbtool_config.h"
34*f1ca1ce2Sapb #endif
35*f1ca1ce2Sapb 
369255b46fSuch #include <sys/cdefs.h>
37*f1ca1ce2Sapb __KERNEL_RCSID(0, "$NetBSD: v7fs_superblock_util.c,v 1.2 2011/07/18 21:51:49 apb Exp $");
389255b46fSuch #if defined _KERNEL_OPT
399255b46fSuch #include "opt_v7fs.h"
409255b46fSuch #endif
419255b46fSuch 
429255b46fSuch #ifdef _KERNEL
439255b46fSuch #include <sys/systm.h>
449255b46fSuch #include <sys/param.h>	/* errno */
459255b46fSuch #else
469255b46fSuch #include <stdio.h>
479255b46fSuch #include <time.h>
489255b46fSuch #endif
499255b46fSuch 
509255b46fSuch #include "v7fs.h"
519255b46fSuch #include "v7fs_impl.h"
529255b46fSuch #include "v7fs_superblock.h"
539255b46fSuch #include "v7fs_inode.h"
549255b46fSuch 
559255b46fSuch #ifdef V7FS_SUPERBLOCK_DEBUG
569255b46fSuch #define	DPRINTF(fmt, args...)	printf("%s: " fmt, __func__, ##args)
579255b46fSuch #define	DPRINTF_(fmt, args...)	printf(fmt, ##args)
589255b46fSuch #else
599255b46fSuch #define	DPRINTF(fmt, args...)	((void)0)
609255b46fSuch #define	DPRINTF_(fmt, args...)	((void)0)
619255b46fSuch #endif
629255b46fSuch 
639255b46fSuch void
v7fs_superblock_status(struct v7fs_self * fs)649255b46fSuch v7fs_superblock_status(struct v7fs_self *fs)
659255b46fSuch {
669255b46fSuch 	struct v7fs_superblock *sb = &fs->superblock;
679255b46fSuch 	struct v7fs_stat *stat = &fs->stat;
689255b46fSuch 
699255b46fSuch 	stat->total_blocks = sb->volume_size - sb->datablock_start_sector;
709255b46fSuch 	stat->total_inode = V7FS_MAX_INODE(sb);
719255b46fSuch 	stat->free_inode = sb->total_freeinode;
729255b46fSuch 	stat->free_blocks = sb->total_freeblock;
739255b46fSuch 	stat->total_files = stat->total_inode - sb->total_freeinode - 1;
749255b46fSuch 
759255b46fSuch 	DPRINTF("block %d/%d, inode %d/%d\n", stat->free_blocks,
769255b46fSuch 	    stat->total_blocks, stat->free_inode, stat->total_inode);
779255b46fSuch }
789255b46fSuch 
799255b46fSuch void
v7fs_superblock_dump(const struct v7fs_self * fs)809255b46fSuch v7fs_superblock_dump(const struct v7fs_self *fs)
819255b46fSuch {
829255b46fSuch 	const struct v7fs_superblock *sb = &fs->superblock;
839255b46fSuch 
849255b46fSuch #define	print(x)	printf("%s: %d\n", #x, sb->x)
859255b46fSuch 	print(datablock_start_sector);
869255b46fSuch 	print(volume_size);
879255b46fSuch 	print(nfreeblock);
889255b46fSuch 	print(nfreeinode);
899255b46fSuch 	print(update_time);
909255b46fSuch 	print(lock_freeblock);
919255b46fSuch 	print(lock_freeinode);
929255b46fSuch 	print(modified);
939255b46fSuch 	print(readonly);
949255b46fSuch #if !defined _KERNEL
959255b46fSuch 	time_t t = sb->update_time;
969255b46fSuch 	printf("%s", ctime(&t));
979255b46fSuch #endif
989255b46fSuch 	print(total_freeblock);
999255b46fSuch 	print(total_freeinode);
1009255b46fSuch #undef print
1019255b46fSuch }
102