*I&Berkeley DB: memp_fopen[P

memp_fopen





#include <db.h>

int5memp_fopen(DB_MPOOL *mp, char *file, u_int32_t flags,6 int mode, size_t pagesize, DB_MPOOL_FINFO *finfop, DB_MPOOLFILE **mpf);





Description



AThe memp_fopen function opens a file in the pool specified by the4DB_MPOOL mp, copying the DB_MPOOLFILE pointerBrepresenting it into the memory location referenced by mpf.

>The file argument is the name of the file to be opened.@If file is NULL, a private file is created that cannot be=shared with any other process (although it may be shared withother threads).

KThe flags and mode arguments specify how files will be opened,and/or created if they do not already exist.SThe flags value is specified by logically OR'ing together one or more of thefollowing values:

[

DB_CREATE
Create any underlying files, as necessary. If the files do not alreadyBexist and the DB_CREATE flag is not specified, the call will fail.Y

DB_NOMMAP
Always copy this file into the local cache instead of mapping it intoCprocess memory (see the description of the mp_mmapsize field1of the DB_ENV structure for further information).?

DB_RDONLY
Open any underlying files for reading only.AAny attempt to write the file using the pool functions will fail,1regardless of the actual permissions of the file.


\All files created by the function memp_fopen are created with mode mode (as describedHin chmod(2)) and modified by the process' umask value at the time$of creation (see umask(2)))).IThe group ownership of created files is based on the system and directory6defaults, and is not further specified by Berkeley DB.

KThe pagesize argument is the size, in bytes, of the unit of transferHbetween the application and the pool, although it is not necessarily the6unit of transfer between the pool and the source file.

?Files opened in the pool may be further configured based on the8finfop argument to memp_fopen, which is a pointer'to a structure of type DB_MPOOL_FINFO).KNo references to the finfop structure are maintained by Berkeley DB,<so it may be discarded when the memp_fopen function returns.PIn order to ensure compatibility with future releases of Berkeley DB, all fieldsEof the DB_MPOOL_FINFO structure that are not explicitly set should be=initialized to 0 before the first time the structure is used.HDo this by declaring the structure external or static, or by calling the6C library routine bzero(3) or memset(3).

AThe fields of the DB_MPOOL_FINFO structure used by memp_fopen areCdescribed below. If finfop is NULL or any of its fields areIset to their default value, defaults appropriate for the system are used.

Y

int ftype;
The ftype field should be the same as a ftype argumentppreviously specified to the memp_register function, unless noKinput or output processing of the file's pages are necessary, in which caseit should be 0.i(See the description of the memp_register function formore information.)a

DBT *pgcookie;
The pgcookie field contains the byte string that is passed to theDpgin and pgout functions for this file, if any. If noHpgin or pgout functions are specified, the pgcookiefield should be NULL.n(See the description of the memp_register function for more information.)X

u_int8_t *fileid;
The fileid field is a unique identifier for the file.IThe mpool functions must be able to uniquely identify files in order thatLmultiple processes sharing a file will correctly share its underlying pages.HNormally, the fileid field should be NULL and the mpool functionsFwill use the file's device and inode numbers (see stat(2))) forLthis purpose. On some filesystems, (e.g., FAT or NFS) file device and inode9numbers are not necessarily unique across system reboots.

MApplications wanting to maintain a shared memory buffer pool across systemMreboots, where the pool contains pages from files stored on such filesystems,@must specify a unique file identifier to the memp_fopen call andBeach process opening or registering the file must provide the sameunique identifier.

JIf the fileid field is non-NULL, it must reference a DB_FILE_ID_LENFlength array of bytes that will be used to uniquely identify the file.HThis should not be necessary for most applications. Specifically, it isEnot necessary if the memory pool is re-instantiated after each systemJreboot, the application is using the Berkeley DB access methods instead ofFcalling the pool functions explicitly, or the files in the memory poolHare stored on filesystems where the file device and inode numbers do notchange across system reboots.f

int32_t lsn_offset;
The lsn_offset field is the zero-based byte offset in the page ofJthe page's log sequence number (LSN), or -1 if no LSN offset is specified.c(See the description of the memp_sync function for more information.)b

u_int32_t clear_len;
The clear_len field is the number of initial bytes in a pageFthat should be set to zero when the page is created as a result of therDB_MPOOL_CREATE or DB_MPOOL_NEW flags being specified to memp_fget.EIf finfop is NULL or clear_len is 0, the entire page iscleared.


The memp_fopenHfunction returns the value of errno on failure, and 0 on success.



Errors

SIf a fatal error occurs in Berkeley DB, the memp_fopen function may fail and returnFDB_RUNRECOVERY, at which point all subsequent database calls will alsoreturn DB_RUNRECOVERY.

The memp_fopen)function may fail and return errnoKfor any of the errors specified for the following Berkeley DB and C library functions:DBmemp->pgin(3),DBmemp->pgout(3), abort(3), close(3),dbenv->db_paniccall(3), fcntl(3), fflush(3), fprintf(3),free(3), fstat(3), fsync(3), getenv(3), getpid(3), getuid(3), isdigit(3),9log_compare,5log_flush, lseek(3), malloc(3), memcmp(3), memcpy(3), memset(3),mmap(3),open(3), pread(3),pstat_getdynamic(3), pwrite(3),read(3),sigfillset(3),sigprocmask(3),stat(3), strerror(3), strlen(3), sysconf(3),time(3), unlink(3), vfprintf(3), vsnprintf(3),and write(3).

In addition, the memp_fopen)function may fail and return errnofor the following conditions:

B

EINVAL
An invalid flag value or parameter was specified.

HThe file has already been entered into the pool, and the pagesizeHvalue is not the same as when the file was entered into the pool, or theDlength of the file is not zero or a multiple of the pagesize.

7The DB_RDONLY flag was specified for an in-memory pool.





See Also

8memp_close,=memp_fclose,!9memp_fget,s memp_fopen,9memp_fput,e9memp_fset,y;memp_fsync,e6memp_open,Amemp_register,g6memp_stat,6memp_stat,6memp_sync,;memp_trickle andt:memp_unlink.
>i˙˙ion

AThe memp_fopen function opens a file in the pool specified by the4DB_MPOOL mp, copying the DB_MPOOLFILE pointerBrepresenting it into the memory location referenced by mpf.

>The file argument is the name of the file to be ope