summaryrefslogtreecommitdiffstats
path: root/sysutils/linneighborhood/files/mntent_compat.c
blob: 62b2eb3b758172fa1c36d6654afa11994ce88338 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "mntent.h"
#include <sys/param.h>
//#include <sys/ucred.h>
#include <sys/mount.h>
#include <fstab.h>

struct statfs *getmntent_mntbufp;
int getmntent_mntcount = 0;
int getmntent_mntpos = 0;
char mntent_global_opts[256];
struct mntent mntent_global_mntent;

FILE * setmntent(char * filep, char * type)
{
	getmntent_mntpos = 0;
	getmntent_mntcount = getmntinfo(&getmntent_mntbufp, MNT_WAIT);
	return (FILE *)1; // dummy
}

void getmntent_addopt(char ** c, const char * s)
{
	int i = strlen(s);
        *(*c)++ = ',';
        strcpy(*c, s);
        *c += i;
}

struct mntent *getmntent(FILE * filep)
{
	char *c = mntent_global_opts+2; 
	struct fstab *fst;
	if (getmntent_mntpos >= getmntent_mntcount)
		return 0;
	if (getmntent_mntbufp[getmntent_mntpos].f_flags & MNT_RDONLY) strcpy(mntent_global_opts, "ro");
		else strcpy(mntent_global_opts, "rw");

        if (getmntent_mntbufp[getmntent_mntpos].f_flags & MNT_SYNCHRONOUS)    getmntent_addopt(&c, "sync");
        if (getmntent_mntbufp[getmntent_mntpos].f_flags & MNT_NOEXEC)         getmntent_addopt(&c, "noexec");
        if (getmntent_mntbufp[getmntent_mntpos].f_flags & MNT_NOSUID)         getmntent_addopt(&c, "nosuid");
#if __FreeBSD_version < 700008
        if (getmntent_mntbufp[getmntent_mntpos].f_flags & MNT_NODEV)          getmntent_addopt(&c, "nodev");
#endif
        if (getmntent_mntbufp[getmntent_mntpos].f_flags & MNT_UNION)          getmntent_addopt(&c, "union");
        if (getmntent_mntbufp[getmntent_mntpos].f_flags & MNT_ASYNC)          getmntent_addopt(&c, "async");
        if (getmntent_mntbufp[getmntent_mntpos].f_flags & MNT_NOATIME)        getmntent_addopt(&c, "noatime");
        if (getmntent_mntbufp[getmntent_mntpos].f_flags & MNT_NOCLUSTERR)     getmntent_addopt(&c, "noclusterr");
        if (getmntent_mntbufp[getmntent_mntpos].f_flags & MNT_NOCLUSTERW)     getmntent_addopt(&c, "noclusterw");
        if (getmntent_mntbufp[getmntent_mntpos].f_flags & MNT_NOSYMFOLLOW)    getmntent_addopt(&c, "nosymfollow");
        if (getmntent_mntbufp[getmntent_mntpos].f_flags & MNT_SUIDDIR)        getmntent_addopt(&c, "suiddir");
		
	mntent_global_mntent.mnt_fsname = getmntent_mntbufp[getmntent_mntpos].f_mntfromname;
	mntent_global_mntent.mnt_dir = getmntent_mntbufp[getmntent_mntpos].f_mntonname;
	mntent_global_mntent.mnt_type = getmntent_mntbufp[getmntent_mntpos].f_fstypename;
        mntent_global_mntent.mnt_opts = mntent_global_opts;
	if ((fst = getfsspec(getmntent_mntbufp[getmntent_mntpos].f_mntfromname)))
        {
        	mntent_global_mntent.mnt_freq = fst->fs_freq;
        	mntent_global_mntent.mnt_passno = fst->fs_passno;
        }
        else if ((fst = getfsfile(getmntent_mntbufp[getmntent_mntpos].f_mntonname)))
        {
        	mntent_global_mntent.mnt_freq = fst->fs_freq;
        	mntent_global_mntent.mnt_passno = fst->fs_passno;
        }
        else if (strcmp(getmntent_mntbufp[getmntent_mntpos].f_fstypename, "ufs") == 0) 
        {
                if (strcmp(getmntent_mntbufp[getmntent_mntpos].f_mntonname, "/") == 0)
                {
	        	mntent_global_mntent.mnt_freq = 1;
        		mntent_global_mntent.mnt_passno = 1;
                }
                else
                {
	        	mntent_global_mntent.mnt_freq = 2;
        		mntent_global_mntent.mnt_passno = 2;
                }
        } 
        else
        {
        	mntent_global_mntent.mnt_freq = 0;
        	mntent_global_mntent.mnt_passno = 0;
        }
        ++getmntent_mntpos;
	return & mntent_global_mntent;
}

int endmntent(FILE * filep)
{
	return 0;
}
OpenPOWER on IntegriCloud