1set	prototyped
2lib	_fxstat,__fxstat,_lxstat,__lxstat,_xmknod,__xmknod,_xstat,__xstat,lstat,mknod,sync sys/types.h sys/stat.h
3lib	_fxstat64,__fxstat64,_lxstat64,__lxstat64,_xstat64,__xstat64 -D_LARGEFILE64_SOURCE sys/types.h sys/stat.h
4mac	fstat,lstat,stat,mknod sys/types.h sys/stat.h
5
6lcl	xstat -D_LARGEFILE64_SOURCE link{
7	#include <sys/types.h>
8	#include <sys/stat.h>
9	struct stat64 { int xxx; }; /* disable if stat64 available */
10	#if _STD_
11	extern int stat(const char* path, struct stat* st)
12	#else
13	int stat(path, st)
14	char*		path;
15	struct stat*	st;
16	#endif
17	{
18	#if _lib___xstat
19		return __xstat(_STAT_VER, path, st);
20	#else
21		return _xstat(_STAT_VER, path, st);
22	#endif
23	}
24	int
25	main()
26	{
27		struct stat	st;
28		return stat(".",&st) < 0;
29	}
30}end
31
32lcl	xstat64 -D_LARGEFILE64_SOURCE link{
33	#include <sys/types.h>
34	#include <sys/stat.h>
35	#if _STD_
36	extern int stat64(const char* path, struct stat64* st)
37	#else
38	int stat64(path, st)
39	char*		path;
40	#endif
41	{
42	#if _lib___xstat64
43		return __xstat64(_STAT_VER, path, st);
44	#else
45		return _xstat64(_STAT_VER, path, st);
46	#endif
47	}
48	int
49	main()
50	{
51		struct stat64	st;
52		return stat64(".",&st) < 0;
53	}
54}end
55
56header	sys/stat.h
57header	sys/mkdev.h
58
59extern	chmod		int	(const char*, mode_t)
60extern	fstat		int	(int, struct stat*)
61extern	lstat		int	(const char*, struct stat*)
62extern	mkdir		int	(const char*, mode_t)
63extern	mkfifo		int	(const char*, mode_t)
64extern	mknod		int	(const char*, mode_t, dev_t)
65extern	stat		int	(const char*, struct stat*)
66
67define	FS_default	"ufs"
68
69macro{
70	#include <sys/types.h>
71	#include <sys/stat.h>
72	#ifndef major
73	#include <sys/param.h>
74	#ifndef major
75	#include <sys/sysmacros.h>
76	#endif
77	<<"#if defined(__STDPP__directive) && defined(__STDPP__initial)">>
78	<<"__STDPP__directive pragma pp:initial">>
79	<<"#endif">>
80	<<"#ifndef major">>
81	#ifdef major
82	<<"#define major(x)">> major((x))
83	#else
84	#ifndef L_BITSMAJOR
85	#define L_BITSMAJOR 8
86	#endif
87	#ifndef L_BITSMINOR
88	#define L_BITSMINOR 8
89	#endif
90	#ifndef L_MAXMAJ
91	#define L_MAXMAJ ((1<<L_BITSMAJOR)-1)
92	#endif
93	#ifndef L_MAXMIN
94	#define L_MAXMIN ((1<<L_BITSMINOR)-1)
95	#endif
96	<<"#define major(x)">> ((int)(((unsigned)(x)>>L_BITSMINOR)&L_MAXMAJ))
97	#endif
98	<<"#endif">>
99	<<"#ifndef minor">>
100	#ifdef minor
101	<<"#define minor(x)">> minor((x))
102	#else
103	<<"#define minor(x)">> ((int)((x)&L_MAXMIN))
104	#endif
105	<<"#endif">>
106	<<"#ifndef makedev">>
107	#ifdef makedev
108	<<"#define makedev(x,y)">> makedev((x),(y))
109	#else
110	<<"#define makedev(x,y)">> ((dev_t)((((x)&0377)<<8)|((y)&0377)))
111	#endif
112	<<"#endif">>
113	#endif
114	<<"#if defined(__STDPP__directive) && defined(__STDPP__initial)">>
115	<<"__STDPP__directive pragma pp:noinitial">>
116	<<"#endif">>
117}end fail{
118	cat <<!
119	#ifndef major
120	#define major(x)	((int)(((unsigned)(x)>>8)&0377))
121	#endif
122	#ifndef minor
123	#define minor(x)	((int)((x)&0377))
124	#endif
125	#ifndef makedev
126	#define makedev(x,y)	((dev_t)((((x)&0377)<<8)|((y)&0377)))
127	#endif
128	!
129}end
130
131hdr	mntent,mnttab stdio.h
132sys	mntent,mnttab stdio.h
133sys	fs_types,mount,statfs,statvfs,vfs,vmount sys/param.h sys/ucred.h
134
135mem	mnttab.mt_dev,mnttab.mt_filsys,mnttab.mt_fstyp sys/types.h mnttab.h
136mem	mntent.mnt_opts,w_mntent.mnt_opts,mnttab.mnt_opts sys/types.h stdio.h mntent.h sys/mntent.h
137mem	mntent.mnt_opts,mnttab.mnt_opts stdio.h sys/types.h mnttab.h sys/mnttab.h
138mem	stat.st_blocks,stat.st_blksize,stat.st_rdev sys/types.h sys/stat.h
139mem	statfs.f_files,statfs.f_bavail sys/types.h - sys/statfs.h - sys/vfs.h - sys/param.h sys/mount.h
140mem	statvfs.f_basetype,statvfs.f_frsize sys/types.h sys/statvfs.h
141
142ary	f_reserved7 sys/types.h sys/statvfs.h note{ statvfs.f_reserved7 can double for statvfs.f_basetype }end compile{
143	int f(vp)struct statvfs* vp;{return vp->f_reserved7[0] = 1;}
144}end
145
146lib	getfsstat,getmntent,getmntinfo,mntctl,mntopen,mntread,mntclose,setmntent
147lib	w_getmntent
148lib	statfs,statvfs
149
150lib	statfs4 sys/types.h - sys/statfs.h - sys/vfs.h - sys/mount.h compile{
151	int f()
152	{
153		struct statfs fs;
154		return statfs("/",&fs,sizeof(fs),0);
155	}
156}end
157
158lib	getmntinfo_statvfs note{ getmntinfo uses statvfs -- since when? }end compile{
159	#include <sys/types.h>
160	#include <sys/mount.h>
161	int
162	gmi(struct statvfs* fs)
163	{
164		fs->f_flag = 0;
165		return getmntinfo(fs, 0);
166	}
167}end
168
169lib	getfsstat_statvfs note{ getfsstat uses statvfs -- just in case it is confused like getmntinfo }end compile{
170	#include <sys/types.h>
171	#include <sys/mount.h>
172	int
173	gfs(struct statvfs* fs)
174	{
175		fs->f_flag = 0;
176		return getfsstat(fs, sizeof(struct statvfs), MNT_WAIT);
177	}
178}end
179
180cat{
181	#if _sys_statvfs
182	#include <sys/statvfs.h>
183	#if !_mem_statvfs_f_basetype
184	#if _ary_f_reserved7
185	#define f_basetype	f_reserved7
186	#endif
187	#endif
188	#else
189	#define _mem_f_basetype_statvfs	1
190	#define _mem_f_frsize_statvfs	1
191	struct statvfs
192	{
193	unsigned long	f_bsize;	/* fundamental file system block size */
194	unsigned long	f_frsize;	/* fragment size */
195	unsigned long	f_blocks;	/* total # of blocks of f_frsize on fs */
196	unsigned long	f_bfree;	/* total # of free blocks of f_frsize */
197	unsigned long	f_bavail;	/* # of free blocks avail to non-superuser */
198	unsigned long	f_files;	/* total # of file nodes (inodes) */
199	unsigned long	f_ffree;	/* total # of free file nodes */
200	unsigned long	f_favail;	/* # of free nodes avail to non-superuser */
201	unsigned long	f_fsid;		/* file system id (dev for now) */
202	char		f_basetype[16]; /* target fs type name, null-terminated */
203	unsigned long	f_flag;		/* bit-mask of flags */
204	unsigned long	f_namemax;	/* maximum file name length */
205	char		f_fstr[32];	/* filesystem-specific string */
206	unsigned long	f_filler[16];	/* reserved for future expansion */
207	};
208	extern int	fstatvfs(int, struct statvfs*);
209	extern int	statvfs(const char*, struct statvfs*);
210	#endif
211	#if _typ_off64_t
212	#undef	off_t
213	#define off_t	off64_t
214	#endif
215	#if _lib_statvfs64 && !defined(statvfs)
216	#define statvfs		statvfs64
217	#if !defined(__USE_LARGEFILE64)
218	extern int		statvfs64(const char*, struct statvfs64*);
219	#endif
220	#endif
221	#if _lib_fstatvfs64 && !defined(fstatvfs)
222	#define fstatvfs	fstatvfs64
223	#if !defined(__USE_LARGEFILE64)
224	extern int		fstatvfs64(int, struct statvfs64*);
225	#endif
226	#endif
227}end
228
229str	st_fstype sys/types.h sys/stat.h note{ stat.st_fstype is a string }end compile{
230	int f(st)struct stat* st;{return st->st_fstype[0];}
231}end
232
233int	st_fstype sys/types.h sys/stat.h note{ stat.st_fstype is an int }end compile{
234	int f(st)struct stat* st;{return st->st_fstype = 1;}
235}end
236
237int	st_spare1 sys/types.h sys/stat.h note{ stat.st_spare1 is an int }end compile{
238	int f(st)struct stat* st;{return st->st_spare1 = 1;}
239}end
240
241ary	st_spare4 sys/types.h sys/stat.h note{ stat.st_spare4 is an array }end compile{
242	int f(st)struct stat* st;{return st->st_spare4[0] = 1;}
243}end
244
245ary	st_extra sys/types.h sys/stat.h note{ stat.st_extra is an array }end compile{
246	int f(st)struct stat* st;{return st->st_extra[0] = 1;}
247}end
248
249ary	st_pad4 sys/types.h sys/stat.h note{ stat.st_pad4 is an array }end compile{
250	int f(st)struct stat* st;{return st->st_pad4[0] = 1;}
251}end
252