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