g_journal_ufs.c revision 332640
167754Smsmith/*- 267754Smsmith * Copyright (c) 2005-2006 Pawel Jakub Dawidek <pjd@FreeBSD.org> 367754Smsmith * All rights reserved. 470243Smsmith * 567754Smsmith * Redistribution and use in source and binary forms, with or without 667754Smsmith * modification, are permitted provided that the following conditions 767754Smsmith * are met: 867754Smsmith * 1. Redistributions of source code must retain the above copyright 967754Smsmith * notice, this list of conditions and the following disclaimer. 1067754Smsmith * 2. Redistributions in binary form must reproduce the above copyright 1167754Smsmith * notice, this list of conditions and the following disclaimer in the 1270243Smsmith * documentation and/or other materials provided with the distribution. 1370243Smsmith * 1467754Smsmith * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 1567754Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1667754Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1767754Smsmith * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 1867754Smsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1967754Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2067754Smsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2167754Smsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2267754Smsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2367754Smsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2467754Smsmith * SUCH DAMAGE. 2567754Smsmith */ 2667754Smsmith 2767754Smsmith#include <sys/cdefs.h> 2867754Smsmith__FBSDID("$FreeBSD: stable/11/sys/geom/journal/g_journal_ufs.c 332640 2018-04-17 02:18:04Z kevans $"); 2967754Smsmith 3067754Smsmith#include <sys/param.h> 3167754Smsmith#include <sys/systm.h> 3267754Smsmith#include <sys/vnode.h> 3367754Smsmith#include <sys/mount.h> 3467754Smsmith 3567754Smsmith#include <ufs/ufs/extattr.h> 3667754Smsmith#include <ufs/ufs/quota.h> 3767754Smsmith#include <ufs/ufs/inode.h> 3867754Smsmith#include <ufs/ufs/ufs_extern.h> 3967754Smsmith#include <ufs/ufs/ufsmount.h> 4067754Smsmith 4167754Smsmith#include <ufs/ffs/fs.h> 4267754Smsmith#include <ufs/ffs/ffs_extern.h> 4367754Smsmith 4467754Smsmith#include <geom/geom.h> 4567754Smsmith#include <geom/journal/g_journal.h> 4667754Smsmith 4767754Smsmithstatic const int superblocks[] = SBLOCKSEARCH; 4867754Smsmith 4967754Smsmithstatic int 5067754Smsmithg_journal_ufs_clean(struct mount *mp) 5167754Smsmith{ 5267754Smsmith struct ufsmount *ump; 5367754Smsmith struct fs *fs; 5467754Smsmith int flags; 5567754Smsmith 5667754Smsmith ump = VFSTOUFS(mp); 5767754Smsmith fs = ump->um_fs; 5867754Smsmith 5967754Smsmith flags = fs->fs_flags; 6067754Smsmith fs->fs_flags &= ~(FS_UNCLEAN | FS_NEEDSFSCK); 6167754Smsmith ffs_sbupdate(ump, MNT_WAIT, 1); 6267754Smsmith fs->fs_flags = flags; 6367754Smsmith 6467754Smsmith return (0); 6567754Smsmith} 6667754Smsmith 6767754Smsmithstatic void 6867754Smsmithg_journal_ufs_dirty(struct g_consumer *cp) 6967754Smsmith{ 7067754Smsmith struct fs *fs; 7167754Smsmith int error, i, sb; 7267754Smsmith 7367754Smsmith if (SBLOCKSIZE % cp->provider->sectorsize != 0) 7467754Smsmith return; 7567754Smsmith for (i = 0; (sb = superblocks[i]) != -1; i++) { 7667754Smsmith if (sb % cp->provider->sectorsize != 0) 7767754Smsmith continue; 7867754Smsmith fs = g_read_data(cp, sb, SBLOCKSIZE, NULL); 7967754Smsmith if (fs == NULL) 8067754Smsmith continue; 8167754Smsmith if (fs->fs_magic != FS_UFS1_MAGIC && 8267754Smsmith fs->fs_magic != FS_UFS2_MAGIC) { 8367754Smsmith g_free(fs); 8467754Smsmith continue; 8567754Smsmith } 8667754Smsmith GJ_DEBUG(0, "clean=%d flags=0x%x", fs->fs_clean, fs->fs_flags); 8767754Smsmith fs->fs_clean = 0; 8867754Smsmith fs->fs_flags |= FS_NEEDSFSCK | FS_UNCLEAN; 8967754Smsmith error = g_write_data(cp, sb, fs, SBLOCKSIZE); 9067754Smsmith g_free(fs); 9167754Smsmith if (error != 0) { 9267754Smsmith GJ_DEBUG(0, "Cannot mark file system %s as dirty " 9367754Smsmith "(error=%d).", cp->provider->name, error); 9467754Smsmith } else { 9567754Smsmith GJ_DEBUG(0, "File system %s marked as dirty.", 9667754Smsmith cp->provider->name); 9767754Smsmith } 9867754Smsmith } 9967754Smsmith} 10067754Smsmith 10167754Smsmithconst struct g_journal_desc g_journal_ufs = { 10267754Smsmith .jd_fstype = "ufs", 10367754Smsmith .jd_clean = g_journal_ufs_clean, 10467754Smsmith .jd_dirty = g_journal_ufs_dirty 10567754Smsmith}; 10667754Smsmith 10767754SmsmithMODULE_DEPEND(g_journal, ufs, 1, 1, 1); 10867754SmsmithMODULE_VERSION(geom_journal, 0); 10967754Smsmith