xref: /plan9/sys/src/ape/lib/ap/plan9/dir.h (revision fb7f0c934c48abaed6040d054ef636408c3c522d)
1 typedef	long	long	vlong;
2 typedef	unsigned long long uvlong;
3 typedef 	unsigned char uchar;
4 typedef	unsigned short ushort;
5 typedef 	unsigned int uint;
6 typedef	unsigned long ulong;
7 
8 #define	GBIT8(p)	((p)[0])
9 #define	GBIT16(p)	((p)[0]|((p)[1]<<8))
10 #define	GBIT32(p)	((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24))
11 #define	GBIT64(p)	((vlong)((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24)) |\
12 				((vlong)((p)[4]|((p)[5]<<8)|((p)[6]<<16)|((p)[7]<<24)) << 32))
13 
14 #define	PBIT8(p,v)	(p)[0]=(v)
15 #define	PBIT16(p,v)	(p)[0]=(v);(p)[1]=(v)>>8
16 #define	PBIT32(p,v)	(p)[0]=(v);(p)[1]=(v)>>8;(p)[2]=(v)>>16;(p)[3]=(v)>>24
17 #define	PBIT64(p,v)	(p)[0]=(v);(p)[1]=(v)>>8;(p)[2]=(v)>>16;(p)[3]=(v)>>24;\
18 			(p)[4]=(v)>>32;(p)[5]=(v)>>40;(p)[6]=(v)>>48;(p)[7]=(v)>>56
19 
20 #define	BIT8SZ		1
21 #define	BIT16SZ		2
22 #define	BIT32SZ		4
23 #define	BIT64SZ		8
24 #define	QIDSZ	(BIT8SZ+BIT32SZ+BIT64SZ)
25 
26 /* STATFIXLEN includes leading 16-bit count */
27 /* The count, however, excludes itself; total size is BIT16SZ+count */
28 #define STATFIXLEN	(BIT16SZ+QIDSZ+5*BIT16SZ+4*BIT32SZ+1*BIT64SZ)	/* amount of fixed length data in a stat buffer */
29 
30 typedef union
31 {
32 	char	clength[8];
33 	vlong	vlength;
34 	struct
35 	{
36 		long	hlength;
37 		long	length;
38 	};
39 } Length;
40 
41 typedef
42 struct Qid
43 {
44 	uvlong	path;
45 	ulong	vers;
46 	uchar	type;
47 } Qid;
48 
49 typedef
50 struct Dir {
51 	/* system-modified data */
52 	ushort	type;	/* server type */
53 	uint	dev;	/* server subtype */
54 	/* file data */
55 	Qid	qid;	/* unique id from server */
56 	ulong	mode;	/* permissions */
57 	ulong	atime;	/* last read time */
58 	ulong	mtime;	/* last write time */
59 	vlong	length;	/* file length: see <u.h> */
60 	char	*name;	/* last element of path */
61 	char	*uid;	/* owner name */
62 	char	*gid;	/* group name */
63 	char	*muid;	/* last modifier name */
64 } Dir;
65 
66 void	_dirtostat(struct stat *, Dir*, Fdinfo*);
67 uint	_convM2D(uchar*, uint, Dir*, char*);
68 uint	_convD2M(Dir*, uchar*, uint);
69 Dir	*_dirstat(char*);
70 int	_dirwstat(char*, Dir*);
71 Dir	*_dirfstat(int);
72 int	_dirfwstat(int, Dir*);
73 long	_dirread(int, Dir**);
74 long _dirreadall(int, Dir**);
75 void _nulldir(Dir*);
76 uint _sizeD2M(Dir*);
77 
78 #ifndef nil
79 #define nil ((void*)0)
80 #endif
81