1 /* 2 * $Id: mtab.c,v 5.2 90/06/23 22:19:44 jsp Rel $ 3 * 4 * Copyright (c) 1989 Jan-Simon Pendry 5 * Copyright (c) 1989 Imperial College of Science, Technology & Medicine 6 * Copyright (c) 1989 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 * @(#)mtab.c 5.1 (Berkeley) 06/29/90 15 */ 16 17 #include "am.h" 18 19 /* 20 * Firewall /etc/mtab entries 21 */ 22 void mnt_free(mp) 23 struct mntent *mp; 24 { 25 free(mp->mnt_fsname); 26 free(mp->mnt_dir); 27 free(mp->mnt_type); 28 free(mp->mnt_opts); 29 free((voidp) mp); 30 } 31 32 /* 33 * Discard memory allocated for mount list 34 */ 35 void discard_mntlist(mp) 36 mntlist *mp; 37 { 38 mntlist *mp2; 39 40 while (mp2 = mp) { 41 mp = mp->mnext; 42 if (mp2->mnt) 43 mnt_free(mp2->mnt); 44 free(mp2); 45 } 46 } 47 48 /* 49 * Throw away a mount list 50 */ 51 void free_mntlist(mp) 52 mntlist *mp; 53 { 54 discard_mntlist(mp); 55 unlock_mntlist(); 56 } 57 58 /* 59 * Utility routine which determines the value of a 60 * numeric option in the mount options (such as port=%d). 61 * Returns 0 if the option is not specified. 62 */ 63 int hasmntval(mnt, opt) 64 struct mntent *mnt; 65 char *opt; 66 { 67 char *str = hasmntopt(mnt, opt); 68 if (str) { 69 char *eq = strchr(str, '='); 70 if (eq) 71 return atoi(eq+1); 72 else 73 plog(XLOG_USER, "bad numeric option \"%s\" in \"%s\"", opt, str); 74 } 75 76 return 0; 77 } 78