PS2SDK
PS2 Homebrew Libraries
devscan.c
Go to the documentation of this file.
1 /*
2 # _____ ___ ____ ___ ____
3 # ____| | ____| | | |____|
4 # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5 #-----------------------------------------------------------------------
6 # Copyright 2001-2004, ps2dev - http://www.ps2dev.org
7 # Licenced under Academic Free License version 2.0
8 # Review ps2sdk README & LICENSE files for further details.
9 */
10 
16 #include <types.h>
17 #include <defs.h>
18 #include <irx.h>
19 
20 #include <loadcore.h>
21 #include <ioman_mod.h>
22 #include <iomanX.h>
23 #include <thbase.h>
24 #include <thsemap.h>
25 #include <stdio.h>
26 #include <sysclib.h>
27 #include <iopmgr.h>
28 
29 #include "devscan.h"
30 #include "debug_printf.h"
31 
35 static dev_table_t dev_info_list[DEVSCAN_MAX+1]; /* one for padding */
36 
47 ModuleInfo_t *devscan_getmodule(const char *name)
48 {
49  ModuleInfo_t *modptr;
50  int len = strlen(name)+1;
51 
52  modptr = GetLoadcoreInternalData()->image_info;
53  while (modptr != 0)
54  {
55  if (!memcmp(modptr->name, name, len))
56  return modptr;
57  modptr = modptr->next;
58  }
59  return 0;
60 }
61 
73 int devscan_setup(int devtype)
74 {
76  iop_device_t **devinfo_table;
77  int i;
78  int count = 0;
79 
80  DPRINTF("%s\n", __func__);
81  // clear device list
82  memset(&dev_info_list,0,sizeof(dev_info_list));
83 
84  /* do the ioman devices */
85  if ((info = devscan_getmodule(IOPMGR_IOMAN_IDENT)))
86  {
87  /* Find the start of the device info array, in .bss. */
88  devinfo_table = (iop_device_t **)(info->text_start + info->text_size + info->data_size + 0x0c);
89 
90  /* The device info table had 16 entries, but some may be empty. Just look at all of them. */
91  for (i = 0; i < DEVSCAN_IOMAX; i++)
92  {
93  if (devinfo_table[i])
94  if ((devinfo_table[i]->type & devtype))
95  {
96  dev_info_list[count].devtype = IOPMGR_DEVTYPE_IOMAN;
97  strncpy(dev_info_list[count].name,devinfo_table[i]->name,255);
98  dev_info_list[count].name[255] = '\0';
99  dev_info_list[count].len = strlen(dev_info_list[count].name);
100  DPRINTF("ioman '%s'\n",dev_info_list[count].name);
101  count++;
102  }
103  }
104  }
105 
106  /* do the iomanx devices */
107  if ((info = devscan_getmodule(IOPMGR_IOMANX_IDENT)))
108  {
109  /* Find the start of the device info array, in .bss. */
110  devinfo_table = (iop_device_t **)(info->text_start + info->text_size + info->data_size);
111 
112  /* The device info table had 32 entries, but some may be empty. Just look at all of them. */
113  for (i = 0; i < DEVSCAN_IOXMAX; i++)
114  {
115  if (devinfo_table[i])
116  /* only add iomanx ones here, so must have extended flag set else we get duplication with new iomanx */
117  if ((devinfo_table[i]->type & IOP_DT_FSEXT) && (devinfo_table[i]->type & devtype))
118  {
119  dev_info_list[count].devtype = IOPMGR_DEVTYPE_IOMANX;
120  strncpy(dev_info_list[count].name,devinfo_table[i]->name,255);
121  dev_info_list[count].name[255] = '\0';
122  dev_info_list[count].len = strlen(dev_info_list[count].name);
123  DPRINTF("iomanx '%s'\n",dev_info_list[count].name);
124  count++;
125  }
126  }
127  }
128  return count;
129 }
130 
141 int devscan_gettype(char *name)
142 {
143  int count = 0;
144  DPRINTF("gettype '%s'\n",name);
145  while (dev_info_list[count].name[0] != 0)
146  {
147  int ret = strncmp(dev_info_list[count].name,name,dev_info_list[count].len );
148  DPRINTF("'%s'",dev_info_list[count].name);
149  if (!ret)
150  return dev_info_list[count].devtype;
151  count++;
152  }
153  return IOPMGR_DEVTYPE_INVALID;
154 }
155 
162 int devscan_getdevlist(char *buffer)
163 {
164  int count;
165  int i;
166  char *bufptr = buffer;
167 
168  DPRINTF("getdevlist\n");
169  /* rescan for devices, before returning list */
171 
172  /* now convert this list into the right format */
173  for (i=0;i<count;i++)
174  {
175  strcpy(bufptr,dev_info_list[i].name);
176  DPRINTF("'%s'\n",bufptr);
177  bufptr += strlen(bufptr)+1;
178  }
179  return count;
180 }
181 
iomanX.h
iopmgr.h
devscan_setup
int devscan_setup(int devtype)
Definition: devscan.c:73
IOP_DT_FSEXT
#define IOP_DT_FSEXT
Definition: iomanX.h:66
thbase.h
sysclib.h
devscan_getmodule
ModuleInfo_t * devscan_getmodule(const char *name)
Definition: devscan.c:47
s_info
Definition: xprintf.c:78
loadcore.h
count
u32 count
start sector of fragmented bd/file
Definition: usbhdfsd-common.h:3
devscan_gettype
int devscan_gettype(char *name)
Definition: devscan.c:141
irx.h
thsemap.h
stdio.h
ioman_mod.h
DEVSCAN_MASK
#define DEVSCAN_MASK
Definition: devscan.h:26
DEVSCAN_MAX
#define DEVSCAN_MAX
Definition: devscan.h:21
defs.h
_iop_device
Definition: ioman.h:64
devscan.h
dev_info_list
static dev_table_t dev_info_list[DEVSCAN_MAX+1]
Definition: devscan.c:35
_ModuleInfo
Definition: loadcore.h:31
tag_LC_internals::image_info
ModuleInfo_t * image_info
Definition: loadcore.h:82
dev_table_t
Definition: devscan.h:31
devscan_getdevlist
int devscan_getdevlist(char *buffer)
Definition: devscan.c:162