HEAD: remove ridiculous dependency of wvmapi (actually wvtnef) on evolution
[wvapps.git] / funfs / funfscodecs.h
blob7f61c849419e4dbb15dc744d8dd695e67b1c7e03
1 #ifndef __FunFSCODEC_H
2 #define __FunFSCODEC_H
4 #include "funfsbyteswap.h"
5 #include "strutils.h"
6 #include "fileutils.h"
8 #include <fcntl.h>
9 #include <sys/types.h>
10 #include <sys/stat.h>
11 #include <dirent.h>
13 #ifndef FUSE_KERNEL_VERSION
14 #include <linux/fuse.h>
15 #endif
17 inline void bswap_fuse_attr(struct fuse_attr *attr)
19 SWAP32(&attr->mode);
20 SWAP32(&attr->nlink);
21 SWAP32(&attr->uid);
22 SWAP32(&attr->gid);
23 SWAP32(&attr->rdev);
24 SWAP64(&attr->size);
25 SWAP32(&attr->blocks);
26 SWAP32(&attr->atime);
27 SWAP32(&attr->mtime);
28 SWAP32(&attr->ctime);
31 inline void encode_fuse_attr(WvBuf &buf, struct fuse_attr *attr)
33 bswap_fuse_attr(attr);
35 buf.put(&attr->mode, 4);
36 buf.put(&attr->nlink, 4);
37 buf.put(&attr->uid, 4);
38 buf.put(&attr->gid, 4);
39 buf.put(&attr->rdev, 4);
40 buf.put(&attr->size, 8);
41 buf.put(&attr->blocks, 4);
42 buf.put(&attr->atime, 4);
43 buf.put(&attr->mtime, 4);
44 buf.put(&attr->ctime, 4);
47 inline void decode_fuse_attr(WvBuf &buf, struct fuse_attr *attr)
49 memcpy(&attr->mode, buf.get(4), 4);
50 memcpy(&attr->nlink, buf.get(4), 4);
51 memcpy(&attr->uid, buf.get(4), 4);
52 memcpy(&attr->gid, buf.get(4), 4);
53 memcpy(&attr->rdev, buf.get(4), 4);
54 memcpy(&attr->size, buf.get(8), 8);
55 memcpy(&attr->blocks, buf.get(4), 4);
56 memcpy(&attr->atime, buf.get(4), 4);
57 memcpy(&attr->mtime, buf.get(4), 4);
58 memcpy(&attr->ctime, buf.get(4), 4);
60 bswap_fuse_attr(attr);
63 inline void bswap_fuse_kstatfs(struct fuse_kstatfs *fst)
65 SWAP32(&fst->block_size);
66 SWAP32(&fst->blocks);
67 SWAP32(&fst->blocks_free);
68 SWAP32(&fst->files);
69 SWAP32(&fst->files_free);
70 SWAP32(&fst->namelen);
73 inline void decode_fuse_kstatfs(WvBuf &buf, struct fuse_kstatfs *fst)
75 memcpy(&fst->block_size, buf.get(4), 4);
76 memcpy(&fst->blocks, buf.get(4), 4);
77 memcpy(&fst->blocks_free, buf.get(4), 4);
78 memcpy(&fst->files, buf.get(4), 4);
79 memcpy(&fst->files_free, buf.get(4), 4);
80 memcpy(&fst->namelen, buf.get(4), 4);
82 bswap_fuse_kstatfs(fst);
85 inline void encode_fuse_kstatfs(WvBuf &buf, struct fuse_kstatfs *fst)
87 bswap_fuse_kstatfs(fst);
89 buf.put(&fst->block_size, 4);
90 buf.put(&fst->blocks, 4);
91 buf.put(&fst->blocks_free, 4);
92 buf.put(&fst->files, 4);
93 buf.put(&fst->files_free, 4);
94 buf.put(&fst->namelen, 4);
97 inline void encode_fuse_dirent(WvBuf &buf, struct dirent *de)
99 buf.putch(de->d_type);
100 assert(de->d_reclen < 256);
101 buf.put(de->d_name, strlen(de->d_name));
102 buf.putch('\0');
105 inline void decode_fuse_dirent(WvBuf &buf, struct fuse_dirent *fde)
107 fde->type = buf.getch();
108 fde->namelen = buf.strchr('\0') - 1;
109 strncpy(fde->name, (const char *)buf.get(fde->namelen + 1), 256);
113 #endif