(ef_close): Reset member fd.

(ef_open): Catch attempt to open open file.
This commit is contained in:
Markus Armbruster 2005-10-23 06:24:08 +00:00
parent a3dd70f8c0
commit bfd14661c5
2 changed files with 6 additions and 2 deletions

View file

@ -46,7 +46,7 @@ struct empfile {
void (*init) (int, char *); /* call this when object is created */ void (*init) (int, char *); /* call this when object is created */
int (*postread) (int, char *); /* specific massage routines for items */ int (*postread) (int, char *); /* specific massage routines for items */
int (*prewrite) (int, char *); int (*prewrite) (int, char *);
int fd; /* file descriptor */ int fd; /* file descriptor, -1 if not open */
int baseid; /* starting item in cache */ int baseid; /* starting item in cache */
int cids; /* # ids in cache */ int cids; /* # ids in cache */
int csize; /* size of cache in bytes */ int csize; /* size of cache in bytes */

View file

@ -49,10 +49,11 @@
static void fillcache(struct empfile *ep, int start); static void fillcache(struct empfile *ep, int start);
/* /*
* Open a the file for table TYPE (EF_SECTOR, ...). * Open the binary file for table TYPE (EF_SECTOR, ...).
* MODE is passed to open(). * MODE is passed to open().
* HOW are EFF_OPEN flags to control operation. * HOW are EFF_OPEN flags to control operation.
* Return non-zero on success, zero on failure. * Return non-zero on success, zero on failure.
* You must call ef_close() before the next ef_open().
*/ */
int int
ef_open(int type, int mode, int how) ef_open(int type, int mode, int how)
@ -68,6 +69,8 @@ ef_open(int type, int mode, int how)
if (CANT_HAPPEN(how & ~EFF_OPEN)) if (CANT_HAPPEN(how & ~EFF_OPEN))
how &= EFF_OPEN; how &= EFF_OPEN;
ep = &empfile[type]; ep = &empfile[type];
if (CANT_HAPPEN(ep->fd >= 0))
return 0;
if ((ep->fd = open(ep->file, mode, 0660)) < 0) { if ((ep->fd = open(ep->file, mode, 0660)) < 0) {
logerror("%s: open failed", ep->file); logerror("%s: open failed", ep->file);
return 0; return 0;
@ -121,6 +124,7 @@ ef_close(int type)
if ((r = close(ep->fd)) < 0) { if ((r = close(ep->fd)) < 0) {
logerror("ef_close: %s close(%d) -> %d", ep->name, ep->fd, r); logerror("ef_close: %s close(%d) -> %d", ep->name, ep->fd, r);
} }
ep->fd = -1;
return 1; return 1;
} }