PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
devfs.c File Reference
#include "types.h"
#include "defs.h"
#include "irx.h"
#include "loadcore.h"
#include "thbase.h"
#include "thevent.h"
#include "thsemap.h"
#include "intrman.h"
#include "stdio.h"
#include "sysclib.h"
#include <errno.h>
#include "devfs.h"
#include "sysmem.h"
#include "iomanX.h"
+ Include dependency graph for devfs.c:

Go to the source code of this file.

Data Structures

struct  subdev_t
 
struct  _devfs_device
 
struct  _ioman_data
 
struct  _directory_file
 

Macros

#define MODNAME   "devfs"
 
#define M_PRINTF(format, args...)
 
#define BANNER   "DEVFS %s\n"
 
#define VERSION   "v0.1"
 
#define MAX_OPENFILES   32
 
#define MAX_OPEN_DIRFILES   16
 

Typedefs

typedef struct _devfs_device devfs_device_t
 
typedef struct _ioman_data ioman_data_t
 
typedef struct _directory_file directory_file_t
 

Functions

 IRX_ID (MODNAME, 1, 1)
 
const char * devfs_subdev_to_str (int subdev)
 
int devfs_fill_dirent (iox_dirent_t *dirent, int devno)
 
devfs_device_tdevfs_create_device (const devfs_node_t *node)
 
int devfs_delete_device (devfs_device_t *dev)
 
devfs_device_tdevfs_find_devicename (const char *name)
 
devfs_device_tdevfs_find_deviceid (HDEV hDev)
 
int devfs_open (iop_file_t *file, const char *name, int mode, int unused)
 
int devfs_close (iop_file_t *file)
 
int devfs_ioctl (iop_file_t *file, int cmd, void *args)
 
int devfs_ioctl2 (iop_file_t *file, int cmd, void *args, unsigned int arglen, void *buf, unsigned int buflen)
 
int devfs_read (iop_file_t *file, void *buf, int len)
 
int devfs_write (iop_file_t *file, void *buf, int len)
 
int devfs_lseek (iop_file_t *file, long loc, int whence)
 
int devfs_lseek64 (iop_file_t *file, long long loc, int whence)
 
int devfs_dopen (iop_file_t *file, const char *name)
 
int devfs_dclose (iop_file_t *file)
 
int devfs_dread (iop_file_t *file, iox_dirent_t *buf)
 
int devfs_getstat (iop_file_t *file, const char *name, iox_stat_t *stat)
 
 IOMANX_RETURN_VALUE_IMPL (0)
 
 IOMANX_RETURN_VALUE_IMPL (EPERM)
 
int init_devfs (void)
 
int _start (int argc, char *argv[])
 
int devfs_check_devname (const char *name)
 
HDEV DevFSAddDevice (const devfs_node_t *node)
 
int DevFSDelDevice (HDEV hDev)
 
int DevFSAddSubDevice (HDEV hDev, u32 subdev_no, s32 mode, devfs_loc_t extent, void *data)
 
int DevFSDelSubDevice (HDEV hDev, u32 subdev_no)
 

Variables

struct irx_export_table _exp_devfs
 
devfs_device_troot_device
 
HDEV dev_count
 
directory_file_t open_dirfiles [MAX_OPEN_DIRFILES]
 
static iop_device_ops_t devfs_ops
 
static iop_device_t devfs_device
 

Detailed Description

DevFS source file

Definition in file devfs.c.


Data Structure Documentation

◆ subdev_t

struct subdev_t

Definition at line 49 of file devfs.c.

+ Collaboration diagram for subdev_t:
Data Fields
void * data
s32 valid
u32 mode
u32 open_refcount
devfs_loc_t extent
struct _ioman_data * open_files[MAX_OPENFILES]

◆ _devfs_device

struct _devfs_device

Definition at line 60 of file devfs.c.

+ Collaboration diagram for _devfs_device:
Data Fields
struct _devfs_device * forw

Pointers to the next device in the chain

struct _devfs_device * back
HDEV hDev
devfs_node_t node
subdev_t subdevs[DEVFS_MAX_SUBDEVS]
u32 subdev_count
u32 open_refcount

◆ _ioman_data

struct _ioman_data

Definition at line 71 of file devfs.c.

+ Collaboration diagram for _ioman_data:
Data Fields
HDEV hDev
devfs_device_t * dev

Pointer to the main device, set to NULL if device closed

