]> git.decadent.org.uk Git - nfs-utils.git/blob - support/include/nfslib.h
1372635b9a6fcf792e805ffbe1027670f1f2d689
[nfs-utils.git] / support / include / nfslib.h
1 /*
2  * support/include/nfslib.h
3  *
4  * General support functions for NFS user-space programs.
5  *
6  * Copyright (C) 1995 Olaf Kirch <okir@monad.swb.de>
7  */
8
9 #ifndef NFSLIB_H
10 #define NFSLIB_H
11
12 #ifdef HAVE_CONFIG_H
13 #include <config.h>
14 #endif
15
16 #include <sys/types.h>
17 #include <sys/socket.h>
18 #include <netinet/in.h>
19 #include <stdio.h>
20 #include <paths.h>
21 #include <rpcsvc/nfs_prot.h>
22 #include <nfs/nfs.h>
23 #include "xlog.h"
24
25 #ifndef _PATH_EXPORTS
26 #define _PATH_EXPORTS           "/etc/exports"
27 #endif
28 #ifndef _PATH_IDMAPDCONF
29 #define _PATH_IDMAPDCONF        "/etc/idmapd.conf"
30 #endif
31 #ifndef _PATH_XTAB
32 #define _PATH_XTAB              NFS_STATEDIR "/xtab"
33 #endif
34 #ifndef _PATH_XTABTMP
35 #define _PATH_XTABTMP           NFS_STATEDIR "/xtab.tmp"
36 #endif
37 #ifndef _PATH_ETAB
38 #define _PATH_ETAB              NFS_STATEDIR "/etab"
39 #endif
40 #ifndef _PATH_ETABTMP
41 #define _PATH_ETABTMP           NFS_STATEDIR "/etab.tmp"
42 #endif
43 #ifndef _PATH_RMTAB
44 #define _PATH_RMTAB             NFS_STATEDIR "/rmtab"
45 #endif
46 #ifndef _PATH_RMTABTMP
47 #define _PATH_RMTABTMP          _PATH_RMTAB ".tmp"
48 #endif
49 #ifndef _PATH_PROC_EXPORTS
50 #define _PATH_PROC_EXPORTS      "/proc/fs/nfs/exports"
51 #define _PATH_PROC_EXPORTS_ALT  "/proc/fs/nfsd/exports"
52 #endif
53
54 enum cle_maptypes {
55         CLE_MAP_IDENT = 0,
56         CLE_MAP_FILE,
57         CLE_MAP_UGIDD,
58 };
59
60 /*
61  * Data related to a single exports entry as returned by getexportent.
62  * FIXME: export options should probably be parsed at a later time to
63  * allow overrides when using exportfs.
64  */
65 struct exportent {
66         char            e_hostname[NFSCLNT_IDMAX+1];
67         char            e_path[NFS_MAXPATHLEN+1];
68         /* The mount path may be different from the exported path due
69            to submount. It may change for every mount. The idea is we
70            set m_path every time when we process a mount. We should not
71            use it for anything else. */
72         char            m_path[NFS_MAXPATHLEN+1];
73         int             e_flags;
74         int             e_maptype;
75         int             e_anonuid;
76         int             e_anongid;
77         int *           e_squids;
78         int             e_nsquids;
79         int *           e_sqgids;
80         int             e_nsqgids;
81         int             e_fsid;
82         char *          e_mountpoint;
83         int             e_fslocmethod;
84         char *          e_fslocdata;
85         char *          e_uuid;
86 };
87
88 struct rmtabent {
89         char            r_client[NFSCLNT_IDMAX+1];
90         char            r_path[NFS_MAXPATHLEN+1];
91         int             r_count;
92 };
93
94 /*
95  * configuration file parsing
96  */
97 void                    setexportent(char *fname, char *type);
98 struct exportent *      getexportent(int,int);
99 void                    putexportent(struct exportent *xep);
100 void                    endexportent(void);
101 struct exportent *      mkexportent(char *hname, char *path, char *opts);
102 void                    dupexportent(struct exportent *dst,
103                                         struct exportent *src);
104 int                     updateexportent(struct exportent *eep, char *options);
105
106 int                     setrmtabent(char *type);
107 struct rmtabent *       getrmtabent(int log, long *pos);
108 void                    putrmtabent(struct rmtabent *xep, long *pos);
109 void                    endrmtabent(void);
110 void                    rewindrmtabent(void);
111 FILE *                  fsetrmtabent(char *fname, char *type);
112 struct rmtabent *       fgetrmtabent(FILE *fp, int log, long *pos);
113 void                    fputrmtabent(FILE *fp, struct rmtabent *xep, long *pos);
114 void                    fendrmtabent(FILE *fp);
115 void                    frewindrmtabent(FILE *fp);
116
117 /*
118  * wildmat borrowed from INN
119  */
120 int                     wildmat(char *text, char *pattern);
121
122 /*
123  * nfsd library functions.
124  */
125 int                     nfsctl(int, struct nfsctl_arg *, union nfsctl_res *);
126 int                     nfssvc(int port, int nrservs, unsigned int versbits, unsigned int portbits, char *haddr);
127 int                     nfsaddclient(struct nfsctl_client *clp);
128 int                     nfsdelclient(struct nfsctl_client *clp);
129 int                     nfsexport(struct nfsctl_export *exp);
130 int                     nfsunexport(struct nfsctl_export *exp);
131 struct nfs_fh_len *     getfh_old(struct sockaddr *addr, dev_t dev, ino_t ino);
132 struct nfs_fh_len *     getfh(struct sockaddr *addr, const char *);
133 struct nfs_fh_len *     getfh_size(struct sockaddr *addr, const char *, int size);
134
135 void qword_print(FILE *f, char *str);
136 void qword_printhex(FILE *f, char *str, int slen);
137 void qword_printint(FILE *f, int num);
138 int qword_eol(FILE *f);
139 int readline(int fd, char **buf, int *lenp);
140 int qword_get(char **bpp, char *dest, int bufsize);
141 int qword_get_int(char **bpp, int *anint);
142 void cache_flush(int force);
143 int check_new_cache(void);
144
145 void closeall(int min);
146
147 int                     svctcp_socket (u_long __number, int __reuse);
148 int                     svcudp_socket (u_long __number, int __reuse);
149
150 #endif /* NFSLIB_H */