don't do a DVD_Mount for GC-mode on Wii, add ifdef for Wii-only SMB code
[libogc.git] / libogc / isfs.c
blob0590bc81ead92f344abdb96a258cc857a9602023
1 /*-------------------------------------------------------------
3 es.c -- ETicket services
5 Copyright (C) 2008
6 Michael Wiedenbauer (shagkur)
7 Dave Murphy (WinterMute)
8 Hector Martin (marcan)
10 This software is provided 'as-is', without any express or implied
11 warranty. In no event will the authors be held liable for any
12 damages arising from the use of this software.
14 Permission is granted to anyone to use this software for any
15 purpose, including commercial applications, and to alter it and
16 redistribute it freely, subject to the following restrictions:
18 1. The origin of this software must not be misrepresented; you
19 must not claim that you wrote the original software. If you use
20 this software in a product, an acknowledgment in the product
21 documentation would be appreciated but is not required.
23 2. Altered source versions must be plainly marked as such, and
24 must not be misrepresented as being the original software.
26 3. This notice may not be removed or altered from any source
27 distribution.
29 -------------------------------------------------------------*/
31 #if defined(HW_RVL)
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include <string.h>
36 #include <malloc.h>
37 #include <time.h>
38 #include <gcutil.h>
39 #include <ipc.h>
41 #include "isfs.h"
43 #define ISFS_STRUCTSIZE (sizeof(struct isfs_cb))
44 #define ISFS_HEAPSIZE (ISFS_STRUCTSIZE<<4)
46 #define ISFS_FUNCNULL 0
47 #define ISFS_FUNCGETSTAT 1
48 #define ISFS_FUNCREADDIR 2
49 #define ISFS_FUNCGETATTR 3
50 #define ISFS_FUNCGETUSAGE 4
52 #define ISFS_IOCTL_FORMAT 1
53 #define ISFS_IOCTL_GETSTATS 2
54 #define ISFS_IOCTL_CREATEDIR 3
55 #define ISFS_IOCTL_READDIR 4
56 #define ISFS_IOCTL_SETATTR 5
57 #define ISFS_IOCTL_GETATTR 6
58 #define ISFS_IOCTL_DELETE 7
59 #define ISFS_IOCTL_RENAME 8
60 #define ISFS_IOCTL_CREATEFILE 9
61 #define ISFS_IOCTL_SETFILEVERCTRL 10
62 #define ISFS_IOCTL_GETFILESTATS 11
63 #define ISFS_IOCTL_GETUSAGE 12
64 #define ISFS_IOCTL_SHUTDOWN 13
66 struct isfs_cb
68 char filepath[ISFS_MAXPATH];
69 union {
70 struct {
71 char filepathOld[ISFS_MAXPATH];
72 char filepathNew[ISFS_MAXPATH];
73 } fsrename;
74 struct {
75 u32 owner_id;
76 u16 group_id;
77 char filepath[ISFS_MAXPATH];
78 u8 ownerperm;
79 u8 groupperm;
80 u8 otherperm;
81 u8 attributes;
82 u8 pad0[2];
83 } fsattr;
84 struct {
85 ioctlv vector[4];
86 u32 no_entries;
87 } fsreaddir;
88 struct {
89 ioctlv vector[4];
90 u32 usage1;
91 u8 pad0[28];
92 u32 usage2;
93 } fsusage;
94 struct {
95 u32 a;
96 u32 b;
97 u32 c;
98 u32 d;
99 u32 e;
100 u32 f;
101 u32 g;
102 } fsstats;
105 isfscallback cb;
106 void *usrdata;
107 u32 functype;
108 void *funcargv[8];
112 static s32 hId = -1;
114 static s32 _fs_fd = -1;
115 static u32 _fs_initialized = 0;
116 static char _dev_fs[] ATTRIBUTE_ALIGN(32) = "/dev/fs";
118 static s32 __isfsGetStatsCB(s32 result,void *usrdata)
120 struct isfs_cb *param = (struct isfs_cb*)usrdata;
121 if(result==0) memcpy(param->funcargv[0],&param->fsstats,sizeof(param->fsstats));
122 return result;
125 static s32 __isfsGetAttrCB(s32 result,void *usrdata)
127 struct isfs_cb *param = (struct isfs_cb*)usrdata;
128 if(result==0) {
129 *(u32*)(param->funcargv[0]) = param->fsattr.owner_id;
130 *(u16*)(param->funcargv[1]) = param->fsattr.group_id;
131 *(u8*)(param->funcargv[2]) = param->fsattr.attributes;
132 *(u8*)(param->funcargv[3]) = param->fsattr.ownerperm;
133 *(u8*)(param->funcargv[4]) = param->fsattr.groupperm;
134 *(u8*)(param->funcargv[5]) = param->fsattr.otherperm;
136 return result;
139 static s32 __isfsGetUsageCB(s32 result,void *usrdata)
141 struct isfs_cb *param = (struct isfs_cb*)usrdata;
142 if(result==0) {
143 *(u32*)(param->funcargv[0]) = param->fsusage.usage1;
144 *(u32*)(param->funcargv[1]) = param->fsusage.usage2;
146 return result;
149 static s32 __isfsReadDirCB(s32 result,void *usrdata)
151 struct isfs_cb *param = (struct isfs_cb*)usrdata;
152 if(result==0) *(u32*)(param->funcargv[0]) = param->fsreaddir.no_entries;
153 return result;
156 static s32 __isfsFunctionCB(s32 result,void *usrdata)
158 struct isfs_cb *param = (struct isfs_cb*)usrdata;
160 if(result>=0) {
161 if(param->functype==ISFS_FUNCGETSTAT) __isfsGetStatsCB(result,usrdata);
162 else if(param->functype==ISFS_FUNCREADDIR) __isfsReadDirCB(result,usrdata);
163 else if(param->functype==ISFS_FUNCGETATTR) __isfsGetAttrCB(result,usrdata);
164 else if(param->functype==ISFS_FUNCGETUSAGE) __isfsGetUsageCB(result,usrdata);
166 if(param->cb!=NULL) param->cb(result,param->usrdata);
168 iosFree(hId,param);
169 return result;
172 s32 ISFS_Initialize()
174 s32 ret = IPC_OK;
176 if(_fs_fd<0) {
177 _fs_fd = IOS_Open(_dev_fs,0);
178 if(_fs_fd<0) return _fs_fd;
181 if(_fs_initialized==0) {
182 hId = iosCreateHeap(ISFS_HEAPSIZE);
183 if(hId<0) return IPC_ENOMEM;
185 _fs_initialized = 1;
187 return ret;
190 s32 ISFS_Deinitialize()
192 if(_fs_fd<0) return ISFS_EINVAL;
194 IOS_Close(_fs_fd);
195 _fs_fd = -1;
197 iosDestroyHeap(hId);
198 _fs_initialized = 0;
200 return 0;
203 s32 ISFS_ReadDir(const char *filepath,char *name_list,u32 *num)
205 s32 ret;
206 s32 len,cnt;
207 s32 ilen,olen;
208 struct isfs_cb *param;
210 if(_fs_fd<0 || filepath==NULL || num==NULL) return ISFS_EINVAL;
211 if(name_list!=NULL && ((u32)name_list%32)!=0) return ISFS_EINVAL;
213 len = strnlen(filepath,ISFS_MAXPATH);
214 if(len>=ISFS_MAXPATH) return ISFS_EINVAL;
216 param = (struct isfs_cb*)iosAlloc(hId,ISFS_STRUCTSIZE);
217 if(param==NULL) return ISFS_ENOMEM;
219 memcpy(param->filepath,filepath,(len+1));
221 param->fsreaddir.vector[0].data = param->filepath;
222 param->fsreaddir.vector[0].len = ISFS_MAXPATH;
223 param->fsreaddir.vector[1].data = &param->fsreaddir.no_entries;
224 param->fsreaddir.vector[1].len = sizeof(u32);
226 if(name_list!=NULL) {
227 ilen = olen = 2;
228 cnt = *num;
229 param->fsreaddir.no_entries = cnt;
230 param->fsreaddir.vector[2].data = name_list;
231 param->fsreaddir.vector[2].len = (cnt*13);
232 param->fsreaddir.vector[3].data = &param->fsreaddir.no_entries;
233 param->fsreaddir.vector[3].len = sizeof(u32);
234 } else
235 ilen = olen = 1;
237 ret = IOS_Ioctlv(_fs_fd,ISFS_IOCTL_READDIR,ilen,olen,param->fsreaddir.vector);
238 if(ret==0) *num = param->fsreaddir.no_entries;
240 if(param!=NULL) iosFree(hId,param);
241 return ret;
244 s32 ISFS_ReadDirAsync(const char *filepath,char *name_list,u32 *num,isfscallback cb,void *usrdata)
246 s32 len,cnt;
247 s32 ilen,olen;
248 struct isfs_cb *param;
250 if(_fs_fd<0 || filepath==NULL || num==NULL) return ISFS_EINVAL;
251 if(name_list!=NULL && ((u32)name_list%32)!=0) return ISFS_EINVAL;
253 len = strnlen(filepath,ISFS_MAXPATH);
254 if(len>=ISFS_MAXPATH) return ISFS_EINVAL;
256 param = (struct isfs_cb*)iosAlloc(hId,ISFS_STRUCTSIZE);
257 if(param==NULL) return ISFS_ENOMEM;
259 param->cb = cb;
260 param->usrdata = usrdata;
261 param->funcargv[0] = num;
262 param->functype = ISFS_FUNCREADDIR;
263 memcpy(param->filepath,filepath,(len+1));
265 param->fsreaddir.vector[0].data = param->filepath;
266 param->fsreaddir.vector[0].len = ISFS_MAXPATH;
267 param->fsreaddir.vector[1].data = &param->fsreaddir.no_entries;
268 param->fsreaddir.vector[1].len = sizeof(u32);
270 if(name_list!=NULL) {
271 ilen = olen = 2;
272 cnt = *num;
273 param->fsreaddir.no_entries = cnt;
274 param->fsreaddir.vector[2].data = name_list;
275 param->fsreaddir.vector[2].len = (cnt*13);
276 param->fsreaddir.vector[3].data = &param->fsreaddir.no_entries;
277 param->fsreaddir.vector[3].len = sizeof(u32);
278 } else
279 ilen = olen = 1;
281 return IOS_IoctlvAsync(_fs_fd,ISFS_IOCTL_READDIR,ilen,olen,param->fsreaddir.vector,__isfsFunctionCB,param);
284 s32 ISFS_CreateDir(const char *filepath,u8 attributes,u8 owner_perm,u8 group_perm,u8 other_perm)
286 s32 ret;
287 s32 len;
288 struct isfs_cb *param;
290 if(_fs_fd<0 || filepath==NULL) return ISFS_EINVAL;
292 len = strnlen(filepath,ISFS_MAXPATH);
293 if(len>=ISFS_MAXPATH) return ISFS_EINVAL;
295 param = (struct isfs_cb*)iosAlloc(hId,ISFS_STRUCTSIZE);
296 if(param==NULL) return ISFS_ENOMEM;
298 memcpy(param->fsattr.filepath ,filepath,(len+1));
300 param->fsattr.attributes = attributes;
301 param->fsattr.ownerperm = owner_perm;
302 param->fsattr.groupperm = group_perm;
303 param->fsattr.otherperm = other_perm;
304 ret = IOS_Ioctl(_fs_fd,ISFS_IOCTL_CREATEDIR,&param->fsattr,sizeof(param->fsattr),NULL,0);
306 if(param!=NULL) iosFree(hId,param);
307 return ret;
310 s32 ISFS_CreateDirAsync(const char *filepath,u8 attributes,u8 owner_perm,u8 group_perm,u8 other_perm,isfscallback cb,void *usrdata)
312 s32 len;
313 struct isfs_cb *param;
315 if(_fs_fd<0 || filepath==NULL) return ISFS_EINVAL;
317 len = strnlen(filepath,ISFS_MAXPATH);
318 if(len>=ISFS_MAXPATH) return ISFS_EINVAL;
320 param = (struct isfs_cb*)iosAlloc(hId,ISFS_STRUCTSIZE);
321 if(param==NULL) return ISFS_ENOMEM;
323 param->cb = cb;
324 param->usrdata = usrdata;
325 param->functype = ISFS_FUNCNULL;
326 memcpy(param->fsattr.filepath,filepath,(len+1));
328 param->fsattr.attributes = attributes;
329 param->fsattr.ownerperm = owner_perm;
330 param->fsattr.groupperm = group_perm;
331 param->fsattr.otherperm = other_perm;
332 return IOS_IoctlAsync(_fs_fd,ISFS_IOCTL_CREATEDIR,&param->fsattr,sizeof(param->fsattr),NULL,0,__isfsFunctionCB,param);
335 s32 ISFS_Open(const char *filepath,u8 mode)
337 s32 ret;
338 s32 len;
339 struct isfs_cb *param;
341 if(_fs_fd<0 || filepath==NULL) return ISFS_EINVAL;
343 len = strnlen(filepath,ISFS_MAXPATH);
344 if(len>=ISFS_MAXPATH) return ISFS_EINVAL;
346 param = (struct isfs_cb*)iosAlloc(hId,ISFS_STRUCTSIZE);
347 if(param==NULL) return ISFS_ENOMEM;
349 memcpy(param->filepath,filepath,(len+1));
350 ret = IOS_Open(param->filepath,mode);
352 if(param!=NULL) iosFree(hId,param);
353 return ret;
356 s32 ISFS_OpenAsync(const char *filepath,u8 mode,isfscallback cb,void *usrdata)
358 s32 len;
359 struct isfs_cb *param;
361 if(_fs_fd<0 || filepath==NULL) return ISFS_EINVAL;
363 len = strnlen(filepath,ISFS_MAXPATH);
364 if(len>=ISFS_MAXPATH) return ISFS_EINVAL;
366 param = (struct isfs_cb*)iosAlloc(hId,ISFS_STRUCTSIZE);
367 if(param==NULL) return ISFS_ENOMEM;
369 param->cb = cb;
370 param->usrdata = usrdata;
371 param->functype = ISFS_FUNCNULL;
372 memcpy(param->filepath,filepath,(len+1));
373 return IOS_OpenAsync(param->filepath,mode,__isfsFunctionCB,param);
376 s32 ISFS_Format()
378 if(_fs_fd<0) return ISFS_EINVAL;
380 return IOS_Ioctl(_fs_fd,ISFS_IOCTL_FORMAT,NULL,0,NULL,0);
383 s32 ISFS_FormatAsync(isfscallback cb,void *usrdata)
385 struct isfs_cb *param;
387 if(_fs_fd<0) return ISFS_EINVAL;
389 param = (struct isfs_cb*)iosAlloc(hId,ISFS_STRUCTSIZE);
390 if(param==NULL) return ISFS_ENOMEM;
392 param->cb = cb;
393 param->usrdata = usrdata;
394 param->functype = ISFS_FUNCNULL;
395 return IOS_IoctlAsync(_fs_fd,ISFS_IOCTL_FORMAT,NULL,0,NULL,0,__isfsFunctionCB,param);
398 s32 ISFS_GetStats(void *stats)
400 s32 ret = ISFS_OK;
401 struct isfs_cb *param;
403 if(_fs_fd<0 || stats==NULL) return ISFS_EINVAL;
405 param = (struct isfs_cb*)iosAlloc(hId,ISFS_STRUCTSIZE);
406 if(param==NULL) return ISFS_ENOMEM;
408 ret = IOS_Ioctl(_fs_fd,ISFS_IOCTL_GETSTATS,NULL,0,&param->fsstats,sizeof(param->fsstats));
409 if(ret==IPC_OK) memcpy(stats,&param->fsstats,sizeof(param->fsstats));
411 if(param!=NULL) iosFree(hId,param);
412 return ret;
415 s32 ISFS_GetStatsAsync(void *stats,isfscallback cb,void *usrdata)
417 struct isfs_cb *param;
419 if(_fs_fd<0 || stats==NULL) return ISFS_EINVAL;
421 param = (struct isfs_cb*)iosAlloc(hId,ISFS_STRUCTSIZE);
422 if(param==NULL) return ISFS_ENOMEM;
424 param->cb = cb;
425 param->usrdata = usrdata;
426 param->functype = ISFS_FUNCGETSTAT;
427 param->funcargv[0] = stats;
428 return IOS_IoctlAsync(_fs_fd,ISFS_IOCTL_GETSTATS,NULL,0,&param->fsstats,sizeof(param->fsstats),__isfsFunctionCB,param);
431 s32 ISFS_Write(s32 fd,const void *buffer,u32 length)
433 if(length<=0 || buffer==NULL || ((u32)buffer%32)!=0) return ISFS_EINVAL;
435 return IOS_Write(fd,buffer,length);
438 s32 ISFS_WriteAsync(s32 fd,const void *buffer,u32 length,isfscallback cb,void *usrdata)
440 struct isfs_cb *param;
442 if(length<=0 || buffer==NULL || ((u32)buffer%32)!=0) return ISFS_EINVAL;
444 param = (struct isfs_cb*)iosAlloc(hId,ISFS_STRUCTSIZE);
445 if(param==NULL) return ISFS_ENOMEM;
447 param->cb = cb;
448 param->usrdata = usrdata;
449 param->functype = ISFS_FUNCNULL;
450 return IOS_WriteAsync(fd,buffer,length,__isfsFunctionCB,param);
453 s32 ISFS_Read(s32 fd,void *buffer,u32 length)
455 if(length<=0 || buffer==NULL || ((u32)buffer%32)!=0) return ISFS_EINVAL;
457 return IOS_Read(fd,buffer,length);
460 s32 ISFS_ReadAsync(s32 fd,void *buffer,u32 length,isfscallback cb,void *usrdata)
462 struct isfs_cb *param;
464 if(length<=0 || buffer==NULL || ((u32)buffer%32)!=0) return ISFS_EINVAL;
466 param = (struct isfs_cb*)iosAlloc(hId,ISFS_STRUCTSIZE);
467 if(param==NULL) return ISFS_ENOMEM;
469 param->cb = cb;
470 param->usrdata = usrdata;
471 param->functype = ISFS_FUNCNULL;
472 return IOS_ReadAsync(fd,buffer,length,__isfsFunctionCB,param);
475 s32 ISFS_Seek(s32 fd,s32 where,s32 whence)
477 return IOS_Seek(fd,where,whence);
480 s32 ISFS_SeekAsync(s32 fd,s32 where,s32 whence,isfscallback cb,void *usrdata)
482 struct isfs_cb *param;
484 param = (struct isfs_cb*)iosAlloc(hId,ISFS_STRUCTSIZE);
485 if(param==NULL) return ISFS_ENOMEM;
487 param->cb = cb;
488 param->usrdata = usrdata;
489 param->functype = ISFS_FUNCNULL;
490 return IOS_SeekAsync(fd,where,whence,__isfsFunctionCB,param);
493 s32 ISFS_CreateFile(const char *filepath,u8 attributes,u8 owner_perm,u8 group_perm,u8 other_perm)
495 s32 ret;
496 s32 len;
497 struct isfs_cb *param;
499 if(_fs_fd<0 || filepath==NULL) return ISFS_EINVAL;
501 len = strnlen(filepath,ISFS_MAXPATH);
502 if(len>=ISFS_MAXPATH) return ISFS_EINVAL;
504 param = (struct isfs_cb*)iosAlloc(hId,ISFS_STRUCTSIZE);
505 if(param==NULL) return ISFS_ENOMEM;
507 memcpy(param->fsattr.filepath,filepath,(len+1));
509 param->fsattr.attributes = attributes;
510 param->fsattr.ownerperm = owner_perm;
511 param->fsattr.groupperm = group_perm;
512 param->fsattr.otherperm = other_perm;
513 ret = IOS_Ioctl(_fs_fd,ISFS_IOCTL_CREATEFILE,&param->fsattr,sizeof(param->fsattr),NULL,0);
515 if(param!=NULL) iosFree(hId,param);
516 return ret;
519 s32 ISFS_CreateFileAsync(const char *filepath,u8 attributes,u8 owner_perm,u8 group_perm,u8 other_perm,isfscallback cb,void *usrdata)
521 s32 len;
522 struct isfs_cb *param;
524 if(_fs_fd<0 || filepath==NULL) return ISFS_EINVAL;
526 len = strnlen(filepath,ISFS_MAXPATH);
527 if(len>=ISFS_MAXPATH) return ISFS_EINVAL;
529 param = (struct isfs_cb*)iosAlloc(hId,ISFS_STRUCTSIZE);
530 if(param==NULL) return ISFS_ENOMEM;
532 param->cb = cb;
533 param->usrdata = usrdata;
534 param->functype = ISFS_FUNCNULL;
535 memcpy(param->fsattr.filepath,filepath,(len+1));
537 param->fsattr.attributes = attributes;
538 param->fsattr.ownerperm = owner_perm;
539 param->fsattr.groupperm = group_perm;
540 param->fsattr.otherperm = other_perm;
541 return IOS_IoctlAsync(_fs_fd,ISFS_IOCTL_CREATEFILE,&param->fsattr,sizeof(param->fsattr),NULL,0,__isfsFunctionCB,param);
544 s32 ISFS_Delete(const char *filepath)
546 s32 ret;
547 s32 len;
548 struct isfs_cb *param;
550 if(_fs_fd<0 || filepath==NULL) return ISFS_EINVAL;
552 len = strnlen(filepath,ISFS_MAXPATH);
553 if(len>=ISFS_MAXPATH) return ISFS_EINVAL;
555 param = (struct isfs_cb*)iosAlloc(hId,ISFS_STRUCTSIZE);
556 if(param==NULL) return ISFS_ENOMEM;
558 memcpy(param->filepath,filepath,(len+1));
559 ret = IOS_Ioctl(_fs_fd,ISFS_IOCTL_DELETE,param->filepath,ISFS_MAXPATH,NULL,0);
561 if(param!=NULL) iosFree(hId,param);
562 return ret;
565 s32 ISFS_DeleteAsync(const char *filepath,isfscallback cb,void *usrdata)
567 s32 len;
568 struct isfs_cb *param;
570 if(_fs_fd<0 || filepath==NULL) return ISFS_EINVAL;
572 len = strnlen(filepath,ISFS_MAXPATH);
573 if(len>=ISFS_MAXPATH) return ISFS_EINVAL;
575 param = (struct isfs_cb*)iosAlloc(hId,ISFS_STRUCTSIZE);
576 if(param==NULL) return ISFS_ENOMEM;
578 param->cb = cb;
579 param->usrdata = usrdata;
580 param->functype = ISFS_FUNCNULL;
581 memcpy(param->filepath,filepath,(len+1));
582 return IOS_IoctlAsync(_fs_fd,ISFS_IOCTL_DELETE,param->filepath,ISFS_MAXPATH,NULL,0,__isfsFunctionCB,param);
585 s32 ISFS_Close(s32 fd)
587 if(fd<0) return 0;
589 return IOS_Close(fd);
592 s32 ISFS_CloseAsync(s32 fd,isfscallback cb,void *usrdata)
594 struct isfs_cb *param;
596 if(fd<0) return 0;
598 param = (struct isfs_cb*)iosAlloc(hId,ISFS_STRUCTSIZE);
599 if(param==NULL) return ISFS_ENOMEM;
601 param->cb = cb;
602 param->usrdata = usrdata;
603 param->functype = ISFS_FUNCNULL;
604 return IOS_CloseAsync(fd,__isfsFunctionCB,param);
607 s32 ISFS_GetFileStats(s32 fd,fstats *status)
609 if(status==NULL || ((u32)status%32)!=0) return ISFS_EINVAL;
611 return IOS_Ioctl(fd,ISFS_IOCTL_GETFILESTATS,NULL,0,status,sizeof(fstats));
614 s32 ISFS_GetFileStatsAsync(s32 fd,fstats *status,isfscallback cb,void *usrdata)
616 struct isfs_cb *param;
618 if(status==NULL || ((u32)status%32)!=0) return ISFS_EINVAL;
620 param = (struct isfs_cb*)iosAlloc(hId,ISFS_STRUCTSIZE);
621 if(param==NULL) return ISFS_ENOMEM;
623 param->cb = cb;
624 param->usrdata = usrdata;
625 param->functype = ISFS_FUNCNULL;
626 return IOS_IoctlAsync(fd,ISFS_IOCTL_GETFILESTATS,NULL,0,status,sizeof(fstats),__isfsFunctionCB,param);
629 s32 ISFS_GetAttr(const char *filepath,u32 *ownerID,u16 *groupID,u8 *attributes,u8 *ownerperm,u8 *groupperm,u8 *otherperm)
631 s32 ret;
632 s32 len;
633 struct isfs_cb *param;
635 if(_fs_fd<0 || filepath==NULL || ownerID==NULL || groupID==NULL
636 || attributes==NULL || ownerperm==NULL || groupperm==NULL || otherperm==NULL) return ISFS_EINVAL;
638 len = strnlen(filepath,ISFS_MAXPATH);
639 if(len>=ISFS_MAXPATH) return ISFS_EINVAL;
641 param = (struct isfs_cb*)iosAlloc(hId,ISFS_STRUCTSIZE);
642 if(param==NULL) return ISFS_ENOMEM;
644 memcpy(param->filepath,filepath,(len+1));
645 ret = IOS_Ioctl(_fs_fd,ISFS_IOCTL_GETATTR,param->filepath,ISFS_MAXPATH,&param->fsattr,sizeof(param->fsattr));
646 if(ret==IPC_OK) {
647 *ownerID = param->fsattr.owner_id;
648 *groupID = param->fsattr.group_id;
649 *ownerperm = param->fsattr.ownerperm;
650 *groupperm = param->fsattr.groupperm;
651 *otherperm = param->fsattr.otherperm;
652 *attributes = param->fsattr.attributes;
655 if(param!=NULL) iosFree(hId,param);
656 return ret;
659 s32 ISFS_GetAttrAsync(const char *filepath,u32 *ownerID,u16 *groupID,u8 *attributes,u8 *ownerperm,u8 *groupperm,u8 *otherperm,isfscallback cb,void *usrdata)
661 s32 len;
662 struct isfs_cb *param;
664 if(_fs_fd<0 || filepath==NULL || ownerID==NULL || groupID==NULL
665 || attributes==NULL || ownerperm==NULL || groupperm==NULL || otherperm==NULL) return ISFS_EINVAL;
667 len = strnlen(filepath,ISFS_MAXPATH);
668 if(len>=ISFS_MAXPATH) return ISFS_EINVAL;
670 param = (struct isfs_cb*)iosAlloc(hId,ISFS_STRUCTSIZE);
671 if(param==NULL) return ISFS_ENOMEM;
673 param->cb = cb;
674 param->usrdata = usrdata;
675 param->functype = ISFS_FUNCGETATTR;
676 param->funcargv[0] = ownerID;
677 param->funcargv[1] = groupID;
678 param->funcargv[2] = attributes;
679 param->funcargv[3] = ownerperm;
680 param->funcargv[4] = groupperm;
681 param->funcargv[5] = otherperm;
682 memcpy(param->filepath,filepath,(len+1));
683 return IOS_IoctlAsync(_fs_fd,ISFS_IOCTL_GETATTR,param->filepath,ISFS_MAXPATH,&param->fsattr,sizeof(param->fsattr),__isfsFunctionCB,param);
686 s32 ISFS_Rename(const char *filepathOld,const char *filepathNew)
688 s32 ret;
689 s32 len0,len1;
690 struct isfs_cb *param;
692 if(_fs_fd<0 || filepathOld==NULL || filepathNew==NULL) return ISFS_EINVAL;
694 len0 = strnlen(filepathOld,ISFS_MAXPATH);
695 if(len0>=ISFS_MAXPATH) return ISFS_EINVAL;
697 len1 = strnlen(filepathNew,ISFS_MAXPATH);
698 if(len1>=ISFS_MAXPATH) return ISFS_EINVAL;
700 param = (struct isfs_cb*)iosAlloc(hId,ISFS_STRUCTSIZE);
701 if(param==NULL) return ISFS_ENOMEM;
703 memcpy(param->fsrename.filepathOld,filepathOld,(len0+1));
704 memcpy(param->fsrename.filepathNew,filepathNew,(len1+1));
705 ret = IOS_Ioctl(_fs_fd,ISFS_IOCTL_RENAME,&param->fsrename,sizeof(param->fsrename),NULL,0);
707 if(param!=NULL) iosFree(hId,param);
708 return ret;
711 s32 ISFS_RenameAsync(const char *filepathOld,const char *filepathNew,isfscallback cb,void *usrdata)
713 s32 len0,len1;
714 struct isfs_cb *param;
716 if(_fs_fd<0 || filepathOld==NULL || filepathNew==NULL) return ISFS_EINVAL;
718 len0 = strnlen(filepathOld,ISFS_MAXPATH);
719 if(len0>=ISFS_MAXPATH) return ISFS_EINVAL;
721 len1 = strnlen(filepathNew,ISFS_MAXPATH);
722 if(len1>=ISFS_MAXPATH) return ISFS_EINVAL;
724 param = (struct isfs_cb*)iosAlloc(hId,ISFS_STRUCTSIZE);
725 if(param==NULL) return ISFS_ENOMEM;
727 param->cb = cb;
728 param->usrdata = usrdata;
729 param->functype = ISFS_FUNCNULL;
730 memcpy(param->fsrename.filepathOld,filepathOld,(len0+1));
731 memcpy(param->fsrename.filepathNew,filepathNew,(len1+1));
732 return IOS_IoctlAsync(_fs_fd,ISFS_IOCTL_RENAME,&param->fsrename,sizeof(param->fsrename),NULL,0,__isfsFunctionCB,param);
735 s32 ISFS_SetAttr(const char *filepath,u32 ownerID,u16 groupID,u8 attributes,u8 ownerperm,u8 groupperm,u8 otherperm)
737 s32 ret, len;
738 struct isfs_cb *param;
740 if(_fs_fd<0 || filepath==NULL) return ISFS_EINVAL;
742 len = strnlen(filepath, ISFS_MAXPATH);
743 if(len>=ISFS_MAXPATH) return ISFS_EINVAL;
745 param = (struct isfs_cb*)iosAlloc(hId, ISFS_STRUCTSIZE);
746 if(param==NULL) return ISFS_ENOMEM;
748 memcpy(param->fsattr.filepath, filepath, (len+1));
749 param->fsattr.owner_id = ownerID;
750 param->fsattr.group_id = groupID;
751 param->fsattr.ownerperm = ownerperm;
752 param->fsattr.groupperm = groupperm;
753 param->fsattr.otherperm = otherperm;
754 param->fsattr.attributes = attributes;
756 ret = IOS_Ioctl(_fs_fd,ISFS_IOCTL_SETATTR,&param->fsattr,sizeof(param->fsattr),NULL,0);
758 if(param!=NULL) iosFree(hId,param);
759 return ret;
762 s32 ISFS_SetAttrAsync(const char *filepath,u32 ownerID,u16 groupID,u8 attributes,u8 ownerperm,u8 groupperm,u8 otherperm,isfscallback cb,void *usrdata)
764 s32 len;
765 struct isfs_cb *param;
767 if(_fs_fd<0 || filepath==NULL) return ISFS_EINVAL;
769 len = strnlen(filepath, ISFS_MAXPATH);
770 if(len>=ISFS_MAXPATH) return ISFS_EINVAL;
772 param = (struct isfs_cb*)iosAlloc(hId, ISFS_STRUCTSIZE);
773 if(param==NULL) return ISFS_ENOMEM;
775 param->cb = cb;
776 param->usrdata = usrdata;
777 param->functype = ISFS_FUNCNULL;
778 memcpy(param->fsattr.filepath, filepath, (len+1));
779 param->fsattr.owner_id = ownerID;
780 param->fsattr.group_id = groupID;
781 param->fsattr.ownerperm = ownerperm;
782 param->fsattr.groupperm = groupperm;
783 param->fsattr.otherperm = otherperm;
784 param->fsattr.attributes = attributes;
785 return IOS_IoctlAsync(_fs_fd,ISFS_IOCTL_SETATTR,&param->fsattr,sizeof(param->fsattr),NULL,0,__isfsFunctionCB,param);
788 s32 ISFS_GetUsage(const char* filepath, u32* usage1, u32* usage2)
790 s32 ret,len;
791 struct isfs_cb *param;
793 if(_fs_fd<0 || filepath==NULL || usage1==NULL || usage2 == NULL)
794 return ISFS_EINVAL;
796 len = strnlen(filepath, ISFS_MAXPATH);
797 if(len>=ISFS_MAXPATH) return ISFS_EINVAL;
799 param = (struct isfs_cb*)iosAlloc(hId, ISFS_STRUCTSIZE);
800 if(param==NULL) return ISFS_ENOMEM;
802 memcpy(param->filepath,filepath,(len+1));
804 param->fsusage.vector[0].data = param->filepath;
805 param->fsusage.vector[0].len = ISFS_MAXPATH;
806 param->fsusage.vector[1].data = &param->fsusage.usage1;
807 param->fsusage.vector[1].len = sizeof(u32);
808 param->fsusage.vector[2].data = &param->fsusage.usage2;
809 param->fsusage.vector[2].len = sizeof(u32);
810 ret = IOS_Ioctlv(_fs_fd,ISFS_IOCTL_GETUSAGE,1,2,param->fsusage.vector);
811 if(ret==IPC_OK) {
812 *usage1 = param->fsusage.usage1;
813 *usage2 = param->fsusage.usage2;
816 if(param!=NULL) iosFree(hId, param);
817 return ret;
820 s32 ISFS_GetUsageAsync(const char* filepath, u32* usage1, u32* usage2,isfscallback cb,void *usrdata)
822 s32 len;
823 struct isfs_cb *param;
825 if(_fs_fd<0 || filepath==NULL || usage1==NULL || usage2 == NULL)
826 return ISFS_EINVAL;
828 len = strnlen(filepath, ISFS_MAXPATH);
829 if(len>=ISFS_MAXPATH) return ISFS_EINVAL;
831 param = (struct isfs_cb*)iosAlloc(hId, ISFS_STRUCTSIZE);
832 if(param==NULL) return ISFS_ENOMEM;
834 param->cb = cb;
835 param->usrdata = usrdata;
836 param->functype = ISFS_FUNCGETUSAGE;
837 param->funcargv[0] = usage1;
838 param->funcargv[1] = usage2;
839 memcpy(param->filepath,filepath,(len+1));
841 param->fsusage.vector[0].data = param->filepath;
842 param->fsusage.vector[0].len = ISFS_MAXPATH;
843 param->fsusage.vector[1].data = &param->fsusage.usage1;
844 param->fsusage.vector[1].len = sizeof(u32);
845 param->fsusage.vector[2].data = &param->fsusage.usage2;
846 param->fsusage.vector[2].len = sizeof(u32);
847 return IOS_IoctlvAsync(_fs_fd,ISFS_IOCTL_GETUSAGE,1,2,param->fsusage.vector,__isfsFunctionCB,param);
851 #endif /* defined(HW_RVL) */