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*)
66extern	mkfifo		mode_t	(mode_t)
67
68define	FS_default	"ufs"
69
70macro{
71	#include <sys/types.h>
72	#include <sys/stat.h>
73	#ifndef major
74	#include <sys/param.h>
75	#ifndef major
76	#include <sys/sysmacros.h>
77	#endif
78	<<"#if defined(__STDPP__directive) && defined(__STDPP__initial)">>
79	<<"__STDPP__directive pragma pp:initial">>
80	<<"#endif">>
81	<<"#ifndef major">>
82	#ifdef major
83	<<"#define major(x)">> major((x))
84	#else
85	#ifndef L_BITSMAJOR
86	#define L_BITSMAJOR 8
87	#endif
88	#ifndef L_BITSMINOR
89	#define L_BITSMINOR 8
90	#endif
91	#ifndef L_MAXMAJ
92	#define L_MAXMAJ ((1<<L_BITSMAJOR)-1)
93	#endif
94	#ifndef L_MAXMIN
95	#define L_MAXMIN ((1<<L_BITSMINOR)-1)
96	#endif
97	<<"#define major(x)">> ((int)(((unsigned)(x)>>L_BITSMINOR)&L_MAXMAJ))
98	#endif
99	<<"#endif">>
100	<<"#ifndef minor">>
101	#ifdef minor
102	<<"#define minor(x)">> minor((x))
103	#else
104	<<"#define minor(x)">> ((int)((x)&L_MAXMIN))
105	#endif
106	<<"#endif">>
107	<<"#ifndef makedev">>
108	#ifdef makedev
109	<<"#define makedev(x,y)">> makedev((x),(y))
110	#else
111	<<"#define makedev(x,y)">> ((dev_t)((((x)&0377)<<8)|((y)&0377)))
112	#endif
113	<<"#endif">>
114	#endif
115	<<"#if defined(__STDPP__directive) && defined(__STDPP__initial)">>
116	<<"__STDPP__directive pragma pp:noinitial">>
117	<<"#endif">>
118}end fail{
119	cat <<!
120	#ifndef major
121	#define major(x)	((int)(((unsigned)(x)>>8)&0377))
122	#endif
123	#ifndef minor
124	#define minor(x)	((int)((x)&0377))
125	#endif
126	#ifndef makedev
127	#define makedev(x,y)	((dev_t)((((x)&0377)<<8)|((y)&0377)))
128	#endif
129	!
130}end
131
132hdr	mntent,mnttab stdio.h
133sys	mntent,mnttab stdio.h
134sys	fs_types,mount,statfs,statvfs,vfs,vmount sys/param.h sys/ucred.h
135
136mem	mnttab.mt_dev,mnttab.mt_filsys,mnttab.mt_fstyp sys/types.h mnttab.h
137mem	mntent.mnt_opts,w_mntent.mnt_opts,mnttab.mnt_opts sys/types.h stdio.h mntent.h sys/mntent.h
138mem	mntent.mnt_opts,mnttab.mnt_opts stdio.h sys/types.h mnttab.h sys/mnttab.h
139mem	stat.st_blocks,stat.st_blksize,stat.st_rdev sys/types.h sys/stat.h
140mem	statfs.f_files,statfs.f_bavail sys/types.h - sys/statfs.h - sys/vfs.h - sys/param.h sys/mount.h
141mem	statvfs.f_basetype,statvfs.f_frsize sys/types.h sys/statvfs.h
142
143ary	f_reserved7 sys/types.h sys/statvfs.h note{ statvfs.f_reserved7 can double for statvfs.f_basetype }end compile{
144	int f(vp)struct statvfs* vp;{return vp->f_reserved7[0] = 1;}
145}end
146
147lib	getfsstat,getmntent,getmntinfo,mntctl,mntopen,mntread,mntclose,setmntent
148lib	w_getmntent
149lib	statfs,statvfs
150
151lib	statfs4 sys/types.h - sys/statfs.h - sys/vfs.h - sys/mount.h compile{
152	int f()
153	{
154		struct statfs fs;
155		return statfs("/",&fs,sizeof(fs),0);
156	}
157}end
158
159lib	getmntinfo_statvfs note{ getmntinfo uses statvfs -- since when? }end compile{
160	#include <sys/types.h>
161	#include <sys/mount.h>
162	int
163	gmi(struct statvfs* fs)
164	{
165		fs->f_flag = 0;
166		return getmntinfo(fs, 0);
167	}
168}end
169
170lib	getfsstat_statvfs note{ getfsstat uses statvfs -- just in case it is confused like getmntinfo }end compile{
171	#include <sys/types.h>
172	#include <sys/mount.h>
173	int
174	gfs(struct statvfs* fs)
175	{
176		fs->f_flag = 0;
177		return getfsstat(fs, sizeof(struct statvfs), MNT_WAIT);
178	}
179}end
180
181cat{
182	#if _sys_statvfs
183	#include <sys/statvfs.h>
184	#if !_mem_statvfs_f_basetype
185	#if _ary_f_reserved7
186	#define f_basetype	f_reserved7
187	#endif
188	#endif
189	#else
190	#define _mem_f_basetype_statvfs	1
191	#define _mem_f_frsize_statvfs	1
192	struct statvfs
193	{
194	unsigned long	f_bsize;	/* fundamental file system block size */
195	unsigned long	f_frsize;	/* fragment size */
196	unsigned long	f_blocks;	/* total # of blocks of f_frsize on fs */
197	unsigned long	f_bfree;	/* total # of free blocks of f_frsize */
198	unsigned long	f_bavail;	/* # of free blocks avail to non-superuser */
199	unsigned long	f_files;	/* total # of file nodes (inodes) */
200	unsigned long	f_ffree;	/* total # of free file nodes */
201	unsigned long	f_favail;	/* # of free nodes avail to non-superuser */
202	unsigned long	f_fsid;		/* file system id (dev for now) */
203	char		f_basetype[16]; /* target fs type name, null-terminated */
204	unsigned long	f_flag;		/* bit-mask of flags */
205	unsigned long	f_namemax;	/* maximum file name length */
206	char		f_fstr[32];	/* filesystem-specific string */
207	unsigned long	f_filler[16];	/* reserved for future expansion */
208	};
209	extern int	fstatvfs(int, struct statvfs*);
210	extern int	statvfs(const char*, struct statvfs*);
211	#endif
212	#if _typ_off64_t
213	#undef	off_t
214	#define off_t	off64_t
215	#endif
216	#if _lib_statvfs64 && !defined(statvfs)
217	#define statvfs		statvfs64
218	#if !defined(__USE_LARGEFILE64)
219	extern int		statvfs64(const char*, struct statvfs64*);
220	#endif
221	#endif
222	#if _lib_fstatvfs64 && !defined(fstatvfs)
223	#define fstatvfs	fstatvfs64
224	#if !defined(__USE_LARGEFILE64)
225	extern int		fstatvfs64(int, struct statvfs64*);
226	#endif
227	#endif
228}end
229
230str	st_fstype sys/types.h sys/stat.h note{ stat.st_fstype is a string }end compile{
231	int f(st)struct stat* st;{return st->st_fstype[0];}
232}end
233
234int	st_fstype sys/types.h sys/stat.h note{ stat.st_fstype is an int }end compile{
235	int f(st)struct stat* st;{return st->st_fstype = 1;}
236}end
237
238int	st_spare1 sys/types.h sys/stat.h note{ stat.st_spare1 is an int }end compile{
239	int f(st)struct stat* st;{return st->st_spare1 = 1;}
240}end
241
242ary	st_spare4 sys/types.h sys/stat.h note{ stat.st_spare4 is an array }end compile{
243	int f(st)struct stat* st;{return st->st_spare4[0] = 1;}
244}end
245
246ary	st_pad4 sys/types.h sys/stat.h note{ stat.st_pad4 is an array }end compile{
247	int f(st)struct stat* st;{return st->st_pad4[0] = 1;}
248}end
249