xref: /plan9-contrib/sys/src/ape/lib/ap/plan9/_dirconv.c (revision 3e12c5d1bb89fc02707907988834ef147769ddaf)
1 #include "lib.h"
2 #include <string.h>
3 #include "sys9.h"
4 #include "dir.h"
5 
6 #define	CHAR(x)		*p++ = f->x
7 #define	SHORT(x)	p[0] = f->x; p[1] = f->x>>8; p += 2
8 #define	LONG(x)		p[0] = f->x; p[1] = f->x>>8; p[2] = f->x>>16; p[3] = f->x>>24; p += 4
9 #define	VLONG(x)	p[0] = f->x; p[1] = f->x>>8; p[2] = f->x>>16; p[3] = f->x>>24;\
10 			p[4] = 0; p[5] = 0; p[6] = 0; p[7] = 0; p += 8
11 #define	STRING(x,n)	memcpy(p, f->x, n); p += n
12 
13 int
convD2M(Dir * f,char * ap)14 convD2M(Dir *f, char *ap)
15 {
16 	unsigned char *p;
17 
18 	p = (unsigned char*)ap;
19 	STRING(name, sizeof(f->name));
20 	STRING(uid, sizeof(f->uid));
21 	STRING(gid, sizeof(f->gid));
22 	LONG(qid.path);
23 	LONG(qid.vers);
24 	LONG(mode);
25 	LONG(atime);
26 	LONG(mtime);
27 	VLONG(length);
28 	SHORT(type);
29 	SHORT(dev);
30 	return p - (unsigned char*)ap;
31 }
32 
33 #undef	CHAR
34 #undef	SHORT
35 #undef	LONG
36 #undef	VLONG
37 #undef	STRING
38 
39 #define	CHAR(x)		f->x = *p++
40 #define	SHORT(x)	f->x = (p[0] | (p[1]<<8)); p += 2
41 #define	LONG(x)		f->x = (p[0] | (p[1]<<8) |\
42 			(p[2]<<16) | (p[3]<<24)); p += 4
43 #define	VLONG(x)	f->x = (p[0] | (p[1]<<8) |\
44 			(p[2]<<16) | (p[3]<<24)); p += 8
45 #define	STRING(x,n)	memcpy(f->x, p, n); p += n
46 
47 int
convM2D(char * ap,Dir * f)48 convM2D(char *ap, Dir *f)
49 {
50 	unsigned char *p;
51 
52 	p = (unsigned char*)ap;
53 	STRING(name, sizeof(f->name));
54 	STRING(uid, sizeof(f->uid));
55 	STRING(gid, sizeof(f->gid));
56 	LONG(qid.path);
57 	LONG(qid.vers);
58 	LONG(mode);
59 	LONG(atime);
60 	LONG(mtime);
61 	VLONG(length);
62 	SHORT(type);
63 	SHORT(dev);
64 	return p - (unsigned char*)ap;
65 }
66