#ifndef _KERNEL_FS_TARFS_H
#define _KERNEL_FS_TARFS_H

#include <desc.h>
#include <device/device.h>
#include <dir_entry.h>
#include <libk/std.h>
#include <proc/proc.h>
#include <proc/reschedule.h>

struct tar_header {
  char filename[100];
  uint8_t mode[8];
  uint8_t uid[8];
  uint8_t gid[8];
  uint8_t size[12];
  uint8_t mtime[12];
  uint8_t checksum[8];
  uint8_t type_flag;
} PACKED;

struct tar_file {
  struct tar_header* header;
  uint8_t* content;
  size_t size;
};

#define TARFS_FILES_MAX 128

struct tarfs {
  struct tar_file tarfs_files[TARFS_FILES_MAX];
  uint8_t* buffer;
};

struct vfs_volume;

int tarfs_mount (struct vfs_volume* volume, bool format);

int tarfs_format (struct vfs_volume* volume);

int tarfs_describe (struct vfs_volume* volume, const char* path, struct desc* desc);

int tarfs_read_file (struct vfs_volume* volume, const char* path, uint8_t* buffer, size_t off,
                     size_t size);

int tarfs_write_file (struct vfs_volume* volume, const char* path, uint8_t* buffer, size_t off,
                      size_t size, uint32_t flags);

int tarfs_read_dir_entry (struct vfs_volume* volume, const char* path, struct dir_entry* entry,
                          size_t entry_num);

int tarfs_create_file (struct vfs_volume* volume, const char* path);

int tarfs_create_dir (struct vfs_volume* volume, const char* path);

int tarfs_remove (struct vfs_volume* volume, const char* path);

#endif // _KERNEL_FS_TARFS_H
