/* fs_remount.c
 *
 * $Id: fs_remount.c,v 1.3 2000/12/18 00:08:37 alderman Exp $
 *
 * Unmount and then remount the filesystem.  Works for flushing
 * the buffer cache.  Should be portable to FreeBSD with a change
 * in the device name and mount point.
 *
 * Linux will require some ioctl - see brian forney's email.
 */
#include <stdio.h>
#include <errno.h>

#include <sys/types.h>
#ifdef __SOLARIS__
#include <sys/mount.h>
#include <sys/mntent.h>
#else 
#include <sys/param.h>
#include <sys/mount.h>
#include <ufs/ufs/ufsmount.h>
#endif /* __SOLARIS__ */

#ifdef __SOLARIS__
#else
#endif /* __SOLARIS__ */

#include "global.h"

int main() {
        char dir[] = DIRNAME;
        char dev[] = DEVNAME;
	int rv = 0;
#ifndef __SOLARIS__
	struct vfsconf vfc;
	struct ufs_args args;
	int mntflags = 0;
	int error = 0;

	args.fspec = dev;
	args.export.ex_root = 0; //DEFAULT_ROOTUID;
	args.export.ex_flags = 0;
	error = getvfsbyname("ufs", &vfc);        
	if (error && vfsisloadable("ufs")) {
                if (vfsload("ufs")) {
                        warn("vfsload(ufs)");
                        return (1);
                }
                endvfsent(); /* flush old table */
                error = getvfsbyname("ufs", &vfc);
        }
        if (error) {
                warnx("ufs filesystem is not available");
                return (1);
        }

#endif /* not __SOLARIS__ */
	
#ifdef __SOLARIS__
	umount(dir);
	rv = mount(dev, dir, NULL, MNTTYPE_UFS, 0, 0, 0, 0);
#else
	unmount(dir, NULL);
	rv = mount(vfc.vfc_name, dir, mntflags, &args);
#endif /* __SOLARIS__ */
        
	if(rv < 0) {
		printf("Error: (%d) %s on %s", errno, dir, dev);
		return errno;
	}
        
}
