code:
/* Generated by the protocol buffer compiler.  DO NOT EDIT! */
/* Generated from: external/filemanager.proto */

/* Do not generate deprecated warnings for self */
#ifndef PROTOBUF_C__NO_DEPRECATED
#define PROTOBUF_C__NO_DEPRECATED
#endif

#include "filemanager.pb-c.h"
void   fm_echo_request__init
                     (FmEchoRequest         *message)
{
  static const FmEchoRequest init_value = FM_ECHO_REQUEST__INIT;
  *message = init_value;
}
size_t fm_echo_request__get_packed_size
                     (const FmEchoRequest *message)
{
  assert(message->base.descriptor == &fm_echo_request__descriptor);
  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t fm_echo_request__pack
                     (const FmEchoRequest *message,
                      uint8_t       *out)
{
  assert(message->base.descriptor == &fm_echo_request__descriptor);
  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t fm_echo_request__pack_to_buffer
                     (const FmEchoRequest *message,
                      ProtobufCBuffer *buffer)
{
  assert(message->base.descriptor == &fm_echo_request__descriptor);
  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
FmEchoRequest *
       fm_echo_request__unpack
                     (ProtobufCAllocator  *allocator,
                      size_t               len,
                      const uint8_t       *data)
{
  return (FmEchoRequest *)
     protobuf_c_message_unpack (&fm_echo_request__descriptor,
                                allocator, len, data);
}
void   fm_echo_request__free_unpacked
                     (FmEchoRequest *message,
                      ProtobufCAllocator *allocator)
{
  if(!message)
    return;
  assert(message->base.descriptor == &fm_echo_request__descriptor);
  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void   fm_open_request__init
                     (FmOpenRequest         *message)
{
  static const FmOpenRequest init_value = FM_OPEN_REQUEST__INIT;
  *message = init_value;
}
size_t fm_open_request__get_packed_size
                     (const FmOpenRequest *message)
{
  assert(message->base.descriptor == &fm_open_request__descriptor);
  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t fm_open_request__pack
                     (const FmOpenRequest *message,
                      uint8_t       *out)
{
  assert(message->base.descriptor == &fm_open_request__descriptor);
  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t fm_open_request__pack_to_buffer
                     (const FmOpenRequest *message,
                      ProtobufCBuffer *buffer)
{
  assert(message->base.descriptor == &fm_open_request__descriptor);
  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
FmOpenRequest *
       fm_open_request__unpack
                     (ProtobufCAllocator  *allocator,
                      size_t               len,
                      const uint8_t       *data)
{
  return (FmOpenRequest *)
     protobuf_c_message_unpack (&fm_open_request__descriptor,
                                allocator, len, data);
}
void   fm_open_request__free_unpacked
                     (FmOpenRequest *message,
                      ProtobufCAllocator *allocator)
{
  if(!message)
    return;
  assert(message->base.descriptor == &fm_open_request__descriptor);
  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void   fm_close_request__init
                     (FmCloseRequest         *message)
{
  static const FmCloseRequest init_value = FM_CLOSE_REQUEST__INIT;
  *message = init_value;
}
size_t fm_close_request__get_packed_size
                     (const FmCloseRequest *message)
{
  assert(message->base.descriptor == &fm_close_request__descriptor);
  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t fm_close_request__pack
                     (const FmCloseRequest *message,
                      uint8_t       *out)
{
  assert(message->base.descriptor == &fm_close_request__descriptor);
  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t fm_close_request__pack_to_buffer
                     (const FmCloseRequest *message,
                      ProtobufCBuffer *buffer)
{
  assert(message->base.descriptor == &fm_close_request__descriptor);
  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
FmCloseRequest *
       fm_close_request__unpack
                     (ProtobufCAllocator  *allocator,
                      size_t               len,
                      const uint8_t       *data)
{
  return (FmCloseRequest *)
     protobuf_c_message_unpack (&fm_close_request__descriptor,
                                allocator, len, data);
}
void   fm_close_request__free_unpacked
                     (FmCloseRequest *message,
                      ProtobufCAllocator *allocator)
{
  if(!message)
    return;
  assert(message->base.descriptor == &fm_close_request__descriptor);
  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void   fm_seek_request__init
                     (FmSeekRequest         *message)
{
  static const FmSeekRequest init_value = FM_SEEK_REQUEST__INIT;
  *message = init_value;
}
size_t fm_seek_request__get_packed_size
                     (const FmSeekRequest *message)
{
  assert(message->base.descriptor == &fm_seek_request__descriptor);
  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t fm_seek_request__pack
                     (const FmSeekRequest *message,
                      uint8_t       *out)
{
  assert(message->base.descriptor == &fm_seek_request__descriptor);
  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t fm_seek_request__pack_to_buffer
                     (const FmSeekRequest *message,
                      ProtobufCBuffer *buffer)
{
  assert(message->base.descriptor == &fm_seek_request__descriptor);
  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
FmSeekRequest *
       fm_seek_request__unpack
                     (ProtobufCAllocator  *allocator,
                      size_t               len,
                      const uint8_t       *data)
{
  return (FmSeekRequest *)
     protobuf_c_message_unpack (&fm_seek_request__descriptor,
                                allocator, len, data);
}
void   fm_seek_request__free_unpacked
                     (FmSeekRequest *message,
                      ProtobufCAllocator *allocator)
{
  if(!message)
    return;
  assert(message->base.descriptor == &fm_seek_request__descriptor);
  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void   fm_read_request__init
                     (FmReadRequest         *message)
{
  static const FmReadRequest init_value = FM_READ_REQUEST__INIT;
  *message = init_value;
}
size_t fm_read_request__get_packed_size
                     (const FmReadRequest *message)
{
  assert(message->base.descriptor == &fm_read_request__descriptor);
  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t fm_read_request__pack
                     (const FmReadRequest *message,
                      uint8_t       *out)
{
  assert(message->base.descriptor == &fm_read_request__descriptor);
  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t fm_read_request__pack_to_buffer
                     (const FmReadRequest *message,
                      ProtobufCBuffer *buffer)
{
  assert(message->base.descriptor == &fm_read_request__descriptor);
  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
FmReadRequest *
       fm_read_request__unpack
                     (ProtobufCAllocator  *allocator,
                      size_t               len,
                      const uint8_t       *data)
{
  return (FmReadRequest *)
     protobuf_c_message_unpack (&fm_read_request__descriptor,
                                allocator, len, data);
}
void   fm_read_request__free_unpacked
                     (FmReadRequest *message,
                      ProtobufCAllocator *allocator)
{
  if(!message)
    return;
  assert(message->base.descriptor == &fm_read_request__descriptor);
  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void   fm_read_response__init
                     (FmReadResponse         *message)
{
  static const FmReadResponse init_value = FM_READ_RESPONSE__INIT;
  *message = init_value;
}
size_t fm_read_response__get_packed_size
                     (const FmReadResponse *message)
{
  assert(message->base.descriptor == &fm_read_response__descriptor);
  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t fm_read_response__pack
                     (const FmReadResponse *message,
                      uint8_t       *out)
{
  assert(message->base.descriptor == &fm_read_response__descriptor);
  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t fm_read_response__pack_to_buffer
                     (const FmReadResponse *message,
                      ProtobufCBuffer *buffer)
{
  assert(message->base.descriptor == &fm_read_response__descriptor);
  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
FmReadResponse *
       fm_read_response__unpack
                     (ProtobufCAllocator  *allocator,
                      size_t               len,
                      const uint8_t       *data)
{
  return (FmReadResponse *)
     protobuf_c_message_unpack (&fm_read_response__descriptor,
                                allocator, len, data);
}
void   fm_read_response__free_unpacked
                     (FmReadResponse *message,
                      ProtobufCAllocator *allocator)
{
  if(!message)
    return;
  assert(message->base.descriptor == &fm_read_response__descriptor);
  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void   fm_write_request__init
                     (FmWriteRequest         *message)
{
  static const FmWriteRequest init_value = FM_WRITE_REQUEST__INIT;
  *message = init_value;
}
size_t fm_write_request__get_packed_size
                     (const FmWriteRequest *message)
{
  assert(message->base.descriptor == &fm_write_request__descriptor);
  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t fm_write_request__pack
                     (const FmWriteRequest *message,
                      uint8_t       *out)
{
  assert(message->base.descriptor == &fm_write_request__descriptor);
  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t fm_write_request__pack_to_buffer
                     (const FmWriteRequest *message,
                      ProtobufCBuffer *buffer)
{
  assert(message->base.descriptor == &fm_write_request__descriptor);
  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
FmWriteRequest *
       fm_write_request__unpack
                     (ProtobufCAllocator  *allocator,
                      size_t               len,
                      const uint8_t       *data)
{
  return (FmWriteRequest *)
     protobuf_c_message_unpack (&fm_write_request__descriptor,
                                allocator, len, data);
}
void   fm_write_request__free_unpacked
                     (FmWriteRequest *message,
                      ProtobufCAllocator *allocator)
{
  if(!message)
    return;
  assert(message->base.descriptor == &fm_write_request__descriptor);
  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void   fm_dent__init
                     (FmDent         *message)
{
  static const FmDent init_value = FM_DENT__INIT;
  *message = init_value;
}
size_t fm_dent__get_packed_size
                     (const FmDent *message)
{
  assert(message->base.descriptor == &fm_dent__descriptor);
  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t fm_dent__pack
                     (const FmDent *message,
                      uint8_t       *out)
{
  assert(message->base.descriptor == &fm_dent__descriptor);
  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t fm_dent__pack_to_buffer
                     (const FmDent *message,
                      ProtobufCBuffer *buffer)
{
  assert(message->base.descriptor == &fm_dent__descriptor);
  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
FmDent *
       fm_dent__unpack
                     (ProtobufCAllocator  *allocator,
                      size_t               len,
                      const uint8_t       *data)
{
  return (FmDent *)
     protobuf_c_message_unpack (&fm_dent__descriptor,
                                allocator, len, data);
}
void   fm_dent__free_unpacked
                     (FmDent *message,
                      ProtobufCAllocator *allocator)
{
  if(!message)
    return;
  assert(message->base.descriptor == &fm_dent__descriptor);
  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void   fm_get_dents_request__init
                     (FmGetDentsRequest         *message)
{
  static const FmGetDentsRequest init_value = FM_GET_DENTS_REQUEST__INIT;
  *message = init_value;
}
size_t fm_get_dents_request__get_packed_size
                     (const FmGetDentsRequest *message)
{
  assert(message->base.descriptor == &fm_get_dents_request__descriptor);
  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t fm_get_dents_request__pack
                     (const FmGetDentsRequest *message,
                      uint8_t       *out)
{
  assert(message->base.descriptor == &fm_get_dents_request__descriptor);
  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t fm_get_dents_request__pack_to_buffer
                     (const FmGetDentsRequest *message,
                      ProtobufCBuffer *buffer)
{
  assert(message->base.descriptor == &fm_get_dents_request__descriptor);
  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
FmGetDentsRequest *
       fm_get_dents_request__unpack
                     (ProtobufCAllocator  *allocator,
                      size_t               len,
                      const uint8_t       *data)
{
  return (FmGetDentsRequest *)
     protobuf_c_message_unpack (&fm_get_dents_request__descriptor,
                                allocator, len, data);
}
void   fm_get_dents_request__free_unpacked
                     (FmGetDentsRequest *message,
                      ProtobufCAllocator *allocator)
{
  if(!message)
    return;
  assert(message->base.descriptor == &fm_get_dents_request__descriptor);
  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void   fm_get_dents_response__init
                     (FmGetDentsResponse         *message)
{
  static const FmGetDentsResponse init_value = FM_GET_DENTS_RESPONSE__INIT;
  *message = init_value;
}
size_t fm_get_dents_response__get_packed_size
                     (const FmGetDentsResponse *message)
{
  assert(message->base.descriptor == &fm_get_dents_response__descriptor);
  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t fm_get_dents_response__pack
                     (const FmGetDentsResponse *message,
                      uint8_t       *out)
{
  assert(message->base.descriptor == &fm_get_dents_response__descriptor);
  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t fm_get_dents_response__pack_to_buffer
                     (const FmGetDentsResponse *message,
                      ProtobufCBuffer *buffer)
{
  assert(message->base.descriptor == &fm_get_dents_response__descriptor);
  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
FmGetDentsResponse *
       fm_get_dents_response__unpack
                     (ProtobufCAllocator  *allocator,
                      size_t               len,
                      const uint8_t       *data)
{
  return (FmGetDentsResponse *)
     protobuf_c_message_unpack (&fm_get_dents_response__descriptor,
                                allocator, len, data);
}
void   fm_get_dents_response__free_unpacked
                     (FmGetDentsResponse *message,
                      ProtobufCAllocator *allocator)
{
  if(!message)
    return;
  assert(message->base.descriptor == &fm_get_dents_response__descriptor);
  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void   fm_timespec__init
                     (FmTimespec         *message)
{
  static const FmTimespec init_value = FM_TIMESPEC__INIT;
  *message = init_value;
}
size_t fm_timespec__get_packed_size
                     (const FmTimespec *message)
{
  assert(message->base.descriptor == &fm_timespec__descriptor);
  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t fm_timespec__pack
                     (const FmTimespec *message,
                      uint8_t       *out)
{
  assert(message->base.descriptor == &fm_timespec__descriptor);
  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t fm_timespec__pack_to_buffer
                     (const FmTimespec *message,
                      ProtobufCBuffer *buffer)
{
  assert(message->base.descriptor == &fm_timespec__descriptor);
  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
FmTimespec *
       fm_timespec__unpack
                     (ProtobufCAllocator  *allocator,
                      size_t               len,
                      const uint8_t       *data)
{
  return (FmTimespec *)
     protobuf_c_message_unpack (&fm_timespec__descriptor,
                                allocator, len, data);
}
void   fm_timespec__free_unpacked
                     (FmTimespec *message,
                      ProtobufCAllocator *allocator)
{
  if(!message)
    return;
  assert(message->base.descriptor == &fm_timespec__descriptor);
  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void   fm_stat_request__init
                     (FmStatRequest         *message)
{
  static const FmStatRequest init_value = FM_STAT_REQUEST__INIT;
  *message = init_value;
}
size_t fm_stat_request__get_packed_size
                     (const FmStatRequest *message)
{
  assert(message->base.descriptor == &fm_stat_request__descriptor);
  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t fm_stat_request__pack
                     (const FmStatRequest *message,
                      uint8_t       *out)
{
  assert(message->base.descriptor == &fm_stat_request__descriptor);
  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t fm_stat_request__pack_to_buffer
                     (const FmStatRequest *message,
                      ProtobufCBuffer *buffer)
{
  assert(message->base.descriptor == &fm_stat_request__descriptor);
  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
FmStatRequest *
       fm_stat_request__unpack
                     (ProtobufCAllocator  *allocator,
                      size_t               len,
                      const uint8_t       *data)
{
  return (FmStatRequest *)
     protobuf_c_message_unpack (&fm_stat_request__descriptor,
                                allocator, len, data);
}
void   fm_stat_request__free_unpacked
                     (FmStatRequest *message,
                      ProtobufCAllocator *allocator)
{
  if(!message)
    return;
  assert(message->base.descriptor == &fm_stat_request__descriptor);
  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void   fm_stat_response__init
                     (FmStatResponse         *message)
{
  static const FmStatResponse init_value = FM_STAT_RESPONSE__INIT;
  *message = init_value;
}
size_t fm_stat_response__get_packed_size
                     (const FmStatResponse *message)
{
  assert(message->base.descriptor == &fm_stat_response__descriptor);
  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t fm_stat_response__pack
                     (const FmStatResponse *message,
                      uint8_t       *out)
{
  assert(message->base.descriptor == &fm_stat_response__descriptor);
  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t fm_stat_response__pack_to_buffer
                     (const FmStatResponse *message,
                      ProtobufCBuffer *buffer)
{
  assert(message->base.descriptor == &fm_stat_response__descriptor);
  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
FmStatResponse *
       fm_stat_response__unpack
                     (ProtobufCAllocator  *allocator,
                      size_t               len,
                      const uint8_t       *data)
{
  return (FmStatResponse *)
     protobuf_c_message_unpack (&fm_stat_response__descriptor,
                                allocator, len, data);
}
void   fm_stat_response__free_unpacked
                     (FmStatResponse *message,
                      ProtobufCAllocator *allocator)
{
  if(!message)
    return;
  assert(message->base.descriptor == &fm_stat_response__descriptor);
  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void   fm_mkdir_request__init
                     (FmMkdirRequest         *message)
{
  static const FmMkdirRequest init_value = FM_MKDIR_REQUEST__INIT;
  *message = init_value;
}
size_t fm_mkdir_request__get_packed_size
                     (const FmMkdirRequest *message)
{
  assert(message->base.descriptor == &fm_mkdir_request__descriptor);
  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t fm_mkdir_request__pack
                     (const FmMkdirRequest *message,
                      uint8_t       *out)
{
  assert(message->base.descriptor == &fm_mkdir_request__descriptor);
  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t fm_mkdir_request__pack_to_buffer
                     (const FmMkdirRequest *message,
                      ProtobufCBuffer *buffer)
{
  assert(message->base.descriptor == &fm_mkdir_request__descriptor);
  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
FmMkdirRequest *
       fm_mkdir_request__unpack
                     (ProtobufCAllocator  *allocator,
                      size_t               len,
                      const uint8_t       *data)
{
  return (FmMkdirRequest *)
     protobuf_c_message_unpack (&fm_mkdir_request__descriptor,
                                allocator, len, data);
}
void   fm_mkdir_request__free_unpacked
                     (FmMkdirRequest *message,
                      ProtobufCAllocator *allocator)
{
  if(!message)
    return;
  assert(message->base.descriptor == &fm_mkdir_request__descriptor);
  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void   fm_rmdir_request__init
                     (FmRmdirRequest         *message)
{
  static const FmRmdirRequest init_value = FM_RMDIR_REQUEST__INIT;
  *message = init_value;
}
size_t fm_rmdir_request__get_packed_size
                     (const FmRmdirRequest *message)
{
  assert(message->base.descriptor == &fm_rmdir_request__descriptor);
  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t fm_rmdir_request__pack
                     (const FmRmdirRequest *message,
                      uint8_t       *out)
{
  assert(message->base.descriptor == &fm_rmdir_request__descriptor);
  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t fm_rmdir_request__pack_to_buffer
                     (const FmRmdirRequest *message,
                      ProtobufCBuffer *buffer)
{
  assert(message->base.descriptor == &fm_rmdir_request__descriptor);
  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
FmRmdirRequest *
       fm_rmdir_request__unpack
                     (ProtobufCAllocator  *allocator,
                      size_t               len,
                      const uint8_t       *data)
{
  return (FmRmdirRequest *)
     protobuf_c_message_unpack (&fm_rmdir_request__descriptor,
                                allocator, len, data);
}
void   fm_rmdir_request__free_unpacked
                     (FmRmdirRequest *message,
                      ProtobufCAllocator *allocator)
{
  if(!message)
    return;
  assert(message->base.descriptor == &fm_rmdir_request__descriptor);
  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void   fm_unlink_request__init
                     (FmUnlinkRequest         *message)
{
  static const FmUnlinkRequest init_value = FM_UNLINK_REQUEST__INIT;
  *message = init_value;
}
size_t fm_unlink_request__get_packed_size
                     (const FmUnlinkRequest *message)
{
  assert(message->base.descriptor == &fm_unlink_request__descriptor);
  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t fm_unlink_request__pack
                     (const FmUnlinkRequest *message,
                      uint8_t       *out)
{
  assert(message->base.descriptor == &fm_unlink_request__descriptor);
  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t fm_unlink_request__pack_to_buffer
                     (const FmUnlinkRequest *message,
                      ProtobufCBuffer *buffer)
{
  assert(message->base.descriptor == &fm_unlink_request__descriptor);
  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
FmUnlinkRequest *
       fm_unlink_request__unpack
                     (ProtobufCAllocator  *allocator,
                      size_t               len,
                      const uint8_t       *data)
{
  return (FmUnlinkRequest *)
     protobuf_c_message_unpack (&fm_unlink_request__descriptor,
                                allocator, len, data);
}
void   fm_unlink_request__free_unpacked
                     (FmUnlinkRequest *message,
                      ProtobufCAllocator *allocator)
{
  if(!message)
    return;
  assert(message->base.descriptor == &fm_unlink_request__descriptor);
  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void   fm_decrypt_self_request__init
                     (FmDecryptSelfRequest         *message)
{
  static const FmDecryptSelfRequest init_value = FM_DECRYPT_SELF_REQUEST__INIT;
  *message = init_value;
}
size_t fm_decrypt_self_request__get_packed_size
                     (const FmDecryptSelfRequest *message)
{
  assert(message->base.descriptor == &fm_decrypt_self_request__descriptor);
  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t fm_decrypt_self_request__pack
                     (const FmDecryptSelfRequest *message,
                      uint8_t       *out)
{
  assert(message->base.descriptor == &fm_decrypt_self_request__descriptor);
  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t fm_decrypt_self_request__pack_to_buffer
                     (const FmDecryptSelfRequest *message,
                      ProtobufCBuffer *buffer)
{
  assert(message->base.descriptor == &fm_decrypt_self_request__descriptor);
  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
FmDecryptSelfRequest *
       fm_decrypt_self_request__unpack
                     (ProtobufCAllocator  *allocator,
                      size_t               len,
                      const uint8_t       *data)
{
  return (FmDecryptSelfRequest *)
     protobuf_c_message_unpack (&fm_decrypt_self_request__descriptor,
                                allocator, len, data);
}
void   fm_decrypt_self_request__free_unpacked
                     (FmDecryptSelfRequest *message,
                      ProtobufCAllocator *allocator)
{
  if(!message)
    return;
  assert(message->base.descriptor == &fm_decrypt_self_request__descriptor);
  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void   fm_decrypt_self_response__init
                     (FmDecryptSelfResponse         *message)
{
  static const FmDecryptSelfResponse init_value = FM_DECRYPT_SELF_RESPONSE__INIT;
  *message = init_value;
}
size_t fm_decrypt_self_response__get_packed_size
                     (const FmDecryptSelfResponse *message)
{
  assert(message->base.descriptor == &fm_decrypt_self_response__descriptor);
  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t fm_decrypt_self_response__pack
                     (const FmDecryptSelfResponse *message,
                      uint8_t       *out)
{
  assert(message->base.descriptor == &fm_decrypt_self_response__descriptor);
  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t fm_decrypt_self_response__pack_to_buffer
                     (const FmDecryptSelfResponse *message,
                      ProtobufCBuffer *buffer)
{
  assert(message->base.descriptor == &fm_decrypt_self_response__descriptor);
  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
FmDecryptSelfResponse *
       fm_decrypt_self_response__unpack
                     (ProtobufCAllocator  *allocator,
                      size_t               len,
                      const uint8_t       *data)
{
  return (FmDecryptSelfResponse *)
     protobuf_c_message_unpack (&fm_decrypt_self_response__descriptor,
                                allocator, len, data);
}
void   fm_decrypt_self_response__free_unpacked
                     (FmDecryptSelfResponse *message,
                      ProtobufCAllocator *allocator)
{
  if(!message)
    return;
  assert(message->base.descriptor == &fm_decrypt_self_response__descriptor);
  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
static const ProtobufCFieldDescriptor fm_echo_request__field_descriptors[1] =
{
  {
    "message",
    1,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_STRING,
    0,   /* quantifier_offset */
    offsetof(FmEchoRequest, message),
    NULL,
    &protobuf_c_empty_string,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
};
static const unsigned fm_echo_request__field_indices_by_name[] = {
  0,   /* field[0] = message */
};
static const ProtobufCIntRange fm_echo_request__number_ranges[1 + 1] =
{
  { 1, 0 },
  { 0, 1 }
};
const ProtobufCMessageDescriptor fm_echo_request__descriptor =
{
  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
  "FmEchoRequest",
  "FmEchoRequest",
  "FmEchoRequest",
  "",
  sizeof(FmEchoRequest),
  1,
  fm_echo_request__field_descriptors,
  fm_echo_request__field_indices_by_name,
  1,  fm_echo_request__number_ranges,
  (ProtobufCMessageInit) fm_echo_request__init,
  NULL,NULL,NULL    /* reserved[123] */
};
static const ProtobufCFieldDescriptor fm_open_request__field_descriptors[3] =
{
  {
    "flags",
    1,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_INT32,
    0,   /* quantifier_offset */
    offsetof(FmOpenRequest, flags),
    NULL,
    NULL,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
  {
    "mode",
    2,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_INT32,
    0,   /* quantifier_offset */
    offsetof(FmOpenRequest, mode),
    NULL,
    NULL,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
  {
    "path",
    3,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_STRING,
    0,   /* quantifier_offset */
    offsetof(FmOpenRequest, path),
    NULL,
    &protobuf_c_empty_string,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
};
static const unsigned fm_open_request__field_indices_by_name[] = {
  0,   /* field[0] = flags */
  1,   /* field[1] = mode */
  2,   /* field[2] = path */
};
static const ProtobufCIntRange fm_open_request__number_ranges[1 + 1] =
{
  { 1, 0 },
  { 0, 3 }
};
const ProtobufCMessageDescriptor fm_open_request__descriptor =
{
  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
  "FmOpenRequest",
  "FmOpenRequest",
  "FmOpenRequest",
  "",
  sizeof(FmOpenRequest),
  3,
  fm_open_request__field_descriptors,
  fm_open_request__field_indices_by_name,
  1,  fm_open_request__number_ranges,
  (ProtobufCMessageInit) fm_open_request__init,
  NULL,NULL,NULL    /* reserved[123] */
};
static const ProtobufCFieldDescriptor fm_close_request__field_descriptors[1] =
{
  {
    "handle",
    1,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_INT32,
    0,   /* quantifier_offset */
    offsetof(FmCloseRequest, handle),
    NULL,
    NULL,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
};
static const unsigned fm_close_request__field_indices_by_name[] = {
  0,   /* field[0] = handle */
};
static const ProtobufCIntRange fm_close_request__number_ranges[1 + 1] =
{
  { 1, 0 },
  { 0, 1 }
};
const ProtobufCMessageDescriptor fm_close_request__descriptor =
{
  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
  "FmCloseRequest",
  "FmCloseRequest",
  "FmCloseRequest",
  "",
  sizeof(FmCloseRequest),
  1,
  fm_close_request__field_descriptors,
  fm_close_request__field_indices_by_name,
  1,  fm_close_request__number_ranges,
  (ProtobufCMessageInit) fm_close_request__init,
  NULL,NULL,NULL    /* reserved[123] */
};
static const ProtobufCFieldDescriptor fm_seek_request__field_descriptors[2] =
{
  {
    "handle",
    1,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_INT32,
    0,   /* quantifier_offset */
    offsetof(FmSeekRequest, handle),
    NULL,
    NULL,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
  {
    "offset",
    2,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_INT64,
    0,   /* quantifier_offset */
    offsetof(FmSeekRequest, offset),
    NULL,
    NULL,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
};
static const unsigned fm_seek_request__field_indices_by_name[] = {
  0,   /* field[0] = handle */
  1,   /* field[1] = offset */
};
static const ProtobufCIntRange fm_seek_request__number_ranges[1 + 1] =
{
  { 1, 0 },
  { 0, 2 }
};
const ProtobufCMessageDescriptor fm_seek_request__descriptor =
{
  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
  "FmSeekRequest",
  "FmSeekRequest",
  "FmSeekRequest",
  "",
  sizeof(FmSeekRequest),
  2,
  fm_seek_request__field_descriptors,
  fm_seek_request__field_indices_by_name,
  1,  fm_seek_request__number_ranges,
  (ProtobufCMessageInit) fm_seek_request__init,
  NULL,NULL,NULL    /* reserved[123] */
};
static const ProtobufCFieldDescriptor fm_read_request__field_descriptors[2] =
{
  {
    "handle",
    1,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_INT32,
    0,   /* quantifier_offset */
    offsetof(FmReadRequest, handle),
    NULL,
    NULL,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
  {
    "size",
    2,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_UINT64,
    0,   /* quantifier_offset */
    offsetof(FmReadRequest, size),
    NULL,
    NULL,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
};
static const unsigned fm_read_request__field_indices_by_name[] = {
  0,   /* field[0] = handle */
  1,   /* field[1] = size */
};
static const ProtobufCIntRange fm_read_request__number_ranges[1 + 1] =
{
  { 1, 0 },
  { 0, 2 }
};
const ProtobufCMessageDescriptor fm_read_request__descriptor =
{
  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
  "FmReadRequest",
  "FmReadRequest",
  "FmReadRequest",
  "",
  sizeof(FmReadRequest),
  2,
  fm_read_request__field_descriptors,
  fm_read_request__field_indices_by_name,
  1,  fm_read_request__number_ranges,
  (ProtobufCMessageInit) fm_read_request__init,
  NULL,NULL,NULL    /* reserved[123] */
};
static const ProtobufCFieldDescriptor fm_read_response__field_descriptors[1] =
{
  {
    "data",
    1,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_BYTES,
    0,   /* quantifier_offset */
    offsetof(FmReadResponse, data),
    NULL,
    NULL,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
};
static const unsigned fm_read_response__field_indices_by_name[] = {
  0,   /* field[0] = data */
};
static const ProtobufCIntRange fm_read_response__number_ranges[1 + 1] =
{
  { 1, 0 },
  { 0, 1 }
};
const ProtobufCMessageDescriptor fm_read_response__descriptor =
{
  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
  "FmReadResponse",
  "FmReadResponse",
  "FmReadResponse",
  "",
  sizeof(FmReadResponse),
  1,
  fm_read_response__field_descriptors,
  fm_read_response__field_indices_by_name,
  1,  fm_read_response__number_ranges,
  (ProtobufCMessageInit) fm_read_response__init,
  NULL,NULL,NULL    /* reserved[123] */
};
static const ProtobufCFieldDescriptor fm_write_request__field_descriptors[2] =
{
  {
    "handle",
    1,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_INT32,
    0,   /* quantifier_offset */
    offsetof(FmWriteRequest, handle),
    NULL,
    NULL,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
  {
    "data",
    2,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_BYTES,
    0,   /* quantifier_offset */
    offsetof(FmWriteRequest, data),
    NULL,
    NULL,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
};
static const unsigned fm_write_request__field_indices_by_name[] = {
  1,   /* field[1] = data */
  0,   /* field[0] = handle */
};
static const ProtobufCIntRange fm_write_request__number_ranges[1 + 1] =
{
  { 1, 0 },
  { 0, 2 }
};
const ProtobufCMessageDescriptor fm_write_request__descriptor =
{
  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
  "FmWriteRequest",
  "FmWriteRequest",
  "FmWriteRequest",
  "",
  sizeof(FmWriteRequest),
  2,
  fm_write_request__field_descriptors,
  fm_write_request__field_indices_by_name,
  1,  fm_write_request__number_ranges,
  (ProtobufCMessageInit) fm_write_request__init,
  NULL,NULL,NULL    /* reserved[123] */
};
static const ProtobufCFieldDescriptor fm_dent__field_descriptors[4] =
{
  {
    "fileno",
    1,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_UINT32,
    0,   /* quantifier_offset */
    offsetof(FmDent, fileno),
    NULL,
    NULL,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
  {
    "recLen",
    2,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_UINT32,
    0,   /* quantifier_offset */
    offsetof(FmDent, reclen),
    NULL,
    NULL,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
  {
    "type",
    3,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_UINT32,
    0,   /* quantifier_offset */
    offsetof(FmDent, type),
    NULL,
    NULL,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
  {
    "name",
    4,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_STRING,
    0,   /* quantifier_offset */
    offsetof(FmDent, name),
    NULL,
    &protobuf_c_empty_string,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
};
static const unsigned fm_dent__field_indices_by_name[] = {
  0,   /* field[0] = fileno */
  3,   /* field[3] = name */
  1,   /* field[1] = recLen */
  2,   /* field[2] = type */
};
static const ProtobufCIntRange fm_dent__number_ranges[1 + 1] =
{
  { 1, 0 },
  { 0, 4 }
};
const ProtobufCMessageDescriptor fm_dent__descriptor =
{
  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
  "FmDent",
  "FmDent",
  "FmDent",
  "",
  sizeof(FmDent),
  4,
  fm_dent__field_descriptors,
  fm_dent__field_indices_by_name,
  1,  fm_dent__number_ranges,
  (ProtobufCMessageInit) fm_dent__init,
  NULL,NULL,NULL    /* reserved[123] */
};
static const ProtobufCFieldDescriptor fm_get_dents_request__field_descriptors[1] =
{
  {
    "path",
    1,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_STRING,
    0,   /* quantifier_offset */
    offsetof(FmGetDentsRequest, path),
    NULL,
    &protobuf_c_empty_string,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
};
static const unsigned fm_get_dents_request__field_indices_by_name[] = {
  0,   /* field[0] = path */
};
static const ProtobufCIntRange fm_get_dents_request__number_ranges[1 + 1] =
{
  { 1, 0 },
  { 0, 1 }
};
const ProtobufCMessageDescriptor fm_get_dents_request__descriptor =
{
  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
  "FmGetDentsRequest",
  "FmGetDentsRequest",
  "FmGetDentsRequest",
  "",
  sizeof(FmGetDentsRequest),
  1,
  fm_get_dents_request__field_descriptors,
  fm_get_dents_request__field_indices_by_name,
  1,  fm_get_dents_request__number_ranges,
  (ProtobufCMessageInit) fm_get_dents_request__init,
  NULL,NULL,NULL    /* reserved[123] */
};
static const ProtobufCFieldDescriptor fm_get_dents_response__field_descriptors[1] =
{
  {
    "dents",
    1,
    PROTOBUF_C_LABEL_REPEATED,
    PROTOBUF_C_TYPE_MESSAGE,
    offsetof(FmGetDentsResponse, n_dents),
    offsetof(FmGetDentsResponse, dents),
    &fm_dent__descriptor,
    NULL,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
};
static const unsigned fm_get_dents_response__field_indices_by_name[] = {
  0,   /* field[0] = dents */
};
static const ProtobufCIntRange fm_get_dents_response__number_ranges[1 + 1] =
{
  { 1, 0 },
  { 0, 1 }
};
const ProtobufCMessageDescriptor fm_get_dents_response__descriptor =
{
  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
  "FmGetDentsResponse",
  "FmGetDentsResponse",
  "FmGetDentsResponse",
  "",
  sizeof(FmGetDentsResponse),
  1,
  fm_get_dents_response__field_descriptors,
  fm_get_dents_response__field_indices_by_name,
  1,  fm_get_dents_response__number_ranges,
  (ProtobufCMessageInit) fm_get_dents_response__init,
  NULL,NULL,NULL    /* reserved[123] */
};
static const ProtobufCFieldDescriptor fm_timespec__field_descriptors[2] =
{
  {
    "tv_sec",
    1,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_INT64,
    0,   /* quantifier_offset */
    offsetof(FmTimespec, tv_sec),
    NULL,
    NULL,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
  {
    "tv_nsec",
    2,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_INT32,
    0,   /* quantifier_offset */
    offsetof(FmTimespec, tv_nsec),
    NULL,
    NULL,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
};
static const unsigned fm_timespec__field_indices_by_name[] = {
  1,   /* field[1] = tv_nsec */
  0,   /* field[0] = tv_sec */
};
static const ProtobufCIntRange fm_timespec__number_ranges[1 + 1] =
{
  { 1, 0 },
  { 0, 2 }
};
const ProtobufCMessageDescriptor fm_timespec__descriptor =
{
  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
  "FmTimespec",
  "FmTimespec",
  "FmTimespec",
  "",
  sizeof(FmTimespec),
  2,
  fm_timespec__field_descriptors,
  fm_timespec__field_indices_by_name,
  1,  fm_timespec__number_ranges,
  (ProtobufCMessageInit) fm_timespec__init,
  NULL,NULL,NULL    /* reserved[123] */
};
static const ProtobufCFieldDescriptor fm_stat_request__field_descriptors[2] =
{
  {
    "handle",
    1,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_INT32,
    0,   /* quantifier_offset */
    offsetof(FmStatRequest, handle),
    NULL,
    NULL,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
  {
    "path",
    2,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_STRING,
    0,   /* quantifier_offset */
    offsetof(FmStatRequest, path),
    NULL,
    &protobuf_c_empty_string,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
};
static const unsigned fm_stat_request__field_indices_by_name[] = {
  0,   /* field[0] = handle */
  1,   /* field[1] = path */
};
static const ProtobufCIntRange fm_stat_request__number_ranges[1 + 1] =
{
  { 1, 0 },
  { 0, 2 }
};
const ProtobufCMessageDescriptor fm_stat_request__descriptor =
{
  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
  "FmStatRequest",
  "FmStatRequest",
  "FmStatRequest",
  "",
  sizeof(FmStatRequest),
  2,
  fm_stat_request__field_descriptors,
  fm_stat_request__field_indices_by_name,
  1,  fm_stat_request__number_ranges,
  (ProtobufCMessageInit) fm_stat_request__init,
  NULL,NULL,NULL    /* reserved[123] */
};
static const ProtobufCFieldDescriptor fm_stat_response__field_descriptors[17] =
{
  {
    "st_dev",
    1,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_UINT32,
    0,   /* quantifier_offset */
    offsetof(FmStatResponse, st_dev),
    NULL,
    NULL,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
  {
    "st_ino",
    2,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_UINT32,
    0,   /* quantifier_offset */
    offsetof(FmStatResponse, st_ino),
    NULL,
    NULL,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
  {
    "st_mode",
    3,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_UINT32,
    0,   /* quantifier_offset */
    offsetof(FmStatResponse, st_mode),
    NULL,
    NULL,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
  {
    "st_nlink",
    4,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_UINT32,
    0,   /* quantifier_offset */
    offsetof(FmStatResponse, st_nlink),
    NULL,
    NULL,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
  {
    "st_uid",
    5,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_UINT32,
    0,   /* quantifier_offset */
    offsetof(FmStatResponse, st_uid),
    NULL,
    NULL,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
  {
    "st_gid",
    6,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_UINT32,
    0,   /* quantifier_offset */
    offsetof(FmStatResponse, st_gid),
    NULL,
    NULL,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
  {
    "st_rdev",
    7,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_UINT32,
    0,   /* quantifier_offset */
    offsetof(FmStatResponse, st_rdev),
    NULL,
    NULL,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
  {
    "st_atim",
    8,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_MESSAGE,
    0,   /* quantifier_offset */
    offsetof(FmStatResponse, st_atim),
    &fm_timespec__descriptor,
    NULL,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
  {
    "st_mtim",
    9,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_MESSAGE,
    0,   /* quantifier_offset */
    offsetof(FmStatResponse, st_mtim),
    &fm_timespec__descriptor,
    NULL,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
  {
    "st_ctim",
    10,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_MESSAGE,
    0,   /* quantifier_offset */
    offsetof(FmStatResponse, st_ctim),
    &fm_timespec__descriptor,
    NULL,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
  {
    "st_size",
    11,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_INT64,
    0,   /* quantifier_offset */
    offsetof(FmStatResponse, st_size),
    NULL,
    NULL,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
  {
    "st_blocks",
    12,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_INT64,
    0,   /* quantifier_offset */
    offsetof(FmStatResponse, st_blocks),
    NULL,
    NULL,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
  {
    "st_blksize",
    13,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_UINT32,
    0,   /* quantifier_offset */
    offsetof(FmStatResponse, st_blksize),
    NULL,
    NULL,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
  {
    "st_flags",
    14,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_UINT32,
    0,   /* quantifier_offset */
    offsetof(FmStatResponse, st_flags),
    NULL,
    NULL,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
  {
    "st_gen",
    15,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_UINT32,
    0,   /* quantifier_offset */
    offsetof(FmStatResponse, st_gen),
    NULL,
    NULL,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
  {
    "st_lspare",
    16,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_INT32,
    0,   /* quantifier_offset */
    offsetof(FmStatResponse, st_lspare),
    NULL,
    NULL,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
  {
    "st_birthtim",
    17,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_MESSAGE,
    0,   /* quantifier_offset */
    offsetof(FmStatResponse, st_birthtim),
    &fm_timespec__descriptor,
    NULL,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
};
static const unsigned fm_stat_response__field_indices_by_name[] = {
  7,   /* field[7] = st_atim */
  16,   /* field[16] = st_birthtim */
  12,   /* field[12] = st_blksize */
  11,   /* field[11] = st_blocks */
  9,   /* field[9] = st_ctim */
  0,   /* field[0] = st_dev */
  13,   /* field[13] = st_flags */
  14,   /* field[14] = st_gen */
  5,   /* field[5] = st_gid */
  1,   /* field[1] = st_ino */
  15,   /* field[15] = st_lspare */
  2,   /* field[2] = st_mode */
  8,   /* field[8] = st_mtim */
  3,   /* field[3] = st_nlink */
  6,   /* field[6] = st_rdev */
  10,   /* field[10] = st_size */
  4,   /* field[4] = st_uid */
};
static const ProtobufCIntRange fm_stat_response__number_ranges[1 + 1] =
{
  { 1, 0 },
  { 0, 17 }
};
const ProtobufCMessageDescriptor fm_stat_response__descriptor =
{
  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
  "FmStatResponse",
  "FmStatResponse",
  "FmStatResponse",
  "",
  sizeof(FmStatResponse),
  17,
  fm_stat_response__field_descriptors,
  fm_stat_response__field_indices_by_name,
  1,  fm_stat_response__number_ranges,
  (ProtobufCMessageInit) fm_stat_response__init,
  NULL,NULL,NULL    /* reserved[123] */
};
static const ProtobufCFieldDescriptor fm_mkdir_request__field_descriptors[2] =
{
  {
    "mode",
    1,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_INT32,
    0,   /* quantifier_offset */
    offsetof(FmMkdirRequest, mode),
    NULL,
    NULL,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
  {
    "path",
    2,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_STRING,
    0,   /* quantifier_offset */
    offsetof(FmMkdirRequest, path),
    NULL,
    &protobuf_c_empty_string,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
};
static const unsigned fm_mkdir_request__field_indices_by_name[] = {
  0,   /* field[0] = mode */
  1,   /* field[1] = path */
};
static const ProtobufCIntRange fm_mkdir_request__number_ranges[1 + 1] =
{
  { 1, 0 },
  { 0, 2 }
};
const ProtobufCMessageDescriptor fm_mkdir_request__descriptor =
{
  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
  "FmMkdirRequest",
  "FmMkdirRequest",
  "FmMkdirRequest",
  "",
  sizeof(FmMkdirRequest),
  2,
  fm_mkdir_request__field_descriptors,
  fm_mkdir_request__field_indices_by_name,
  1,  fm_mkdir_request__number_ranges,
  (ProtobufCMessageInit) fm_mkdir_request__init,
  NULL,NULL,NULL    /* reserved[123] */
};
static const ProtobufCFieldDescriptor fm_rmdir_request__field_descriptors[1] =
{
  {
    "path",
    1,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_STRING,
    0,   /* quantifier_offset */
    offsetof(FmRmdirRequest, path),
    NULL,
    &protobuf_c_empty_string,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
};
static const unsigned fm_rmdir_request__field_indices_by_name[] = {
  0,   /* field[0] = path */
};
static const ProtobufCIntRange fm_rmdir_request__number_ranges[1 + 1] =
{
  { 1, 0 },
  { 0, 1 }
};
const ProtobufCMessageDescriptor fm_rmdir_request__descriptor =
{
  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
  "FmRmdirRequest",
  "FmRmdirRequest",
  "FmRmdirRequest",
  "",
  sizeof(FmRmdirRequest),
  1,
  fm_rmdir_request__field_descriptors,
  fm_rmdir_request__field_indices_by_name,
  1,  fm_rmdir_request__number_ranges,
  (ProtobufCMessageInit) fm_rmdir_request__init,
  NULL,NULL,NULL    /* reserved[123] */
};
static const ProtobufCFieldDescriptor fm_unlink_request__field_descriptors[1] =
{
  {
    "path",
    1,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_STRING,
    0,   /* quantifier_offset */
    offsetof(FmUnlinkRequest, path),
    NULL,
    &protobuf_c_empty_string,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
};
static const unsigned fm_unlink_request__field_indices_by_name[] = {
  0,   /* field[0] = path */
};
static const ProtobufCIntRange fm_unlink_request__number_ranges[1 + 1] =
{
  { 1, 0 },
  { 0, 1 }
};
const ProtobufCMessageDescriptor fm_unlink_request__descriptor =
{
  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
  "FmUnlinkRequest",
  "FmUnlinkRequest",
  "FmUnlinkRequest",
  "",
  sizeof(FmUnlinkRequest),
  1,
  fm_unlink_request__field_descriptors,
  fm_unlink_request__field_indices_by_name,
  1,  fm_unlink_request__number_ranges,
  (ProtobufCMessageInit) fm_unlink_request__init,
  NULL,NULL,NULL    /* reserved[123] */
};
static const ProtobufCFieldDescriptor fm_decrypt_self_request__field_descriptors[1] =
{
  {
    "path",
    1,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_STRING,
    0,   /* quantifier_offset */
    offsetof(FmDecryptSelfRequest, path),
    NULL,
    &protobuf_c_empty_string,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
};
static const unsigned fm_decrypt_self_request__field_indices_by_name[] = {
  0,   /* field[0] = path */
};
static const ProtobufCIntRange fm_decrypt_self_request__number_ranges[1 + 1] =
{
  { 1, 0 },
  { 0, 1 }
};
const ProtobufCMessageDescriptor fm_decrypt_self_request__descriptor =
{
  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
  "FmDecryptSelfRequest",
  "FmDecryptSelfRequest",
  "FmDecryptSelfRequest",
  "",
  sizeof(FmDecryptSelfRequest),
  1,
  fm_decrypt_self_request__field_descriptors,
  fm_decrypt_self_request__field_indices_by_name,
  1,  fm_decrypt_self_request__number_ranges,
  (ProtobufCMessageInit) fm_decrypt_self_request__init,
  NULL,NULL,NULL    /* reserved[123] */
};
static const ProtobufCFieldDescriptor fm_decrypt_self_response__field_descriptors[1] =
{
  {
    "data",
    1,
    PROTOBUF_C_LABEL_NONE,
    PROTOBUF_C_TYPE_BYTES,
    0,   /* quantifier_offset */
    offsetof(FmDecryptSelfResponse, data),
    NULL,
    NULL,
    0,             /* flags */
    0,NULL,NULL    /* reserved1,reserved2, etc */
  },
};
static const unsigned fm_decrypt_self_response__field_indices_by_name[] = {
  0,   /* field[0] = data */
};
static const ProtobufCIntRange fm_decrypt_self_response__number_ranges[1 + 1] =
{
  { 1, 0 },
  { 0, 1 }
};
const ProtobufCMessageDescriptor fm_decrypt_self_response__descriptor =
{
  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
  "FmDecryptSelfResponse",
  "FmDecryptSelfResponse",
  "FmDecryptSelfResponse",
  "",
  sizeof(FmDecryptSelfResponse),
  1,
  fm_decrypt_self_response__field_descriptors,
  fm_decrypt_self_response__field_indices_by_name,
  1,  fm_decrypt_self_response__number_ranges,
  (ProtobufCMessageInit) fm_decrypt_self_response__init,
  NULL,NULL,NULL    /* reserved[123] */
};


code:
/* Generated by the protocol buffer compiler.  DO NOT EDIT! */
/* Generated from: external/filemanager.proto */

#ifndef PROTOBUF_C_external_2ffilemanager_2eproto__INCLUDED
#define PROTOBUF_C_external_2ffilemanager_2eproto__INCLUDED

#include <protobuf-c/protobuf-c.h>

PROTOBUF_C__BEGIN_DECLS

#if PROTOBUF_C_VERSION_NUMBER < 1003000
# error This file was generated by a newer version of protoc-c which is incompatible with your libprotobuf-c headers. Please update your headers.
#elif 1003001 < PROTOBUF_C_MIN_COMPILER_VERSION
# error This file was generated by an older version of protoc-c which is incompatible with your libprotobuf-c headers. Please regenerate this file with a newer version of protoc-c.
#endif

typedef struct _FmEchoRequest FmEchoRequest;
typedef struct _FmOpenRequest FmOpenRequest;
typedef struct _FmCloseRequest FmCloseRequest;
typedef struct _FmSeekRequest FmSeekRequest;
typedef struct _FmReadRequest FmReadRequest;
typedef struct _FmReadResponse FmReadResponse;
typedef struct _FmWriteRequest FmWriteRequest;
typedef struct _FmDent FmDent;
typedef struct _FmGetDentsRequest FmGetDentsRequest;
typedef struct _FmGetDentsResponse FmGetDentsResponse;
typedef struct _FmTimespec FmTimespec;
typedef struct _FmStatRequest FmStatRequest;
typedef struct _FmStatResponse FmStatResponse;
typedef struct _FmMkdirRequest FmMkdirRequest;
typedef struct _FmRmdirRequest FmRmdirRequest;
typedef struct _FmUnlinkRequest FmUnlinkRequest;
typedef struct _FmDecryptSelfRequest FmDecryptSelfRequest;
typedef struct _FmDecryptSelfResponse FmDecryptSelfResponse;

/* --- enums --- */

/* --- messages --- */

struct  _FmEchoRequest
{
  ProtobufCMessage base;
  char *message;
};
#define FM_ECHO_REQUEST__INIT \
 { PROTOBUF_C_MESSAGE_INIT (&fm_echo_request__descriptor) \
    , (char *)protobuf_c_empty_string }

struct  _FmOpenRequest
{
  ProtobufCMessage base;
  int32_t flags;
  int32_t mode;
  char *path;
};
#define FM_OPEN_REQUEST__INIT \
 { PROTOBUF_C_MESSAGE_INIT (&fm_open_request__descriptor) \
    , 0, 0, (char *)protobuf_c_empty_string }

struct  _FmCloseRequest
{
  ProtobufCMessage base;
  int32_t handle;
};
#define FM_CLOSE_REQUEST__INIT \
 { PROTOBUF_C_MESSAGE_INIT (&fm_close_request__descriptor) \
    , 0 }

struct  _FmSeekRequest
{
  ProtobufCMessage base;
  int32_t handle;
  int64_t offset;
};
#define FM_SEEK_REQUEST__INIT \
 { PROTOBUF_C_MESSAGE_INIT (&fm_seek_request__descriptor) \
    , 0, 0 }

struct  _FmReadRequest
{
  ProtobufCMessage base;
  int32_t handle;
  uint64_t size;
};
#define FM_READ_REQUEST__INIT \
 { PROTOBUF_C_MESSAGE_INIT (&fm_read_request__descriptor) \
    , 0, 0 }

struct  _FmReadResponse
{
  ProtobufCMessage base;
  ProtobufCBinaryData data;
};
#define FM_READ_RESPONSE__INIT \
 { PROTOBUF_C_MESSAGE_INIT (&fm_read_response__descriptor) \
    , {0,NULL} }

struct  _FmWriteRequest
{
  ProtobufCMessage base;
  int32_t handle;
  ProtobufCBinaryData data;
};
#define FM_WRITE_REQUEST__INIT \
 { PROTOBUF_C_MESSAGE_INIT (&fm_write_request__descriptor) \
    , 0, {0,NULL} }

struct  _FmDent
{
  ProtobufCMessage base;
  uint32_t fileno;
  uint32_t reclen;
  uint32_t type;
  char *name;
};
#define FM_DENT__INIT \
 { PROTOBUF_C_MESSAGE_INIT (&fm_dent__descriptor) \
    , 0, 0, 0, (char *)protobuf_c_empty_string }

struct  _FmGetDentsRequest
{
  ProtobufCMessage base;
  char *path;
};
#define FM_GET_DENTS_REQUEST__INIT \
 { PROTOBUF_C_MESSAGE_INIT (&fm_get_dents_request__descriptor) \
    , (char *)protobuf_c_empty_string }

struct  _FmGetDentsResponse
{
  ProtobufCMessage base;
  size_t n_dents;
  FmDent **dents;
};
#define FM_GET_DENTS_RESPONSE__INIT \
 { PROTOBUF_C_MESSAGE_INIT (&fm_get_dents_response__descriptor) \
    , 0,NULL }

struct  _FmTimespec
{
  ProtobufCMessage base;
  int64_t tv_sec;
  int32_t tv_nsec;
};
#define FM_TIMESPEC__INIT \
 { PROTOBUF_C_MESSAGE_INIT (&fm_timespec__descriptor) \
    , 0, 0 }

struct  _FmStatRequest
{
  ProtobufCMessage base;
  int32_t handle;
  char *path;
};
#define FM_STAT_REQUEST__INIT \
 { PROTOBUF_C_MESSAGE_INIT (&fm_stat_request__descriptor) \
    , 0, (char *)protobuf_c_empty_string }

struct  _FmStatResponse
{
  ProtobufCMessage base;
  uint32_t st_dev;
  uint32_t st_ino;
  uint32_t st_mode;
  uint32_t st_nlink;
  uint32_t st_uid;
  uint32_t st_gid;
  uint32_t st_rdev;
  FmTimespec *st_atim;
  FmTimespec *st_mtim;
  FmTimespec *st_ctim;
  int64_t st_size;
  int64_t st_blocks;
  uint32_t st_blksize;
  uint32_t st_flags;
  uint32_t st_gen;
  int32_t st_lspare;
  FmTimespec *st_birthtim;
};
#define FM_STAT_RESPONSE__INIT \
 { PROTOBUF_C_MESSAGE_INIT (&fm_stat_response__descriptor) \
    , 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, NULL }

struct  _FmMkdirRequest
{
  ProtobufCMessage base;
  int32_t mode;
  char *path;
};
#define FM_MKDIR_REQUEST__INIT \
 { PROTOBUF_C_MESSAGE_INIT (&fm_mkdir_request__descriptor) \
    , 0, (char *)protobuf_c_empty_string }

struct  _FmRmdirRequest
{
  ProtobufCMessage base;
  char *path;
};
#define FM_RMDIR_REQUEST__INIT \
 { PROTOBUF_C_MESSAGE_INIT (&fm_rmdir_request__descriptor) \
    , (char *)protobuf_c_empty_string }

struct  _FmUnlinkRequest
{
  ProtobufCMessage base;
  char *path;
};
#define FM_UNLINK_REQUEST__INIT \
 { PROTOBUF_C_MESSAGE_INIT (&fm_unlink_request__descriptor) \
    , (char *)protobuf_c_empty_string }

struct  _FmDecryptSelfRequest
{
  ProtobufCMessage base;
  char *path;
};
#define FM_DECRYPT_SELF_REQUEST__INIT \
 { PROTOBUF_C_MESSAGE_INIT (&fm_decrypt_self_request__descriptor) \
    , (char *)protobuf_c_empty_string }

struct  _FmDecryptSelfResponse
{
  ProtobufCMessage base;
  ProtobufCBinaryData data;
};
#define FM_DECRYPT_SELF_RESPONSE__INIT \
 { PROTOBUF_C_MESSAGE_INIT (&fm_decrypt_self_response__descriptor) \
    , {0,NULL} }

/* FmEchoRequest methods */
void   fm_echo_request__init
                     (FmEchoRequest         *message);
size_t fm_echo_request__get_packed_size
                     (const FmEchoRequest   *message);
size_t fm_echo_request__pack
                     (const FmEchoRequest   *message,
                      uint8_t             *out);
size_t fm_echo_request__pack_to_buffer
                     (const FmEchoRequest   *message,
                      ProtobufCBuffer     *buffer);
FmEchoRequest *
       fm_echo_request__unpack
                     (ProtobufCAllocator  *allocator,
                      size_t               len,
                      const uint8_t       *data);
void   fm_echo_request__free_unpacked
                     (FmEchoRequest *message,
                      ProtobufCAllocator *allocator);
/* FmOpenRequest methods */
void   fm_open_request__init
                     (FmOpenRequest         *message);
size_t fm_open_request__get_packed_size
                     (const FmOpenRequest   *message);
size_t fm_open_request__pack
                     (const FmOpenRequest   *message,
                      uint8_t             *out);
size_t fm_open_request__pack_to_buffer
                     (const FmOpenRequest   *message,
                      ProtobufCBuffer     *buffer);
FmOpenRequest *
       fm_open_request__unpack
                     (ProtobufCAllocator  *allocator,
                      size_t               len,
                      const uint8_t       *data);
void   fm_open_request__free_unpacked
                     (FmOpenRequest *message,
                      ProtobufCAllocator *allocator);
/* FmCloseRequest methods */
void   fm_close_request__init
                     (FmCloseRequest         *message);
size_t fm_close_request__get_packed_size
                     (const FmCloseRequest   *message);
size_t fm_close_request__pack
                     (const FmCloseRequest   *message,
                      uint8_t             *out);
size_t fm_close_request__pack_to_buffer
                     (const FmCloseRequest   *message,
                      ProtobufCBuffer     *buffer);
FmCloseRequest *
       fm_close_request__unpack
                     (ProtobufCAllocator  *allocator,
                      size_t               len,
                      const uint8_t       *data);
void   fm_close_request__free_unpacked
                     (FmCloseRequest *message,
                      ProtobufCAllocator *allocator);
/* FmSeekRequest methods */
void   fm_seek_request__init
                     (FmSeekRequest         *message);
size_t fm_seek_request__get_packed_size
                     (const FmSeekRequest   *message);
size_t fm_seek_request__pack
                     (const FmSeekRequest   *message,
                      uint8_t             *out);
size_t fm_seek_request__pack_to_buffer
                     (const FmSeekRequest   *message,
                      ProtobufCBuffer     *buffer);
FmSeekRequest *
       fm_seek_request__unpack
                     (ProtobufCAllocator  *allocator,
                      size_t               len,
                      const uint8_t       *data);
void   fm_seek_request__free_unpacked
                     (FmSeekRequest *message,
                      ProtobufCAllocator *allocator);
/* FmReadRequest methods */
void   fm_read_request__init
                     (FmReadRequest         *message);
size_t fm_read_request__get_packed_size
                     (const FmReadRequest   *message);
size_t fm_read_request__pack
                     (const FmReadRequest   *message,
                      uint8_t             *out);
size_t fm_read_request__pack_to_buffer
                     (const FmReadRequest   *message,
                      ProtobufCBuffer     *buffer);
FmReadRequest *
       fm_read_request__unpack
                     (ProtobufCAllocator  *allocator,
                      size_t               len,
                      const uint8_t       *data);
void   fm_read_request__free_unpacked
                     (FmReadRequest *message,
                      ProtobufCAllocator *allocator);
/* FmReadResponse methods */
void   fm_read_response__init
                     (FmReadResponse         *message);
size_t fm_read_response__get_packed_size
                     (const FmReadResponse   *message);
size_t fm_read_response__pack
                     (const FmReadResponse   *message,
                      uint8_t             *out);
size_t fm_read_response__pack_to_buffer
                     (const FmReadResponse   *message,
                      ProtobufCBuffer     *buffer);
FmReadResponse *
       fm_read_response__unpack
                     (ProtobufCAllocator  *allocator,
                      size_t               len,
                      const uint8_t       *data);
void   fm_read_response__free_unpacked
                     (FmReadResponse *message,
                      ProtobufCAllocator *allocator);
/* FmWriteRequest methods */
void   fm_write_request__init
                     (FmWriteRequest         *message);
size_t fm_write_request__get_packed_size
                     (const FmWriteRequest   *message);
size_t fm_write_request__pack
                     (const FmWriteRequest   *message,
                      uint8_t             *out);
size_t fm_write_request__pack_to_buffer
                     (const FmWriteRequest   *message,
                      ProtobufCBuffer     *buffer);
FmWriteRequest *
       fm_write_request__unpack
                     (ProtobufCAllocator  *allocator,
                      size_t               len,
                      const uint8_t       *data);
void   fm_write_request__free_unpacked
                     (FmWriteRequest *message,
                      ProtobufCAllocator *allocator);
/* FmDent methods */
void   fm_dent__init
                     (FmDent         *message);
size_t fm_dent__get_packed_size
                     (const FmDent   *message);
size_t fm_dent__pack
                     (const FmDent   *message,
                      uint8_t             *out);
size_t fm_dent__pack_to_buffer
                     (const FmDent   *message,
                      ProtobufCBuffer     *buffer);
FmDent *
       fm_dent__unpack
                     (ProtobufCAllocator  *allocator,
                      size_t               len,
                      const uint8_t       *data);
void   fm_dent__free_unpacked
                     (FmDent *message,
                      ProtobufCAllocator *allocator);
/* FmGetDentsRequest methods */
void   fm_get_dents_request__init
                     (FmGetDentsRequest         *message);
size_t fm_get_dents_request__get_packed_size
                     (const FmGetDentsRequest   *message);
size_t fm_get_dents_request__pack
                     (const FmGetDentsRequest   *message,
                      uint8_t             *out);
size_t fm_get_dents_request__pack_to_buffer
                     (const FmGetDentsRequest   *message,
                      ProtobufCBuffer     *buffer);
FmGetDentsRequest *
       fm_get_dents_request__unpack
                     (ProtobufCAllocator  *allocator,
                      size_t               len,
                      const uint8_t       *data);
void   fm_get_dents_request__free_unpacked
                     (FmGetDentsRequest *message,
                      ProtobufCAllocator *allocator);
/* FmGetDentsResponse methods */
void   fm_get_dents_response__init
                     (FmGetDentsResponse         *message);
size_t fm_get_dents_response__get_packed_size
                     (const FmGetDentsResponse   *message);
size_t fm_get_dents_response__pack
                     (const FmGetDentsResponse   *message,
                      uint8_t             *out);
size_t fm_get_dents_response__pack_to_buffer
                     (const FmGetDentsResponse   *message,
                      ProtobufCBuffer     *buffer);
FmGetDentsResponse *
       fm_get_dents_response__unpack
                     (ProtobufCAllocator  *allocator,
                      size_t               len,
                      const uint8_t       *data);
void   fm_get_dents_response__free_unpacked
                     (FmGetDentsResponse *message,
                      ProtobufCAllocator *allocator);
/* FmTimespec methods */
void   fm_timespec__init
                     (FmTimespec         *message);
size_t fm_timespec__get_packed_size
                     (const FmTimespec   *message);
size_t fm_timespec__pack
                     (const FmTimespec   *message,
                      uint8_t             *out);
size_t fm_timespec__pack_to_buffer
                     (const FmTimespec   *message,
                      ProtobufCBuffer     *buffer);
FmTimespec *
       fm_timespec__unpack
                     (ProtobufCAllocator  *allocator,
                      size_t               len,
                      const uint8_t       *data);
void   fm_timespec__free_unpacked
                     (FmTimespec *message,
                      ProtobufCAllocator *allocator);
/* FmStatRequest methods */
void   fm_stat_request__init
                     (FmStatRequest         *message);
size_t fm_stat_request__get_packed_size
                     (const FmStatRequest   *message);
size_t fm_stat_request__pack
                     (const FmStatRequest   *message,
                      uint8_t             *out);
size_t fm_stat_request__pack_to_buffer
                     (const FmStatRequest   *message,
                      ProtobufCBuffer     *buffer);
FmStatRequest *
       fm_stat_request__unpack
                     (ProtobufCAllocator  *allocator,
                      size_t               len,
                      const uint8_t       *data);
void   fm_stat_request__free_unpacked
                     (FmStatRequest *message,
                      ProtobufCAllocator *allocator);
/* FmStatResponse methods */
void   fm_stat_response__init
                     (FmStatResponse         *message);
size_t fm_stat_response__get_packed_size
                     (const FmStatResponse   *message);
size_t fm_stat_response__pack
                     (const FmStatResponse   *message,
                      uint8_t             *out);
size_t fm_stat_response__pack_to_buffer
                     (const FmStatResponse   *message,
                      ProtobufCBuffer     *buffer);
FmStatResponse *
       fm_stat_response__unpack
                     (ProtobufCAllocator  *allocator,
                      size_t               len,
                      const uint8_t       *data);
void   fm_stat_response__free_unpacked
                     (FmStatResponse *message,
                      ProtobufCAllocator *allocator);
/* FmMkdirRequest methods */
void   fm_mkdir_request__init
                     (FmMkdirRequest         *message);
size_t fm_mkdir_request__get_packed_size
                     (const FmMkdirRequest   *message);
size_t fm_mkdir_request__pack
                     (const FmMkdirRequest   *message,
                      uint8_t             *out);
size_t fm_mkdir_request__pack_to_buffer
                     (const FmMkdirRequest   *message,
                      ProtobufCBuffer     *buffer);
FmMkdirRequest *
       fm_mkdir_request__unpack
                     (ProtobufCAllocator  *allocator,
                      size_t               len,
                      const uint8_t       *data);
void   fm_mkdir_request__free_unpacked
                     (FmMkdirRequest *message,
                      ProtobufCAllocator *allocator);
/* FmRmdirRequest methods */
void   fm_rmdir_request__init
                     (FmRmdirRequest         *message);
size_t fm_rmdir_request__get_packed_size
                     (const FmRmdirRequest   *message);
size_t fm_rmdir_request__pack
                     (const FmRmdirRequest   *message,
                      uint8_t             *out);
size_t fm_rmdir_request__pack_to_buffer
                     (const FmRmdirRequest   *message,
                      ProtobufCBuffer     *buffer);
FmRmdirRequest *
       fm_rmdir_request__unpack
                     (ProtobufCAllocator  *allocator,
                      size_t               len,
                      const uint8_t       *data);
void   fm_rmdir_request__free_unpacked
                     (FmRmdirRequest *message,
                      ProtobufCAllocator *allocator);
/* FmUnlinkRequest methods */
void   fm_unlink_request__init
                     (FmUnlinkRequest         *message);
size_t fm_unlink_request__get_packed_size
                     (const FmUnlinkRequest   *message);
size_t fm_unlink_request__pack
                     (const FmUnlinkRequest   *message,
                      uint8_t             *out);
size_t fm_unlink_request__pack_to_buffer
                     (const FmUnlinkRequest   *message,
                      ProtobufCBuffer     *buffer);
FmUnlinkRequest *
       fm_unlink_request__unpack
                     (ProtobufCAllocator  *allocator,
                      size_t               len,
                      const uint8_t       *data);
void   fm_unlink_request__free_unpacked
                     (FmUnlinkRequest *message,
                      ProtobufCAllocator *allocator);
/* FmDecryptSelfRequest methods */
void   fm_decrypt_self_request__init
                     (FmDecryptSelfRequest         *message);
size_t fm_decrypt_self_request__get_packed_size
                     (const FmDecryptSelfRequest   *message);
size_t fm_decrypt_self_request__pack
                     (const FmDecryptSelfRequest   *message,
                      uint8_t             *out);
size_t fm_decrypt_self_request__pack_to_buffer
                     (const FmDecryptSelfRequest   *message,
                      ProtobufCBuffer     *buffer);
FmDecryptSelfRequest *
       fm_decrypt_self_request__unpack
                     (ProtobufCAllocator  *allocator,
                      size_t               len,
                      const uint8_t       *data);
void   fm_decrypt_self_request__free_unpacked
                     (FmDecryptSelfRequest *message,
                      ProtobufCAllocator *allocator);
/* FmDecryptSelfResponse methods */
void   fm_decrypt_self_response__init
                     (FmDecryptSelfResponse         *message);
size_t fm_decrypt_self_response__get_packed_size
                     (const FmDecryptSelfResponse   *message);
size_t fm_decrypt_self_response__pack
                     (const FmDecryptSelfResponse   *message,
                      uint8_t             *out);
size_t fm_decrypt_self_response__pack_to_buffer
                     (const FmDecryptSelfResponse   *message,
                      ProtobufCBuffer     *buffer);
FmDecryptSelfResponse *
       fm_decrypt_self_response__unpack
                     (ProtobufCAllocator  *allocator,
                      size_t               len,
                      const uint8_t       *data);
void   fm_decrypt_self_response__free_unpacked
                     (FmDecryptSelfResponse *message,
                      ProtobufCAllocator *allocator);
/* --- per-message closures --- */

typedef void (*FmEchoRequest_Closure)
                 (const FmEchoRequest *message,
                  void *closure_data);
typedef void (*FmOpenRequest_Closure)
                 (const FmOpenRequest *message,
                  void *closure_data);
typedef void (*FmCloseRequest_Closure)
                 (const FmCloseRequest *message,
                  void *closure_data);
typedef void (*FmSeekRequest_Closure)
                 (const FmSeekRequest *message,
                  void *closure_data);
typedef void (*FmReadRequest_Closure)
                 (const FmReadRequest *message,
                  void *closure_data);
typedef void (*FmReadResponse_Closure)
                 (const FmReadResponse *message,
                  void *closure_data);
typedef void (*FmWriteRequest_Closure)
                 (const FmWriteRequest *message,
                  void *closure_data);
typedef void (*FmDent_Closure)
                 (const FmDent *message,
                  void *closure_data);
typedef void (*FmGetDentsRequest_Closure)
                 (const FmGetDentsRequest *message,
                  void *closure_data);
typedef void (*FmGetDentsResponse_Closure)
                 (const FmGetDentsResponse *message,
                  void *closure_data);
typedef void (*FmTimespec_Closure)
                 (const FmTimespec *message,
                  void *closure_data);
typedef void (*FmStatRequest_Closure)
                 (const FmStatRequest *message,
                  void *closure_data);
typedef void (*FmStatResponse_Closure)
                 (const FmStatResponse *message,
                  void *closure_data);
typedef void (*FmMkdirRequest_Closure)
                 (const FmMkdirRequest *message,
                  void *closure_data);
typedef void (*FmRmdirRequest_Closure)
                 (const FmRmdirRequest *message,
                  void *closure_data);
typedef void (*FmUnlinkRequest_Closure)
                 (const FmUnlinkRequest *message,
                  void *closure_data);
typedef void (*FmDecryptSelfRequest_Closure)
                 (const FmDecryptSelfRequest *message,
                  void *closure_data);
typedef void (*FmDecryptSelfResponse_Closure)
                 (const FmDecryptSelfResponse *message,
                  void *closure_data);

/* --- services --- */

/* --- descriptors --- */

extern const ProtobufCMessageDescriptor fm_echo_request__descriptor;
extern const ProtobufCMessageDescriptor fm_open_request__descriptor;
extern const ProtobufCMessageDescriptor fm_close_request__descriptor;
extern const ProtobufCMessageDescriptor fm_seek_request__descriptor;
extern const ProtobufCMessageDescriptor fm_read_request__descriptor;
extern const ProtobufCMessageDescriptor fm_read_response__descriptor;
extern const ProtobufCMessageDescriptor fm_write_request__descriptor;
extern const ProtobufCMessageDescriptor fm_dent__descriptor;
extern const ProtobufCMessageDescriptor fm_get_dents_request__descriptor;
extern const ProtobufCMessageDescriptor fm_get_dents_response__descriptor;
extern const ProtobufCMessageDescriptor fm_timespec__descriptor;
extern const ProtobufCMessageDescriptor fm_stat_request__descriptor;
extern const ProtobufCMessageDescriptor fm_stat_response__descriptor;
extern const ProtobufCMessageDescriptor fm_mkdir_request__descriptor;
extern const ProtobufCMessageDescriptor fm_rmdir_request__descriptor;
extern const ProtobufCMessageDescriptor fm_unlink_request__descriptor;
extern const ProtobufCMessageDescriptor fm_decrypt_self_request__descriptor;
extern const ProtobufCMessageDescriptor fm_decrypt_self_response__descriptor;

PROTOBUF_C__END_DECLS

#endif  /* PROTOBUF_C_external_2ffilemanager_2eproto__INCLUDED */

repo_name: veiledmerc/mira

license: mit


code:
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++, C#, and Java: http://www.viva64.com

#include "LogManager.hpp"
#include <Messaging/Rpc/Connection.hpp>
#include <Messaging/MessageManager.hpp>

#include <Utils/Kdlsym.hpp>
#include <Utils/Kernel.hpp>
#include <Utils/Hook.hpp>

#include <Utils/SysWrappers.hpp>

#include <sys/proc.h>
#include <sys/socket.h>
#include <sys/filedesc.h>
#include <sys/syslimits.h>
#include <sys/param.h>
#include <sys/conf.h>
#include <sys/uio.h>

#include <Mira.hpp>

using namespace Mira::Plugins;
using namespace Mira::Plugins::LogManagerExtent;

LogManager::LogManager(uint16_t p_Port, char* p_Device) :
    m_Socket(-1),
    m_Port(p_Port),
    m_Thread(nullptr),
    m_Running(false)
{
    // Zero out the address
    memset(&m_Address, 0, sizeof(m_Address));

    // Get the current device path
    auto s_DevicePath = p_Device == nullptr ? DEFAULT_PATH : p_Device;

    // Calcualte the path length and cap it
    auto s_DevicePathLength = strlen(s_DevicePath);
    if (s_DevicePathLength >= sizeof(m_Device))
        s_DevicePathLength = sizeof(m_Device) - 1;

    memcpy(m_Device, s_DevicePath, s_DevicePathLength);
}

LogManager::~LogManager()
{

}

bool LogManager::OnLoad()
{
    WriteLog(LL_Info, "starting log server");
    return Startup();
}

bool LogManager::OnUnload()
{
    WriteLog(LL_Error, "unloading log server");
    return Teardown();
}

bool LogManager::OnSuspend()
{
    WriteLog(LL_Error, "suspending log server");
    return Teardown();
}

bool LogManager::OnResume()
{
    WriteLog(LL_Error, "resuming log server");
    return Startup();
}

bool LogManager::Startup()
{
    WriteLog(LL_Error, "here");

    auto s_MainThread = Mira::Framework::GetFramework()->GetMainThread();
    if (s_MainThread == nullptr)
    {
        WriteLog(LL_Error, "could not get main thread");
        return false;
    }

    WriteLog(LL_Error, "here");

    auto kthread_add = (int(*)(void(*func)(void*), void* arg, struct proc* procptr, struct thread** tdptr, int flags, int pages, const char* fmt, ...))kdlsym(kthread_add);
    WriteLog(LL_Error, "m_Socket (%d) &m_Socket (%p) s_MainThread (%p)", m_Socket, &m_Socket, s_MainThread);

    // Create a socket
    m_Socket = ksocket_t(AF_INET, SOCK_STREAM, 0, s_MainThread);
    WriteLog(LL_Error, "socket: (%d)", m_Socket);
    if (m_Socket < 0)
    {
        WriteLog(LL_Error, "could not initialize socket (%d).", m_Socket);
        return false;
    }
    WriteLog(LL_Info, "socket created: (%d).", m_Socket);

    // Set our server to listen on 0.0.0.0:<port>
    memset(&m_Address, 0, sizeof(m_Address));
    m_Address.sin_family = AF_INET;
    m_Address.sin_addr.s_addr = htonl(INADDR_ANY);
    m_Address.sin_port = htons(m_Port);
    m_Address.sin_len = sizeof(m_Address);

    WriteLog(LL_Error, "here");

    // Bind to port
    auto s_Ret = kbind_t(m_Socket, reinterpret_cast<struct sockaddr*>(&m_Address), sizeof(m_Address), s_MainThread);
    WriteLog(LL_Error, "ret (%d).", s_Ret);
    if (s_Ret < 0)
    {
        WriteLog(LL_Error, "could not bind socket (%d).", s_Ret);
        kshutdown_t(m_Socket, SHUT_RDWR, s_MainThread);
        kclose_t(m_Socket, s_MainThread);
        m_Socket = -1;
        return false;
    }
    WriteLog(LL_Info, "socket (%d) bound to port (%d).", m_Socket, m_Port);

    // Listen on the port for new connections
    s_Ret = klisten_t(m_Socket, 1, s_MainThread);
    if (s_Ret < 0)
    {
        WriteLog(LL_Error, "could not listen on socket (%d).", s_Ret);
        kshutdown_t(m_Socket, SHUT_RDWR, s_MainThread);
        kclose_t(m_Socket, s_MainThread);
        m_Socket = -1;
        return false;
    }

    // Create the new server processing thread, 8MiB stack
    s_Ret = kthread_add(LogManager::ServerThread, this, Mira::Framework::GetFramework()->GetInitParams()->process, reinterpret_cast<thread**>(&m_Thread), 0, 200, "LogServer");
    WriteLog(LL_Debug, "logserver kthread_add returned (%d).", s_Ret);

    return s_Ret == 0;
}

bool LogManager::Teardown()
{
    auto s_MainThread = Mira::Framework::GetFramework()->GetMainThread();
    if (s_MainThread == nullptr)
    {
        WriteLog(LL_Error, "could not get main thread");
        return false;
    }

    // Set that we no longer want to run this server instance
    m_Running = false;
    WriteLog(LL_Debug, "we are no longer running...");

    // Close the server socket
    if (m_Socket > 0)
    {
        kshutdown_t(m_Socket, SHUT_RDWR, s_MainThread);
        kclose_t(m_Socket, s_MainThread);
        m_Socket = -1;
    }

    WriteLog(LL_Debug, "socket is killed");

    return true;
}

void LogManager::ServerThread(void* p_UserArgs)
{
    auto kthread_exit = (void(*)(void))kdlsym(kthread_exit);

    auto s_MainThread = Mira::Framework::GetFramework()->GetMainThread();
    if (s_MainThread == nullptr)
    {
        WriteLog(LL_Error, "no main thread");
        kthread_exit();
        return;
    }

    //auto _mtx_lock_flags = (void(*)(struct mtx *m, int opts, const char *file, int line))kdlsym(_mtx_lock_flags);
    //auto _mtx_unlock_flags = (void(*)(struct mtx *m, int opts, const char *file, int line))kdlsym(_mtx_unlock_flags);

    // Check for invalid usage
    LogManager* s_LogManager = static_cast<LogManager*>(p_UserArgs);
    if (s_LogManager == nullptr)
    {
        WriteLog(LL_Error, "invalid usage, userargs are null.");
        kthread_exit();
        return;
    }

    // Set our running state
    s_LogManager->m_Running = true;

    // Create our timeout
    struct timeval s_Timeout
    {
        .tv_sec = 3,
        .tv_usec = 0
    };

    int s_ClientSocket = -1;
    struct sockaddr_in s_ClientAddress = { 0 };
    size_t s_ClientAddressLen = sizeof(s_ClientAddress);
    memset(&s_ClientAddress, 0, s_ClientAddressLen);
    s_ClientAddress.sin_len = s_ClientAddressLen;
    char s_Buffer[2] = { 0 };

    WriteLog(LL_Info, "Opening %s", s_LogManager->m_Device);
    auto s_LogDevice = kopen_t(s_LogManager->m_Device, 0x00, 0, s_MainThread);
    if (s_LogDevice < 0)
    {
        WriteLog(LL_Error, "could not open %s for reading (%d).", s_LogManager->m_Device, s_LogDevice);
        kclose_t(s_ClientSocket, s_MainThread);
        goto cleanup;
    }

    WriteLog(LL_Error, "here");
    // Loop and try to accept a client
    while ((s_ClientSocket = kaccept_t(s_LogManager->m_Socket, reinterpret_cast<struct sockaddr*>(&s_ClientAddress), &s_ClientAddressLen, s_MainThread)) > 0)
    {
        WriteLog(LL_Error, "here");
        if (!s_LogManager->m_Running)
            break;

        WriteLog(LL_Error, "here");
        // SO_LINGER
        s_Timeout.tv_sec = 0;
        auto result = ksetsockopt_t(s_ClientSocket, SOL_SOCKET, SO_LINGER, (caddr_t)&s_Timeout, sizeof(s_Timeout), s_MainThread);
        if (result < 0)
        {
            WriteLog(LL_Error, "could not set send timeout (%d).", result);
            kshutdown_t(s_ClientSocket, SHUT_RDWR, s_MainThread);
            kclose_t(s_ClientSocket, s_MainThread);
            continue;
        }

        WriteLog(LL_Error, "here");

        uint32_t l_Addr = (uint32_t)s_ClientAddress.sin_addr.s_addr;

        WriteLog(LL_Debug, "got new log connection (%d) from IP (%03d.%03d.%03d.%03d).", s_ClientSocket,
            (l_Addr & 0xFF),
            (l_Addr >> 8) & 0xFF,
            (l_Addr >> 16) & 0xFF,
            (l_Addr >> 24) & 0xFF);

        // Loop reading the data from the klog
        auto bytesRead = 0;
        while ((bytesRead = kread_t(s_LogDevice, s_Buffer, 1, s_MainThread)) > 0)
        {
            if (kwrite_t(s_ClientSocket, s_Buffer, 1, s_MainThread) <= 0)
                break;

            memset(s_Buffer, 0, sizeof(s_Buffer));
        }

        WriteLog(LL_Error, "here");

        WriteLog(LL_Debug, "log connection (%d) disconnected from IP (%03d.%03d.%03d.%03d).", s_ClientSocket,
            (l_Addr & 0xFF),
            (l_Addr >> 8) & 0xFF,
            (l_Addr >> 16) & 0xFF,
            (l_Addr >> 24) & 0xFF);

        // Close down the client socket that was created
        kshutdown_t(s_ClientSocket, SHUT_RDWR, s_MainThread);
        kclose_t(s_ClientSocket, s_MainThread);

        WriteLog(LL_Error, "here");
    }

cleanup:
    // Disconnects all clients, set running to false
    WriteLog(LL_Debug, "logserver tearing down");
    s_LogManager->Teardown();

    WriteLog(LL_Debug, "logserver exiting cleanly");
    kthread_exit();
}


code:
#pragma once
#include <Utils/IModule.hpp>
#include <Utils/Vector.hpp>
#include <Utils/Hook.hpp>

#include <netinet/in.h>
#include <sys/syslimits.h>
#include <sys/param.h>

#define DEFAULT_PATH "/dev/klog"

struct thread;

namespace Mira
{
    namespace Plugins
    {
        namespace LogManagerExtent
        {
            class LogManager : public Mira::Utils::IModule
            {
            private:
                // Server address
                struct sockaddr_in m_Address;

                // Socket
                int32_t m_Socket;

                // Server port
                uint16_t m_Port;

                // Thread
                void* m_Thread;

                // Device path
                char m_Device[PATH_MAX];

                // Running
                volatile bool m_Running;

            public:
                LogManager(uint16_t p_Port = 9998, char* p_Device = nullptr);
                virtual ~LogManager();

                bool Startup();
                bool Teardown();
                virtual const char* GetName() override { return "LogServer"; }
                virtual bool OnLoad() override;
                virtual bool OnUnload() override;
                virtual bool OnSuspend() override;
                virtual bool OnResume() override;

            private:
                static void ServerThread(void* p_UserData);
            };
        }
    }
}


code:
#include "ModuleLoader.hpp"
#include <Messaging/Rpc/Connection.hpp>
#include <Messaging/MessageManager.hpp>

#include <Utils/Kdlsym.hpp>
#include <Utils/Kernel.hpp>
#include <Utils/Hook.hpp>

#include <Utils/SysWrappers.hpp>

#include <sys/proc.h>
#include <sys/socket.h>
#include <sys/filedesc.h>
#include <sys/syslimits.h>
#include <sys/param.h>
#include <sys/conf.h>
#include <sys/sysent.h>
#include <sys/uio.h>
#include <vm/vm.h>
#include <fcntl.h>
#include <Mira.hpp>
#include <Utils/Kdlsym.hpp>

using namespace Mira::Plugins;

ModuleLoader::ModuleLoader()
{

}

ModuleLoader::~ModuleLoader()
{

}

void ModuleLoader::GetRoot()
{
    struct prison **prison0 = NULL;
    struct vnode **rootvnode = NULL;
    struct thread *td = curthread;

	/* Resolve credentials */
	struct ucred *cred;
	struct filedesc *fd;

	fd = td->td_proc->p_fd;
	cred = td->td_proc->p_ucred;

	/* Escalate process to uid0 */
	cred->cr_uid = 0;
	cred->cr_ruid = 0;
	cred->cr_rgid = 0;
	cred->cr_groups[0] = 0;

	/* Break out of FreeBSD jail */
	prison0 = (struct prison **)kdlsym(prison0);
	cred->cr_prison = prison0[0];

	/* Set sony auth ID flag */
	cred->cr_sceAuthID = 0x3800000000000007ULL;

	/* Obtain system credentials for Sony stuff */
	cred->cr_sceCaps[0] = 0xffffffffffffffff;
	cred->cr_sceCaps[1] = 0xffffffffffffffff;

	/* Set vnode to real root "/" to defeat sandbox */
	rootvnode = (struct vnode **)kdlsym(rootvnode);
	fd->fd_rdir = rootvnode[0];
	fd->fd_jdir = rootvnode[0];

}

bool ModuleLoader::SpawnKproc()
{
    auto kproc_create = (int(*)(void (*func)(void *), void *arg, struct proc **newpp, int flags, int pages, const char *fmt, ...)) kdlsym(kproc_create);
    auto kmalloc = (void*(*)(size_t size, struct	malloc_type *type, int Flags))kdlsym(malloc);
    auto kM_TEMP = (struct	malloc_type *)kdlsym(M_TEMP);

    struct proc *p = (struct proc*)kmalloc(sizeof(struct proc), kM_TEMP, 0x102);
    WriteLog(LL_Info, "KprocMain allocated at: 0x%llx", (uint64_t)p);
    WriteLog(LL_Info, "Spawing KprocMain...");
    kproc_create(ModuleLoader::KprocMain, NULL, &p, 0, 0, "MiraModuleLoader");
    return true;
}

void ModuleLoader::KprocMain(void *)
{
    WriteLog(LL_Info, "ModuleLoader::KprocMain Getting root...");
    ModuleLoader::GetRoot();

    // create new vmspace
    WriteLog(LL_Info, "ModuleLoader::KprocMain Creating new vmspace...");
	vm_offset_t sv_minuser;
	struct vmspace *vmspace;
	struct proc *p = curproc;
	struct sysentvec *sv = (struct sysentvec *)kdlsym(self_orbis_sysvec);

    // allocate user mode virtual space
    auto kvmspace_alloc = (struct vmspace*(*)(vm_offset_t min, vm_offset_t max)) kdlsym(vmspace_alloc);
    auto kpmap_activate = (void(*)(struct thread *td)) kdlsym(pmap_activate);
    auto kmem_alloc = (vm_offset_t(*)(vm_map_t, vm_size_t))kdlsym(kmem_alloc);

	sv_minuser = MAX(sv->sv_minuser, PAGE_SIZE);
	vmspace = kvmspace_alloc(sv_minuser, sv->sv_maxuser);
	if (!vmspace)
	{
		WriteLog(LL_Error, "ModuleLoader::KprocMain Could not allocate new vm space\n");
		return;
	}

    // setup vmspace
    WriteLog(LL_Info, "ModuleLoader::KprocMain Activate vmspace...");
	p->p_vmspace = vmspace;
	if (p == curthread->td_proc)
		kpmap_activate(curthread);

    WriteLog(LL_Info, "ModuleLoader::KprocMain Creating stdin/out/err...\n");
    kopen_t("/dev/console", O_RDONLY,0, curthread);
    kopen_t("/dev/console", O_RDONLY,0, curthread);
    kopen_t("/dev/console", O_RDONLY,0, curthread);

    WriteLog(LL_Info, "ModuleLoader::KprocMain Starting server...\n");
    // Create a socket
    WriteLog(LL_Info, "ModuleLoader::KprocMain Creating socket...\n");
    int ms  = ksocket_t(AF_INET, SOCK_STREAM, 0, curthread);
    if (ms < 0)
    {
        WriteLog(LL_Error, "could not initialize socket (%d).", ms);
        ms = 0;
        return;
    }
    WriteLog(LL_Info, "ModuleLoader::KprocMain socket created: (%d).", s);

    struct sockaddr_in m_Address;
    uint16_t m_Port = 9025;

    // Set our server to listen on 0.0.0.0:<port>
    auto memset = (void*(*)(void *s, int c, size_t n))kdlsym(memset);
    memset(&m_Address, 0, sizeof(m_Address));
    m_Address.sin_family = AF_INET;
    m_Address.sin_addr.s_addr = htonl(INADDR_ANY);
    m_Address.sin_port = htons(m_Port);
    m_Address.sin_len = sizeof(m_Address);

    // Bind to port
    WriteLog(LL_Info, "ModuleLoader::KprocMain Binding to port %d", m_Port);
    int s_Ret = kbind_t(ms, reinterpret_cast<struct sockaddr*>(&m_Address), sizeof(m_Address), curthread);
    if (s_Ret < 0)
    {
        WriteLog(LL_Error, "could not bind socket (%d).", s_Ret);
        kshutdown_t(ms, SHUT_RDWR, curthread);
        kclose_t(ms, curthread);
        return;
    }
    WriteLog(LL_Info, "ModuleLoader::KprocMain socket (%d) bound to port (%d).", ms, m_Port);

    // Listen on the port for new connections
    s_Ret = klisten_t(ms, 1, curthread);
    if (s_Ret < 0)
    {
        WriteLog(LL_Error, "ModuleLoader::KprocMain could not listen on socket (%d).", s_Ret);
        kshutdown_t(ms, SHUT_RDWR, curthread);
        kclose_t(ms, curthread);
        return;
    }

    for(;;)
    {
        WriteLog(LL_Info, "ModuleLoader::KprocMain accepting new payload on 9025 (%d)", s);
        int s = kaccept_t(ms, (sockaddr *) NULL, 0, curthread);

        if(s < 0)
        {
            WriteLog(LL_Error, "Accept failed, maybe we got a suspend signal");
            WriteLog(LL_Error, "Killing process\n");
            kshutdown_t(ms, SHUT_RDWR, curthread);
            kclose_t(ms, curthread);
            return;
        }

        WriteLog(LL_Info, "Got connection %d", s);

        // Alloc RWX memory
        WriteLog(LL_Info, "Allocating memory for module");
        unsigned char *mem = NULL;
        vm_map_t map = (vm_map_t)(*(uint64_t *)(kdlsym(kernel_map)));
        mem = (unsigned char *)kmem_alloc(map, 0x80000);
        if (mem == NULL)
        {
            WriteLog(LL_Error, "Memory allocation failed");
        }
        else
        {
            WriteLog(LL_Info, "Memory allocated at 0x%llx", mem);

            // Read payload from socket
            int32_t currentSize = 0;
            int32_t recvSize = 0;

            // Recv one byte at a time until we get our buffer
            while ((recvSize = krecv_t(s, mem + currentSize, 0x80000 - currentSize, 0, curthread)) > 0)
                currentSize += recvSize;

            // Close socket
            WriteLog(LL_Info, "Received %d bytes", currentSize);
            WriteLog(LL_Info, "Closing socket %d", s);
            kclose_t(s, curthread);

            auto kproc_create = (int(*)(void (*func)(void *), void *arg, struct proc **newpp, int flags, int pages, const char *fmt, ...)) kdlsym(kproc_create);
            auto kmalloc = (void*(*)(size_t size, struct	malloc_type *type, int Flags))kdlsym(malloc);
            auto kM_TEMP = (struct	malloc_type *)kdlsym(M_TEMP);

            struct proc *p = (struct proc*)kmalloc(sizeof(struct proc), kM_TEMP, 0x102);
            WriteLog(LL_Info, "ModuleProc allocated at: 0x%llx", (uint64_t)p);
            WriteLog(LL_Info, "Spawing ModuleProc...");
            kproc_create((void(*)(void *))mem, NULL, &p, 0, 0, "MiraModuleProc");
        }
    }
}

bool ModuleLoader::OnLoad()
{
    WriteLog(LL_Info, "Module Loader OnLoad");
    return this->SpawnKproc();
}

bool ModuleLoader::OnUnload()
{
    return true;
}

bool ModuleLoader::OnSuspend()
{
    WriteLog(LL_Info, "Module Loader OnSuspend");
    return true;
}

bool ModuleLoader::OnResume()
{
    WriteLog(LL_Info, "Module Loader OnResume");
    return this->SpawnKproc();
}


code:
#pragma once
#include <Utils/IModule.hpp>
#include <Utils/Vector.hpp>
#include <Utils/Hook.hpp>

#include <netinet/in.h>
#include <sys/syslimits.h>
#include <sys/param.h>

namespace Mira
{
    namespace Plugins
    {
        class ModuleLoader : public Utils::IModule
        {
        public:
            ModuleLoader();
            virtual ~ModuleLoader();

            virtual const char* GetName() override { return "ModuleLoader"; }
            virtual const char* GetDescription() override { return "Loads raw binaries into kernel space and executes them";}

            // Module callbacks
            virtual bool OnLoad() override;
            virtual bool OnUnload() override;
            virtual bool OnSuspend() override;
            virtual bool OnResume() override;

        protected:
        private:
            // Necessary methods
            static void KprocMain(void *);
            bool SpawnKproc();
            static void GetRoot();
        };
    }
}