umount_bsd44.c revision 174294
150724Scg/* 253413Sroger * Copyright (c) 1997-2006 Erez Zadok 353413Sroger * Copyright (c) 1990 Jan-Simon Pendry 450724Scg * Copyright (c) 1990 Imperial College of Science, Technology & Medicine 553413Sroger * Copyright (c) 1990 The Regents of the University of California. 650724Scg * All rights reserved. 750724Scg * 850724Scg * This code is derived from software contributed to Berkeley by 950724Scg * Jan-Simon Pendry at Imperial College, London. 1050724Scg * 1150724Scg * Redistribution and use in source and binary forms, with or without 1250724Scg * modification, are permitted provided that the following conditions 1350724Scg * are met: 1450724Scg * 1. Redistributions of source code must retain the above copyright 1550724Scg * notice, this list of conditions and the following disclaimer. 1650724Scg * 2. Redistributions in binary form must reproduce the above copyright 1750724Scg * notice, this list of conditions and the following disclaimer in the 1850724Scg * documentation and/or other materials provided with the distribution. 1950724Scg * 3. All advertising materials mentioning features or use of this software 2050724Scg * must display the following acknowledgment: 2150724Scg * This product includes software developed by the University of 2250724Scg * California, Berkeley and its contributors. 2350724Scg * 4. Neither the name of the University nor the names of its contributors 2450724Scg * may be used to endorse or promote products derived from this software 2550724Scg * without specific prior written permission. 2650724Scg * 2750724Scg * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2850724Scg * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2950724Scg * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 3050724Scg * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 3150724Scg * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3250724Scg * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3350724Scg * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3450724Scg * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3550724Scg * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3650724Scg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3750724Scg * SUCH DAMAGE. 3850724Scg * 3950724Scg * 4050724Scg * File: am-utils/conf/umount/umount_bsd44.c 4150733Speter * 4250724Scg */ 4350724Scg 4453413Sroger/* 4553413Sroger * Unmounting filesystems under BSD 4.4. 4653413Sroger */ 4754831Scg 4854831Scg#ifdef HAVE_CONFIG_H 4953413Sroger# include <config.h> 5053413Sroger#endif /* HAVE_CONFIG_H */ 5153413Sroger#include <am_defs.h> 5253413Sroger#include <amu.h> 5353465Scg 5453465Scg 5553465Scgint 5650724Scgumount_fs(char *mntdir, const char *mnttabname, u_int unmount_flags) 5750724Scg{ 5850724Scg int error; 5950724Scg 6053413Srogereintr: 6153413Sroger error = unmount(mntdir, 0); 6253413Sroger if (error < 0) 6353413Sroger error = errno; 6453413Sroger 6550724Scg switch (error) { 6650724Scg case EINVAL: 6750724Scg case ENOTBLK: 6850724Scg case ENOENT: 6953413Sroger plog(XLOG_WARNING, "unmount: %s is not mounted", mntdir); 7056154Speter error = 0; /* Not really an error */ 7150724Scg break; 7250724Scg 7350724Scg case EINTR: 7450724Scg /* not sure why this happens, but it does. ask kirk one day... */ 7555209Scg dlog("%s: unmount: %m", mntdir); 7650724Scg goto eintr; 7750724Scg 7850724Scg#ifdef MNT2_GEN_OPT_FORCE 7954831Scg case EBUSY: 8050724Scg case EIO: 8155209Scg case ESTALE: 8250724Scg /* caller determines if forced unmounts should be used */ 8355209Scg if (unmount_flags & AMU_UMOUNT_FORCE) { 8450724Scg error = umount2_fs(mntdir, unmount_flags); 8550724Scg if (error < 0) 8650724Scg error = errno; 8750724Scg else 8854831Scg return error; 8950724Scg } 9050724Scg /* fallthrough */ 9150724Scg#endif /* MNT2_GEN_OPT_FORCE */ 9250724Scg 9355209Scg default: 9450724Scg dlog("%s: unmount: %m", mntdir); 9550724Scg break; 9654831Scg } 9753413Sroger 9854831Scg return error; 9950724Scg} 10054831Scg 10154831Scg 10255209Scg#ifdef MNT2_GEN_OPT_FORCE 10355209Scg/* force unmount, no questions asked, without touching mnttab file */ 10455209Scgint 10555209Scgumount2_fs(const char *mntdir, u_int unmount_flags) 10655209Scg{ 10754831Scg int error = 0; 10854831Scg if (unmount_flags & AMU_UMOUNT_FORCE) { 10950724Scg plog(XLOG_INFO, "umount2_fs: trying unmount/forced on %s", mntdir); 11050724Scg error = unmount(mntdir, MNT2_GEN_OPT_FORCE); 11150724Scg if (error < 0 && (errno == EINVAL || errno == ENOENT)) 11254831Scg error = 0; /* ignore EINVAL/ENOENT */ 11354831Scg if (error < 0) 11454831Scg plog(XLOG_WARNING, "%s: unmount/force: %m", mntdir); 11555209Scg else 11654831Scg dlog("%s: unmount/force: OK", mntdir); 11754831Scg } 11854831Scg return error; 11950724Scg} 12050724Scg#endif /* MNT2_GEN_OPT_FORCE */ 12150724Scg