Index: uspace/srv/fs/fat/fat.h
===================================================================
--- uspace/srv/fs/fat/fat.h	(revision 0dbe5ac3da1c850ebb3e4d5701b7b4409a026277)
+++ uspace/srv/fs/fat/fat.h	(revision 5d95f02bc12b9857f647e740b9a09558e914a1f3)
@@ -47,5 +47,5 @@
 #endif
 
-#define min(a, b)		((a) < (b) ? (a) : (b))
+#define min(a, b)	((a) < (b) ? (a) : (b))
 
 /*
@@ -56,14 +56,17 @@
 #define RSCNT(bs)	uint16_t_le2host((bs)->rscnt)
 #define FATCNT(bs)	(bs)->fatcnt
-#define SF(bs)		(uint16_t_le2host((bs)->sec_per_fat) !=0 ? \
+
+#define SF(bs)		(uint16_t_le2host((bs)->sec_per_fat) ? \
     uint16_t_le2host((bs)->sec_per_fat) : \
     uint32_t_le2host(bs->fat32.sectors_per_fat))
+
 #define RDE(bs)		uint16_t_le2host((bs)->root_ent_max)
-#define TS(bs)		(uint16_t_le2host((bs)->totsec16) != 0 ? \
-			uint16_t_le2host((bs)->totsec16) : \
-			uint32_t_le2host(bs->totsec32))
-
-#define BS_BLOCK		0
-#define BS_SIZE			512
+
+#define TS(bs)		(uint16_t_le2host((bs)->totsec16) ? \
+    uint16_t_le2host((bs)->totsec16) : \
+    uint32_t_le2host(bs->totsec32))
+
+#define BS_BLOCK	0
+#define BS_SIZE		512
 
 typedef struct fat_bs {
Index: uspace/srv/fs/fat/fat_dentry.c
===================================================================
--- uspace/srv/fs/fat/fat_dentry.c	(revision 0dbe5ac3da1c850ebb3e4d5701b7b4409a026277)
+++ uspace/srv/fs/fat/fat_dentry.c	(revision 5d95f02bc12b9857f647e740b9a09558e914a1f3)
@@ -221,8 +221,9 @@
 uint8_t fat_dentry_chksum(uint8_t *name)
 {
-	uint8_t i, sum=0;
-	for (i=0; i<(FAT_NAME_LEN+FAT_EXT_LEN); i++) {
+	uint8_t i, sum = 0;
+
+	for (i = 0; i < (FAT_NAME_LEN + FAT_EXT_LEN); i++)
 		sum = ((sum & 1) ? 0x80 : 0) + (sum >> 1) + name[i];
-	}
+
 	return sum;
 }
@@ -269,5 +270,5 @@
 {
 	int i;
-	for (i=FAT_LFN_PART3_SIZE-1; i>=0 && *offset>0; i--) {
+	for (i = FAT_LFN_PART3_SIZE - 1; i >= 0 && *offset > 0; i--) {
 		if (d->lfn.part3[i] == 0 || d->lfn.part3[i] == FAT_LFN_PAD)
 			continue;
@@ -275,5 +276,5 @@
 		dst[(*offset)] = uint16_t_le2host(d->lfn.part3[i]);
 	}
-	for (i=FAT_LFN_PART2_SIZE-1; i>=0 && *offset>0; i--) {
+	for (i = FAT_LFN_PART2_SIZE - 1; i >= 0 && *offset > 0; i--) {
 		if (d->lfn.part2[i] == 0 || d->lfn.part2[i] == FAT_LFN_PAD)
 			continue;
@@ -281,5 +282,5 @@
 		dst[(*offset)] = uint16_t_le2host(d->lfn.part2[i]);
 	}
-	for (i=FAT_LFN_PART1_SIZE-1; i>=0 && *offset>0; i--) {
+	for (i = FAT_LFN_PART1_SIZE - 1; i >= 0 && *offset > 0; i--) {
 		if (d->lfn.part1[i] == 0 || d->lfn.part1[i] == FAT_LFN_PAD)
 			continue;
@@ -290,29 +291,27 @@
 }
 
-size_t fat_lfn_set_entry(const uint16_t *src, size_t *offset, size_t size, fat_dentry_t *d)
+size_t fat_lfn_set_entry(const uint16_t *src, size_t *offset, size_t size,
+    fat_dentry_t *d)
 {
 	size_t idx;
-	for (idx=0; idx < FAT_LFN_PART1_SIZE; idx++) {
+	for (idx = 0; idx < FAT_LFN_PART1_SIZE; idx++) {
 		if (*offset < size) {
 			d->lfn.part1[idx] = host2uint16_t_le(src[*offset]);
 			(*offset)++;
-		}
-		else
+		} else
 			d->lfn.part1[idx] = FAT_LFN_PAD;
 	}
-	for (idx=0; idx < FAT_LFN_PART2_SIZE; idx++) {
+	for (idx = 0; idx < FAT_LFN_PART2_SIZE; idx++) {
 		if (*offset < size) {
 			d->lfn.part2[idx] = host2uint16_t_le(src[*offset]);
 			(*offset)++;
-		}
-		else
+		} else
 			d->lfn.part2[idx] = FAT_LFN_PAD;
 	}
-	for (idx=0; idx < FAT_LFN_PART3_SIZE; idx++) {
+	for (idx = 0; idx < FAT_LFN_PART3_SIZE; idx++) {
 		if (*offset < size) {
 			d->lfn.part3[idx] = host2uint16_t_le(src[*offset]);
 			(*offset)++;
-		}
-		else
+		} else
 			d->lfn.part3[idx] = FAT_LFN_PAD;
 	}
@@ -339,6 +338,5 @@
 			else
 				*dst = pad;
-		}
-		else
+		} else
 			break;
 
Index: uspace/srv/fs/fat/fat_dentry.h
===================================================================
--- uspace/srv/fs/fat/fat_dentry.h	(revision 0dbe5ac3da1c850ebb3e4d5701b7b4409a026277)
+++ uspace/srv/fs/fat/fat_dentry.h	(revision 5d95f02bc12b9857f647e740b9a09558e914a1f3)
@@ -71,14 +71,14 @@
 #define FAT_LFN_ERASED		0x80
 
-#define FAT_LFN_ORDER(d) (d->lfn.order)
+#define FAT_LFN_ORDER(d) ((d)->lfn.order)
 #define FAT_IS_LFN(d) \
-    ((FAT_LFN_ORDER(d) & FAT_LFN_LAST) == FAT_LFN_LAST)
+    ((FAT_LFN_ORDER((d)) & FAT_LFN_LAST) == FAT_LFN_LAST)
 #define FAT_LFN_COUNT(d) \
-    (FAT_LFN_ORDER(d) ^ FAT_LFN_LAST)
-#define FAT_LFN_PART1(d) (d->lfn.part1)
-#define FAT_LFN_PART2(d) (d->lfn.part2)
-#define FAT_LFN_PART3(d) (d->lfn.part3)
-#define FAT_LFN_ATTR(d) (d->lfn.attr)
-#define FAT_LFN_CHKSUM(d) (d->lfn.check_sum)
+    (FAT_LFN_ORDER((d)) ^ FAT_LFN_LAST)
+#define FAT_LFN_PART1(d) ((d)->lfn.part1)
+#define FAT_LFN_PART2(d) ((d)->lfn.part2)
+#define FAT_LFN_PART3(d) ((d)->lfn.part3)
+#define FAT_LFN_ATTR(d) ((d)->lfn.attr)
+#define FAT_LFN_CHKSUM(d) ((d)->lfn.check_sum)
 
 #define FAT_LFN_NAME_SIZE   260
@@ -98,38 +98,36 @@
 } fat_dentry_clsf_t;
 
-typedef struct {
-	union {
-		struct {
-			uint8_t		name[8];
-			uint8_t		ext[3];
-			uint8_t		attr;
-			uint8_t		lcase;
-			uint8_t		ctime_fine;
-			uint16_t	ctime;
-			uint16_t	cdate;
-			uint16_t	adate;
-			union {
-				uint16_t	eaidx;		/* FAT12/FAT16 */
-				uint16_t	firstc_hi;	/* FAT32 */
-			} __attribute__ ((packed));
-			uint16_t	mtime;
-			uint16_t	mdate;
-			union {
-				uint16_t	firstc;		/* FAT12/FAT16 */
-				uint16_t	firstc_lo;	/* FAT32 */
-			} __attribute__ ((packed));
-			uint32_t	size;
+typedef union {
+	struct {
+		uint8_t		name[8];
+		uint8_t		ext[3];
+		uint8_t		attr;
+		uint8_t		lcase;
+		uint8_t		ctime_fine;
+		uint16_t	ctime;
+		uint16_t	cdate;
+		uint16_t	adate;
+		union {
+			uint16_t	eaidx;		/* FAT12/FAT16 */
+			uint16_t	firstc_hi;	/* FAT32 */
 		} __attribute__ ((packed));
-		struct {
-			uint8_t		order;
-			uint16_t	part1[FAT_LFN_PART1_SIZE];
-			uint8_t		attr;
-			uint8_t		type;
-			uint8_t		check_sum;
-			uint16_t	part2[FAT_LFN_PART2_SIZE];
-			uint16_t	firstc_lo; /* MUST be 0 */
-			uint16_t	part3[FAT_LFN_PART3_SIZE];
-		} __attribute__ ((packed)) lfn;
-	};
+		uint16_t	mtime;
+		uint16_t	mdate;
+		union {
+			uint16_t	firstc;		/* FAT12/FAT16 */
+			uint16_t	firstc_lo;	/* FAT32 */
+		} __attribute__ ((packed));
+		uint32_t	size;
+	} __attribute__ ((packed));
+	struct {
+		uint8_t		order;
+		uint16_t	part1[FAT_LFN_PART1_SIZE];
+		uint8_t		attr;
+		uint8_t		type;
+		uint8_t		check_sum;
+		uint16_t	part2[FAT_LFN_PART2_SIZE];
+		uint16_t	firstc_lo; /* MUST be 0 */
+		uint16_t	part3[FAT_LFN_PART3_SIZE];
+	} __attribute__ ((packed)) lfn;
 } __attribute__ ((packed)) fat_dentry_t;
 
