Manually mounting an in-memory IFS

QNX SDP8.0TechnotesDeveloperUser

The mount and mount_ifs utilities allow you to mount an IFS from a specified location in memory.

For example, to manually mount a 10 MB IFS located in memory at 0x0F800000:

mount -tifs -ooffset=0x0F800000,size=0xA00000 /dev/mem /ifs2

If you can’t use the utilities (e.g., because they are not safety certified), you can create your own application code to perform the mounting.

An application needs to perform the following steps to mount an in-memory IFS:

  1. Call shm_open() and shm_ctl() to create, configure, and seal a shared memory object that encapsulates the in-memory IFS.
  2. Call shm_create_handle() to create a handle to the shared memory object (shm_handle) for consumption by SYSMGR_PID (i.e., the pid parameter is SYSMGR_PID).
  3. Call close() on the shared memory object file descriptor.
  4. Call mount(), specifying shm_handle, offset, and size in the option string (i.e, using the data parameter).

    The shm_handle value is an integer representation of the shared memory handle created by the call to shm_create_handle().

    The offset value represents an offset from the start of the shared memory region associated with the specified shared memory handle, not a physical address.

For example (with error checking omitted, in the interest of brevity):

shm_handle_t shm_handle;
int shm_fd = shm_open(SHM_ANON, O_RDWR, S_IRUSR | S_IWUSR);

uint64_t offset = physical-offset-of-IFS-in-memory;
uint64_t size = size-of-IFS;

/* Account for non-page-aligned images */
uint64_t pagesize = sysconf(_SC_PAGESIZE);
uint64_t paddr = offset - (offset % pagesize);
offset %= pagesize;

/* With SHMCTL_PHYS, size must be a multiple of the page size */
uint64_t num_pages = (offset + size + pagesize - 1) / pagesize;
uint64_t num_bytes = num_pages * pagesize;

shm_ctl(shm_fd, SHMCTL_PHYS | SHMCTL_SEAL, paddr, num_bytes);
shm_create_handle(shm_fd, SYSMGR_PID, O_RDONLY, &shm_handle, 0);

/* Close fd, so that the handle is the only reference remaining */
close(shm_fd);

snprintf(mountstr, PATH_MAX, "shm_handle=%" PRIu64 ",offset=%" PRIu64 ",size=%" PRIu64, shm_handle, offset, size);

mount(spec, dir, flags, "ifs", mountstr, -1);
Page updated: