ebmDevMag.com home
ebm Developer's Magazine
links

developer's mag
main page

article
part 1
part 2
part 3
part 4
part 5
part 6


2 - Open Up!

First we'll examine the nuts and bolts of opening a file - the call is ebo_mapin():

int  ebo_mapin(const ebo_name_t *,off_t objbase,void *vmbase,size_t *size,int rw) 

First parameter is of type ebo_name_t, which is the structure that uniquely defines every ebm file:

struct ebo_name_t
{
char secure_type[EBO_LEN_STYPE]; // 2 char max (1 char & null byte)
char publisher[EBO_LEN_PUB]; // 31+1 char long
char name[EBO_LEN_NAME]; // 63+1 char long
char extension[EBO_LEN_EXT]; // 31+1 char long
};

objbase is the base mapping address of your file. Unless there is some need to map in only part of a file, this should left zero, to map from your file's start.

vmbase is a pointer to the memory location (mapping) start - this variable is going to be your pointer to the memory mapping. Beware of using just any value here; first off, it must be an even multiple of the virtual memory block size (currently 4k, and defined in code as EBO_BLK_SIZE), and it must also be a memory address your program isn't using. You can accomplish both with the line

void *ptr=(void*)ebo_roundup(OS_availaddr));

ebo_roundup() is a macro to make sure a memory address is even with the 4k virtual memory page; OS_availaddr is a variable that indicates the upper memory used by your program. Virtual memory extends for about four gigabytes (the first gigabyte of which is available to the programmer), so the ceiling isn't usually a problem, but you must use this variable to coordinate with the operating system as to what memory is available for use. This is accomplished by increasing this value by the size of your file, so as to protect the memory from reuse.

The next value is the size. Note that this parameter is a pointer to a variable, so it can return a value as well. You start by defining the maximum size you feel the file will need; once opened, the OS returns the actual file size in this pointer. You can pass any large value to this function; however, plan to reuse the original value to adjust the OS_availaddr value to mark this memory in use.

Finally, you pass a read/write flag. If one, the file is opened for read-write access; zero is read-only. But before you go ahead and open all files read-write for simplicity, remember that the file's timestamp will be updated, and this will mark it for synchronization to your P.C. next time you use the File Manager. Unless you want this, it's a time-consuming operation you can avoid by opening read-only.

The return value of ebo_mapin() indicates failure if less than zero, and success otherwise.

Previous Section
Next Section

Copyright © 2001-2006 ebmDevMag.com - Legal Notice