@@ -144,12 +142,12 @@
 extern size_t fat_lfn_size(const fat_dentry_t *);
 extern size_t fat_lfn_get_entry(const fat_dentry_t *, uint16_t *, size_t *);
-extern size_t fat_lfn_set_entry(const uint16_t *, size_t *, size_t, fat_dentry_t *);
+extern size_t fat_lfn_set_entry(const uint16_t *, size_t *, size_t,
+    fat_dentry_t *);
 
-extern void str_to_ascii(char *dst, const char *src, size_t count, uint8_t pad);
-extern size_t utf16_length(const uint16_t *wstr);
+extern void str_to_ascii(char *, const char *, size_t, uint8_t);
+extern size_t utf16_length(const uint16_t *);
 
-extern bool fat_valid_name(const char *name);
-extern bool fat_valid_short_name(const char *name);
-
+extern bool fat_valid_name(const char *);
+extern bool fat_valid_short_name(const char *);
 
 #endif
Index: uspace/srv/fs/fat/fat_directory.c
===================================================================
--- uspace/srv/fs/fat/fat_directory.c	(revision 0dbe5ac3da1c850ebb3e4d5701b7b4409a026277)
+++ uspace/srv/fs/fat/fat_directory.c	(revision 5d95f02bc12b9857f647e740b9a09558e914a1f3)
@@ -46,7 +46,4 @@
 #include <stdio.h>
 
