Skip to content

Commit a2f5ae3

Browse files
committed
Fixing the logic between the sqlite3 stmt and the calls to sqlite3_step()
1 parent 3fba46c commit a2f5ae3

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

example/example.sqlite

0 Bytes
Binary file not shown.

src/fs.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,8 @@ crypt4gh_sqlite_open(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)
546546
}
547547

548548
found = 1;
549+
err = 0;
550+
break; /* leave the stmt as-is now, don't call sqlite3_step() */
549551
}
550552

551553
if(err || !found){
@@ -592,8 +594,8 @@ struct fuse_bufvec3 {
592594
static int c4gh_read(off_t offset, size_t size, struct fs_file *fh, char* b);
593595

594596
static void
595-
crypt4gh_sqlite_read(fuse_req_t req, fuse_ino_t ino, size_t size,
596-
off_t offset, struct fuse_file_info *fi)
597+
crypt4gh_sqlite_read(fuse_req_t req, fuse_ino_t ino,
598+
size_t size, off_t offset, struct fuse_file_info *fi)
597599
{
598600
D1("READ ino:%lu | offset: %zu | size: %zu", ino, offset, size);
599601
struct fs_file *fh = (struct fs_file *)fi->fh;
@@ -612,7 +614,7 @@ crypt4gh_sqlite_read(fuse_req_t req, fuse_ino_t ino, size_t size,
612614
*/
613615

614616
size_t limit = offset + size;
615-
size_t append_offset = fh->prepend_size + fh->payload_size;
617+
size_t append_start = fh->prepend_size + fh->payload_size;
616618

617619
struct fuse_buf *prepend_fbuf = NULL, *append_fbuf = NULL, *data_fbuf = NULL;
618620
size_t prepend_len = 0;
@@ -632,35 +634,33 @@ crypt4gh_sqlite_read(fuse_req_t req, fuse_ino_t ino, size_t size,
632634
/* memset(prepend_fbuf, '\0', sizeof(struct fuse_buf)); */
633635

634636
prepend_fbuf->size = prepend_len;
635-
//prepend_fbuf->flags = 0;
636637
prepend_fbuf->mem = fh->prepend + offset;
637-
//prepend_fbuf->pos = offset; // not used with .mem
638-
639638
}
639+
D3("prepend_len: %zu | prepend size: %zu", prepend_len, fh->prepend_size);
640640

641641
/* Prepare append data */
642-
if(fh->append != NULL && limit > append_offset) {
642+
if(fh->append != NULL && limit > append_start) {
643643

644-
append_len = (limit - append_offset);
644+
append_len = limit - append_start;
645645
if ( size < append_len )
646646
append_len = size;
647+
if(append_len > fh->append_size)
648+
append_len = fh->append_size;
647649

648650
append_fbuf = (struct fuse_buf *)calloc(1, sizeof(struct fuse_buf));
649651
if(!append_fbuf){ err = -ENOMEM; goto error; }
650652
/* memset(append_fbuf, '\0', sizeof(struct fuse_buf)); */
651-
653+
654+
off_t append_offset = (offset < append_start) ? 0 : (offset - append_start);
652655
append_fbuf->size = append_len;
653-
//append_fbuf->flags = 0;
654-
append_fbuf->mem = fh->append + ((offset < append_offset) ? 0 : (offset - append_offset));
655-
//append_fbuf->pos = ((offset < append_offset) ? 0 : (offset - append_offset)); // not used with .mem
656-
656+
append_fbuf->mem = fh->append + append_offset;
657+
D3("append offset: %ld", append_offset);
658+
657659
}
658-
659-
D3("prepend_len: %zu | prepend size: %zu", prepend_len, fh->prepend_size);
660660
D3("append_len: %zu | append size: %zu", append_len, fh->append_size);
661661

662662
/* Now the data */
663-
if(limit > fh->prepend_size && offset < append_offset
663+
if(limit > fh->prepend_size && offset < append_start
664664
&& fh->payload_size > 0){
665665

666666
size_t data_offset = offset + prepend_len - fh->prepend_size;

0 commit comments

Comments
 (0)