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