Commit 0db59294 authored by Petri Hintukainen's avatar Petri Hintukainen

disc: simplify passing file system access functions

parent 6f16e18b
...@@ -1423,8 +1423,7 @@ BLURAY *bd_init(void) ...@@ -1423,8 +1423,7 @@ BLURAY *bd_init(void)
static int _bd_open(BLURAY *bd, static int _bd_open(BLURAY *bd,
const char *device_path, const char *keyfile_path, const char *device_path, const char *keyfile_path,
void *read_blocks_handle, fs_access *p_fs)
int (*read_blocks)(void *handle, void *buf, int lba, int num_blocks))
{ {
BD_ENC_INFO enc_info; BD_ENC_INFO enc_info;
...@@ -1436,7 +1435,7 @@ static int _bd_open(BLURAY *bd, ...@@ -1436,7 +1435,7 @@ static int _bd_open(BLURAY *bd,
return 0; return 0;
} }
bd->disc = disc_open(device_path, read_blocks_handle, read_blocks, bd->disc = disc_open(device_path, p_fs,
&enc_info, keyfile_path, &enc_info, keyfile_path,
(void*)bd->regs, (void*)bd_psr_read, (void*)bd_psr_write); (void*)bd->regs, (void*)bd_psr_read, (void*)bd_psr_write);
...@@ -1456,7 +1455,7 @@ int bd_open_disc(BLURAY *bd, const char *device_path, const char *keyfile_path) ...@@ -1456,7 +1455,7 @@ int bd_open_disc(BLURAY *bd, const char *device_path, const char *keyfile_path)
return 0; return 0;
} }
return _bd_open(bd, device_path, keyfile_path, NULL, NULL); return _bd_open(bd, device_path, keyfile_path, NULL);
} }
int bd_open_stream(BLURAY *bd, int bd_open_stream(BLURAY *bd,
...@@ -1467,7 +1466,8 @@ int bd_open_stream(BLURAY *bd, ...@@ -1467,7 +1466,8 @@ int bd_open_stream(BLURAY *bd,
return 0; return 0;
} }
return _bd_open(bd, NULL, NULL, read_blocks_handle, read_blocks); fs_access fs = { read_blocks_handle, read_blocks, NULL, NULL };
return _bd_open(bd, NULL, NULL, &fs);
} }
BLURAY *bd_open(const char *device_path, const char *keyfile_path) BLURAY *bd_open(const char *device_path, const char *keyfile_path)
......
...@@ -249,8 +249,7 @@ static void _set_paths(BD_DISC *p, const char *device_path) ...@@ -249,8 +249,7 @@ static void _set_paths(BD_DISC *p, const char *device_path)
} }
BD_DISC *disc_open(const char *device_path, BD_DISC *disc_open(const char *device_path,
void *read_blocks_handle, fs_access *p_fs,
int (*read_blocks)(void *handle, void *buf, int lba, int num_blocks),
struct bd_enc_info *enc_info, struct bd_enc_info *enc_info,
const char *keyfile_path, const char *keyfile_path,
void *regs, void *psr_read, void *psr_write) void *regs, void *psr_read, void *psr_write)
...@@ -258,13 +257,19 @@ BD_DISC *disc_open(const char *device_path, ...@@ -258,13 +257,19 @@ BD_DISC *disc_open(const char *device_path,
BD_DISC *p = _disc_init(); BD_DISC *p = _disc_init();
if (p) { if (p) {
if (p_fs && p_fs->open_dir) {
p->fs_handle = p_fs->fs_handle;
p->pf_file_open_bdrom = p_fs->open_file;
p->pf_dir_open_bdrom = p_fs->open_dir;
}
_set_paths(p, device_path); _set_paths(p, device_path);
#ifdef ENABLE_UDF #ifdef ENABLE_UDF
/* check if disc root directory can be opened. If not, treat it as device/image file. */ /* check if disc root directory can be opened. If not, treat it as device/image file. */
BD_DIR_H *dp_img = device_path ? dir_open(device_path) : NULL; BD_DIR_H *dp_img = device_path ? dir_open(device_path) : NULL;
if (!dp_img) { if (!dp_img) {
void *udf = udf_image_open(device_path, read_blocks_handle, read_blocks); void *udf = udf_image_open(device_path, p_fs ? p_fs->fs_handle : NULL, p_fs ? p_fs->read_blocks : NULL);
if (!udf) { if (!udf) {
BD_DEBUG(DBG_FILE | DBG_CRIT, "failed opening UDF image %s\n", device_path); BD_DEBUG(DBG_FILE | DBG_CRIT, "failed opening UDF image %s\n", device_path);
} else { } else {
...@@ -283,7 +288,6 @@ BD_DISC *disc_open(const char *device_path, ...@@ -283,7 +288,6 @@ BD_DISC *disc_open(const char *device_path,
BD_DEBUG(DBG_FILE, "%s does not seem to be image file or device node\n", device_path); BD_DEBUG(DBG_FILE, "%s does not seem to be image file or device node\n", device_path);
} }
#else #else
(void)read_blocks_handle;
(void)read_blocks; (void)read_blocks;
#endif #endif
......
...@@ -29,6 +29,18 @@ struct bd_file_s; ...@@ -29,6 +29,18 @@ struct bd_file_s;
struct bd_dir_s; struct bd_dir_s;
struct bd_enc_info; struct bd_enc_info;
/* application provided file system access (optional) */
typedef struct fs_access {
void *fs_handle;
/* method 1: block (device) access */
int (*read_blocks)(void *fs_handle, void *buf, int lba, int num_blocks);
/* method 2: file access */
struct bd_dir_s *(*open_dir) (void *fs_handle, const char *rel_path);
struct bd_file_s *(*open_file)(void *fs_handle, const char *rel_path);
} fs_access;
/* /*
* BluRay Virtual File System * BluRay Virtual File System
* *
...@@ -38,8 +50,7 @@ struct bd_enc_info; ...@@ -38,8 +50,7 @@ struct bd_enc_info;
typedef struct bd_disc BD_DISC; typedef struct bd_disc BD_DISC;
BD_PRIVATE BD_DISC *disc_open(const char *device_path, BD_PRIVATE BD_DISC *disc_open(const char *device_path,
void *read_blocks_handle, fs_access *p_fs,
int (*read_blocks)(void *handle, void *buf, int lba, int num_blocks),
struct bd_enc_info *enc_info, struct bd_enc_info *enc_info,
const char *keyfile_path, const char *keyfile_path,
void *regs, void *psr_read, void *psr_write); void *regs, void *psr_read, void *psr_write);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment