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