-int fat_directory_block_load(fat_directory_t *);
-
-
 int fat_directory_open(fat_node_t *nodep, fat_directory_t *di)
 {
@@ -57,8 +54,9 @@
 
 	di->bs = block_bb_get(di->nodep->idx->service_id);
-	di->blocks = ROUND_UP(nodep->size, BPS(di->bs))/BPS(di->bs);
+	di->blocks = ROUND_UP(nodep->size, BPS(di->bs)) / BPS(di->bs);
 	di->pos = 0;
 	di->bnum = 0;
 	di->last = false;
+
 	return EOK;
 }
@@ -66,5 +64,5 @@
 int fat_directory_close(fat_directory_t *di)
 {
-	int rc=EOK;
+	int rc = EOK;
 	
 	if (di->b)
@@ -74,5 +72,5 @@
 }
 
-int fat_directory_block_load(fat_directory_t *di)
+static int fat_directory_block_load(fat_directory_t *di)
 {
 	uint32_t i;
@@ -86,5 +84,6 @@
 		}
 		if (!di->b) {
-			rc = fat_block_get(&di->b, di->bs, di->nodep, i, BLOCK_FLAGS_NONE);
+			rc = fat_block_get(&di->b, di->bs, di->nodep, i,
+			    BLOCK_FLAGS_NONE);
 			if (rc != EOK) {
 				di->b = NULL;
@@ -95,4 +94,5 @@
 		return EOK;
 	}
+
 	return ENOENT;
 }
@@ -104,5 +104,5 @@
 	di->pos += 1;
 	rc = fat_directory_block_load(di);
-	if (rc!=EOK)
+	if (rc != EOK)
 		di->pos -= 1;
 	
@@ -112,14 +112,13 @@
 int fat_directory_prev(fat_directory_t *di)
 {
-	int rc=EOK;
+	int rc = EOK;
 	
 	if (di->pos > 0) {
 		di->pos -= 1;
-		rc=fat_directory_block_load(di);
-	}
-	else
+		rc = fat_directory_block_load(di);
+	} else
 		return ENOENT;
 	
-	if (rc!=EOK)
+	if (rc != EOK)
 		di->pos += 1;
 	
@@ -134,5 +133,5 @@
 	di->pos = pos;
 	rc = fat_directory_block_load(di);
-	if (rc!=EOK)
+	if (rc != EOK)
 		di->pos = _pos;
 	
@@ -161,59 +160,66 @@
 	int long_entry_count = 0;
 	uint8_t checksum = 0;
