shithub: lwext4

Download patch

ref: c2de0281bf8490efacec1a3009e7a3ba11ed3dbe
parent: 733b2c40d7121900e339bee8784977467a9fe8c9
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Tue Nov 3 14:28:01 EST 2020

add initial Plan 9 port

--- a/include/ext4.h
+++ b/include/ext4.h
@@ -611,7 +611,7 @@
  * @return  Directory entry id (NULL if no entry)*/
 const ext4_direntry *ext4_dir_entry_next(ext4_dir *dir);
 
-/**@brief   Rewine directory entry offset.
+/**@brief   Rewind directory entry offset.
  *
  * @param   dir Directory handle.*/
 void ext4_dir_entry_rewind(ext4_dir *dir);
--- a/include/ext4_types.h
+++ b/include/ext4_types.h
@@ -64,7 +64,11 @@
 
 #define UUID_SIZE 16
 
+#ifndef __plan9__
 #pragma pack(push, 1)
+#else
+#pragma pack on
+#endif
 
 /*
  * Structure of the super block
@@ -178,7 +182,11 @@
 	uint32_t checksum;		/* crc32c(superblock) */
 };
 
+#ifndef __plan9__
 #pragma pack(pop)
+#else
+#pragma pack off
+#endif
 
 #define EXT4_SUPERBLOCK_MAGIC 0xEF53
 #define EXT4_SUPERBLOCK_SIZE 1024
@@ -365,7 +373,11 @@
 #define EXT4_INODE_INDIRECT_BLOCK_COUNT                                        \
 	(EXT4_INODE_BLOCKS - EXT4_INODE_DIRECT_BLOCK_COUNT)
 
+#ifndef __plan9__
 #pragma pack(push, 1)
+#else
+#pragma pack on
+#endif
 
 /*
  * Structure of an inode on the disk
@@ -418,7 +430,11 @@
 	uint32_t version_hi; /* High 32 bits for 64-bit version */
 };
 
+#ifndef __plan9__
 #pragma pack(pop)
+#else
+#pragma pack off
+#endif
 
 #define EXT4_INODE_MODE_FIFO 0x1000
 #define EXT4_INODE_MODE_CHARDEV 0x2000
@@ -479,7 +495,11 @@
 
 #define EXT4_DIRENTRY_DIR_CSUM 0xDE
 
+#ifndef __plan9__
 #pragma pack(push, 1)
+#else
+#pragma pack on
+#endif
 
 union ext4_dir_en_internal {
 	uint8_t name_length_high; /* Higher 8 bits of name length */
@@ -564,7 +584,11 @@
 	uint32_t checksum;		/* crc32c(uuid+inum+dirblock) */
 };
 
+#ifndef __plan9__
 #pragma pack(pop)
