HelenOS sources
#ifndef EXFAT_EXFAT_H_
#define EXFAT_EXFAT_H_
#include "exfat_fat.h"
#include <fibril_synch.h>
#include <libfs.h>
#include <stdint.h>
#include <stdbool.h>
#include "../../vfs/vfs.h"
#ifndef dprintf
#define dprintf(...) printf(__VA_ARGS__)
#endif
#define BS_BLOCK 0
#define BS_SIZE 512
#define BPS(bs) ((uint32_t) (1 << (bs->bytes_per_sector)))
#define SPC(bs) ((uint32_t) (1 << (bs->sec_per_cluster)))
#define BPC(bs) ((uint32_t) (BPS(bs) * SPC(bs)))
#define VOL_FS(bs) uint64_t_le2host(bs->volume_start)
#define VOL_CNT(bs) uint64_t_le2host(bs->volume_count)
#define FAT_FS(bs) uint32_t_le2host(bs->fat_sector_start)
#define FAT_CNT(bs) uint32_t_le2host(bs->fat_sector_count)
#define DATA_FS(bs) uint32_t_le2host(bs->data_start_sector)
#define DATA_CNT(bs) uint32_t_le2host(bs->data_clusters)
#define ROOT_FC(bs) uint32_t_le2host(bs->rootdir_cluster)
#define VOL_FLAGS(bs) uint16_t_le2host(bs->volume_flags)
#define EXFAT_NODE(node) ((node) ? (exfat_node_t *) (node)->data : NULL)
#define FS_NODE(node) ((node) ? (node)->bp : NULL)
#define DPS(bs) (BPS((bs)) / sizeof(exfat_dentry_t))
typedef struct exfat_bs {
uint8_t jump[3];
uint8_t oem_name[8];
uint8_t __reserved[53];
uint64_t volume_start;
uint64_t volume_count;
uint32_t fat_sector_start;
uint32_t fat_sector_count;
uint32_t data_start_sector;
uint32_t data_clusters;
uint32_t rootdir_cluster;
uint32_t volume_serial;
struct {
uint8_t minor;
uint8_t major;
} __attribute__((packed)) version;
uint16_t volume_flags;
uint8_t bytes_per_sector;
uint8_t sec_per_cluster;
uint8_t fat_count;
uint8_t drive_no;
uint8_t allocated_percent;
uint8_t _reserved2[7];
uint8_t bootcode[390];
uint16_t signature;
} __attribute__((__packed__)) exfat_bs_t;
typedef enum {
EXFAT_UNKNOW,
EXFAT_DIRECTORY,
EXFAT_FILE,
EXFAT_BITMAP,
EXFAT_UCTABLE
} exfat_node_type_t;
struct exfat_node;
struct exfat_idx_t;
typedef struct {
ht_link_t uph_link;
ht_link_t uih_link;
fibril_mutex_t lock;
service_id_t service_id;
fs_index_t index;
bool parent_fragmented;
exfat_cluster_t pfc;
unsigned pdi;
struct exfat_node *nodep;
} exfat_idx_t;
typedef struct exfat_node {
fs_node_t *bp;
fibril_mutex_t lock;
exfat_node_type_t type;
exfat_idx_t *idx;
exfat_cluster_t firstc;
link_t ffn_link;
aoff64_t size;
unsigned lnkcnt;
unsigned refcnt;
bool dirty;
bool fragmented;
bool lastc_cached_valid;
exfat_cluster_t lastc_cached_value;
bool currc_cached_valid;
aoff64_t currc_cached_bn;
exfat_cluster_t currc_cached_value;
} exfat_node_t;
extern vfs_out_ops_t exfat_ops;
extern libfs_ops_t exfat_libfs_ops;
extern errno_t exfat_idx_get_new(exfat_idx_t **, service_id_t);
extern exfat_idx_t *exfat_idx_get_by_pos(service_id_t, exfat_cluster_t, unsigned);
extern exfat_idx_t *exfat_idx_get_by_index(service_id_t, fs_index_t);
extern void exfat_idx_destroy(exfat_idx_t *);
extern void exfat_idx_hashin(exfat_idx_t *);
extern void exfat_idx_hashout(exfat_idx_t *);
extern errno_t exfat_idx_init(void);
extern void exfat_idx_fini(void);
extern errno_t exfat_idx_init_by_service_id(service_id_t);
extern void exfat_idx_fini_by_service_id(service_id_t);
extern errno_t exfat_node_expand(service_id_t, exfat_node_t *, exfat_cluster_t);
extern errno_t exfat_node_put(fs_node_t *);
extern errno_t exfat_bitmap_get(fs_node_t **, service_id_t);
extern errno_t exfat_uctable_get(fs_node_t **, service_id_t);
#endif
HelenOS homepage, sources at GitHub