pathinfo improvements - ctime, atime, mtime support added
[libogc.git] / libdi / di_read.c
blob7527b59d0417cae04b2306fb45f8d44321251143
1 #include <errno.h>
2 #include "di.h"
4 extern int di_fd;
5 static uint32_t dic[8] __attribute__((aligned(32)));
7 int _DI_ReadDVD_A8(void* buf, uint32_t len, uint32_t lba);
8 int _DI_ReadDVD_D0(void* buf, uint32_t len, uint32_t lba);
10 int _DI_ReadDVD_A8_Async(void* buf, uint32_t len, uint32_t lba,ipccallback ipc_cb);
11 int _DI_ReadDVD_D0_Async(void* buf, uint32_t len, uint32_t lba,ipccallback ipc_cb);
14 Internal function, used when a modchip has been detected.
15 Please refrain from using this function directly.
17 int _DI_ReadDVD_A8_Async(void* buf, uint32_t len, uint32_t lba, ipccallback ipc_cb){
18 int ret;
20 if(!buf){
21 errno = EINVAL;
22 return -1;
25 if((uint32_t)buf & 0x1F){ // This only works with 32 byte aligned addresses!
26 errno = EFAULT;
27 return -1;
30 dic[0] = DVD_READ_UNENCRYPTED << 24;
31 dic[1] = len << 11; // 1 LB is 2048 bytes
32 dic[2] = lba << 9; // Nintendo's read function uses byteOffset >> 2, so we only shift 9 left, not 11.
34 ret = IOS_IoctlAsync(di_fd, DVD_READ_UNENCRYPTED, dic, 0x20, buf, len << 11,ipc_cb, buf);
36 if(ret == 2) errno = EIO;
38 return (ret == 1)? 0 : -ret;
42 Internal function, used when the drive is DVDVideo compatible.
43 Please refrain from using this function directly.
45 int _DI_ReadDVD_D0_Async(void* buf, uint32_t len, uint32_t lba, ipccallback ipc_cb){
46 int ret;
48 if(!buf){
49 errno = EINVAL;
50 return -1;
53 if((uint32_t)buf & 0x1F){
54 errno = EFAULT;
55 return -1;
58 dic[0] = DVD_READ << 24;
59 dic[1] = 0; // Unknown what this does as of now. (Sets some value to 0x10 in the drive if set).
60 dic[2] = 0; // USE_DEFAULT_CONFIG flag. Drive will use default config if this bit is set.
61 dic[3] = len;
62 dic[4] = lba;
64 ret = IOS_IoctlAsync(di_fd, DVD_READ, dic, 0x20, buf, len << 11,ipc_cb, buf);
66 if(ret == 2) errno = EIO;
68 return (ret == 1)? 0 : -ret;
75 Internal function, used when a modchip has been detected.
76 Please refrain from using this function directly.
78 int _DI_ReadDVD_A8(void* buf, uint32_t len, uint32_t lba){
79 int ret, retry_count = LIBDI_MAX_RETRIES;
81 if(!buf){
82 errno = EINVAL;
83 return -1;
86 if((uint32_t)buf & 0x1F){ // This only works with 32 byte aligned addresses!
87 errno = EFAULT;
88 return -1;
91 dic[0] = DVD_READ_UNENCRYPTED << 24;
92 dic[1] = len << 11; // 1 LB is 2048 bytes
93 dic[2] = lba << 9; // Nintendo's read function uses byteOffset >> 2, so we only shift 9 left, not 11.
95 do{
96 ret = IOS_Ioctl(di_fd, DVD_READ_UNENCRYPTED, dic, 0x20, buf, len << 11);
97 retry_count--;
98 }while(ret != 1 && retry_count > 0);
100 if(ret == 2) errno = EIO;
102 return (ret == 1)? 0 : -ret;
106 Internal function, used when the drive is DVDVideo compatible.
107 Please refrain from using this function directly.
109 int _DI_ReadDVD_D0(void* buf, uint32_t len, uint32_t lba){
110 int ret, retry_count = LIBDI_MAX_RETRIES;
112 if(!buf){
113 errno = EINVAL;
114 return -1;
117 if((uint32_t)buf & 0x1F){
118 errno = EFAULT;
119 return -1;
122 dic[0] = DVD_READ << 24;
123 dic[1] = 0; // Unknown what this does as of now. (Sets some value to 0x10 in the drive if set).
124 dic[2] = 0; // USE_DEFAULT_CONFIG flag. Drive will use default config if this bit is set.
125 dic[3] = len;
126 dic[4] = lba;
130 do{
131 ret = IOS_Ioctl(di_fd, DVD_READ, dic, 0x20, buf, len << 11);
132 retry_count--;
133 }while(ret != 1 && retry_count > 0);
135 if(ret == 2) errno = EIO;
137 return (ret == 1)? 0 : -ret;