+	int rc;
 
 	do {
-		if (fat_directory_get(di, &d) == EOK) {
-			switch (fat_classify_dentry(d)) {
-			case FAT_DENTRY_LAST:
-				long_entry_count = 0;
-				long_entry = false;
-				return ENOENT;
-			case FAT_DENTRY_LFN:
-				if (long_entry) {
-					/* We found long entry */
-					long_entry_count--;
-					if ((FAT_LFN_ORDER(d) == long_entry_count) && 
-						(checksum == FAT_LFN_CHKSUM(d))) {
-						/* Right order! */
-						fat_lfn_get_entry(d, wname, &lfn_offset);
-					} else {
-						/* Something wrong with order. Skip this long entries set */
-						long_entry_count = 0;
-						long_entry = false;
-					}
+		rc = fat_directory_get(di, &d);
+		if (rc != EOK)
+			return rc;
+
+		switch (fat_classify_dentry(d)) {
+		case FAT_DENTRY_LAST:
+			long_entry_count = 0;
+			long_entry = false;
+			return ENOENT;
+		case FAT_DENTRY_LFN:
+			if (long_entry) {
+				/* We found long entry */
+				long_entry_count--;
+				if ((FAT_LFN_ORDER(d) == long_entry_count) && 
+					(checksum == FAT_LFN_CHKSUM(d))) {
+					/* Right order! */
+					fat_lfn_get_entry(d, wname,
+					    &lfn_offset);
 				} else {
-					if (FAT_IS_LFN(d)) {
-						/* We found Last long entry! */
-						if (FAT_LFN_COUNT(d) <= FAT_LFN_MAX_COUNT) {
-							long_entry = true;
-							long_entry_count = FAT_LFN_COUNT(d);
-							lfn_size = (FAT_LFN_ENTRY_SIZE * 
-								(FAT_LFN_COUNT(d) - 1)) + fat_lfn_size(d);
-							lfn_offset = lfn_size;
-							fat_lfn_get_entry(d, wname, &lfn_offset);
-							checksum = FAT_LFN_CHKSUM(d);
-						}
-					}
+					/*
+					 * Something wrong with order.
+					 * Skip this long entries set.
+					 */
+					long_entry_count = 0;
+					long_entry = false;
 				}
-				break;
-			case FAT_DENTRY_VALID:
-				if (long_entry && 
-					(checksum == fat_dentry_chksum(d->name))) {
-					wname[lfn_size] = '\0';
-					if (utf16_to_str(name, FAT_LFN_NAME_SIZE, wname) != EOK)
-						fat_dentry_name_get(d, name);
+			} else if (FAT_IS_LFN(d)) {
+				/* We found Last long entry! */
+				if (FAT_LFN_COUNT(d) <= FAT_LFN_MAX_COUNT) {
+					long_entry = true;
+					long_entry_count = FAT_LFN_COUNT(d);
+					lfn_size = (FAT_LFN_ENTRY_SIZE * 
+					    (FAT_LFN_COUNT(d) - 1)) +
+					    fat_lfn_size(d);
+					lfn_offset = lfn_size;
+					fat_lfn_get_entry(d, wname,
+					    &lfn_offset);
+					checksum = FAT_LFN_CHKSUM(d);
 				}
-				else
+			}
+			break;
+		case FAT_DENTRY_VALID:
+			if (long_entry && 
+			    (checksum == fat_dentry_chksum(d->name))) {
+				wname[lfn_size] = '\0';
+				if (utf16_to_str(name, FAT_LFN_NAME_SIZE,
+				    wname) != EOK)
 					fat_dentry_name_get(d, name);
+			} else
+				fat_dentry_name_get(d, name);
 				
-				*de = d;
-				return EOK;
-			default:
-			case FAT_DENTRY_SKIP:
-			case FAT_DENTRY_FREE:
-				long_entry_count = 0;
-				long_entry = false;
-				break;
-			}
+			*de = d;
+			return EOK;
+		default:
+		case FAT_DENTRY_SKIP:
+		case FAT_DENTRY_FREE:
+			long_entry_count = 0;
+			long_entry = false;
+			break;
 		}
 	} while (fat_directory_next(di) == EOK);
@@ -239,13 +245,12 @@
 	while (!flag && fat_directory_prev(di) == EOK) {
 		if (fat_directory_get(di, &d) == EOK &&
-			fat_classify_dentry(d) == FAT_DENTRY_LFN &&			
-			checksum == FAT_LFN_CHKSUM(d)) {
-				if (FAT_IS_LFN(d))
-					flag = true;
-				memset(d, 0, sizeof(fat_dentry_t));
-				d->name[0] = FAT_DENTRY_ERASED;
-				di->b->dirty = true;
-		}
-		else
+		    fat_classify_dentry(d) == FAT_DENTRY_LFN &&			
+		    checksum == FAT_LFN_CHKSUM(d)) {
+			if (FAT_IS_LFN(d))
+				flag = true;
+			memset(d, 0, sizeof(fat_dentry_t));
+			d->name[0] = FAT_DENTRY_ERASED;
+			di->b->dirty = true;
+		} else
 			break;
 	}
@@ -257,8 +262,11 @@
 {
 	int rc;
-	bool enable_lfn = true; /* We can use this variable to switch off LFN support */
+	bool enable_lfn = true; /* TODO: make this a mount option */
 	
 	if (fat_valid_short_name(name)) {
-		/* NAME could be directly stored in dentry without creating LFN */
+		/*
+		 * NAME could be directly stored in dentry without creating
+		 * LFN.
+		 */
 		fat_dentry_name_set(de, name);
 		if (fat_directory_is_sfn_exist(di, de))
@@ -313,5 +321,5 @@
 			if (rc != EOK)
 				return rc;
-			fat_lfn_set_entry(wname, &lfn_offset, lfn_size+1, d);
+			fat_lfn_set_entry(wname, &lfn_offset, lfn_size + 1, d);
 			FAT_LFN_CHKSUM(d) = checksum;
 			FAT_LFN_ORDER(d) = ++idx;
@@ -327,9 +335,10 @@
 }
 
-int fat_directory_create_sfn(fat_directory_t *di, fat_dentry_t *de, const char *lname)
-{
-	char name[FAT_NAME_LEN+1];
-	char ext[FAT_EXT_LEN+1];
-	char number[FAT_NAME_LEN+1];
+int fat_directory_create_sfn(fat_directory_t *di, fat_dentry_t *de,
+    const char *lname)
+{
+	char name[FAT_NAME_LEN + 1];
+	char ext[FAT_EXT_LEN + 1];
+	char number[FAT_NAME_LEN + 1];
 	memset(name, FAT_PAD, FAT_NAME_LEN);
 	memset(ext, FAT_PAD, FAT_EXT_LEN);
@@ -349,9 +358,9 @@
 
 	unsigned idx;
-	for (idx=1; idx <= FAT_MAX_SFN; idx++) {
+	for (idx = 1; idx <= FAT_MAX_SFN; idx++) {
 		snprintf(number, sizeof(number), "%u", idx);
 
 		/* Fill de->name with FAT_PAD */
-		memset(de->name, FAT_PAD, FAT_NAME_LEN+FAT_EXT_LEN);
+		memset(de->name, FAT_PAD, FAT_NAME_LEN + FAT_EXT_LEN);
 		/* Copy ext */
 		memcpy(de->ext, ext, str_size(ext));
@@ -361,15 +370,16 @@
 		/* Copy number */
 		size_t offset;
-		if (str_size(name)+str_size(number)+1 >FAT_NAME_LEN)
-			offset = FAT_NAME_LEN - str_size(number)-1;
+		if (str_size(name)+str_size(number) + 1 > FAT_NAME_LEN)
+			offset = FAT_NAME_LEN - str_size(number) - 1;
 		else
 			offset = str_size(name);
 		de->name[offset] = '~';
 		offset++;
-		memcpy(de->name+offset, number, str_size(number));
+		memcpy(de->name + offset, number, str_size(number));
 
 		if (!fat_directory_is_sfn_exist(di, de))
 			return EOK;
 	}
+
 	return ERANGE;
 }
@@ -381,8 +391,9 @@
 
 	rc = fat_directory_get(di, &d);
-	if (rc!=EOK)
+	if (rc != EOK)
 		return rc;
 	memcpy(d, de, sizeof(fat_dentry_t));
 	di->b->dirty = true;
+
 	return EOK;
 }
@@ -397,15 +408,18 @@
 		return ENOSPC;
 	}
-	rc = fat_alloc_clusters(di->bs, di->nodep->idx->service_id, 1, &mcl, &lcl);
+	rc = fat_alloc_clusters(di->bs, di->nodep->idx->service_id, 1, &mcl,
+	    &lcl);
 	if (rc != EOK)
 		return rc;
 	rc = fat_zero_cluster(di->bs, di->nodep->idx->service_id, mcl);
 	if (rc != EOK) {
-		(void) fat_free_clusters(di->bs, di->nodep->idx->service_id, mcl);
+		(void) fat_free_clusters(di->bs, di->nodep->idx->service_id,
+		    mcl);
 		return rc;
 	}
 	rc = fat_append_clusters(di->bs, di->nodep, mcl, lcl);
 	if (rc != EOK) {
-		(void) fat_free_clusters(di->bs, di->nodep->idx->service_id, mcl);
+		(void) fat_free_clusters(di->bs, di->nodep->idx->service_id,
+		    mcl);
 		return rc;
 	}
@@ -422,37 +436,44 @@
 	size_t found;
 	aoff64_t pos;
+	int rc;
 	
 	do {
 		found = 0;
-		pos=0;
+		pos = 0;
 		fat_directory_seek(di, 0);
 		do {
-			if (fat_directory_get(di, &d) == EOK) {
-				switch (fat_classify_dentry(d)) {
-				case FAT_DENTRY_LAST:
-				case FAT_DENTRY_FREE:
-					if (found==0) pos = di->pos;
-					found++;
-					if (found == count) {
-						fat_directory_seek(di, pos);
-						return EOK;
-					}
-					break;
-				case FAT_DENTRY_VALID:
-				case FAT_DENTRY_LFN:
-				case FAT_DENTRY_SKIP:
-				default:
-					found = 0;
-					break;
+			rc = fat_directory_get(di, &d);
+			if (rc != EOK)
+				return rc;
+
+			switch (fat_classify_dentry(d)) {
+			case FAT_DENTRY_LAST:
+			case FAT_DENTRY_FREE:
+				if (found == 0)
+					pos = di->pos;
+				found++;
+				if (found == count) {
+					fat_directory_seek(di, pos);
+					return EOK;
 				}
+				break;
+			case FAT_DENTRY_VALID:
+			case FAT_DENTRY_LFN:
+			case FAT_DENTRY_SKIP:
+			default:
+				found = 0;
+				break;
 			}
 		} while (fat_directory_next(di) == EOK);	
 	} while (fat_directory_expand(di) == EOK);
+
 	return ENOSPC;
 }
 
-int fat_directory_lookup_name(fat_directory_t *di, const char *name, fat_dentry_t **de)
+int fat_directory_lookup_name(fat_directory_t *di, const char *name,
+    fat_dentry_t **de)
 {
 	char entry[FAT_LFN_NAME_SIZE];
+
 	fat_directory_seek(di, 0);
 	while (fat_directory_read(di, entry, de) == EOK) {
@@ -464,4 +485,5 @@
 		}
 	}
+
 	return ENOENT;
 }
@@ -470,22 +492,28 @@
 {
 	fat_dentry_t *d;
+	int rc;
+
 	fat_directory_seek(di, 0);
 	do {
-		if (fat_directory_get(di, &d) == EOK) {
-			switch (fat_classify_dentry(d)) {
-			case FAT_DENTRY_LAST:
-				return false;
-			case FAT_DENTRY_VALID:
-					if (bcmp(de->name, d->name, FAT_NAME_LEN+FAT_EXT_LEN)==0)
-						return true;
-					break;
-			default:
-			case FAT_DENTRY_LFN:
-			case FAT_DENTRY_SKIP:
-			case FAT_DENTRY_FREE:
-				break;
-			}
+		rc = fat_directory_get(di, &d);
+		if (rc != EOK)
+			return false;
+
+		switch (fat_classify_dentry(d)) {
+		case FAT_DENTRY_LAST:
+			return false;
+		case FAT_DENTRY_VALID:
+			if (bcmp(de->name, d->name,
+			    FAT_NAME_LEN + FAT_EXT_LEN)==0)
+				return true;
+			break;
+		default:
+		case FAT_DENTRY_LFN:
+		case FAT_DENTRY_SKIP:
+		case FAT_DENTRY_FREE:
+			break;
 		}
 	} while (fat_directory_next(di) == EOK);	
+
 	return false;
 }
Index: uspace/srv/fs/fat/fat_directory.h
===================================================================
--- uspace/srv/fs/fat/fat_directory.h	(revision 0dbe5ac3da1c850ebb3e4d5701b7b4409a026277)
+++ uspace/srv/fs/fat/fat_directory.h	(revision 5d95f02bc12b9857f647e740b9a09558e914a1f3)
@@ -63,12 +63,13 @@
 extern int fat_directory_write(fat_directory_t *, const char *, fat_dentry_t *);
 extern int fat_directory_erase(fat_directory_t *);
-extern int fat_directory_lookup_name(fat_directory_t *, const char *, fat_dentry_t **);
+extern int fat_directory_lookup_name(fat_directory_t *, const char *,
+    fat_dentry_t **);
 extern bool fat_directory_is_sfn_exist(fat_directory_t *, fat_dentry_t *);
 
-extern int fat_directory_lookup_free(fat_directory_t *di, size_t count);
-extern int fat_directory_write_dentry(fat_directory_t *di, fat_dentry_t *de);
-extern int fat_directory_create_sfn(fat_directory_t *di, fat_dentry_t *de, const char *lname);
-extern int fat_directory_expand(fat_directory_t *di);
-
+extern int fat_directory_lookup_free(fat_directory_t *, size_t);
+extern int fat_directory_write_dentry(fat_directory_t *, fat_dentry_t *);
+extern int fat_directory_create_sfn(fat_directory_t *, fat_dentry_t *,
+    const char *);
+extern int fat_directory_expand(fat_directory_t *);
 
 #endif
Index: uspace/srv/fs/fat/fat_fat.c
===================================================================
--- uspace/srv/fs/fat/fat_fat.c	(revision 0dbe5ac3da1c850ebb3e4d5701b7b4409a026277)
+++ uspace/srv/fs/fat/fat_fat.c	(revision 5d95f02bc12b9857f647e740b9a09558e914a1f3)
@@ -51,11 +51,4 @@
 #include <mem.h>
 
-/*
- * Convenience macros for computing some frequently used values from the
- * primitive boot sector members.
- */
-#define CLBN2PBN(bs, cl, bn) \
-	(SSA((bs)) + ((cl) - FAT_CLST_FIRST) * SPC((bs)) + (bn) % SPC((bs)))
-
 #define IS_ODD(number)	(number & 0x1)
 
@@ -244,5 +237,6 @@
  * @return		EOK on success or a negative error code.
  */
-int fat_fill_gap(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t mcl, aoff64_t pos)
+int
+fat_fill_gap(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t mcl, aoff64_t pos)
 {
 	block_t *b;
@@ -286,5 +280,5 @@
 }
 
-/** Get cluster from the first FAT. FAT12 version
+/** Get cluster from the first FAT.
  *
  * @param bs		Buffer holding the boot sector for the file system.
@@ -304,5 +298,5 @@
 	int rc;
 
-	offset = (clst + clst/2);
+	offset = (clst + clst / 2);
 	if (offset / BPS(bs) >= SF(bs))
 		return ERANGE;
@@ -313,12 +307,13 @@
 		return rc;
 
-	byte1 = ((uint8_t*) b->data)[offset % BPS(bs)];
+	byte1 = ((uint8_t *) b->data)[offset % BPS(bs)];
 	/* This cluster access spans a sector boundary. Check only for FAT12 */
 	if ((offset % BPS(bs)) + 1 == BPS(bs)) {
-		/* Is it last sector of FAT? */
+		/* Is this the last sector of FAT? */
 		if (offset / BPS(bs) < SF(bs)) {
-			/* No. Reading next sector */
+			/* No, read the next sector */
 			rc = block_get(&b1, service_id, 1 + RSCNT(bs) +
-				SF(bs)*fatno + offset / BPS(bs), BLOCK_FLAGS_NONE);
+			    SF(bs) * fatno + offset / BPS(bs),
+			    BLOCK_FLAGS_NONE);
 			if (rc != EOK) {
 				block_put(b);
@@ -336,13 +331,11 @@
 				return rc;
 			}
-		}
-		else {
-			/* Yes. It is last sector of FAT */
+		} else {
+			/* Yes. This is the last sector of FAT */
 			block_put(b);
 			return ERANGE;
 		}
-	}
-	else
-		byte2 = ((uint8_t*) b->data)[(offset % BPS(bs))+1];
+	} else
+		byte2 = ((uint8_t *) b->data)[(offset % BPS(bs)) + 1];
 
 	*value = uint16_t_le2host(byte1 | (byte2 << 8));
@@ -353,8 +346,9 @@
 	
 	rc = block_put(b);
+
 	return rc;
 }
 
-/** Get cluster from the first FAT. FAT16 version
+/** Get cluster from the first FAT.
  *
  * @param bs		Buffer holding the boot sector for the file system.
@@ -387,5 +381,5 @@
 }
 
-/** Get cluster from the first FAT. FAT32 version
+/** Get cluster from the first FAT.
  *
  * @param bs		Buffer holding the boot sector for the file system.
@@ -411,5 +405,6 @@
 		return rc;
 
-	*value = uint32_t_le2host(*(uint32_t *)(b->data + offset % BPS(bs))) & FAT32_MASK;
+	*value = uint32_t_le2host(*(uint32_t *)(b->data + offset % BPS(bs))) &
+	    FAT32_MASK;
 
 	rc = block_put(b);
@@ -436,18 +431,15 @@
 	assert(fatno < FATCNT(bs));
 
-	if (FAT_IS_FAT12(bs)) {
+	if (FAT_IS_FAT12(bs))
 		rc = fat_get_cluster_fat12(bs, service_id, fatno, clst, value);
-	}
-	else {
-		if (FAT_IS_FAT32(bs))
-			rc = fat_get_cluster_fat32(bs, service_id, fatno, clst, value);
-		else
-			rc = fat_get_cluster_fat16(bs, service_id, fatno, clst, value);
-	}
+	else if (FAT_IS_FAT16(bs))
+		rc = fat_get_cluster_fat16(bs, service_id, fatno, clst, value);
+	else
+		rc = fat_get_cluster_fat32(bs, service_id, fatno, clst, value);
 
 	return rc;
 }
 
-/** Set cluster in one instance of FAT. FAT12 version.
+/** Set cluster in one instance of FAT.
  *
  * @param bs		Buffer holding the boot sector for the file system.
@@ -463,10 +455,10 @@
     fat_cluster_t clst, fat_cluster_t value)
 {
-	block_t *b, *b1=NULL;
+	block_t *b, *b1 = NULL;
 	aoff64_t offset;
 	uint16_t byte1, byte2;
 	int rc;
 
-	offset = (clst + clst/2);
+	offset = (clst + clst / 2);
 	if (offset / BPS(bs) >= SF(bs))
 		return ERANGE;
@@ -479,11 +471,12 @@
 	byte1 = ((uint8_t*) b->data)[offset % BPS(bs)];
 	bool border = false;
-	/* This cluster access spans a sector boundary. Check only for FAT12 */
-	if ((offset % BPS(bs))+1 == BPS(bs)) {
-		/* Is it last sector of FAT? */
+	/* This cluster access spans a sector boundary. */
+	if ((offset % BPS(bs)) + 1 == BPS(bs)) {
+		/* Is it the last sector of FAT? */
 		if (offset / BPS(bs) < SF(bs)) {
-			/* No. Reading next sector */
+			/* No, read the next sector */
 			rc = block_get(&b1, service_id, 1 + RSCNT(bs) +
-				SF(bs)*fatno + offset / BPS(bs), BLOCK_FLAGS_NONE);
+			    SF(bs) * fatno + offset / BPS(bs),
+			    BLOCK_FLAGS_NONE);
 			if (rc != EOK) {
 				block_put(b);
@@ -494,9 +487,8 @@
 			 * first byte of next sector
 			 */
-			byte2 = ((uint8_t*) b1->data)[0];
+			byte2 = ((uint8_t *) b1->data)[0];
 			border = true;
-		}
-		else {
-			/* Yes. It is last sector of fat */
+		} else {
+			/* Yes. This is the last sector of FAT */
 			block_put(b);
 			return ERANGE;
@@ -504,5 +496,5 @@
 	}
 	else
-		byte2 = ((uint8_t*) b->data)[(offset % BPS(bs))+1];
+		byte2 = ((uint8_t*) b->data)[(offset % BPS(bs)) + 1];
 
 	if (IS_ODD(clst)) {
@@ -519,7 +511,7 @@
 	byte2 = byte2 | (value >> 8);
 
-	((uint8_t*) b->data)[(offset % BPS(bs))] = byte1;
+	((uint8_t *) b->data)[(offset % BPS(bs))] = byte1;
 	if (border) {
-		((uint8_t*) b1->data)[0] = byte2;
+		((uint8_t *) b1->data)[0] = byte2;
 
 		b1->dirty = true;
@@ -530,12 +522,13 @@
 		}
 	} else 
-		((uint8_t*) b->data)[(offset % BPS(bs))+1] = byte2;
+		((uint8_t *) b->data)[(offset % BPS(bs)) + 1] = byte2;
 
 	b->dirty = true;	/* need to sync block */
 	rc = block_put(b);
+
 	return rc;
 }
 
-/** Set cluster in one instance of FAT. FAT16 version.
+/** Set cluster in one instance of FAT.
  *
  * @param bs		Buffer holding the boot sector for the file system.
@@ -566,8 +559,9 @@
 	b->dirty = true;	/* need to sync block */
 	rc = block_put(b);
+
 	return rc;
 }
 
-/** Set cluster in one instance of FAT. FAT32 version.
+/** Set cluster in one instance of FAT.
  *
  * @param bs		Buffer holding the boot sector for the file system.
@@ -602,4 +596,5 @@
 	b->dirty = true;	/* need to sync block */
 	rc = block_put(b);
+
 	return rc;
 }
