Esempio n. 1
0
/*
 * Get file fragmentation information.
 */
static int
frag_f(
	int		argc,
	char		**argv)
{
	xfs_agnumber_t	agno;
	double		answer;

	if (!init(argc, argv))
		return 0;
	for (agno = 0; agno < mp->m_sb.sb_agcount; agno++)
		scan_ag(agno);
	if (extcount_actual)
		answer = (double)(extcount_actual - extcount_ideal) * 100.0 /
			 (double)extcount_actual;
	else
		answer = 0.0;
	dbprintf(_("actual %llu, ideal %llu, fragmentation factor %.2f%%\n"),
		extcount_actual, extcount_ideal, answer);
	return 0;
}
Esempio n. 2
0
File: phase2.c Progetto: hyakki-/sgi
void
phase2(xfs_mount_t *mp, libxfs_init_t *args)
{
    xfs_agnumber_t		i;
    xfs_agblock_t		b;
    int			j;
    ino_tree_node_t		*ino_rec;

    /* now we can start using the buffer cache routines */
    set_mp(mp);

    /* Check whether this fs has internal or external log */
    if (mp->m_sb.sb_logstart == 0) {
        if (!args->logname) {
            fprintf (stderr,
                     "This filesystem has an external log.  "
                     "Specify log device with the -l option.\n");
            exit (1);
        }

        fprintf (stderr, "Phase 2 - using external log on %s\n",
                 args->logname);
    } else
        fprintf (stderr, "Phase 2 - using internal log\n");

    /* Zero log if applicable */
    if (!no_modify)  {
        do_log("        - zero log...\n");
        zero_log(mp, args);
    }

    do_log("        - scan filesystem freespace and inode maps...\n");

    /*
     * account for space used by ag headers and log if internal
     */
    set_bmap_log(mp);
    set_bmap_fs(mp);

    bad_ino_btree = 0;

    for (i = 0; i < mp->m_sb.sb_agcount; i++)  {
        scan_ag(i);
#ifdef XR_INODE_TRACE
        print_inode_list(i);
#endif
    }

    /*
     * make sure we know about the root inode chunk
     */
    if ((ino_rec = find_inode_rec(0, mp->m_sb.sb_rootino)) == NULL)  {
        ASSERT(mp->m_sb.sb_rbmino == mp->m_sb.sb_rootino + 1 &&
               mp->m_sb.sb_rsumino == mp->m_sb.sb_rootino + 2);
        do_warn("root inode chunk not found\n");

        /*
         * mark the first 3 used, the rest are free
         */
        ino_rec = set_inode_used_alloc(0,
                                       (xfs_agino_t) mp->m_sb.sb_rootino);
        set_inode_used(ino_rec, 1);
        set_inode_used(ino_rec, 2);

        for (j = 3; j < XFS_INODES_PER_CHUNK; j++)
            set_inode_free(ino_rec, j);

        /*
         * also mark blocks
         */
        for (b = 0; b < mp->m_ialloc_blks; b++)  {
            set_agbno_state(mp, 0,
                            b + XFS_INO_TO_AGBNO(mp, mp->m_sb.sb_rootino),
                            XR_E_INO);
        }
    } else  {
        do_log("        - found root inode chunk\n");

        /*
         * blocks are marked, just make sure they're in use
         */
        if (is_inode_free(ino_rec, 0))  {
            do_warn("root inode marked free, ");
            set_inode_used(ino_rec, 0);
            if (!no_modify)
                do_warn("correcting\n");
            else
                do_warn("would correct\n");
        }

        if (is_inode_free(ino_rec, 1))  {
            do_warn("realtime bitmap inode marked free, ");
            set_inode_used(ino_rec, 1);
            if (!no_modify)
                do_warn("correcting\n");
            else
                do_warn("would correct\n");
        }

        if (is_inode_free(ino_rec, 2))  {
            do_warn("realtime summary inode marked free, ");
            set_inode_used(ino_rec, 2);
            if (!no_modify)
                do_warn("correcting\n");
            else
                do_warn("would correct\n");
        }
    }
}