Logging fixes

This commit is contained in:
Michal Moskal 2017-07-25 15:28:28 +01:00
parent d84b2b187c
commit 7960c9f15e
3 changed files with 24 additions and 19 deletions

View File

@ -36,7 +36,7 @@
#include "uf2.h" #include "uf2.h"
#define DBG printf #define DBG LOG
typedef struct { typedef struct {
uint8_t JumpInstruction[3]; uint8_t JumpInstruction[3];
@ -592,6 +592,7 @@ void readBlock(uint8_t *dest, int blkno) {
if (fd >= 0) { if (fd >= 0) {
lseek(fd, bl->targetAddr, SEEK_SET); lseek(fd, bl->targetAddr, SEEK_SET);
bl->payloadSize = read(fd, bl->data, 256); bl->payloadSize = read(fd, bl->data, 256);
close(fd);
} else { } else {
bl->payloadSize = -1; bl->payloadSize = -1;
} }

View File

@ -21,20 +21,9 @@
#define NUM_BLOCKS NUM_FAT_BLOCKS #define NUM_BLOCKS NUM_FAT_BLOCKS
#define FAIL(args...) \ uint64_t ntohll(uint64_t a) {
do { \ return ((uint64_t)ntohl(a & 0xffffffff) << 32) | ntohl(a >> 32);
fprintf(stderr, args); \ }
fprintf(stderr, "\n"); \
exit(1); \
} while (0)
#define LOG(args...) \
do { \
fprintf(stderr, args); \
fprintf(stderr, "\n"); \
} while (0)
uint64_t ntohll(uint64_t a) { return ((uint64_t)ntohl(a & 0xffffffff) << 32) | ntohl(a >> 32); }
#define htonll ntohll #define htonll ntohll
void readAll(int fd, void *dst, uint32_t length) { void readAll(int fd, void *dst, uint32_t length) {
@ -82,9 +71,8 @@ void startclient() {
void handleread(int off, int len) { void handleread(int off, int len) {
uint8_t buf[512]; uint8_t buf[512];
// fprintf(stderr, "read @%d len=%d\n", off, len); LOG("read @%d len=%d", off, len);
// htonl(EPERM); reply.error = 0; // htonl(EPERM);
reply.error = 0;
writeAll(sock, &reply, sizeof(struct nbd_reply)); writeAll(sock, &reply, sizeof(struct nbd_reply));
for (int i = 0; i < len; ++i) { for (int i = 0; i < len; ++i) {
read_block(off + i, buf); read_block(off + i, buf);
@ -94,7 +82,7 @@ void handleread(int off, int len) {
void handlewrite(int off, int len) { void handlewrite(int off, int len) {
uint8_t buf[512]; uint8_t buf[512];
// fprintf(stderr, "write @%d len=%d\n", off, len); LOG("write @%d len=%d", off, len);
for (int i = 0; i < len; ++i) { for (int i = 0; i < len; ++i) {
readAll(sock, buf, 512); readAll(sock, buf, 512);
write_block(off + i, buf); write_block(off + i, buf);

View File

@ -34,4 +34,20 @@ void readAll(int fd, void *dst, uint32_t length);
STATIC_ASSERT(sizeof(UF2_Block) == 512); STATIC_ASSERT(sizeof(UF2_Block) == 512);
#define FAIL(args...) \
do { \
fprintf(stderr, args); \
fprintf(stderr, "\n"); \
exit(1); \
} while (0)
#define LOG(args...) \
do { \
fprintf(stderr, args); \
fprintf(stderr, "\n"); \
fflush(stderr); \
} while (0)
#endif #endif