File rgfs.c changed (mode: 100644) (index 065c688..b93d051) |
... |
... |
static int rgfs_recv_hl(const char *op, void *buf, size_t buf_size) |
425 |
425 |
return off; |
return off; |
426 |
426 |
|
|
427 |
427 |
off += r; |
off += r; |
428 |
|
if (off >= 4) { |
|
|
428 |
|
if ((to_read == 0) && (off >= 4)) { |
429 |
429 |
to_read = be32toh(*(uint32_t *) buf); |
to_read = be32toh(*(uint32_t *) buf); |
430 |
430 |
xlog("to_read=%u\n", to_read); |
xlog("to_read=%u\n", to_read); |
431 |
431 |
} |
} |
432 |
432 |
|
|
433 |
433 |
if (rgfs_debug > 10) { |
if (rgfs_debug > 10) { |
434 |
434 |
char debug[4096 * 2 + 1]; |
char debug[4096 * 2 + 1]; |
435 |
|
uint16_t max = off > 4096 ? 4096 : off; |
|
|
435 |
|
uint16_t max = r > 4096 ? 4096 : r; |
436 |
436 |
for (uint16_t i = 0; i < max; i++) |
for (uint16_t i = 0; i < max; i++) |
437 |
|
sprintf(debug + i * 2, "%02hhx", * (unsigned char *) (buf + i)); |
|
438 |
|
xlog(" %s: RECV %u: %s\n", op, off, debug); |
|
|
437 |
|
sprintf(debug + i * 2, "%02hhx", |
|
438 |
|
* (unsigned char *) (buf + off - r + i)); |
|
439 |
|
xlog(" %s: RECV now=%d total=%u: now: %s\n", |
|
440 |
|
op, r, off, debug); |
439 |
441 |
} |
} |
440 |
442 |
|
|
441 |
443 |
if (off == 4 + to_read) { |
if (off == 4 + to_read) { |
442 |
|
xlog(" Readed 4 + %u\n", to_read); |
|
|
444 |
|
xlog(" Readed 4 + %u; return %lu\n", to_read, off); |
443 |
445 |
return off; |
return off; |
444 |
446 |
} |
} |
445 |
447 |
} |
} |
|
... |
... |
static int rgfs_fuse_read(const char *path, char *out, size_t size, |
597 |
599 |
off_t offset, struct fuse_file_info *fi) |
off_t offset, struct fuse_file_info *fi) |
598 |
600 |
{ |
{ |
599 |
601 |
int r, err = 0, i; |
int r, err = 0, i; |
600 |
|
unsigned char buf[16 * 4096], cmd; |
|
|
602 |
|
unsigned char buf[16 * 4096], cmd; // TODO: size is 65536, so, just use size + 1 + 4 |
601 |
603 |
uint16_t path_len, len; |
uint16_t path_len, len; |
602 |
604 |
uint64_t u64; |
uint64_t u64; |
603 |
605 |
|
|
|
... |
... |
static int rgfs_fuse_read(const char *path, char *out, size_t size, |
606 |
608 |
path, size, offset); |
path, size, offset); |
607 |
609 |
|
|
608 |
610 |
// Limit how much data we request to the server |
// Limit how much data we request to the server |
609 |
|
// 1 + 4 + 8 is the answer's header. |
|
610 |
|
if (size > sizeof(buf) - 1 - 4) |
|
611 |
|
size = sizeof(buf) - 1 - 4; |
|
|
611 |
|
// 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 |
|
} |
612 |
616 |
|
|
613 |
617 |
path_len = strlen(path); |
path_len = strlen(path); |
614 |
618 |
len = 1 + 2 + 8 + 8; |
len = 1 + 2 + 8 + 8; |
|
... |
... |
static int rgfs_fuse_read(const char *path, char *out, size_t size, |
634 |
638 |
switch (cmd) { |
switch (cmd) { |
635 |
639 |
case 0x00: err = - be32toh(*(uint32_t *) (buf + i)); break; |
case 0x00: err = - be32toh(*(uint32_t *) (buf + i)); break; |
636 |
640 |
case 0x01: /* block */ |
case 0x01: /* block */ |
637 |
|
xlog(" received %llu bytes block\n", r - i); |
|
638 |
641 |
memcpy(out, buf + i, r - i); |
memcpy(out, buf + i, r - i); |
639 |
642 |
err = r - i; |
err = r - i; |
640 |
643 |
break; |
break; |
|
... |
... |
static int rgfs_fuse_read(const char *path, char *out, size_t size, |
642 |
645 |
} |
} |
643 |
646 |
} |
} |
644 |
647 |
|
|
645 |
|
if (err < 0) |
|
646 |
|
xlog(" server returned error %d!\n", err); |
|
|
648 |
|
xlog(" returning %d\n", err); |
647 |
649 |
|
|
648 |
650 |
return err; |
return err; |
649 |
651 |
} |
} |