psb
psb

Reputation: 402

Make executable-embedded binary blob accessible as a filesystem file while app runs. C/C++

The expected steps is somewhat like (let's assume we only target Linux, for simplicity):

  1. Embed some binary blob into an C/C++ executable at compile time. [ok, can do this].
  2. When app runs embedded blobs are made available to other programs as a read-only files on a filesystem with an app defined paths and filenames (e.g. somewhere like "/tmp/my_embedded_resource.bin"). [fmemopen and then ... ?]
  3. When app quits (even if it crashes) those read-only "files" (links?) are automatically removed.

So, the gist of this question is inside points (2) and (3) above.

Thanks in advance.

Upvotes: 0

Views: 425

Answers (2)

jordanvrtanoski
jordanvrtanoski

Reputation: 5557

What you are looking for is FUSE - Filesystem in Userspace.

FUSE allows you to create a file system that will be exported by the application running in the user space (no need for kernel modules).

Following is link toward the hello world FUSE example, and will be a good starting pint.

You will need to create custom functions as follows:

  • readdir function should return the files that are located in the virtual directory,
  • open and read should provide the content of the files
  • getattr should provides the file attributes and
  • init will be called by FUSE to initialize the resources for the FS

FUSE is *nix library available for Linux and macOS.

Upvotes: 1

Keyword: Shared Memory Objects

Have a look at shm_open.

Upvotes: 1

Related Questions