48#define FSW_PATH_MAX (4096)
51#define FSW_CONCAT3(a,b,c) a##b##c
53#define FSW_FSTYPE_TABLE_NAME(t) FSW_CONCAT3(fsw_,t,_table)
56#define FSW_INVALID_BNO (~0U)
77#define FSW_SWAPVALUE_U16(v) ((((fsw_u16)(v) & 0xff00) >> 8) | \
78 (((fsw_u16)(v) & 0x00ff) << 8))
79#define FSW_SWAPVALUE_U32(v) ((((fsw_u32)(v) & 0xff000000UL) >> 24) | \
80 (((fsw_u32)(v) & 0x00ff0000UL) >> 8) | \
81 (((fsw_u32)(v) & 0x0000ff00UL) << 8) | \
82 (((fsw_u32)(v) & 0x000000ffUL) << 24))
83#define FSW_SWAPVALUE_U64(v) ((((fsw_u64)(v) & 0xff00000000000000ULL) >> 56) | \
84 (((fsw_u64)(v) & 0x00ff000000000000ULL) >> 40) | \
85 (((fsw_u64)(v) & 0x0000ff0000000000ULL) >> 24) | \
86 (((fsw_u64)(v) & 0x000000ff00000000ULL) >> 8) | \
87 (((fsw_u64)(v) & 0x00000000ff000000ULL) << 8) | \
88 (((fsw_u64)(v) & 0x0000000000ff0000ULL) << 24) | \
89 (((fsw_u64)(v) & 0x000000000000ff00ULL) << 40) | \
90 (((fsw_u64)(v) & 0x00000000000000ffULL) << 56))
92#ifdef FSW_LITTLE_ENDIAN
94#define fsw_u16_le_swap(v) (v)
95#define fsw_u16_be_swap(v) FSW_SWAPVALUE_U16(v)
96#define fsw_u32_le_swap(v) (v)
97#define fsw_u32_be_swap(v) FSW_SWAPVALUE_U32(v)
98#define fsw_u64_le_swap(v) (v)
99#define fsw_u64_be_swap(v) FSW_SWAPVALUE_U64(v)
101#define fsw_u16_le_sip(var)
102#define fsw_u16_be_sip(var) (var = FSW_SWAPVALUE_U16(var))
103#define fsw_u32_le_sip(var)
104#define fsw_u32_be_sip(var) (var = FSW_SWAPVALUE_U32(var))
105#define fsw_u64_le_sip(var)
106#define fsw_u64_be_sip(var) (var = FSW_SWAPVALUE_U64(var))
111#define fsw_u16_le_swap(v) FSW_SWAPVALUE_U16(v)
112#define fsw_u16_be_swap(v) (v)
113#define fsw_u32_le_swap(v) FSW_SWAPVALUE_U32(v)
114#define fsw_u32_be_swap(v) (v)
115#define fsw_u64_le_swap(v) FSW_SWAPVALUE_U64(v)
116#define fsw_u64_be_swap(v) (v)
118#define fsw_u16_le_sip(var) (var = FSW_SWAPVALUE_U16(var))
119#define fsw_u16_be_sip(var)
120#define fsw_u32_le_sip(var) (var = FSW_SWAPVALUE_U32(var))
121#define fsw_u32_be_sip(var)
122#define fsw_u64_le_sip(var) (var = FSW_SWAPVALUE_U64(var))
123#define fsw_u64_be_sip(var)
126#fail Neither FSW_BIG_ENDIAN nor FSW_LITTLE_ENDIAN are defined
139#define VOLSTRUCTNAME fsw_volume
143#ifndef DNODESTRUCTNAME
144#define DNODESTRUCTNAME fsw_dnode
192#ifdef FSW_LITTLE_ENDIAN
193#define FSW_STRING_TYPE_UTF16_LE FSW_STRING_TYPE_UTF16
194#define FSW_STRING_TYPE_UTF16_BE FSW_STRING_TYPE_UTF16_SWAPPED
196#define FSW_STRING_TYPE_UTF16_LE FSW_STRING_TYPE_UTF16_SWAPPED
197#define FSW_STRING_TYPE_UTF16_BE FSW_STRING_TYPE_UTF16
201#define FSW_STRING_INIT { FSW_STRING_TYPE_EMPTY, 0, 0, NULL }
424 struct fsw_string *lookup_path,
char separator,
488#define S_ISUID 0004000
489#define S_ISGID 0002000
490#define S_ISTXT 0001000
492#define S_IRWXU 0000700
493#define S_IRUSR 0000400
494#define S_IWUSR 0000200
495#define S_IXUSR 0000100
497#define S_IRWXG 0000070
498#define S_IRGRP 0000040
499#define S_IWGRP 0000020
500#define S_IXGRP 0000010
502#define S_IRWXO 0000007
503#define S_IROTH 0000004
504#define S_IWOTH 0000002
505#define S_IXOTH 0000001
507#define S_IFMT 0170000
508#define S_IFIFO 0010000
509#define S_IFCHR 0020000
510#define S_IFDIR 0040000
511#define S_IFBLK 0060000
512#define S_IFREG 0100000
513#define S_IFLNK 0120000
514#define S_IFSOCK 0140000
515#define S_ISVTX 0001000
516#define S_IFWHT 0160000
518#define S_ISDIR(m) (((m) & 0170000) == 0040000)
519#define S_ISCHR(m) (((m) & 0170000) == 0020000)
520#define S_ISBLK(m) (((m) & 0170000) == 0060000)
521#define S_ISREG(m) (((m) & 0170000) == 0100000)
522#define S_ISFIFO(m) (((m) & 0170000) == 0010000)
523#define S_ISLNK(m) (((m) & 0170000) == 0120000)
524#define S_ISSOCK(m) (((m) & 0170000) == 0140000)
525#define S_ISWHT(m) (((m) & 0170000) == 0160000)
fsw_status_t fsw_dnode_get_path(struct VOLSTRUCTNAME *vol, struct DNODESTRUCTNAME *dno, struct fsw_string *out_path)
void fsw_strfree(struct fsw_string *s)
fsw_status_t fsw_dnode_stat(struct fsw_dnode *dno, struct fsw_dnode_stat *sb)
int fsw_streq(struct fsw_string *s1, struct fsw_string *s2)
fsw_status_t fsw_dnode_fill(struct fsw_dnode *dno)
fsw_status_t fsw_block_get(struct VOLSTRUCTNAME *vol, fsw_u32 phys_bno, fsw_u32 cache_level, void **buffer_out)
int fsw_strsize(struct fsw_string *s)
int fsw_streq_cstr(struct fsw_string *s1, const char *s2)
int fsw_dnode_is_root(struct fsw_dnode *dno)
fsw_status_t fsw_dnode_create(struct VOLSTRUCTNAME *vol, struct DNODESTRUCTNAME *parent_dno, fsw_u32 dnode_id, int type, struct fsw_string *name, struct DNODESTRUCTNAME **dno_out)
fsw_status_t fsw_dnode_dir_read(struct fsw_shandle *shand, struct fsw_dnode **child_dno_out)
void fsw_shandle_close(struct fsw_shandle *shand)
int fsw_strlen(struct fsw_string *s)
fsw_status_t fsw_dnode_lookup_path(struct fsw_dnode *dno, struct fsw_string *lookup_path, char separator, struct fsw_dnode **child_dno_out)
@ FSW_EXTENT_TYPE_PHYSBLOCK
@ FSW_EXTENT_TYPE_INVALID
void fsw_dnode_mkcomplete(struct DNODESTRUCTNAME *dno)
fsw_status_t fsw_strdup_coerce(struct fsw_string *dest, int type, struct fsw_string *src)
fsw_status_t fsw_get_bless_info(struct VOLSTRUCTNAME *vol, int type, struct fsw_string *out_path)
fsw_status_t fsw_memdup(void **dest_out, void *src, int len)
fsw_status_t fsw_shandle_read(struct fsw_shandle *shand, fsw_u32 *buffer_size_inout, void *buffer)
fsw_status_t fsw_shandle_open(struct DNODESTRUCTNAME *dno, struct fsw_shandle *shand)
fsw_status_t fsw_volume_stat(struct fsw_volume *vol, struct fsw_volume_stat *sb)
fsw_status_t fsw_dnode_create_root(struct VOLSTRUCTNAME *vol, fsw_u32 dnode_id, struct DNODESTRUCTNAME **dno_out)
void fsw_set_blocksize(struct VOLSTRUCTNAME *vol, fsw_u32 phys_blocksize, fsw_u32 log_blocksize)
void * fsw_strdata(struct fsw_string *s)
void fsw_block_release(struct VOLSTRUCTNAME *vol, fsw_u32 phys_bno, void *buffer)
fsw_status_t fsw_dnode_lookup(struct fsw_dnode *dno, struct fsw_string *lookup_name, struct fsw_dnode **child_dno_out)
fsw_status_t fsw_dnode_resolve(struct fsw_dnode *dno, struct fsw_dnode **target_dno_out)
fsw_status_t fsw_mount(void *host_data, struct fsw_host_table *host_table, struct fsw_fstype_table *fstype_table, struct fsw_volume **vol_out)
void fsw_unmount(struct fsw_volume *vol)
void fsw_strsplit(struct fsw_string *lookup_name, struct fsw_string *buffer, char separator)
fsw_status_t fsw_alloc_zero(int len, void **ptr_out)
fsw_status_t fsw_dnode_readlink(struct fsw_dnode *dno, struct fsw_string *link_target)
void fsw_dnode_release(struct fsw_dnode *dno)
void fsw_dnode_retain(struct fsw_dnode *dno)
fsw_status_t fsw_dnode_readlink_data(struct DNODESTRUCTNAME *dno, struct fsw_string *link_target)
@ BLESSED_TYPE_SYSTEM_FILE
@ BLESSED_TYPE_SYSTEM_FOLDER
@ BLESSED_TYPE_OSX_FOLDER
@ FSW_STRING_TYPE_UTF16_SWAPPED
@ FSW_STRING_TYPE_ISO88591
fsw_u32 phys_bno
Physical block number.
void * data
Block data buffer.
fsw_u32 refcount
Reference count.
fsw_u32 cache_level
Level of importance of this block.
void(* store_attr_posix)(struct fsw_dnode_stat *sb, fsw_u16 posix_mode)
Callbock for storing a Posix-style file mode.
void(* store_time_posix)(struct fsw_dnode_stat *sb, int which, fsw_u32 posix_time)
Callback for storing a Posix-style timestamp.
void * host_data
Hook for a host-specific data structure.
fsw_u64 used_bytes
Bytes actually used by the file on disk.
struct VOLSTRUCTNAME * vol
The volume this dnode belongs to.
struct fsw_dnode * prev
Doubly-linked list of all dnodes: next dnode.
fsw_u32 dnode_id
Unique id number (usually the inode number)
fsw_u64 size
Data size in bytes.
struct fsw_dnode * next
Doubly-linked list of all dnodes: previous dnode.
fsw_u32 complete
Flag to be set on all dnode info was filled.
fsw_u32 refcount
Reference count.
struct DNODESTRUCTNAME * parent
Parent directory dnode.
int type
Type of the dnode - file, dir, symlink, special.
struct fsw_string name
Name of this item in the parent directory.
int type
Type of extent specification.
fsw_u32 log_count
Logical block count.
fsw_u32 log_start
Starting logical block number.
void * buffer
Allocated buffer pointer (for FSW_EXTENT_TYPE_BUFFER only)
fsw_u32 phys_start
Starting physical block number (for FSW_EXTENT_TYPE_PHYSBLOCK only)
fsw_status_t(* dnode_stat)(struct VOLSTRUCTNAME *vol, struct DNODESTRUCTNAME *dno, struct fsw_dnode_stat *sb)
fsw_u32 volume_struct_size
Size for allocating the fsw_volume structure.
fsw_status_t(* volume_stat)(struct VOLSTRUCTNAME *vol, struct fsw_volume_stat *sb)
void(* volume_free)(struct VOLSTRUCTNAME *vol)
void(* dnode_free)(struct VOLSTRUCTNAME *vol, struct DNODESTRUCTNAME *dno)
fsw_status_t(* dir_lookup)(struct VOLSTRUCTNAME *vol, struct DNODESTRUCTNAME *dno, struct fsw_string *lookup_name, struct DNODESTRUCTNAME **child_dno)
fsw_u32 dnode_struct_size
Size for allocating the fsw_dnode structure.
fsw_status_t(* dir_read)(struct VOLSTRUCTNAME *vol, struct DNODESTRUCTNAME *dno, struct fsw_shandle *shand, struct DNODESTRUCTNAME **child_dno)
fsw_status_t(* get_extent)(struct VOLSTRUCTNAME *vol, struct DNODESTRUCTNAME *dno, struct fsw_extent *extent)
struct fsw_string name
String giving the name of the file system.
fsw_status_t(* get_bless_info)(struct VOLSTRUCTNAME *vol, fsw_u32 type, struct DNODESTRUCTNAME **dno_out)
fsw_status_t(* dnode_fill)(struct VOLSTRUCTNAME *vol, struct DNODESTRUCTNAME *dno)
fsw_status_t(* readlink)(struct VOLSTRUCTNAME *vol, struct DNODESTRUCTNAME *dno, struct fsw_string *link_target)
fsw_status_t(* volume_mount)(struct VOLSTRUCTNAME *vol)
fsw_status_t(* read_block)(struct fsw_volume *vol, fsw_u32 phys_bno, void *buffer)
int native_string_type
String type used by the host environment.
void(* change_blocksize)(struct fsw_volume *vol, fsw_u32 old_phys_blocksize, fsw_u32 old_log_blocksize, fsw_u32 new_phys_blocksize, fsw_u32 new_log_blocksize)
struct fsw_extent extent
Current extent.
fsw_u64 pos
Current file pointer in bytes.
struct fsw_dnode * dnode
The dnode this handle reads data from.
void * data
Data pointer (may be NULL if type is EMPTY or len is zero)
int len
Length in characters.
int size
Total data size in bytes.
int type
Encoding of the string - empty, ISO-8859-1, UTF8, UTF16.
fsw_u64 free_bytes
Bytes still available for storing file data.
fsw_u64 total_bytes
Total size of data area size in bytes.
fsw_u32 phys_blocksize
Block size for disk access / file system structures.
struct fsw_blockcache * bcache
Array of block cache entries.
struct fsw_dnode * dnode_head
List of all dnodes allocated for this volume.
struct fsw_string label
Volume label.
fsw_u32 log_blocksize
Block size for logical file data.
int host_string_type
String type used by the host environment.
fsw_u32 bcache_size
Number of entries in the block cache array.
struct fsw_fstype_table * fstype_table
Dispatch table for file system specific functions.
struct fsw_host_table * host_table
Dispatch table for host-specific functions.
void * host_data
Hook for a host-specific data structure.
struct DNODESTRUCTNAME * root
Root directory dnode.