1 /* 2 * $Id: umount_fs.c,v 5.2.1.2 91/03/03 20:34:23 jsp Alpha $ 3 * 4 * Copyright (c) 1990 Jan-Simon Pendry 5 * Copyright (c) 1990 Imperial College of Science, Technology & Medicine 6 * Copyright (c) 1990 The Regents of the University of California. 7 * All rights reserved. 8 * 9 * This code is derived from software contributed to Berkeley by 10 * Jan-Simon Pendry at Imperial College, London. 11 * 12 * %sccs.include.redist.c% 13 * 14 * @(#)umount_fs.c 5.2 (Berkeley) 03/17/91 15 */ 16 17 #include "am.h" 18 19 #ifdef NEED_UMOUNT_BSD 20 21 #include <sys/mount.h> /* For MNT_NOFORCE */ 22 23 int umount_fs P((char *fs_name)); 24 int umount_fs(fs_name) 25 char *fs_name; 26 { 27 int error; 28 29 eintr: 30 error = unmount(fs_name, MNT_NOFORCE); 31 if (error < 0) 32 error = errno; 33 34 switch (error) { 35 case EINVAL: 36 case ENOTBLK: 37 case ENOENT: 38 plog(XLOG_WARNING, "unmount: %s is not mounted", fs_name); 39 error = 0; /* Not really an error */ 40 break; 41 42 case EINTR: 43 #ifdef DEBUG 44 /* not sure why this happens, but it does. ask kirk one day... */ 45 dlog("%s: unmount: %m", fs_name); 46 #endif /* DEBUG */ 47 goto eintr; 48 49 #ifdef DEBUG 50 default: 51 dlog("%s: unmount: %m", fs_name); 52 break; 53 #endif /* DEBUG */ 54 } 55 56 return error; 57 } 58 59 #endif /* NEED_UMOUNT_BSD */ 60 61 #ifdef NEED_UMOUNT_FS 62 63 int umount_fs(fs_name) 64 char *fs_name; 65 { 66 mntlist *mlist, *mp, *mp_save = 0; 67 int error = 0; 68 69 mp = mlist = read_mtab(fs_name); 70 71 /* 72 * Search the mount table looking for 73 * the correct (ie last) matching entry 74 */ 75 while (mp) { 76 if (strcmp(mp->mnt->mnt_fsname, fs_name) == 0 || 77 strcmp(mp->mnt->mnt_dir, fs_name) == 0) 78 mp_save = mp; 79 mp = mp->mnext; 80 } 81 82 if (mp_save) { 83 #ifdef DEBUG 84 dlog("Trying unmount(%s)", mp_save->mnt->mnt_dir); 85 #endif /* DEBUG */ 86 if (UNMOUNT_TRAP(mp_save->mnt) < 0) { 87 switch (error = errno) { 88 case EINVAL: 89 case ENOTBLK: 90 plog(XLOG_WARNING, "unmount: %s is not mounted", mp_save->mnt->mnt_dir); 91 error = 0; /* Not really an error */ 92 break; 93 94 case ENOENT: 95 plog(XLOG_ERROR, "mount point %s: %m", mp_save->mnt->mnt_dir); 96 break; 97 98 default: 99 #ifdef DEBUG 100 dlog("%s: unmount: %m", mp_save->mnt->mnt_dir); 101 #endif /* DEBUG */ 102 break; 103 } 104 } 105 106 #ifdef UPDATE_MTAB 107 if (!error) { 108 mnt_free(mp_save->mnt); 109 mp_save->mnt = 0; 110 111 rewrite_mtab(mlist); 112 } 113 #endif /* UPDATE_MTAB */ 114 } else { 115 plog(XLOG_ERROR, "Couldn't find how to unmount %s", fs_name); 116 /* 117 * Assume it is already unmounted 118 */ 119 error = 0; 120 } 121 122 free_mntlist(mlist); 123 124 return error; 125 } 126 127 #endif /* NEED_UMOUNT_FS */ 128