File rgfs.c changed (mode: 100644) (index b93d051..de28b26) |
... |
... |
static int rgfs_recv_hl(const char *op, void *buf, size_t buf_size) |
415 |
415 |
while (1) { |
while (1) { |
416 |
416 |
xlog(" Waiting for data (off=%d to_read=%u)\n", off, to_read); |
xlog(" Waiting for data (off=%d to_read=%u)\n", off, to_read); |
417 |
417 |
if (off == buf_size) { |
if (off == buf_size) { |
418 |
|
xlog("Buffer is too small!\n"); |
|
|
418 |
|
xlog(" Buffer is too small!\n"); |
419 |
419 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
420 |
420 |
} |
} |
421 |
421 |
r = rgfs_recv(buf + off, buf_size - off); |
r = rgfs_recv(buf + off, buf_size - off); |
|
... |
... |
static int rgfs_recv_hl(const char *op, void *buf, size_t buf_size) |
427 |
427 |
off += r; |
off += r; |
428 |
428 |
if ((to_read == 0) && (off >= 4)) { |
if ((to_read == 0) && (off >= 4)) { |
429 |
429 |
to_read = be32toh(*(uint32_t *) buf); |
to_read = be32toh(*(uint32_t *) buf); |
430 |
|
xlog("to_read=%u\n", to_read); |
|
|
430 |
|
xlog(" to_read=%u\n", to_read); |
431 |
431 |
} |
} |
432 |
432 |
|
|
433 |
433 |
if (rgfs_debug > 10) { |
if (rgfs_debug > 10) { |
|
... |
... |
static int rgfs_recv_hl(const char *op, void *buf, size_t buf_size) |
441 |
441 |
} |
} |
442 |
442 |
|
|
443 |
443 |
if (off == 4 + to_read) { |
if (off == 4 + to_read) { |
444 |
|
xlog(" Readed 4 + %u; return %lu\n", to_read, off); |
|
|
444 |
|
xlog(" Readed 4 + %u; return %lu\n", to_read, off); |
445 |
445 |
return off; |
return off; |
446 |
446 |
} |
} |
447 |
447 |
} |
} |
|
... |
... |
static int rgfs_fuse_read(const char *path, char *out, size_t size, |
599 |
599 |
off_t offset, struct fuse_file_info *fi) |
off_t offset, struct fuse_file_info *fi) |
600 |
600 |
{ |
{ |
601 |
601 |
int r, err = 0, i; |
int r, err = 0, i; |
602 |
|
unsigned char buf[16 * 4096], cmd; // TODO: size is 65536, so, just use size + 1 + 4 |
|
603 |
|
uint16_t path_len, len; |
|
|
602 |
|
unsigned char *buf, cmd; |
|
603 |
|
uint16_t path_len, len, min; |
604 |
604 |
uint64_t u64; |
uint64_t u64; |
605 |
605 |
|
|
606 |
606 |
(void) fi; |
(void) fi; |
607 |
607 |
xlog("read: path=%s size=%zu offset=%zd\n", |
xlog("read: path=%s size=%zu offset=%zd\n", |
608 |
608 |
path, size, offset); |
path, size, offset); |
609 |
609 |
|
|
|
610 |
|
path_len = strlen(path); |
|
611 |
|
len = 1 + 2 + 8 + 8 + path_len; |
|
612 |
|
min = 4 + 1 + size; |
|
613 |
|
if (min < len) |
|
614 |
|
min = len; |
|
615 |
|
|
610 |
616 |
// Limit how much data we request to the server |
// Limit how much data we request to the server |
611 |
617 |
// 4 + 1 is the answer's header. |
// 4 + 1 is the answer's header. |
612 |
|
if (size > sizeof(buf) - 4 - 1) { |
|
613 |
|
size = sizeof(buf) - 4 - 1; |
|
614 |
|
xlog(" truncated size to %zu\n", size); |
|
615 |
|
} |
|
616 |
|
|
|
617 |
|
path_len = strlen(path); |
|
618 |
|
len = 1 + 2 + 8 + 8; |
|
619 |
|
if (path_len > sizeof(buf) - len) { |
|
620 |
|
xlog(" buffer too small\n"); |
|
|
618 |
|
buf = malloc(min); |
|
619 |
|
if (!buf) { |
|
620 |
|
xlog(" cannot alloc memory!\n"); |
621 |
621 |
return -EIO; |
return -EIO; |
622 |
622 |
} |
} |
623 |
|
len += path_len; |
|
624 |
623 |
|
|
625 |
624 |
i = 0; |
i = 0; |
626 |
625 |
buf[i++] = 0x04; |
buf[i++] = 0x04; |
|
... |
... |
static int rgfs_fuse_read(const char *path, char *out, size_t size, |
645 |
644 |
} |
} |
646 |
645 |
} |
} |
647 |
646 |
|
|
|
647 |
|
free(buf); |
|
648 |
|
|
648 |
649 |
xlog(" returning %d\n", err); |
xlog(" returning %d\n", err); |
649 |
650 |
|
|
650 |
651 |
return err; |
return err; |