Skip to content

Commit

Permalink
Merge pull request #839 from cvmfs/feature-cvmfs-chunked
Browse files Browse the repository at this point in the history
Add support for chunked files available in libcvmfs revision >= 18
  • Loading branch information
btovar committed Jul 7, 2015
2 parents 55df584 + 61e22a5 commit 8df6d18
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions parrot/src/pfs_service_cvmfs.cc
Expand Up @@ -11,6 +11,10 @@ See the file COPYING for details.
#ifndef LIBCVMFS_VERSION
#define LIBCVMFS_VERSION 1
#endif
#ifndef LIBCVMFS_REVISION
#define LIBCVMFS_REVISION 0
#endif


extern "C" {
#include "buffer.h"
Expand Down Expand Up @@ -145,6 +149,26 @@ int compat_cvmfs_open(const char *path) {
#endif
}

pfs_ssize_t compat_cvmfs_read(int fd, void *d, pfs_size_t length, pfs_off_t offset, pfs_off_t last_offset) {
pfs_ssize_t result;

debug(D_LOCAL, "read %d 0x%p %lld %lld", fd, d,(long long)length,(long long)offset);

#if LIBCVMFS_REVISION < 18
if(offset != last_offset)
::lseek64(fd, offset, SEEK_SET);
result =::read(fd, d, length);
#else
result = cvmfs_pread(cvmfs_active_filesystem->cvmfs_ctx, fd, d, length, offset);
if (result < 0) {
errno = -result;
result = -1;
}
#endif

return result;
}

int compat_cvmfs_close(int fd) {
assert (cvmfs_active_filesystem != NULL);
#if LIBCVMFS_VERSION == 1
Expand Down Expand Up @@ -1078,16 +1102,9 @@ class pfs_file_cvmfs:public pfs_file {
}

virtual pfs_ssize_t read(void *d, pfs_size_t length, pfs_off_t offset) {
pfs_ssize_t result;

debug(D_LOCAL, "read %d 0x%p %lld %lld", fd, d,(long long)length,(long long)offset);

if(offset != last_offset)
::lseek64(fd, offset, SEEK_SET);
result =::read(fd, d, length);
pfs_ssize_t result = compat_cvmfs_read(fd, d, length, offset, last_offset);
if(result > 0)
last_offset = offset + result;

return result;
}

Expand Down

0 comments on commit 8df6d18

Please sign in to comment.