@@ -625,8 +620,8 @@
 	if (FAT_IS_FAT12(bs))
 		rc = fat_set_cluster_fat12(bs, service_id, fatno, clst, value);
-	else if (FAT_IS_FAT32(bs))
+	else if (FAT_IS_FAT16(bs))
+		rc = fat_set_cluster_fat16(bs, service_id, fatno, clst, value);
+	else
 		rc = fat_set_cluster_fat32(bs, service_id, fatno, clst, value);
-	else
-		rc = fat_set_cluster_fat16(bs, service_id, fatno, clst, value);
 
 	return rc;
@@ -695,21 +690,22 @@
 	 */
 	fibril_mutex_lock(&fat_alloc_lock);
-	for (clst=FAT_CLST_FIRST; clst < CC(bs)+2 && found < nclsts; clst++) {
+	for (clst = FAT_CLST_FIRST; clst < CC(bs) + 2 && found < nclsts;
+	    clst++) {
 		rc = fat_get_cluster(bs, service_id, FAT1, clst, &value);
 		if (rc != EOK)
-		break;
+			break;
 
 		if (value == FAT_CLST_RES0) {
-		/*
-		 * The cluster is free. Put it into our stack
-		 * of found clusters and mark it as non-free.
-		 */
-		lifo[found] = clst;
-		rc = fat_set_cluster(bs, service_id, FAT1, clst,
-		    (found == 0) ?  clst_last1 : lifo[found - 1]);
-		if (rc != EOK)
-			break;
-
-		found++;
+			/*
+			 * The cluster is free. Put it into our stack
+			 * of found clusters and mark it as non-free.
+			 */
+			lifo[found] = clst;
+			rc = fat_set_cluster(bs, service_id, FAT1, clst,
+			    (found == 0) ?  clst_last1 : lifo[found - 1]);
+			if (rc != EOK)
+				break;
+
+			found++;
 		}
 	}
@@ -727,13 +723,12 @@
 
 	/* If something wrong - free the clusters */
-	if (found > 0) {
-		while (found--) {
-		rc = fat_set_cluster(bs, service_id, FAT1, lifo[found],
+	while (found--) {
+		(void) fat_set_cluster(bs, service_id, FAT1, lifo[found],
 		    FAT_CLST_RES0);
-		}
 	}
 
 	free(lifo);
 	fibril_mutex_unlock(&fat_alloc_lock);
+
 	return ENOSPC;
 }
@@ -757,7 +752,9 @@
 	while (firstc < FAT_CLST_LAST1(bs)) {
 		assert(firstc >= FAT_CLST_FIRST && firstc < clst_bad);
+
 		rc = fat_get_cluster(bs, service_id, FAT1, firstc, &nextc);
 		if (rc != EOK)
 			return rc;
+
 		for (fatno = FAT1; fatno < FATCNT(bs); fatno++) {
 			rc = fat_set_cluster(bs, service_id, fatno, firstc,
@@ -766,5 +763,4 @@
 				return rc;
 		}
-
 		firstc = nextc;
 	}
@@ -782,6 +778,5 @@
  * @return		EOK on success or a negative error code.
  */
-int
-fat_append_clusters(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t mcl,
+int fat_append_clusters(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t mcl,
     fat_cluster_t lcl)
 {
@@ -942,5 +937,6 @@
 	 * sanitized to support file systems with this property.
 	 */
-	if (!FAT_IS_FAT32(bs) && (RDE(bs) * sizeof(fat_dentry_t)) % BPS(bs) != 0)
+	if (!FAT_IS_FAT32(bs) &&
+	    (RDE(bs) * sizeof(fat_dentry_t)) % BPS(bs) != 0)
 		return ENOTSUP;
 
@@ -955,5 +951,7 @@
 			return EIO;
 
-		/* Check that first byte of FAT contains the media descriptor. */
+		/*
+		 * Check that first byte of FAT contains the media descriptor.
+		 */
 		if ((e0 & 0xff) != bs->mdesc)
 			return ENOTSUP;
@@ -964,5 +962,5 @@
 		 */
 		if (!FAT_IS_FAT12(bs) && 
-			((e0 >> 8) != (FAT_MASK(bs) >> 8) || e1 != FAT_MASK(bs)))
+		    ((e0 >> 8) != (FAT_MASK(bs) >> 8) || e1 != FAT_MASK(bs)))
 			return ENOTSUP;
 	}
Index: uspace/srv/fs/fat/fat_fat.h
===================================================================
--- uspace/srv/fs/fat/fat_fat.h	(revision 0dbe5ac3da1c850ebb3e4d5701b7b4409a026277)
+++ uspace/srv/fs/fat/fat_fat.h	(revision 5d95f02bc12b9857f647e740b9a09558e914a1f3)
@@ -76,4 +76,7 @@
 #define CC(bs)	  (DS(bs) / SPC(bs))
 
+#define CLBN2PBN(bs, cl, bn) \
+	(SSA((bs)) + ((cl) - FAT_CLST_FIRST) * SPC((bs)) + (bn) % SPC((bs)))
+
 #define FAT_IS_FAT12(bs)	(CC(bs) < FAT12_CLST_MAX)
 #define FAT_IS_FAT16(bs) \
