Skip to content

Commit

Permalink
Using the mount-trick method. The old link based one was removed.
Browse files Browse the repository at this point in the history
  • Loading branch information
pocomane committed May 7, 2021
1 parent 985d765 commit e6441ef
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 67 deletions.
8 changes: 0 additions & 8 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ arm-linux-gnueabihf-gcc -std=c99 -static -D_XOPEN_SOURCE=700 -o mbc mbc.c
should be able to compile the utility, since it does not have any dependency
(except standard C library and linux interface).

The default utility works by creating symbolic links to the target rom files.
Another system is avaiable, using mount/bind points. To enable this feature, the
source must be compiled defining `USE_MOUNT_POINTS`, e.g. :

```
arm-linux-gnueabihf-gcc -std=c99 -static -DUSE_MOUNT_POINT -D_XOPEN_SOURCE=700 -o mbc mbc.c
```

# Support

Some functionalities need specific support for each system. To handle
Expand Down
2 changes: 0 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ fi

echo "building..."
cd build
arm-linux-musleabihf-gcc -std=c99 -Wall -DUSE_MOUNT_POINTS -D_XOPEN_SOURCE=700 -static -O2 -o mbc_mnt ../mbc.c ||die
arm-linux-musleabihf-strip mbc_mnt ||die
arm-linux-musleabihf-gcc -std=c99 -Wall -D_XOPEN_SOURCE=700 -static -O2 -o mbc ../mbc.c ||die
arm-linux-musleabihf-strip mbc ||die
mkdir -p hook/expose ||die
Expand Down
74 changes: 17 additions & 57 deletions mbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,8 +645,6 @@ static void get_link_path(system_t* sys, char* out, int size) {
}
}

#ifdef USE_MOUNT_POINTS

static int get_aux_rom_path(system_t* sys, char* out, int len){
return (0>= snprintf(out, len, "/%s/%s.%s/%s.%s", MBC_TMP_DIR, sys->id, sys->romext, MBC_LINK_NAM, sys->romext));
}
Expand Down Expand Up @@ -696,9 +694,23 @@ static int filesystem_unbind(const char* path) {
static int rom_link(system_t* sys, char* path) {

// Some cores do not simply list the content of the rom-dir. For example the
// NeoGeo shows the roms by an internal name, not the file one. So the
// best way to handle the rom-dir is to bind it to another dir containing
// just one file.
// NeoGeo shows the roms by an internal name, not the file one. So the best
// way to handle the rom-dir is to create an temporary sub-dir containing
// just one file. The dir must have a name that place it as the first item of
// the list.
//
// Moreover the core base directory could be on a filesystem without symbolic
// links support (e.g. vfat in /media/usb0), so we have to bind-mount a
// feature-full fs in the temporary directory. The bind-mount removal will
// fail until the MiSTer main app ends the loading
//
// Once bind-mounted, whe have two options:
// 1) create a link to the desired (we need to use realpath to allow link
// created from any working-dir)
// 2) make another bind-mount to the target file;
//
// Here we use the system 2)
//

char aux_dir_path[PATH_MAX] = {0};
get_aux_rom_path(sys, aux_dir_path, sizeof(aux_dir_path));
Expand Down Expand Up @@ -762,58 +774,6 @@ static int rom_unlink(system_t* sys) {
return result;
}


#else // USE_MOUNT_POINTS

static int rom_unlink(system_t* sys) {
char rompath[PATH_MAX] = {0};

get_link_path(sys, rompath, sizeof(rompath));
if (unlink(rompath)) return -1;

path_parentize(rompath);
rmdir(rompath); // No issue if error
path_parentize(rompath);
rmdir(rompath); // No issue if error

return 0;
}

static int rom_link(system_t* sys, char* path) {

// Some cores do not simply list the content of the rom-dir. For example the
// NeoGeo shows the roms by an internal name, not the file one. So the
// best way to handle the rom-dir is to bind it to another dir containing
// just one file.

rom_unlink(sys); // It is expected that this can fail in some cases

char rompath[PATH_MAX] = {0};
get_link_path(sys, rompath, sizeof(rompath));

if (mkparent(rompath, 0777) < 0) {
PRINTERR("Can not create %s parent directory\n", rompath);
return -1;
}

char* rpath = realpath(path, 0);
if (!rpath) {
PRINTERR("Can not resolve %s\n", path);
return -1;
}

int ret = symlink(rpath, rompath);
if (0 != ret) {
PRINTERR("Can not link %s -> %s\n", rompath, rpath);
return -1;
}

return 0;
}


#endif // USE_MOUNT_POINTS

static int emulate_system_sequence(system_t* sys) {
if (NULL == sys) {
return -1;
Expand Down

0 comments on commit e6441ef

Please sign in to comment.