1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-12 09:18:10 +03:00

Fix based on Andrew's insight as re-using a tdb after fork means

parent and child share seek pointer. Damn....
Jeremy.
(This used to be commit 0e75c0fc1a)
This commit is contained in:
Jeremy Allison 2001-09-19 03:33:47 +00:00
parent 3e9bcd111d
commit af0d86a9fc

View File

@ -281,8 +281,12 @@ static int tdb_write(TDB_CONTEXT *tdb, tdb_off off, void *buf, tdb_len len)
if (tdb->map_ptr)
memcpy(off + (char *)tdb->map_ptr, buf, len);
#ifdef HAVE_PWRITE
else if (pwrite(tdb->fd, buf, len, off) != (ssize_t)len) {
#else
else if (lseek(tdb->fd, off, SEEK_SET) != off
|| write(tdb->fd, buf, len) != (ssize_t)len) {
#endif
TDB_LOG((tdb, 0,"tdb_write failed at %d len=%d (%s)\n",
off, len, strerror(errno)));
return TDB_ERRCODE(TDB_ERR_IO, -1);
@ -298,8 +302,12 @@ static int tdb_read(TDB_CONTEXT *tdb,tdb_off off,void *buf,tdb_len len,int cv)
if (tdb->map_ptr)
memcpy(buf, off + (char *)tdb->map_ptr, len);
#ifdef HAVE_PREAD
else if (pread(tdb->fd, buf, len, off) != (ssize_t)len) {
#else
else if (lseek(tdb->fd, off, SEEK_SET) != off
|| read(tdb->fd, buf, len) != (ssize_t)len) {
#endif
TDB_LOG((tdb, 0,"tdb_read failed at %d len=%d (%s)\n",
off, len, strerror(errno)));
return TDB_ERRCODE(TDB_ERR_IO, -1);
@ -602,27 +610,39 @@ static int expand_file(TDB_CONTEXT *tdb, tdb_off size, tdb_off addition)
}
#else
char b = 0;
#ifdef HAVE_PWRITE
if (pwrite(tdb->fd, &b, 1, (size+addition) - 1) != 1) {
#else
if (lseek(tdb->fd, (size+addition) - 1, SEEK_SET) != (size+addition) - 1 ||
write(tdb->fd, &b, 1) != 1) {
#endif
TDB_LOG((tdb, 0, "expand_file to %d failed (%s)\n",
size+addition, strerror(errno)));
return -1;
}
#endif
/* now fill the file with something. This ensures that the file isn't sparse, which would be
very bad if we ran out of disk. This must be done with write, not via mmap */
memset(buf, 0x42, sizeof(buf));
if (lseek(tdb->fd, size, SEEK_SET) != size)
return -1;
while (addition) {
int n = addition>sizeof(buf)?sizeof(buf):addition;
int ret = write(tdb->fd, buf, n);
#ifdef HAVE_PWRITE
int ret = pwrite(tdb->fd, buf, n, size);
#else
int ret;
if (lseek(tdb->fd, size, SEEK_SET) != size)
return -1;
ret = write(tdb->fd, buf, n);
#endif
if (ret != n) {
TDB_LOG((tdb, 0, "expand_file write of %d failed (%s)\n",
n, strerror(errno)));
return -1;
}
addition -= n;
size += n;
}
return 0;
}