tdb/tdb.c: tdb_oob() significance (when not using MMAP)

dhruva dhruvakm at gmail.com
Tue Oct 17 11:48:12 GMT 2006


Hi,
 If we are not using MMAP for writing TDB files (using lseek & write),
does tdb_oob() still have any significance? Since a call to lseek() &
write() will expand the file if the file is shorter than the length,
IMHO, the out of bound check may not be required. Can we put a #ifdef
HAVE_MMAP inside the implementation of tdb_oob() and return '0' is
HAVE_MMAP is not defined?

 On VMS port, we are finding some cases where the call to stat returns
a size smaller than the total lenght (file pointer offset + size of
data to be written). I initially thought of calling ftruncate() to
increase the file size in tdb_oob() which worked. I have a basic doubt
on the relevance of tdb_oob() when not using MMAP.

Proposed change (only the ifdef blocks):

static int tdb_oob(TDB_CONTEXT *tdb, tdb_off len, int probe)
{
#ifdef HAVE_MMAP /* Proposed change */
	struct stat st;
	if (len <= tdb->map_size)
		return 0;
	if (tdb->flags & TDB_INTERNAL) {
		if (!probe) {
			/* Ensure ecode is set for log fn. */
			tdb->ecode = TDB_ERR_IO;
			TDB_LOG((tdb, 0,"tdb_oob len %d beyond internal malloc size %d\n",
				 (int)len, (int)tdb->map_size));
		}
		return TDB_ERRCODE(TDB_ERR_IO, -1);
	}

	if (fstat(tdb->fd, &st) == -1)
		return TDB_ERRCODE(TDB_ERR_IO, -1);

	if (st.st_size < (size_t)len) {
		if (!probe) {
			/* Ensure ecode is set for log fn. */
			tdb->ecode = TDB_ERR_IO;
			TDB_LOG((tdb, 0,"tdb_oob len %d beyond eof at %d\n",
				 (int)len, (int)st.st_size));
		}
		return TDB_ERRCODE(TDB_ERR_IO, -1);
	}

	/* Unmap, update size, remap */
	if (tdb_munmap(tdb) == -1)
		return TDB_ERRCODE(TDB_ERR_IO, -1);
	tdb->map_size = st.st_size;
	tdb_mmap(tdb);
#endif /* Proposed change */
	return 0;
}
with best regards,
dk

-- 
dhruva (dk)
Contents reflect my personal views only!


More information about the samba-technical mailing list