sdk-core v2026.11.05
PS2 SDK - core tier (build-critical EE/IOP modules)
Loading...
Searching...
No Matches
diskio.c
1/*-----------------------------------------------------------------------*/
2/* Low level disk I/O module SKELETON for FatFs (C)ChaN, 2025 */
3/*-----------------------------------------------------------------------*/
4/* If a working storage control module is available, it should be */
5/* attached to the FatFs via a glue function rather than modifying it. */
6/* This is an example of glue functions to attach various exsisting */
7/* storage control modules to the FatFs module with a defined API. */
8/*-----------------------------------------------------------------------*/
9
10#include <bdm.h>
11#include <cdvdman.h>
12
13#include "ff.h" /* Basic definitions of FatFs */
14#include "diskio.h" /* Declarations FatFs MAI */
15#include "fs_driver.h" /* Declarations of fs driver functions */
16
17/*-----------------------------------------------------------------------*/
18/* Get Drive Status */
19/*-----------------------------------------------------------------------*/
20
21DSTATUS disk_status (
22 BYTE pdrv /* Physical drive nmuber to identify the drive */
23)
24{
25 int result;
26
27 result = (fatfs_fs_driver_get_mounted_bd_from_index(pdrv) == NULL) ? (STA_NOINIT | STA_NODISK) : 0;
28
29 return result;
30}
31
32
33
34/*-----------------------------------------------------------------------*/
35/* Inidialize a Drive */
36/*-----------------------------------------------------------------------*/
37
38DSTATUS disk_initialize (
39 BYTE pdrv /* Physical drive nmuber to identify the drive */
40)
41{
42 int result;
43
44 result = (fatfs_fs_driver_get_mounted_bd_from_index(pdrv) == NULL) ? (STA_NOINIT | STA_NODISK) : 0;
45
46 return result;
47}
48
49
50
51/*-----------------------------------------------------------------------*/
52/* Read Sector(s) */
53/*-----------------------------------------------------------------------*/
54
55DRESULT disk_read (
56 BYTE pdrv, /* Physical drive nmuber to identify the drive */
57 BYTE *buff, /* Data buffer to store read data */
58 LBA_t sector, /* Start sector in LBA */
59 UINT count /* Number of sectors to read */
60)
61{
62 DRESULT res;
63 struct block_device *mounted_bd;
64
65 mounted_bd = fatfs_fs_driver_get_mounted_bd_from_index(pdrv);
66
67 if (mounted_bd == NULL) {
68 return RES_NOTRDY;
69 }
70
71 res = mounted_bd->read(mounted_bd, sector, buff, count);
72
73 return (res == count) ? RES_OK : RES_ERROR;
74}
75
76
77
78/*-----------------------------------------------------------------------*/
79/* Write Sector(s) */
80/*-----------------------------------------------------------------------*/
81
82#if FF_FS_READONLY == 0
83
84DRESULT disk_write (
85 BYTE pdrv, /* Physical drive nmuber to identify the drive */
86 const BYTE *buff, /* Data to be written */
87 LBA_t sector, /* Start sector in LBA */
88 UINT count /* Number of sectors to write */
89)
90{
91 DRESULT res;
92 struct block_device *mounted_bd;
93
94 mounted_bd = fatfs_fs_driver_get_mounted_bd_from_index(pdrv);
95
96 if (mounted_bd == NULL) {
97 return RES_NOTRDY;
98 }
99
100 res = mounted_bd->write(mounted_bd, sector, buff, count);
101
102 return (res == count) ? RES_OK : RES_ERROR;
103}
104
105#endif
106
107
108/*-----------------------------------------------------------------------*/
109/* Miscellaneous Functions */
110/*-----------------------------------------------------------------------*/
111
112DRESULT disk_ioctl (
113 BYTE pdrv, /* Physical drive nmuber (0..) */
114 BYTE cmd, /* Control code */
115 void *buff /* Buffer to send/receive control data */
116)
117{
118 struct block_device *mounted_bd;
119
120 mounted_bd = fatfs_fs_driver_get_mounted_bd_from_index(pdrv);
121
122 if (mounted_bd == NULL) {
123 return RES_NOTRDY;
124 }
125
126 switch (cmd) {
127 case CTRL_SYNC:
128 mounted_bd->flush(mounted_bd);
129 break;
130 case GET_SECTOR_COUNT:
131 *(unsigned int *)buff = mounted_bd->sectorCount;
132 break;
133 case GET_SECTOR_SIZE:
134 *(unsigned int *)buff = mounted_bd->sectorSize;
135 break;
136 case GET_BLOCK_SIZE:
137 *(unsigned int *)buff = 0;
138 break;
139 default:
140 return RES_PARERR;
141 }
142
143 return RES_OK;
144}
145
146DWORD get_fattime(void)
147{
148 // ps2 specific routine to get time and date
149 int year, month, day, hour, minute, sec;
150 sceCdCLOCK cdtime;
151
152 if (sceCdReadClock(&cdtime) != 0 && cdtime.stat == 0) {
153 sec = btoi(cdtime.second);
154 minute = btoi(cdtime.minute);
155 hour = btoi(cdtime.hour);
156 day = btoi(cdtime.day);
157 month = btoi(cdtime.month & 0x7F); // Ignore century bit (when an old CDVDMAN is used).
158 year = btoi(cdtime.year) + 2000;
159 } else {
160 year = 2005;
161 month = 1;
162 day = 6;
163 hour = 14;
164 minute = 12;
165 sec = 10;
166 }
167
168 /* Pack date and time into a DWORD variable */
169 return ((DWORD)(year - 1980) << 25) | ((DWORD)month << 21) | ((DWORD)day << 16) | ((DWORD)hour << 11) | ((DWORD)minute << 5) | ((DWORD)sec >> 1);
170}
int sceCdReadClock(sceCdCLOCK *clock)
Definition scmd.c:116
u32 count
start sector of fragmented bd/file