+#else
+#pragma pack off
+#endif
 
 #define EXT4_DIRENT_TAIL(block, blocksize) \
 	((struct ext4_dir_entry_tail *)(((char *)(block)) + ((blocksize) - \
@@ -618,7 +642,11 @@
 #define JBD_SUPERBLOCK_V2	4
 #define JBD_REVOKE_BLOCK	5
 
+#ifndef __plan9__
 #pragma pack(push, 1)
+#else
+#pragma pack on
+#endif
 
 /*
  * Standard header for all descriptor blocks:
@@ -629,7 +657,11 @@
 	uint32_t		sequence;
 };
 
+#ifndef __plan9__
 #pragma pack(pop)
+#else
+#pragma pack off
+#endif
 
 /*
  * Checksum types.
@@ -643,7 +675,11 @@
 
 #define JBD_CHECKSUM_BYTES (32 / sizeof(uint32_t))
 
+#ifndef __plan9__
 #pragma pack(push, 1)
+#else
+#pragma pack on
+#endif
 
 /*
  * Commit block header for storing transactional checksums:
@@ -691,7 +727,11 @@
 	uint32_t		blocknr_high; /* most-significant high 32bits. */
 };
 
+#ifndef __plan9__
 #pragma pack(pop)
+#else
+#pragma pack off
+#endif
 
 /* Definitions for the journal tag flags word: */
 #define JBD_FLAG_ESCAPE		1	/* on-disk block is escaped */
@@ -699,7 +739,11 @@
 #define JBD_FLAG_DELETED	4	/* block deleted by this transaction */
 #define JBD_FLAG_LAST_TAG	8	/* last tag in this descriptor block */
 
+#ifndef __plan9__
 #pragma pack(push, 1)
+#else
+#pragma pack on
+#endif
 
 /* Tail of descriptor block, for checksumming */
 struct jbd_block_tail {
@@ -720,12 +764,20 @@
 	uint32_t		checksum;
 };
 
+#ifndef __plan9__
 #pragma pack(pop)
+#else
+#pragma pack off
+#endif
 
 #define JBD_USERS_MAX 48
 #define JBD_USERS_SIZE (UUID_SIZE * JBD_USERS_MAX)
 
+#ifndef __plan9__
 #pragma pack(push, 1)
+#else
+#pragma pack on
+#endif
 
 /*
  * The journal superblock.  All fields are in big-endian byte order.
@@ -778,7 +830,11 @@
 /* 0x0400 */
 };
 
+#ifndef __plan9__
 #pragma pack(pop)
+#else
+#pragma pack off
+#endif
 
 #define JBD_SUPERBLOCK_SIZE sizeof(struct jbd_sb)
 
--- /dev/null
+++ b/include/plan9/generated/ext4_config.h
@@ -1,0 +1,30 @@
+#ifndef __plan9_generated_config_h__
+#define __plan9_generated_config_h__
+
+#include <u.h>
+#include <libc.h>
+#include <stdio.h>
+
+typedef u8int uint8_t;
+typedef u16int uint16_t;
+typedef u32int uint32_t;
+typedef u64int uint64_t;
+
+typedef s8int int8_t;
+typedef s16int int16_t;
+typedef s32int int32_t;
+typedef s64int int64_t;
+
+typedef ulong size_t;
+typedef uintptr ptrdiff_t;
+
+typedef enum { false, true } bool;
+
+#define NULL nil
+
+#define CONFIG_HAVE_OWN_ERRNO 1
+#define CONFIG_HAVE_OWN_ASSERT 0
+#define CONFIG_DEBUG_PRINTF 0
+#define CONFIG_DEBUG_ASSERT 1
+
+#endif
--- a/src/ext4.c
+++ b/src/ext4.c
@@ -657,9 +657,11 @@
 
 int ext4_journal_start(const char *mount_point __unused)
 {
-	int r = EOK;
+	int r;
 #if CONFIG_JOURNALING_ENABLE
 	r = __ext4_journal_start(mount_point);
+#else
+	r = EOK;
 #endif
 	return r;
 }
@@ -666,9 +668,11 @@
 
 int ext4_journal_stop(const char *mount_point __unused)
 {
-	int r = EOK;
+	int r;
 #if CONFIG_JOURNALING_ENABLE
 	r = __ext4_journal_stop(mount_point);
+#else
+	r = EOK;
 #endif
 	return r;
 }
@@ -675,9 +679,11 @@
 
 int ext4_recover(const char *mount_point __unused)
 {
-	int r = EOK;
+	int r;
 #if CONFIG_JOURNALING_ENABLE
 	r = __ext4_recover(mount_point);
+#else
+	r = EOK;
 #endif
 	return r;
 }
@@ -684,9 +690,11 @@
 
 static int ext4_trans_start(struct ext4_mountpoint *mp __unused)
 {
-	int r = EOK;
+	int r;
 #if CONFIG_JOURNALING_ENABLE
 	r = __ext4_trans_start(mp);
+#else
+	r = EOK;
 #endif
 	return r;
 }
@@ -693,9 +701,11 @@
 
 static int ext4_trans_stop(struct ext4_mountpoint *mp __unused)
 {
-	int r = EOK;
+	int r;
 #if CONFIG_JOURNALING_ENABLE
 	r = __ext4_trans_stop(mp);
+#else
+	r = EOK;
 #endif
 	return r;
 }
@@ -818,7 +828,7 @@
 static int ext4_trunc_inode(struct ext4_mountpoint *mp,
 			    uint32_t index, uint64_t new_size)
 {
-	int r = EOK;
+	int r;
 	struct ext4_fs *const fs = &mp->fs;
 	struct ext4_inode_ref inode_ref;
 	uint64_t inode_size;
@@ -890,7 +900,7 @@
 			  struct ext4_inode_ref *parent,
 			  struct ext4_inode_ref *dir)
 {
-	int r = EOK;
+	int r;
 	bool is_dir = ext4_inode_is_type(&mp->fs.sb, dir->inode,
 			EXT4_INODE_MODE_DIRECTORY);
 	uint32_t block_size = ext4_sb_get_block_size(&mp->fs.sb);
@@ -964,7 +974,6 @@
 	if (parent_inode)
 		*parent_inode = ref.index;
 
-	len = ext4_path_check(path, &is_goal);
 	while (1) {
 
 		len = ext4_path_check(path, &is_goal);
@@ -1133,7 +1142,7 @@
 		struct ext4_inode_ref *child_ref, bool rename)
 {
 	bool is_goal = false;
-	uint32_t inode_mode = EXT4_INODE_MODE_DIRECTORY;
+	uint32_t inode_mode;
 	uint32_t next_inode;
 
 	int r;
@@ -1156,7 +1165,6 @@
 	if (r != EOK)
 		return r;
 
-	len = ext4_path_check(path, &is_goal);
 	while (1) {
 
 		len = ext4_path_check(path, &is_goal);
@@ -1962,7 +1970,8 @@
 			/*ext4_fs_append_inode_block has failed and no
 			 * more blocks might be written. But node size
 			 * should be updated.*/
-			r = rr;
+			/* FIXME wth is happening here exactly? */
+			//r = rr;
 			goto out_fsize;
 		}
 	}
@@ -2657,11 +2666,11 @@
 		  const void *data, size_t data_size)
 {
 	bool found;
-	int r = EOK;
+	int r;
 	ext4_file f;
 	uint32_t inode;
 	uint8_t name_index;
-	const char *dissected_name = NULL;
+	const char *dissected_name;
 	size_t dissected_len = 0;
 	struct ext4_inode_ref inode_ref;
 	struct ext4_mountpoint *mp = ext4_get_mount(path);
@@ -2710,11 +2719,11 @@
 		  void *buf, size_t buf_size, size_t *data_size)
 {
 	bool found;
-	int r = EOK;
+	int r;
 	ext4_file f;
 	uint32_t inode;
 	uint8_t name_index;
-	const char *dissected_name = NULL;
+	const char *dissected_name;
 	size_t dissected_len = 0;
 	struct ext4_inode_ref inode_ref;
 	struct ext4_mountpoint *mp = ext4_get_mount(path);
@@ -2750,13 +2759,13 @@
 
 int ext4_listxattr(const char *path, char *list, size_t size, size_t *ret_size)
 {
-	int r = EOK;
+	int r;
 	ext4_file f;
 	uint32_t inode;
 	size_t list_len, list_size = 0;
 	struct ext4_inode_ref inode_ref;
 	struct ext4_xattr_list_entry *xattr_list = NULL,
-				     *entry = NULL;
+				     *entry;
 	struct ext4_mountpoint *mp = ext4_get_mount(path);
 	if (!mp)
 		return ENOENT;
@@ -2830,11 +2839,11 @@
 int ext4_removexattr(const char *path, const char *name, size_t name_len)
 {
 	bool found;
-	int r = EOK;
+	int r;
 	ext4_file f;
 	uint32_t inode;
 	uint8_t name_index;
-	const char *dissected_name = NULL;
+	const char *dissected_name;
 	size_t dissected_len = 0;
 	struct ext4_inode_ref inode_ref;
 	struct ext4_mountpoint *mp = ext4_get_mount(path);
@@ -3204,10 +3213,10 @@
 		goto Finish;
 	}
 
-	memset(&dir->de.name, 0, sizeof(dir->de.name));
+	memset(dir->de.name, 0, sizeof(dir->de.name));
 	name_length = ext4_dir_en_get_name_len(&dir->f.mp->fs.sb,
 					       it.curr);
-	memcpy(&dir->de.name, it.curr->name, name_length);
+	memcpy(dir->de.name, it.curr->name, name_length);
 
 	/* Directly copying the content isn't safe for Big-endian targets*/
 	dir->de.inode = ext4_dir_en_get_inode(it.curr);
--- a/src/ext4_balloc.c
+++ b/src/ext4_balloc.c
@@ -353,7 +353,7 @@
 			    ext4_fsblk_t goal,
 			    ext4_fsblk_t *fblock)
 {
-	ext4_fsblk_t alloc = 0;
+	ext4_fsblk_t alloc;
 	ext4_fsblk_t bmp_blk_adr;
 	uint32_t rel_blk_idx = 0;
 	uint64_t free_blocks;
--- a/src/ext4_dir_idx.c
+++ b/src/ext4_dir_idx.c
@@ -397,7 +397,7 @@
 
 	/* Set limit and current number of entries */
 	struct ext4_dir_idx_climit *climit;
-	climit = (struct ext4_dir_idx_climit *)&root->en;
+	climit = (struct ext4_dir_idx_climit *)root->en;
 
 	ext4_dir_dx_climit_set_count(climit, 1);
 
@@ -501,7 +501,7 @@
 		entry_space -= sizeof(struct ext4_dir_idx_tail);
 	entry_space = entry_space / sizeof(struct ext4_dir_idx_entry);
 
-	struct ext4_dir_idx_climit *climit = (void *)&root->en;
+	struct ext4_dir_idx_climit *climit = (void *)root->en;
 	uint16_t limit = ext4_dir_dx_climit_get_limit(climit);
 	if (limit != entry_space)
 		return EXT4_ERR_BAD_DX_DIR;
@@ -557,7 +557,7 @@
 
 	block_size = ext4_sb_get_block_size(sb);
 	root = (struct ext4_dir_idx_root *)root_block->data;
-	entries = (struct ext4_dir_idx_entry *)&root->en;
+	entries = (struct ext4_dir_idx_entry *)root->en;
 	limit = ext4_dir_dx_climit_get_limit((void *)entries);
 	ind_level = ext4_dir_dx_rinfo_get_indirect_levels(&root->info);
 
@@ -632,7 +632,6 @@
 	}
 
 	/* Unreachable */
-	return EOK;
 }
 
 /**@brief Check if the the next block would be checked during entry search.
@@ -897,7 +896,7 @@
 				  struct ext4_dir_idx_block *index_block,
 				  struct ext4_block *new_data_block)
 {
-	int rc = EOK;
+	int rc;
 	struct ext4_sblock *sb = &inode_ref->fs->sb;
 	uint32_t block_size = ext4_sb_get_block_size(&inode_ref->fs->sb);
 
@@ -1156,6 +1155,7 @@
 
 			if (meta_csum)
 				entry_space -= sizeof(struct ext4_dir_idx_tail);
+			USED(entry_space);
 
 			ext4_dir_dx_climit_set_limit(right_climit, node_limit);
 
@@ -1200,6 +1200,7 @@
 			struct ext4_dir_idx_climit *new_climit = (void*)new_en;
 			if (meta_csum)
 				entry_space -= sizeof(struct ext4_dir_idx_tail);
+			USED(entry_space);
 
 			ext4_dir_dx_climit_set_limit(new_climit, node_limit);
 
@@ -1311,7 +1312,7 @@
 	/* Check if insert operation passed */
 	r = ext4_dir_try_insert_entry(&fs->sb, parent, &target_block, child,
 					name, name_len);
-	if (r == EOK)
+	if (r != EOK)
 		goto release_target_index;
 
 	/* Split entries to two blocks (includes sorting by hash value) */
@@ -1318,10 +1319,8 @@
 	struct ext4_block new_block;
 	r = ext4_dir_dx_split_data(parent, &hinfo, &target_block, dx_blk,
 				    &new_block);
-	if (r != EOK) {
-		rc2 = r;
+	if (r == EOK)
 		goto release_target_index;
-	}
 
 	/* Where to save new entry */
 	uint32_t blk_hash = ext4_dir_dx_entry_get_hash(dx_blk->position + 1);
@@ -1331,6 +1330,8 @@
 	else
 		r = ext4_dir_try_insert_entry(&fs->sb, parent, &target_block,
 						child, name, name_len);
+	if (r != EOK)
+		goto release_target_index;
 
 	/* Cleanup */
 	r = ext4_block_set(fs->bdev, &new_block);
--- a/src/ext4_extent.c
+++ b/src/ext4_extent.c
@@ -500,6 +500,8 @@
 {
 	ext4_fsblk_t block = 0;
 
+	USED(flags);
+
 	*errp = ext4_allocate_single_block(inode_ref, goal, &block);
 	if (count)
 		*count = 1;
@@ -510,6 +512,7 @@
 				 ext4_fsblk_t block, uint32_t count,
 				 uint32_t flags __unused)
 {
+	USED(flags);
 	ext4_balloc_free_blocks(inode_ref, block, count);
 }
 
@@ -545,6 +548,7 @@
 {
 	uint16_t size;
 
+	USED(inode_ref);
 	size = sizeof(inode_ref->inode->blocks);
 	size -= sizeof(struct ext4_extent_header);
 	size /= sizeof(struct ext4_extent);
@@ -559,6 +563,7 @@
 {
 	uint16_t size;
 
+	USED(inode_ref);
 	size = sizeof(inode_ref->inode->blocks);
 	size -= sizeof(struct ext4_extent_header);
 	size /= sizeof(struct ext4_extent_index);
@@ -734,8 +739,9 @@
 	struct ext4_extent_tail *tail;
 	struct ext4_sblock *sb = &inode_ref->fs->sb;
 	const char *error_msg;
-	(void)error_msg;
 
+	USED(pblk);
+
 	if (to_le16(eh->magic) != EXT4_EXTENT_MAGIC) {
 		error_msg = "invalid magic";
 		goto corrupted;
@@ -767,6 +773,7 @@
 	return EOK;
 
 corrupted:
+	USED(error_msg);
 	ext4_dbg(DEBUG_EXTENT, "Bad extents B+ tree block: %s. "
 			       "Blocknr: %" PRId64 "\n",
 		 error_msg, pblk);
@@ -780,6 +787,7 @@
 {
 	int err;
 
+	USED(flags);
 	err = ext4_trans_block_get(inode_ref->fs->bdev, bh, pblk);
 	if (err != EOK)
 		goto errout;
@@ -857,7 +865,7 @@
 {
 	struct ext4_extent_header *eh;
 	struct ext4_block bh = EXT4_BLOCK_ZERO();
-	ext4_fsblk_t buf_block = 0;
+	ext4_fsblk_t buf_block;
 	struct ext4_extent_path *path = *orig_path;
 	int32_t depth, ppos = 0;
 	int32_t i;
@@ -1011,7 +1019,7 @@
 {
 	int i, npath_at, ret;
 	ext4_lblk_t insert_index;
-	ext4_fsblk_t newblock = 0;
+	ext4_fsblk_t newblock;
 	int depth = ext_depth(inode_ref->inode);
 	npath_at = depth - at;
 
@@ -1153,7 +1161,7 @@
 	struct ext4_extent *ex;
 	uint32_t border;
 	int32_t k;
-	int err = EOK;
+	int err;
 
 	eh = path[depth].header;
 	ex = path[depth].extent;
@@ -1358,7 +1366,7 @@
 {
 	struct ext4_extent_header *neh;
 	struct ext4_block bh = EXT4_BLOCK_ZERO();
-	ext4_fsblk_t newblock, goal = 0;
+	ext4_fsblk_t newblock, goal;
 	int err = EOK;
 
 	/* Try to prepend new index to old one */
@@ -1431,7 +1439,7 @@
 			   struct ext4_extent_path **ppath,
 			   struct ext4_extent *newext, int flags)
 {
-	int depth, level = 0, ret = 0;
+	int depth, level = 0, ret;
 	struct ext4_extent_path *path = *ppath;
 	struct ext4_extent_path *npath = NULL;
 	bool ins_right_leaf = false;
@@ -1532,7 +1540,7 @@
 static int ext4_ext_remove_idx(struct ext4_inode_ref *inode_ref,
 			       struct ext4_extent_path *path, int32_t depth)
 {
-	int err = EOK;
+	int err;
 	int32_t i = depth;
 	ext4_fsblk_t leaf;
 
@@ -1705,7 +1713,7 @@
 			     ext4_lblk_t to)
 {
 	struct ext4_extent_path *path = NULL;
-	int ret = EOK;
+	int ret;
 	int32_t depth = ext_depth(inode_ref->inode);
 	int32_t i;
 
@@ -1852,7 +1860,7 @@
 	ext4_lblk_t ee_block;
 	int32_t ee_len;
 	int32_t depth = ext_depth(inode_ref->inode);
-	int err = EOK;
+	int err;
 
 	ex = (*ppath)[depth].extent;
 	ee_block = to_le32(ex->first_block);
@@ -1904,7 +1912,7 @@
 					   struct ext4_extent_path **ppath,
 					   ext4_lblk_t split, uint32_t blocks)
 {
-	int32_t depth = ext_depth(inode_ref->inode), err = EOK;
+	int32_t depth = ext_depth(inode_ref->inode), err;
 	struct ext4_extent *ex = (*ppath)[depth].extent;
 
 	ext4_assert(to_le32(ex->first_block) <= split);
@@ -1999,8 +2007,8 @@
 			? (path->index - EXT_FIRST_INDEX(path->header))
 			: 0;
 
-		(void)a;
-		(void)b;
+		USED(a);
+		USED(b);
 		ext4_dbg(DEBUG_EXTENT,
 			 "depth %" PRId32 ", p_block: %" PRIu64 ","
 			 "p_ext offset: %td, p_idx offset: %td\n",
--- a/src/ext4_hash.c
+++ b/src/ext4_hash.c
@@ -252,7 +252,7 @@
 {
 	uint32_t hash[4];
 	uint32_t data[8];
-	uint32_t major = 0, minor = 0;
+	uint32_t major, minor = 0;
 	int unsigned_char = 0;
 
 	if (!name || !hash_major)
--- a/src/ext4_journal.c
+++ b/src/ext4_journal.c
@@ -486,7 +486,7 @@
  * @return standard error code*/
 int jbd_put_fs(struct jbd_fs *jbd_fs)
 {
-	int rc = EOK;
+	int rc;
 	rc = jbd_write_sb(jbd_fs);
 
 	ext4_fs_put_inode_ref(&jbd_fs->inode_ref);
@@ -856,6 +856,7 @@
 				   void *arg)
 {
 	uint32_t *iblock = arg;
+	USED(tag_info);
 	ext4_dbg(DEBUG_JBD, "Block in block_tag: %" PRIu64 "\n", tag_info->block);
 	(*iblock)++;
 	wrap(&jbd_fs->sb, *iblock);
@@ -1811,8 +1812,8 @@
 			  data_block = EXT4_BLOCK_ZERO();
 	int32_t tag_tbl_size = 0;
 	uint32_t desc_iblock = 0;
-	uint32_t data_iblock = 0;
-	char *tag_start = NULL, *tag_ptr = NULL;
+	uint32_t data_iblock;
+	char *tag_start, *tag_ptr = NULL;
 	struct jbd_buf *jbd_buf, *tmp;
 	struct ext4_fs *fs = journal->jbd_fs->inode_ref.fs;
 	uint32_t checksum = EXT4_CRC32_INIT;
@@ -1843,7 +1844,7 @@
 				true,
 				RB_FIND(jbd_revoke_tree,
 					&trans->revoke_root,
-					&tmp_rec));
+					&tmp_rec) != NULL);
 		jbd_trans_remove_block_rec(journal,
 					jbd_buf->block_rec, trans);
 		trans->data_cnt--;
@@ -1877,7 +1878,7 @@
 					true,
 					RB_FIND(jbd_revoke_tree,
 						&trans->revoke_root,
-						&tmp_rec));
+						&tmp_rec) != NULL);
 			jbd_trans_remove_block_rec(journal,
 					jbd_buf->block_rec, trans);
 			trans->data_cnt--;
@@ -2112,6 +2113,7 @@
 	if (res != EOK)
 		trans->error = res;
 
+	USED(bc);
 	TAILQ_REMOVE(&trans->buf_queue, jbd_buf, buf_node);
 	TAILQ_REMOVE(&block_rec->dirty_buf_queue,
 			jbd_buf,
@@ -2159,7 +2161,7 @@
 static int __jbd_journal_commit_trans(struct jbd_journal *journal,
 				      struct jbd_trans *trans)
 {
-	int rc = EOK;
+	int rc;
 	uint32_t last = journal->last;
 	struct jbd_revoke_rec *rec, *tmp;
 
@@ -2261,7 +2263,7 @@
 struct jbd_trans *
 jbd_journal_new_trans(struct jbd_journal *journal)
 {
-	struct jbd_trans *trans = NULL;
+	struct jbd_trans *trans;
 	trans = ext4_calloc(1, sizeof(struct jbd_trans));
 	if (!trans)
 		return NULL;
@@ -2282,9 +2284,7 @@
 int jbd_journal_commit_trans(struct jbd_journal *journal,
 			     struct jbd_trans *trans)
 {
-	int r = EOK;
-	r = __jbd_journal_commit_trans(journal, trans);
-	return r;
+	return __jbd_journal_commit_trans(journal, trans);
 }
 
 /**
--- a/src/ext4_mkfs.c
+++ b/src/ext4_mkfs.c
@@ -318,6 +318,7 @@
 		if (has_superblock(info, j)) {
 			bg_start_block++;
 			blk_off += info->bg_desc_reserve_blocks;
+			USED(blk_off);
 		}
 
 		uint64_t dsc_blk = bg_start_block + blk;
@@ -340,13 +341,13 @@
 static int write_bgroups(struct ext4_blockdev *bd, struct fs_aux_info *aux_info,
 			 struct ext4_mkfs_info *info)
 {
-	int r = EOK;
+	int r;
 
 	struct ext4_block b;
 	struct ext4_bgroup *bg_desc;
 
 	uint32_t i;
-	uint32_t bg_free_blk = 0;
+	uint32_t bg_free_blk;
 	uint64_t sb_free_blk = 0;
 	uint32_t block_size = ext4_sb_get_block_size(aux_info->sb);
 	uint32_t dsc_size = ext4_sb_get_desc_size(aux_info->sb);
@@ -465,7 +466,7 @@
 int ext4_mkfs_read_info(struct ext4_blockdev *bd, struct ext4_mkfs_info *info)
 {
 	int r;
-	struct ext4_sblock *sb = NULL;
+	struct ext4_sblock *sb;
 	r = ext4_block_init(bd);
 	if (r != EOK)
 		return r;
@@ -569,7 +570,7 @@
 
 static int create_dirs(struct ext4_fs *fs)
 {
-	int r = EOK;
+	int r;
 	struct ext4_inode_ref root;
 	struct ext4_inode_ref child;
 
--- a/src/ext4_xattr.c
+++ b/src/ext4_xattr.c
@@ -465,7 +465,7 @@
 static void ext4_xattr_find_entry(struct ext4_xattr_info *i,
 				  struct ext4_xattr_search *s)
 {
-	struct ext4_xattr_entry *entry = NULL;
+	struct ext4_xattr_entry *entry;
 
 	s->not_found = true;
 	s->here = NULL;
@@ -859,7 +859,7 @@
 	    ext4_inode_get_extra_isize(&fs->sb, inode_ref->inode);
 	struct ext4_block block;
 	bool block_loaded = false;
-	ext4_fsblk_t xattr_block = 0;
+	ext4_fsblk_t xattr_block;
 	struct ext4_xattr_entry *entry;
 	struct ext4_xattr_list_entry *list_prev = NULL;
 	xattr_block = ext4_inode_get_file_acl(inode_ref->inode, &fs->sb);
@@ -997,12 +997,12 @@
 		   const char *name, size_t name_len, void *buf, size_t buf_len,
 		   size_t *data_len)
 {
-	int ret = EOK;
+	int ret;
 	struct ext4_xattr_finder ibody_finder;
 	struct ext4_xattr_finder block_finder;
 	struct ext4_xattr_info i;
 	size_t value_len = 0;
-	size_t value_offs = 0;
+	size_t value_offs;
 	struct ext4_fs *fs = inode_ref->fs;
 	ext4_fsblk_t xattr_block;
 	xattr_block = ext4_inode_get_file_acl(inode_ref->inode, &fs->sb);
@@ -1170,7 +1170,7 @@
 int ext4_xattr_remove(struct ext4_inode_ref *inode_ref, uint8_t name_index,
 		      const char *name, size_t name_len)
 {
-	int ret = EOK;
+	int ret;
 	struct ext4_block block;
 	struct ext4_xattr_finder ibody_finder;
 	struct ext4_xattr_finder block_finder;
@@ -1246,8 +1246,7 @@
 			ext4_block_set(fs->bdev, &new_block);
 			ext4_xattr_try_free_block(inode_ref);
 		} else {
-			struct ext4_xattr_header *header =
-			    EXT4_XATTR_BHDR(&new_block);
+			struct ext4_xattr_header *header;
 			header = EXT4_XATTR_BHDR(&new_block);
 			ext4_assert(block_finder.s.first);
 			ext4_xattr_rehash(header, block_finder.s.first);
@@ -1283,7 +1282,7 @@
 				struct ext4_xattr_info *i,
 				bool no_insert)
 {
-	int ret = EOK;
+	int ret;
 	bool allocated = false;
 	struct ext4_fs *fs = inode_ref->fs;
 	struct ext4_block block, new_block;
@@ -1417,7 +1416,7 @@
 static int ext4_xattr_block_remove(struct ext4_inode_ref *inode_ref,
 				   struct ext4_xattr_info *i)
 {
-	int ret = EOK;
+	int ret;
 	bool allocated = false;
 	const void *value = i->value;
 	struct ext4_fs *fs = inode_ref->fs;
@@ -1485,7 +1484,7 @@
 		   const char *name, size_t name_len, const void *value,
 		   size_t value_len)
 {
-	int ret = EOK;
+	int ret;
 	struct ext4_fs *fs = inode_ref->fs;
 	struct ext4_xattr_finder ibody_finder;
 	struct ext4_xattr_info i;
--- /dev/null
+++ b/src/mkfile
@@ -1,0 +1,66 @@
+</$objtype/mkfile
+
+CFLAGS=$CFLAGS -p -I../include/plan9 -I../include
+LIB=liblwext4.a
+
+HFILES=\
+	../include/ext4.h\
+	../include/ext4_balloc.h\
+	../include/ext4_bcache.h\
+	../include/ext4_bitmap.h\
+	../include/ext4_block_group.h\
+	../include/ext4_blockdev.h\
+	../include/ext4_config.h\
+	../include/ext4_crc32.h\
+	../include/ext4_debug.h\
+	../include/ext4_dir.h\
+	../include/ext4_dir_idx.h\
+	../include/ext4_errno.h\
+	../include/ext4_extent.h\
+	../include/ext4_fs.h\
+	../include/ext4_hash.h\
+	../include/ext4_ialloc.h\
+	../include/ext4_inode.h\
+	../include/ext4_journal.h\
+	../include/ext4_mbr.h\
+	../include/ext4_misc.h\
+	../include/ext4_mkfs.h\
+	../include/ext4_oflags.h\
+	../include/ext4_super.h\
+	../include/ext4_trans.h\
+	../include/ext4_types.h\
+	../include/ext4_xattr.h\
+	../include/misc/queue.h\
+	../include/misc/tree.h\
+
+UPDATE=\
+	mkfile\
+	$HFILES\
+	${OFILES:%.$O=%.c}\
+
+OFILES=\
+	ext4.$O\
+	ext4_balloc.$O\
+	ext4_bcache.$O\
+	ext4_bitmap.$O\
+	ext4_block_group.$O\
+	ext4_blockdev.$O\
+	ext4_crc32.$O\
+	ext4_debug.$O\
+	ext4_dir.$O\
+	ext4_dir_idx.$O\
+	ext4_extent.$O\
+	ext4_fs.$O\
+	ext4_hash.$O\
+	ext4_ialloc.$O\
+	ext4_inode.$O\
+	ext4_journal.$O\
+	ext4_mbr.$O\
+	ext4_mkfs.$O\
+	ext4_super.$O\
+	ext4_trans.$O\
+	ext4_xattr.$O\
+
+default:V: all
+
+</sys/src/cmd/mklib