#ifndef __LIBUFS_H__
#define __LIBUFS_H__
#include <stdbool.h>
#define LIBUFS_BUFALIGN 128
struct uufsd {
union {
struct fs d_fs;
char d_sb[SBLOCKSIZE];
} d_sbunion __aligned(LIBUFS_BUFALIGN);
union {
struct cg d_cg;
char d_buf[MAXBSIZE];
} d_cgunion __aligned(LIBUFS_BUFALIGN);
union {
union dinodep d_ino[1];
char d_inos[MAXBSIZE];
} d_inosunion __aligned(LIBUFS_BUFALIGN);
const char *d_name;
const char *d_error;
ufs2_daddr_t d_sblock;
struct fs_summary_info *d_si;
union dinodep d_dp;
ino_t d_inomin;
ino_t d_inomax;
off_t d_sblockloc;
int64_t d_bsize;
int64_t d_lookupflags;
int64_t d_mine;
int32_t d_ccg;
int32_t d_ufs;
int32_t d_fd;
int32_t d_lcg;
};
#define d_inos d_inosunion.d_inos
#define d_fs d_sbunion.d_fs
#define d_cg d_cgunion.d_cg
#ifdef _LIBUFS
#define BUF_MALLOC(newbufpp, data, size) { \
if (data != NULL && (((intptr_t)data) & (LIBUFS_BUFALIGN - 1)) == 0) \
*newbufpp = (void *)data; \
else \
*newbufpp = aligned_alloc(LIBUFS_BUFALIGN, size); \
}
static inline void
ERROR(struct uufsd *u, const char *str)
{
#ifdef _LIBUFS_DEBUGGING
if (str != NULL) {
fprintf(stderr, "libufs: %s", str);
if (errno != 0)
fprintf(stderr, ": %s", strerror(errno));
fprintf(stderr, "\n");
}
#endif
if (u != NULL)
u->d_error = str;
}
#endif
__BEGIN_DECLS
void ffs_clrblock(struct fs *, u_char *, ufs1_daddr_t);
void ffs_clusteracct(struct fs *, struct cg *, ufs1_daddr_t, int);
void ffs_fragacct(struct fs *, int, int32_t [], int);
int ffs_isblock(struct fs *, u_char *, ufs1_daddr_t);
int ffs_isfreeblock(struct fs *, u_char *, ufs1_daddr_t);
bool ffs_oldfscompat_inode_read(struct fs *, union dinodep, time_t);
int ffs_sbsearch(void *, struct fs **, int, char *,
int (*)(void *, off_t, void **, int));
void ffs_setblock(struct fs *, u_char *, ufs1_daddr_t);
int ffs_sbget(void *, struct fs **, off_t, int, char *,
int (*)(void *, off_t, void **, int));
int ffs_sbput(void *, struct fs *, off_t,
int (*)(void *, off_t, void *, int));
void ffs_update_dinode_ckhash(struct fs *, struct ufs2_dinode *);
int ffs_verify_dinode_ckhash(struct fs *, struct ufs2_dinode *);
ssize_t bread(struct uufsd *, ufs2_daddr_t, void *, size_t);
ssize_t bwrite(struct uufsd *, ufs2_daddr_t, const void *, size_t);
int berase(struct uufsd *, ufs2_daddr_t, ufs2_daddr_t);
ufs2_daddr_t cgballoc(struct uufsd *);
int cgbfree(struct uufsd *, ufs2_daddr_t, long);
ino_t cgialloc(struct uufsd *);
int cgget(int, struct fs *, int, struct cg *);
int cgput(int, struct fs *, struct cg *);
int cgread(struct uufsd *);
int cgread1(struct uufsd *, int);
int cgwrite(struct uufsd *);
int cgwrite1(struct uufsd *, int);
int getinode(struct uufsd *, union dinodep *, ino_t);
int putinode(struct uufsd *);
int sbread(struct uufsd *);
int sbfind(struct uufsd *, int);
int sbwrite(struct uufsd *, int);
int sbget(int, struct fs **, off_t, int);
int sbsearch(int, struct fs **, int);
int sbput(int, struct fs *, int);
int ufs_disk_close(struct uufsd *);
int ufs_disk_fillout(struct uufsd *, const char *);
int ufs_disk_fillout_blank(struct uufsd *, const char *);
int ufs_disk_write(struct uufsd *);
uint32_t calculate_crc32c(uint32_t, const void *, size_t);
__END_DECLS
#endif