diff --git a/sdbfs/lib/access.c b/sdbfs/lib/access.c index fbaf97b38866cd52d88ce864a01be40c5da3cc40..9b47ecb66a92c6e3e95c5f6be1f2610b03c9970e 100644 --- a/sdbfs/lib/access.c +++ b/sdbfs/lib/access.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012 CERN (www.cern.ch) + * Copyright (C) 2012,2013 CERN (www.cern.ch) * Author: Alessandro Rubini <rubini@gnudd.com> * * Released according to the GNU GPL, version 2 or any later version. @@ -19,8 +19,10 @@ int sdbfs_fstat(struct sdbfs *fs, struct sdb_device *record_return) return 0; } -int sdbfs_fread(struct sdbfs *fs, int offset, char *buf, int count) +int sdbfs_fread(struct sdbfs *fs, int offset, void *buf, int count) { + int ret = count; + if (!fs->currentp) return -ENOENT; if (offset < 0) @@ -30,12 +32,27 @@ int sdbfs_fread(struct sdbfs *fs, int offset, char *buf, int count) if (fs->data) memcpy(buf, fs->data + fs->f_offset + offset, count); else - fs->read(fs, fs->f_offset + offset, buf, count); - fs->read_offset = offset + count; - return count; + ret = fs->read(fs, fs->f_offset + offset, buf, count); + if (ret > 0) + fs->read_offset = offset + ret; + return ret; } -int sdbfs_fwrite(struct sdbfs *fs, int offset, char *buf, int count) +int sdbfs_fwrite(struct sdbfs *fs, int offset, void *buf, int count) { - return -ENOSYS; + int ret = count; + + if (!fs->currentp) + return -ENOENT; + if (offset < 0) + offset = fs->read_offset; + if (offset + count > fs->f_len) + count = fs->f_len - offset; + if (fs->data) + memcpy(buf, fs->data + fs->f_offset + offset, count); + else + ret = fs->write(fs, fs->f_offset + offset, buf, count); + if (ret > 0) + fs->read_offset = offset + ret; + return ret; } diff --git a/sdbfs/lib/glue.c b/sdbfs/lib/glue.c index a7d47ab7dd95ef442c453547a6892308166da0dd..4a57bfc1c46bc5fa8ee33d64eebc631798206adc 100644 --- a/sdbfs/lib/glue.c +++ b/sdbfs/lib/glue.c @@ -74,6 +74,8 @@ static struct sdb_device *sdbfs_readentry(struct sdbfs *fs, */ if (fs->data) return (struct sdb_device *)(fs->data + offset); + if (!fs->read) + return NULL; fs->read(fs, offset, &fs->current_record, sizeof(fs->current_record)); return &fs->current_record; } diff --git a/sdbfs/lib/libsdbfs.h b/sdbfs/lib/libsdbfs.h index c41684d4d23e5133a80df1c91535b901cb06cffe..698c7703c343c127cdbe95a36bd35af4694cd3d7 100644 --- a/sdbfs/lib/libsdbfs.h +++ b/sdbfs/lib/libsdbfs.h @@ -59,8 +59,8 @@ struct sdb_device *sdbfs_scan(struct sdbfs *fs, int newscan); /* Defined in access.c */ int sdbfs_fstat(struct sdbfs *fs, struct sdb_device *record_return); -int sdbfs_fread(struct sdbfs *fs, int offset, char *buf, int count); -int sdbfs_fwrite(struct sdbfs *fs, int offset, char *buf, int count); +int sdbfs_fread(struct sdbfs *fs, int offset, void *buf, int count); +int sdbfs_fwrite(struct sdbfs *fs, int offset, void *buf, int count); /* This is needed to convert endianness. Hoping it is not defined elsewhere */ static inline uint64_t htonll(uint64_t ll)