code: mafs

ref: a566629485f872d51d4d5661d8b4aa32bd45f3e2
dir: /extents.h/

View raw version

/*
 * an ordered linked list sorted by block number (->low, ->high).
 * ->big or ->small sorted by size and then block number.
 */
typedef struct Extent Extent;
typedef struct Extents Extents;

/*
When allocating blocks from extents:
1. Of all the extents with the len we need, pick the extent with the lowest blkno.
2. If no extent of the len we need is available, then break up the smallest extent.
*/
struct Extent {
	struct Extent *low, *high;	/* sorted by blkno */
	struct Extent *small, *big;	/* sorted by len */
	u64 blkno;					/* block number */
	u64 len; 					/* in blocks */
};
struct Extents {
	Extent *lru;	/* least recently used extent */
	QLock el;
	u32 n;			/* number of extents */
};

extern int chatty9p;
void	*emalloc(u32 sz);
s8	*estrdup(s8 *s);
void	panic(char *fmt, ...);
s8	find(Extents *es, u64 bno);
Extent *add(Extents *es, u64 blkno, u64 len);

void	showblocknos(Extents *es);
void	showextents(char *msg, Extents *es);
s32	sizeofextents(Extents *es);
s32	saveextents(Extents *es, s8 *buf, u32 nbuf);
s32	loadextents(Extents *es, s8 *buf, u32 nbuf);

u64	 balloc(Extents *es, u64 n);
void bfree(Extents *es, u64 blkno, u64 len);
u64	 nfrees(Extents *es);

Extent *lowest(Extents *es);