2 * Copyright (C) 2008 dhewg, #wiidev efnet
4 * this file is part of wiifuse
5 * http://wiibrew.org/index.php?title=Wiifuse
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include "../../shared.h"
35 bool wrapper_init (u8
**data
, u16
*data_size
) {
36 return nand_init (data
, data_size
);
39 bool wrapper_deinit () {
40 return nand_deinit ();
43 enum remote_result
wrapper_access (struct client_request
*request
) {
46 if (!request
->data
|| request
->data_size
!= 1)
49 mode
= request
->data
[0];
51 LOG (2, "access %s 0x%02x", request
->filename
, mode
);
53 return nand_access (request
->filename
, mode
);
56 enum remote_result
wrapper_getattr (struct client_request
*request
, u8
**data
,
58 enum remote_result res
= RES_UNKNOWN
;
59 struct remote_attr attributes
;
61 LOG (2, "getattr %s", request
->filename
);
63 memset (&attributes
, 0, sizeof (struct remote_attr
));
65 res
= nand_getattr (request
->filename
, &attributes
);
69 *data
= malloc (*data_size
);
70 memset (*data
, 0, *data_size
);
71 *data
[0] = attributes
.is_dir
;
72 put_be32 (*data
+ 1, attributes
.nlink
);
73 put_be32 (*data
+ 3, attributes
.size
);
74 put_be32 (*data
+ 7, attributes
.owner
);
75 put_be32 (*data
+ 11, attributes
.group
);
76 put_be16 (*data
+ 15, attributes
.perms
);
82 enum remote_result
wrapper_open (struct client_request
*request
) {
83 LOG (2, "open %s", request
->filename
);
85 return nand_open (request
->filename
);
88 enum remote_result
wrapper_read (struct client_request
*request
, u8
**data
,
90 enum remote_result res
;
94 if (!request
->data
|| request
->data_size
!= 10)
97 size
= get_be16 (request
->data
);
98 offset
= get_be64 (&request
->data
[2]);
100 LOG (2, "read %s off=0x%016llx size=0x%04x", request
->filename
, offset
,
103 *data
= memalign (32, size
);
104 memset (*data
, 0, size
);
106 res
= nand_read (request
->filename
, offset
, &size
, *data
);
118 enum remote_result
wrapper_opendir (struct client_request
*request
) {
119 LOG (2, "opendir %s", request
->filename
);
121 return nand_opendir (request
->filename
);
124 enum remote_result
wrapper_readdir (struct client_request
*request
, u8
**data
,
126 LOG (2, "readdir %s", request
->filename
);
128 return nand_readdir (request
->filename
, data
, data_size
);
131 enum remote_result
wrapper_mkdir (struct client_request
*request
) {
134 if (!request
->data
|| request
->data_size
!= 2)
137 perms
= get_be16 (request
->data
);
139 LOG (2, "mkdir %s 0%o", request
->filename
, perms
);
141 return nand_mkdir (request
->filename
, perms
);
144 enum remote_result
wrapper_rmdir (struct client_request
*request
) {
145 LOG (2, "rmdir %s", request
->filename
);
147 return nand_rmdir (request
->filename
);
150 enum remote_result
wrapper_create (struct client_request
*request
) {
153 if (!request
->data
|| request
->data_size
!= 2)
156 perms
= get_be16 (request
->data
);
158 LOG (2, "create %s 0%o", request
->filename
, perms
);
160 return nand_create (request
->filename
, perms
);
163 enum remote_result
wrapper_write (struct client_request
*request
, u8
**data
,
165 enum remote_result res
;
169 if (!request
->data
|| request
->data_size
< 10)
172 size
= get_be16 (request
->data
);
173 offset
= get_be64 (&request
->data
[2]);
175 LOG (2, "write %s off=0x%016llx size=0x%04x", request
->filename
,
178 res
= nand_write (request
->filename
, offset
, &size
, request
->data
+ 10);
182 put_be64 (*data
, size
);
189 enum remote_result
wrapper_chown (struct client_request
*request
) {
192 if (!request
->data
|| request
->data_size
!= 8)
195 uid
= get_be32 (request
->data
);
196 gid
= get_be32 (&(request
->data
[4]));
198 LOG (2, "chown %s uid %u gid %u", request
->filename
, uid
, gid
);
200 return nand_chown (request
->filename
, uid
, gid
);
203 enum remote_result
wrapper_chmod (struct client_request
*request
) {
206 if (!request
->data
|| request
->data_size
!= 2)
209 perms
= get_be16 (request
->data
);
211 LOG (2, "chmod %s 0%o", request
->filename
, perms
);
213 return nand_chmod (request
->filename
, perms
);
216 enum remote_result
wrapper_rename (struct client_request
*request
) {
218 enum remote_result res
;
223 src
= memalign (32, strlen (request
->filename
) + 1);
224 strcpy (src
, request
->filename
);
226 dst
= memalign (32, request
->data_size
+ 1);
227 memcpy (dst
, request
->data
, request
->data_size
);
228 dst
[request
->data_size
] = 0;
230 LOG (2, "rename %s -> %s", src
, dst
);
232 res
= nand_rename (src
, dst
);
240 enum remote_result
wrapper_unlink (struct client_request
*request
) {
241 LOG (2, "unlink %s", request
->filename
);
243 return nand_unlink (request
->filename
);
246 enum remote_result
wrapper_statfs (struct client_request
*request
, u8
**data
,
257 LOG (2, "statfs %s", request
->filename
);
259 res
= nand_statfs (request
->filename
, &bsize
, &blocks
, &bfree
, &files
,
264 *data
= malloc (*data_size
);
268 put_be64 (p
, blocks
);