int subdev
u32 mode
devfs_loc_t loc

◆ _directory_file

struct _directory_file

Definition at line 85 of file devfs.c.

Data Fields
HDEV hDev

Should always be set to -1

u32 devno

The number of the file being listed

u32 opened

If this directory file is in an opened state

Macro Definition Documentation

◆ MODNAME

#define MODNAME   "devfs"

Definition at line 37 of file devfs.c.

◆ M_PRINTF

#define M_PRINTF ( format,
args... )
Value:
printf(MODNAME ": " format, ## args)

Definition at line 40 of file devfs.c.

◆ BANNER

#define BANNER   "DEVFS %s\n"

Definition at line 42 of file devfs.c.

◆ VERSION

#define VERSION   "v0.1"

Definition at line 43 of file devfs.c.

◆ MAX_OPENFILES

#define MAX_OPENFILES   32

Definition at line 44 of file devfs.c.

◆ MAX_OPEN_DIRFILES

#define MAX_OPEN_DIRFILES   16

Definition at line 45 of file devfs.c.

Function Documentation

◆ devfs_subdev_to_str()

const char * devfs_subdev_to_str ( int subdev)

Simple function to convert a number to a string

Parameters
subdevThe number to convert.
Returns
A constant string containing the number. Returns an empty string if not possible to convert.

Definition at line 103 of file devfs.c.

Referenced by devfs_fill_dirent().

◆ devfs_fill_dirent()

int devfs_fill_dirent ( iox_dirent_t * dirent,
int devno )

Scans the device list and fills in the corresponding directory entry

Parameters
direntPointer to a iox_dirent_t structure.
devnoThe sequential device number to read
Returns
Always 0

Definition at line 137 of file devfs.c.

References DEVFS_MAX_SUBDEVS, DEVFS_MODE_R, DEVFS_MODE_W, devfs_subdev_to_str(), FIO_S_IFREG, FIO_S_IRUSR, FIO_S_IWUSR, _devfs_device::forw, devfs_loc_t::loc32, devfs_node_t::name, and root_device.

◆ devfs_create_device()

devfs_device_t * devfs_create_device ( const devfs_node_t * node)

Creates a new device based on the node data supplied

Parameters
nodePointer to a devfs_node_t structure
Returns
A new device structure or NULL on error.

Definition at line 198 of file devfs.c.

References devfs_node_t::desc, and devfs_node_t::name.

Referenced by DevFSAddDevice().

◆ devfs_delete_device()

int devfs_delete_device ( devfs_device_t * dev)

Deletes a device

Parameters
devPointer to a previously allocated device structure
Returns
Always 0

Definition at line 248 of file devfs.c.

References devfs_node_t::desc, and devfs_node_t::name.

Referenced by DevFSDelDevice().

◆ devfs_find_devicename()

devfs_device_t * devfs_find_devicename ( const char * name)

Trys to find a device with a matching name.

The name can be a full device name with subdev on the end, the function should still find the device.

Parameters
nameThe name of the device to find
Returns
A pointer to the device, if not found returns NULL

Definition at line 276 of file devfs.c.

References _devfs_device::forw, devfs_node_t::name, and root_device.

Referenced by devfs_getstat(), devfs_open(), and DevFSAddDevice().

◆ devfs_find_deviceid()

devfs_device_t * devfs_find_deviceid ( HDEV hDev)

Finds a device from its device handle.

Parameters
hDevHandle to the device.
Returns
A pointer to the device, if not found returns NULL

Definition at line 309 of file devfs.c.

References _devfs_device::forw, and root_device.

Referenced by DevFSAddSubDevice(), DevFSDelDevice(), and DevFSDelSubDevice().

◆ devfs_open()

int devfs_open ( iop_file_t * file,
const char * name,
int mode,
int unused )

ioman open handler @oaram file: Pointer to the ioman file structure

Parameters
nameName of file to open
modeOpen file mode settings
Returns
0 if success, -1 on error

Definition at line 337 of file devfs.c.

References devfs_find_devicename(), DEVFS_MAX_SUBDEVS, DEVFS_MODE_EX, DEVFS_MODE_R, DEVFS_MODE_W, EPERM, devfs_node_t::name, and _iop_file::privdata.

◆ devfs_close()

int devfs_close ( iop_file_t * file)

ioman close handler

Parameters
filePointer to an ioman file structure
Returns
0 on success, else -1

Definition at line 469 of file devfs.c.

References EPERM, INVALID_HDEV, devfs_node_t::name, and _iop_file::privdata.

◆ devfs_ioctl()

int devfs_ioctl ( iop_file_t * file,
int cmd,
void * args )

ioman ioctl handler

Parameters
filePointer to an ioman file structure
cmdioctl command number
argsPointer to a buffer containing any arguments
Returns
>= 0 Defined by the type of command, -1 on error

Definition at line 532 of file devfs.c.

References devfs_info_t::data, DEVFS_IOCTL_GETDESC, DEVFS_IOCTL_TYPE_1, EPERM, INVALID_HDEV, devfs_node_t::ioctl, devfs_info_t::loc, devfs_info_t::mode, _iop_file::privdata, and devfs_info_t::subdev.

◆ devfs_ioctl2()

int devfs_ioctl2 ( iop_file_t * file,
int cmd,
void * args,
unsigned int arglen,
void * buf,
unsigned int buflen )

ioman ioctl2 handler

Parameters
filePointer to an ioman file structure
cmdioctl command number
argsPointer a buffer containing command arguments
arglenLength of args buffer
bufPointer to a return buffer
buflenLength of buf
Returns
>= 0 Depends on command, -1 on error

Definition at line 580 of file devfs.c.

References devfs_info_t::data, devfs_node_t::desc, DEVFS_IOCTL_GETDESC, DEVFS_IOCTL_TYPE_2, DEVFS_MAX_DESC_LENGTH, EPERM, INVALID_HDEV, devfs_node_t::ioctl, devfs_info_t::loc, devfs_info_t::mode, _iop_file::privdata, and devfs_info_t::subdev.

◆ devfs_read()

int devfs_read ( iop_file_t * file,
void * buf,
int len )

ioman read handler

Parameters
filePointer to an ioman file structure
bufBuffer to read data to
lenLength of data to read
Returns
Length of data read. 0 on eof or file pointer out of range. -1 on error.

Definition at line 632 of file devfs.c.

References devfs_info_t::data, DEVFS_MODE_R, EPERM, INVALID_HDEV, devfs_info_t::loc, devfs_info_t::mode, _iop_file::privdata, devfs_node_t::read, and devfs_info_t::subdev.

◆ devfs_write()

int devfs_write ( iop_file_t * file,
void * buf,
int len )

ioman write handler

Parameters
filePointer to an ioman file structure
bufPointer to the buffer to write
lenLength of data to write
Returns
Number of bytes written, 0 on eof or -1 on error

Definition at line 680 of file devfs.c.

References devfs_info_t::data, DEVFS_MODE_W, EPERM, INVALID_HDEV, devfs_info_t::loc, devfs_info_t::mode, _iop_file::privdata, devfs_info_t::subdev, and devfs_node_t::write.

◆ devfs_lseek()

int devfs_lseek ( iop_file_t * file,
long loc,
int whence )

ioman lseek handler

Parameters
filePointer to a ioman file structure
locLocation to seek to
whenceSeek base.
Returns
location seeked to, -1 on error.

Definition at line 727 of file devfs.c.

References EPERM, INVALID_HDEV, devfs_loc_t::loc64, and _iop_file::privdata.

◆ devfs_lseek64()

int devfs_lseek64 ( iop_file_t * file,
long long loc,
int whence )

ioman lseek64 handler

Parameters
filePointer to an ioman file structure
loc64bit seek location
whenceSeek base

Definition at line 775 of file devfs.c.

References EPERM, INVALID_HDEV, devfs_loc_t::loc64, and _iop_file::privdata.

◆ devfs_dopen()

int devfs_dopen ( iop_file_t * file,
const char * name )

ioman dopen handler

Parameters
filePointer to an ioman file structure
nameName of directory to open
Returns
0 if success, -1 on error

Definition at line 823 of file devfs.c.

References _directory_file::devno, EPERM, _directory_file::hDev, INVALID_HDEV, and _iop_file::privdata.

◆ devfs_dclose()

int devfs_dclose ( iop_file_t * file)

ioman dclose handler

Parameters
filePointer to an ioman file structure
Returns
Always returns 0

Definition at line 852 of file devfs.c.

References _directory_file::hDev, INVALID_HDEV, _directory_file::opened, and _iop_file::privdata.

◆ devfs_dread()

int devfs_dread ( iop_file_t * file,
iox_dirent_t * buf )

Definition at line 871 of file devfs.c.

◆ devfs_getstat()

int devfs_getstat ( iop_file_t * file,
const char * name,
iox_stat_t * stat )

ioman getstat handler

Parameters
filePointer to an ioman file structure
nameName of the file to stat
statBuffer to receive the stat
Returns
0 on success, -1 on error

Definition at line 900 of file devfs.c.

References devfs_find_devicename(), DEVFS_MAX_SUBDEVS, DEVFS_MODE_R, DEVFS_MODE_W, EPERM, FIO_S_IFREG, FIO_S_IRUSR, FIO_S_IWUSR, devfs_loc_t::loc32, and devfs_node_t::name.

◆ init_devfs()

int init_devfs ( void )

DevFS initialise function

Returns
>= 0 on success, -1 on error

Definition at line 1026 of file devfs.c.

References root_device.

Referenced by _start().

◆ _start()

int _start ( int argc,
char * argv[] )

Main start function of the module

Parameters
argcUnused
argvUnused
Returns
0 on success, -1 on error

Definition at line 1044 of file devfs.c.

References init_devfs().

◆ devfs_check_devname()

int devfs_check_devname ( const char * name)

Function to check a device name only contains alphabetic characters

Parameters
nameThe name to check.
Returns
0 if the name is invalid, else 1

Definition at line 1073 of file devfs.c.

References DEVFS_MAX_DEVNAME_LENGTH.

Referenced by DevFSAddDevice().

Variable Documentation

◆ root_device

devfs_device_t* root_device

Pointer to the root device

Definition at line 82 of file devfs.c.

Referenced by devfs_fill_dirent(), devfs_find_deviceid(), devfs_find_devicename(), DevFSAddDevice(), DevFSDelDevice(), and init_devfs().

◆ dev_count

HDEV dev_count

Definition at line 83 of file devfs.c.

◆ open_dirfiles

directory_file_t open_dirfiles[MAX_OPEN_DIRFILES]

Definition at line 96 of file devfs.c.

◆ devfs_ops

iop_device_ops_t devfs_ops
static
Initial value:
= {
IOMANX_RETURN_VALUE(0),
IOMANX_RETURN_VALUE(0),
IOMANX_RETURN_VALUE(EPERM),
IOMANX_RETURN_VALUE(EPERM),
IOMANX_RETURN_VALUE(EPERM),
IOMANX_RETURN_VALUE(EPERM),
IOMANX_RETURN_VALUE(EPERM),
IOMANX_RETURN_VALUE(EPERM),
&devfs_dread,
IOMANX_RETURN_VALUE(EPERM),
IOMANX_RETURN_VALUE(EPERM),
IOMANX_RETURN_VALUE(EPERM),
IOMANX_RETURN_VALUE(EPERM),
IOMANX_RETURN_VALUE(EPERM),
IOMANX_RETURN_VALUE(EPERM),
IOMANX_RETURN_VALUE_S64(EPERM),
IOMANX_RETURN_VALUE(EPERM),
IOMANX_RETURN_VALUE(EPERM),
IOMANX_RETURN_VALUE(EPERM),
}
int devfs_dopen(iop_file_t *file, const char *name)
Definition devfs.c:823
int devfs_getstat(iop_file_t *file, const char *name, iox_stat_t *stat)
Definition devfs.c:900
int devfs_close(iop_file_t *file)
Definition devfs.c:469
int devfs_dclose(iop_file_t *file)
Definition devfs.c:852
int devfs_ioctl(iop_file_t *file, int cmd, void *args)
Definition devfs.c:532
int devfs_open(iop_file_t *file, const char *name, int mode, int unused)
Definition devfs.c:337
int devfs_ioctl2(iop_file_t *file, int cmd, void *args, unsigned int arglen, void *buf, unsigned int buflen)
Definition devfs.c:580
int devfs_read(iop_file_t *file, void *buf, int len)
Definition devfs.c:632
#define EPERM
Definition errno.h:21

Definition at line 985 of file devfs.c.

◆ devfs_device

iop_device_t devfs_device
static
Initial value:
= {
"devfs",
IOP_DT_FS | IOP_DT_FSEXT,
0x100,
"PS2 Device FS Driver",
&devfs_ops,
}
#define IOP_DT_FSEXT
Definition iomanX.h:66

Definition at line 1015 of file devfs.c.