#ifndef __TFS_H__
#define __TFS_H__

#define TFS_OPEN 1
#define TFS_WRITE 2
#define TFS_CLOSE 3
#define TFS_MKDIR 4

#define _FILE_OFFSET_BITS 64
#include <unistd.h>

/* Commands have a fixed header size + variable payload. */

#define PACKED __attribute__((packed))

static inline int size_to_buffer(int size) { return size + 2; }
static inline int buffer_to_size(int size) { return size - 2; }

struct tfs_cmd {
    short unsigned int size;  // (...)
    short int cmd;
    short int fd;
    short int write_size; // writes max 64k
    long long int write_offset;
} PACKED;


/* (...) Messages bytes on wire after .size field (a)

   == payload_size + 14 (tfs_cmd is 16 bytes including .size field)

   Messages will be concatenated in a byte stream.  We use a "Pascal
   string" size prefix format which allows reuse of more generic
   binary message routing and processing tools. */


#define INIT_TFS_CMD(it) memset(it, 0, sizeof(struct tfs_cmd))

#endif

