forked from waninkoko/mload-module
-
Notifications
You must be signed in to change notification settings - Fork 0
/
di.c
89 lines (66 loc) · 1.72 KB
/
di.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
Custom IOS Module (MLOAD)
Copyright (C) 2008 neimod.
Copyright (C) 2010 Hermes.
Copyright (C) 2010 Waninkoko.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "syscalls.h"
#include "types.h"
/* IOCTL commands */
#define IOCTL_DI_READID 0x70
#define IOCTL_DI_RESET 0x8A
/* Variables */
static u32 inbuf[8] ATTRIBUTE_ALIGN(32);
s32 __DI_Init(void)
{
/* Open /dev/di */
return os_open("/dev/di", 0);
}
void __DI_Close(s32 fd)
{
/* Close /dev/di */
os_close(fd);
}
s32 DI_Reset(void)
{
s32 fd, ret;
/* Open DI */
fd = __DI_Init();
if (fd < 0)
return fd;
/* Prepare input */
inbuf[0] = IOCTL_DI_RESET << 24;
inbuf[1] = 1;
/* Reset drive */
ret = os_ioctl(fd, IOCTL_DI_RESET, inbuf, sizeof(inbuf), NULL, 0);
/* Close DI */
__DI_Close(fd);
return ret;
}
s32 DI_ReadDiskId(void *id)
{
s32 fd, ret;
/* Open DI */
fd = __DI_Init();
if (fd < 0)
return fd;
/* Prepare input */
inbuf[0] = IOCTL_DI_RESET << 24;
inbuf[1] = 1;
/* Reset drive */
ret = os_ioctl(fd, IOCTL_DI_READID, inbuf, sizeof(inbuf), id, 32);
/* Close DI */
__DI_Close(fd);
return ret;
}