GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usr.bin/rdistd/filesys-os.c Lines: 0 30 0.0 %
Date: 2017-11-07 Branches: 0 10 0.0 %

Line Branch Exec Source
1
/*	$OpenBSD: filesys-os.c,v 1.13 2015/01/20 09:00:16 guenther Exp $	*/
2
3
/*
4
 * Copyright (c) 1983 Regents of the University of California.
5
 * All rights reserved.
6
 *
7
 * Redistribution and use in source and binary forms, with or without
8
 * modification, are permitted provided that the following conditions
9
 * are met:
10
 * 1. Redistributions of source code must retain the above copyright
11
 *    notice, this list of conditions and the following disclaimer.
12
 * 2. Redistributions in binary form must reproduce the above copyright
13
 *    notice, this list of conditions and the following disclaimer in the
14
 *    documentation and/or other materials provided with the distribution.
15
 * 3. Neither the name of the University nor the names of its contributors
16
 *    may be used to endorse or promote products derived from this software
17
 *    without specific prior written permission.
18
 *
19
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29
 * SUCH DAMAGE.
30
 */
31
32
#include <sys/types.h>
33
#include <sys/mount.h>
34
#include <stdlib.h>
35
#include <string.h>
36
37
#include "server.h"
38
39
/*
40
 * OS specific file system routines
41
 */
42
43
static struct statfs   *mnt = NULL;
44
static int 		entries_left;
45
46
/*
47
 * getfsstat() version of get mount info routines.
48
 */
49
int
50
setmountent(void)
51
{
52
	long size;
53
54
	size = getfsstat(NULL, 0, MNT_WAIT);
55
	if (size == -1)
56
		return (0);
57
58
	free(mnt);
59
	size *= sizeof(struct statfs);
60
	mnt = xmalloc(size);
61
62
	entries_left = getfsstat(mnt, size, MNT_WAIT);
63
	if (entries_left == -1)
64
		return (0);
65
66
	return (1);
67
}
68
69
/*
70
 * getfsstat() version of getmountent()
71
 */
72
mntent_t *
73
getmountent(void)
74
{
75
	static mntent_t mntstruct;
76
	static char remote_dev[HOST_NAME_MAX+1 + PATH_MAX + 1];
77
78
	if (!entries_left)
79
		return (NULL);
80
81
	memset(&mntstruct, 0, sizeof(mntstruct));
82
83
	if (mnt->f_flags & MNT_RDONLY)
84
		mntstruct.me_flags |= MEFLAG_READONLY;
85
86
	if (strcmp(mnt->f_fstypename, "nfs") == 0) {
87
		strlcpy(remote_dev, mnt->f_mntfromname, sizeof(remote_dev));
88
		mntstruct.me_path = remote_dev;
89
		mntstruct.me_flags |= MEFLAG_NFS;
90
	} else
91
		mntstruct.me_path = mnt->f_mntonname;
92
93
	mnt++;
94
	entries_left--;
95
96
	return (&mntstruct);
97
}
98
99
/*
100
 * Done with iterations
101
 */
102
void
103
endmountent(void)
104
{
105
	free(mnt);
106
	mnt = NULL;
107
}
108
109
/*
110
 * Make a new (copy) of a mntent structure.
111
 */
112
mntent_t *
113
newmountent(const mntent_t *old)
114
{
115
	mntent_t *new;
116
117
	new = xmalloc(sizeof *new);
118
	new->me_path = xstrdup(old->me_path);
119
	new->me_flags = old->me_flags;
120
121
	return (new);
122
}