Index: uspace/srv/fs/fat/fat_fat.c
===================================================================
--- uspace/srv/fs/fat/fat_fat.c	(revision 933cadfdb63d0a16870db764880b5c144894e112)
+++ uspace/srv/fs/fat/fat_fat.c	(revision 3dbe4ca2665cf8a432e3a111f27932a595dceba1)
@@ -29,5 +29,5 @@
 /** @addtogroup fs
  * @{
- */ 
+ */
 
 /**
@@ -54,8 +54,4 @@
  * primitive boot sector members.
  */
-#define RDS(bs)		((sizeof(fat_dentry_t) * RDE((bs))) / BPS((bs))) + \
-			(((sizeof(fat_dentry_t) * RDE((bs))) % BPS((bs))) != 0)
-#define SSA(bs)		(RSCNT((bs)) + FATCNT((bs)) * SF((bs)) + RDS(bs))
-
 #define CLBN2PBN(bs, cl, bn) \
 	(SSA((bs)) + ((cl) - FAT_CLST_FIRST) * SPC((bs)) + (bn) % SPC((bs)))
@@ -65,5 +61,5 @@
  * during allocation of clusters. The lock does not have to be held durring
  * deallocation of clusters.
- */  
+ */
 static FIBRIL_MUTEX_INITIALIZE(fat_alloc_lock);
 
@@ -77,15 +73,15 @@
  * @param numc		If non-NULL, output argument holding the number of
  *			clusters seen during the walk.
- * @param max_clusters	Maximum number of clusters to visit.	
+ * @param max_clusters	Maximum number of clusters to visit.
  *
  * @return		EOK on success or a negative error code.
  */
-int 
+int
 fat_cluster_walk(fat_bs_t *bs, devmap_handle_t devmap_handle, fat_cluster_t firstc,
     fat_cluster_t *lastc, uint16_t *numc, uint16_t max_clusters)
 {
-	block_t *b;
 	uint16_t clusters = 0;
-	fat_cluster_t clst = firstc;
+	fat_cluster_t clst = firstc, clst_last1 = FAT_CLST_LAST1(bs);
+	fat_cluster_t clst_bad = FAT_CLST_BAD(bs);
 	int rc;
 
@@ -99,27 +95,19 @@
 	}
 
-	while (clst < FAT_CLST_LAST1 && clusters < max_clusters) {
-		aoff64_t fsec;	/* sector offset relative to FAT1 */
-		unsigned fidx;	/* FAT1 entry index */
-
+	while (clst < clst_last1 && clusters < max_clusters) {
 		assert(clst >= FAT_CLST_FIRST);
 		if (lastc)
 			*lastc = clst;	/* remember the last cluster number */
-		fsec = (clst * sizeof(fat_cluster_t)) / BPS(bs);
-		fidx = clst % (BPS(bs) / sizeof(fat_cluster_t));
+
 		/* read FAT1 */
-		rc = block_get(&b, devmap_handle, RSCNT(bs) + fsec,
-		    BLOCK_FLAGS_NONE);
-		if (rc != EOK)
-			return rc;
-		clst = uint16_t_le2host(((fat_cluster_t *)b->data)[fidx]);
-		assert(clst != FAT_CLST_BAD);
-		rc = block_put(b);
-		if (rc != EOK)
-			return rc;
+		rc = fat_get_cluster(bs, devmap_handle, FAT1, clst, &clst);
+		if (rc != EOK)
+			return rc;
+
+		assert(clst != clst_bad);
 		clusters++;
 	}
 
-	if (lastc && clst < FAT_CLST_LAST1)
+	if (lastc && clst < clst_last1)
 		*lastc = clst;
 	if (numc)
@@ -151,5 +139,5 @@
 		return ELIMIT;
 
-	if (nodep->firstc == FAT_CLST_ROOT) 
+	if (nodep->firstc == FAT_CLST_ROOT)
 		goto fall_through;
 
@@ -178,5 +166,5 @@
 	if (rc != EOK)
 		return rc;
-	
+
 	/*
 	 * Update the "current" cluster cache.
@@ -198,5 +186,5 @@
  * @param clp		If not NULL, address where the cluster containing bn
  *			will be stored.
- *			stored 
+ *			stored
  * @param bn		Block number.
  * @param flags		Flags passed to libblock.
@@ -275,8 +263,8 @@
 			return rc;
 	}
-	
+
 	if (o >= pos)
 		return EOK;
-	
+
 	/* zero out the initial part of the new cluster chain */
 	for (o = boundary; o < pos; o += BPS(bs)) {
@@ -308,17 +296,63 @@
     fat_cluster_t clst, fat_cluster_t *value)
 {
-	block_t *b;
-	fat_cluster_t *cp;
-	int rc;
+	block_t *b, *b1;
+	aoff64_t offset;
+	int rc;
+
+	assert(fatno < FATCNT(bs));
+
+	if (FAT_IS_FAT12(bs))
+		offset = (clst + clst/2);
+	else
+		offset = (clst * sizeof(fat_cluster_t));
 
 	rc = block_get(&b, devmap_handle, RSCNT(bs) + SF(bs) * fatno +
-	    (clst * sizeof(fat_cluster_t)) / BPS(bs), BLOCK_FLAGS_NONE);
+	    offset / BPS(bs), BLOCK_FLAGS_NONE);
 	if (rc != EOK)
 		return rc;
-	cp = (fat_cluster_t *)b->data +
-	    clst % (BPS(bs) / sizeof(fat_cluster_t));
-	*value = uint16_t_le2host(*cp);
+
+	/* This cluster access spans a sector boundary. Check only for FAT12 */
+	if (FAT_IS_FAT12(bs) && (offset % BPS(bs)+1 == BPS(bs))) {
+		/* Is it last sector of FAT? */
+		if (offset / BPS(bs) < SF(bs)) {
+			/* No. Reading next sector */
+			rc = block_get(&b1, devmap_handle, 1 + RSCNT(bs) +
+			    SF(bs)*fatno + offset / BPS(bs), BLOCK_FLAGS_NONE);
+			if (rc != EOK) {
+				block_put(b);
+				return rc;
+			}
+			/*
+			 * Combining value with last byte of current sector and
+			 * first byte of next sector
+			 */
+			*value  = *(uint8_t *)(b->data + BPS(bs) - 1);
+			*value |= *(uint8_t *)(b1->data);
+
+			rc = block_put(b1);
+			if (rc != EOK) {
+				block_put(b);
+				return rc;
+			}
+		}
+		else {
+			/* Yes. It is last sector of FAT */
+			block_put(b);
+			return ERANGE;
+		}
+	}
+	else
+		*value = *(fat_cluster_t *)(b->data + offset % BPS(bs));
+
+	if (FAT_IS_FAT12(bs)) {
+		if (clst & 0x0001)
+		*value = (*value) >> 4;
+		else
+		*value = (*value) & 0x0fff;
+	}
+
+	*value = uint16_t_le2host(*value);
 	rc = block_put(b);
-	
+
 	return rc;
 }
@@ -338,17 +372,79 @@
     fat_cluster_t clst, fat_cluster_t value)
 {
-	block_t *b;
-	fat_cluster_t *cp;
-	int rc;
+	block_t *b, *b1;
+	aoff64_t offset;
+	fat_cluster_t *cp, temp;
+	int rc;
+	int spans = 0;
 
 	assert(fatno < FATCNT(bs));
+
+	if (FAT_IS_FAT12(bs))
+		offset = (clst + clst/2);
+	else
+		offset = (clst * sizeof(fat_cluster_t));
+
 	rc = block_get(&b, devmap_handle, RSCNT(bs) + SF(bs) * fatno +
-	    (clst * sizeof(fat_cluster_t)) / BPS(bs), BLOCK_FLAGS_NONE);
+	    offset / BPS(bs), BLOCK_FLAGS_NONE);
 	if (rc != EOK)
 		return rc;
-	cp = (fat_cluster_t *)b->data +
-	    clst % (BPS(bs) / sizeof(fat_cluster_t));
-	*cp = host2uint16_t_le(value);
-	b->dirty = true;		/* need to sync block */
+
+	/* This cluster access spans a sector boundary. Check only for FAT12 */
+	if (FAT_IS_FAT12(bs) && (offset % BPS(bs)+1 == BPS(bs))) {
+		/* Is it last sector of FAT? */
+		if (offset / BPS(bs) < SF(bs)) {
+			/* No. Reading next sector */
+			rc = block_get(&b1, devmap_handle, 1 + RSCNT(bs) +
+			    SF(bs)*fatno + offset / BPS(bs), BLOCK_FLAGS_NONE);
+			if (rc != EOK) {
+				block_put(b);
+				return rc;
+			}
+			/*
+			 * Combining value with last byte of current sector and
+			 * first byte of next sector
+			 */
+			spans=1;
+			cp = &temp;
+			*cp  = *(uint8_t *)(b->data + BPS(bs) - 1);
+			*cp |= *(uint8_t *)(b1->data);
+		}
+		else {
+			/* Yes. It is last sector of fat */
+			block_put(b);
+			return ERANGE;
+		}
+	}
+	else
+		cp = (fat_cluster_t *)(b->data + offset % BPS(bs));
+
+	value = host2uint16_t_le(value);
+	if (FAT_IS_FAT12(bs)) {
+		if (clst & 0x0001) {
+			*cp &= 0x000f;
+			*cp |= value << 4;
+		}
+		else {
+			*cp &= 0xf000;
+			*cp |= value & 0x0fff;
+		}
+
+		if (spans)
+		{
+			*(uint8_t *)(b->data + BPS(bs) - 1) = cp[0];
+			*(uint8_t *)(b1->data) = cp[1];
+
+			b1->dirty = true;
+			rc = block_put(b1);
+			if (rc != EOK) {
+				block_put(b);
+				return rc;
+			}
+		}
+	}
+	else
+		*cp = value;
+
+	b->dirty = true;	/* need to sync block */
 	rc = block_put(b);
 	return rc;
@@ -369,4 +465,5 @@
 	uint8_t fatno;
 	unsigned c;
+	fat_cluster_t clst_last1 = FAT_CLST_LAST1(bs);
 	int rc;
 
@@ -374,5 +471,5 @@
 		for (c = 0; c < nclsts; c++) {
 			rc = fat_set_cluster(bs, devmap_handle, fatno, lifo[c],
-			    c == 0 ? FAT_CLST_LAST1 : lifo[c - 1]);
+			    c == 0 ? clst_last1 : lifo[c - 1]);
 			if (rc != EOK)
 				return rc;
@@ -404,94 +501,57 @@
     fat_cluster_t *mcl, fat_cluster_t *lcl)
 {
-	block_t *blk;
-	fat_cluster_t *lifo;	/* stack for storing free cluster numbers */ 
-	unsigned found = 0;	/* top of the free cluster number stack */
-	unsigned b, c, cl; 
-	int rc;
+	fat_cluster_t *lifo;    /* stack for storing free cluster numbers */
+	unsigned found = 0;     /* top of the free cluster number stack */
+	fat_cluster_t clst, value, clst_last1 = FAT_CLST_LAST1(bs);
+	int rc = EOK;
 
 	lifo = (fat_cluster_t *) malloc(nclsts * sizeof(fat_cluster_t));
 	if (!lifo)
 		return ENOMEM;
-	
 	/*
 	 * Search FAT1 for unused clusters.
 	 */
 	fibril_mutex_lock(&fat_alloc_lock);
-	for (b = 0, cl = 0; b < SF(bs); b++) {
-		rc = block_get(&blk, devmap_handle, RSCNT(bs) + b,
-		    BLOCK_FLAGS_NONE);
-		if (rc != EOK)
-			goto error;
-		for (c = 0; c < BPS(bs) / sizeof(fat_cluster_t); c++, cl++) {
-			/*
-			 * Check if the entire cluster is physically there.
-			 * This check becomes necessary when the file system is
-			 * created with fewer total sectors than how many is
-			 * inferred from the size of the file allocation table
-			 * or when the last cluster ends beyond the end of the
-			 * device.
-			 */
-			if ((cl >= FAT_CLST_FIRST) &&
-			    CLBN2PBN(bs, cl, SPC(bs) - 1) >= TS(bs)) {
-				rc = block_put(blk);
-				if (rc != EOK)
-					goto error;
-				goto out;
-			}
-
-			fat_cluster_t *clst = (fat_cluster_t *)blk->data + c;
-			if (uint16_t_le2host(*clst) == FAT_CLST_RES0) {
-				/*
-				 * The cluster is free. Put it into our stack
-				 * of found clusters and mark it as non-free.
-				 */
-				lifo[found] = cl;
-				*clst = (found == 0) ?
-				    host2uint16_t_le(FAT_CLST_LAST1) :
-				    host2uint16_t_le(lifo[found - 1]);
-				blk->dirty = true;	/* need to sync block */
-				if (++found == nclsts) {
-					/* we are almost done */
-					rc = block_put(blk);
-					if (rc != EOK)
-						goto error;
-					/* update the shadow copies of FAT */
-					rc = fat_alloc_shadow_clusters(bs,
-					    devmap_handle, lifo, nclsts);
-					if (rc != EOK)
-						goto error;
-					*mcl = lifo[found - 1];
-					*lcl = lifo[0];
-					free(lifo);
-					fibril_mutex_unlock(&fat_alloc_lock);
-					return EOK;
-				}
-			}
-		}
-		rc = block_put(blk);
-		if (rc != EOK) {
-error:
+	for (clst=FAT_CLST_FIRST; clst < CC(bs)+2 && found < nclsts; clst++) {
+		rc = fat_get_cluster(bs, devmap_handle, FAT1, clst, &value);
+		if (rc != EOK)
+		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, devmap_handle, FAT1, clst,
+		    (found == 0) ?  clst_last1 : lifo[found - 1]);
+		if (rc != EOK)
+			break;
+
+		found++;
+		}
+	}
+
+	if (rc == EOK && found == nclsts) {
+		rc = fat_alloc_shadow_clusters(bs, devmap_handle, lifo, nclsts);
+		if (rc == EOK) {
+			*mcl = lifo[found - 1];
+			*lcl = lifo[0];
+			free(lifo);
 			fibril_mutex_unlock(&fat_alloc_lock);
-			free(lifo);
-			return rc;
-		}
-	}
-out:
-	fibril_mutex_unlock(&fat_alloc_lock);
-
-	/*
-	 * We could not find enough clusters. Now we need to free the clusters
-	 * we have allocated so far.
-	 */
-	while (found--) {
+			return EOK;
+		}
+	}
+
+	/* If something wrong - free the clusters */
+	if (found > 0) {
+		while (found--) {
 		rc = fat_set_cluster(bs, devmap_handle, FAT1, lifo[found],
 		    FAT_CLST_RES0);
-		if (rc != EOK) {
-			free(lifo);
-			return rc;
-		}
-	}
-	
+		}
+	}
+
 	free(lifo);
+	fibril_mutex_unlock(&fat_alloc_lock);
 	return ENOSPC;
 }
@@ -509,10 +569,10 @@
 {
 	unsigned fatno;
-	fat_cluster_t nextc;
+	fat_cluster_t nextc, clst_bad = FAT_CLST_BAD(bs);
 	int rc;
 
 	/* Mark all clusters in the chain as free in all copies of FAT. */
-	while (firstc < FAT_CLST_LAST1) {
-		assert(firstc >= FAT_CLST_FIRST && firstc < FAT_CLST_BAD);
+	while (firstc < FAT_CLST_LAST1(bs)) {
+		assert(firstc >= FAT_CLST_FIRST && firstc < clst_bad);
 		rc = fat_get_cluster(bs, devmap_handle, FAT1, firstc, &nextc);
 		if (rc != EOK)
@@ -565,6 +625,6 @@
 
 		for (fatno = FAT1; fatno < bs->fatcnt; fatno++) {
-			rc = fat_set_cluster(bs, nodep->idx->devmap_handle, fatno,
-			    lastc, mcl);
+			rc = fat_set_cluster(bs, nodep->idx->devmap_handle,
+			    fatno, lastc, mcl);
 			if (rc != EOK)
 				return rc;
@@ -590,4 +650,5 @@
 int fat_chop_clusters(fat_bs_t *bs, fat_node_t *nodep, fat_cluster_t lcl)
 {
+	fat_cluster_t clst_last1 = FAT_CLST_LAST1(bs);
 	int rc;
 	devmap_handle_t devmap_handle = nodep->idx->devmap_handle;
@@ -618,5 +679,5 @@
 		for (fatno = FAT1; fatno < bs->fatcnt; fatno++) {
 			rc = fat_set_cluster(bs, devmap_handle, fatno, lcl,
-			    FAT_CLST_LAST1);
+			    clst_last1);
 			if (rc != EOK)
 				return rc;
@@ -677,10 +738,9 @@
 
 	/* Check total number of sectors. */
-
 	if (bs->totsec16 == 0 && bs->totsec32 == 0)
 		return ENOTSUP;
 
 	if (bs->totsec16 != 0 && bs->totsec32 != 0 &&
-	    bs->totsec16 != bs->totsec32) 
+	    bs->totsec16 != bs->totsec32)
 		return ENOTSUP;
 
@@ -705,5 +765,4 @@
 
 	/* Check signature of each FAT. */
-
 	for (fat_no = 0; fat_no < bs->fatcnt; fat_no++) {
 		rc = fat_get_cluster(bs, devmap_handle, fat_no, 0, &e0);
@@ -723,5 +782,5 @@
 		 * set to one.
 		 */
-		if ((e0 >> 8) != 0xff || e1 != 0xffff)
+                if (!FAT_IS_FAT12(bs) && ((e0 >> 8) != 0xff || e1 != 0xffff))
 			return ENOTSUP;
 	}
@@ -732,3 +791,3 @@
 /**
  * @}
- */ 
+ */
Index: uspace/srv/fs/fat/fat_fat.h
===================================================================
--- uspace/srv/fs/fat/fat_fat.h	(revision 933cadfdb63d0a16870db764880b5c144894e112)
+++ uspace/srv/fs/fat/fat_fat.h	(revision 3dbe4ca2665cf8a432e3a111f27932a595dceba1)
@@ -29,5 +29,5 @@
 /** @addtogroup fs
  * @{
- */ 
+ */
 
 #ifndef FAT_FAT_FAT_H_
@@ -40,10 +40,17 @@
 #define FAT1		0
 
-#define FAT_CLST_RES0	0x0000
-#define FAT_CLST_RES1	0x0001
-#define FAT_CLST_FIRST	0x0002
-#define FAT_CLST_BAD	0xfff7
-#define FAT_CLST_LAST1	0xfff8
-#define FAT_CLST_LAST8  0xffff
+#define FAT_CLST_RES0	  0x0000
+#define FAT_CLST_RES1	  0x0001
+#define FAT_CLST_FIRST	  0x0002
+
+#define FAT12_CLST_BAD	  0x0ff7
+#define FAT12_CLST_LAST1  0x0ff8
+#define FAT12_CLST_LAST8  0x0fff
+#define FAT16_CLST_BAD    0xfff7
+#define FAT16_CLST_LAST1  0xfff8
+#define FAT16_CLST_LAST8  0xffff
+
+#define FAT12_CLST_MAX    4085
+#define FAT16_CLST_MAX    65525
 
 /* internally used to mark root directory's parent */
@@ -51,4 +58,25 @@
 /* internally used to mark root directory */
 #define FAT_CLST_ROOT		FAT_CLST_RES1
+
+/*
+ * Convenience macros for computing some frequently used values from the
+ * primitive boot sector members.
+ */
+#define RDS(bs)	  ((sizeof(fat_dentry_t) * RDE((bs))) / BPS((bs))) + \
+		   (((sizeof(fat_dentry_t) * RDE((bs))) % BPS((bs))) != 0)
+#define SSA(bs)	  (RSCNT((bs)) + FATCNT((bs)) * SF((bs)) + RDS(bs))
+#define DS(bs)	  (TS(bs) - SSA(bs))
+#define CC(bs)	  (DS(bs) / SPC(bs))
+
+#define FAT_IS_FAT12(bs)	(CC(bs) < FAT12_CLST_MAX)
+#define FAT_IS_FAT16(bs) \
+    ((CC(bs) >= FAT12_CLST_MAX) && (CC(bs) < FAT16_CLST_MAX))
+
+#define FAT_CLST_LAST1(bs) \
+    (FAT_IS_FAT12(bs) ? FAT12_CLST_LAST1 : FAT16_CLST_LAST1)
+#define FAT_CLST_LAST8(bs) \
+    (FAT_IS_FAT12(bs) ? FAT12_CLST_LAST8 : FAT16_CLST_LAST8)
+#define FAT_CLST_BAD(bs) \
+    (FAT_IS_FAT12(bs) ? FAT12_CLST_BAD : FAT16_CLST_BAD)
 
 /* forward declarations */
Index: uspace/srv/fs/fat/fat_ops.c
===================================================================
--- uspace/srv/fs/fat/fat_ops.c	(revision 933cadfdb63d0a16870db764880b5c144894e112)
+++ uspace/srv/fs/fat/fat_ops.c	(revision 3dbe4ca2665cf8a432e3a111f27932a595dceba1)
@@ -29,5 +29,5 @@
 /** @addtogroup fs
  * @{
- */ 
+ */
 
 /**
@@ -105,8 +105,8 @@
 	node->dirty = false;
 	node->lastc_cached_valid = false;
-	node->lastc_cached_value = FAT_CLST_LAST1;
+	node->lastc_cached_value = FAT16_CLST_LAST1;
 	node->currc_cached_valid = false;
 	node->currc_cached_bn = 0;
-	node->currc_cached_value = FAT_CLST_LAST1;
+	node->currc_cached_value = FAT16_CLST_LAST1;
 }
 
@@ -117,9 +117,9 @@
 	fat_dentry_t *d;
 	int rc;
-	
+
 	assert(node->dirty);
 
 	bs = block_bb_get(node->idx->devmap_handle);
-	
+
 	/* Read the block that contains the dentry of interest. */
 	rc = _fat_block_get(&b, bs, node->idx->devmap_handle, node->idx->pfc,
@@ -137,7 +137,7 @@
 		d->attr = FAT_ATTR_SUBDIR;
 	}
-	
+
 	/* TODO: update other fields? (e.g time fields) */
-	
+
 	b->dirty = true;		/* need to sync block */
 	rc = block_put(b);
@@ -256,5 +256,5 @@
 	fn->data = nodep;
 	nodep->bp = fn;
-	
+
 	*nodepp = nodep;
 	return EOK;
@@ -292,5 +292,5 @@
 	 * We must instantiate the node from the file system.
 	 */
-	
+
 	assert(idxp->pfc);
 
@@ -311,5 +311,5 @@
 	d = ((fat_dentry_t *)b->data) + (idxp->pdi % DPS(bs));
 	if (d->attr & FAT_ATTR_SUBDIR) {
-		/* 
+		/*
 		 * The only directory which does not have this bit set is the
 		 * root directory itself. The root directory node is handled
@@ -317,5 +317,6 @@
 		 */
 		nodep->type = FAT_DIRECTORY;
-		/*
+
+                /*
 		 * Unfortunately, the 'size' field of the FAT dentry is not
 		 * defined for the directory entry type. We must determine the
@@ -335,5 +336,6 @@
 		nodep->size = uint32_t_le2host(d->size);
 	}
-	nodep->firstc = uint16_t_le2host(d->firstc);
+
+        nodep->firstc = uint16_t_le2host(d->firstc);
 	nodep->lnkcnt = 1;
 	nodep->refcnt = 1;
@@ -384,5 +386,5 @@
 		if (rc != EOK)
 			return rc;
-		for (j = 0; j < DPS(bs); j++) { 
+		for (j = 0; j < DPS(bs); j++) {
 			d = ((fat_dentry_t *)b->data) + j;
 			switch (fat_classify_dentry(d)) {
@@ -522,5 +524,5 @@
 	rc = fat_idx_get_new(&idxp, devmap_handle);
 	if (rc != EOK) {
-		(void) fat_free_clusters(bs, devmap_handle, mcl);	
+		(void) fat_free_clusters(bs, devmap_handle, mcl);
 		(void) fat_node_put(FS_NODE(nodep));
 		return rc;
@@ -619,5 +621,5 @@
 	 * a new one.
 	 */
-	
+
 	fibril_mutex_lock(&parentp->idx->lock);
 	bs = block_bb_get(parentp->idx->devmap_handle);
@@ -651,5 +653,5 @@
 	}
 	j = 0;
-	
+
 	/*
 	 * We need to grow the parent in order to create a new unused dentry.
@@ -698,9 +700,9 @@
 	rc = block_put(b);
 	fibril_mutex_unlock(&parentp->idx->lock);
-	if (rc != EOK) 
+	if (rc != EOK)
 		return rc;
 
 	fibril_mutex_lock(&childp->idx->lock);
-	
+
 	if (childp->type == FAT_DIRECTORY) {
 		/*
@@ -779,5 +781,5 @@
 	if (!parentp)
 		return EBUSY;
-	
+
 	rc = fat_has_children(&has_children, cfn);
 	if (rc != EOK)
@@ -795,5 +797,5 @@
 	    NULL, (childp->idx->pdi * sizeof(fat_dentry_t)) / BPS(bs),
 	    BLOCK_FLAGS_NONE);
-	if (rc != EOK) 
+	if (rc != EOK)
 		goto error;
 	d = (fat_dentry_t *)b->data +
@@ -840,5 +842,5 @@
 		return EOK;
 	}
-	
+
 	fibril_mutex_lock(&nodep->idx->lock);
 	bs = block_bb_get(nodep->idx->devmap_handle);
@@ -848,5 +850,5 @@
 	for (i = 0; i < blocks; i++) {
 		fat_dentry_t *d;
-	
+
 		rc = fat_block_get(&b, bs, nodep, i, BLOCK_FLAGS_NONE);
 		if (rc != EOK) {
@@ -876,5 +878,5 @@
 		if (rc != EOK) {
 			fibril_mutex_unlock(&nodep->idx->lock);
-			return rc;	
+			return rc;
 		}
 	}
@@ -951,9 +953,9 @@
 	enum cache_mode cmode;
 	fat_bs_t *bs;
-	
+
 	/* Accept the mount options */
 	char *opts;
 	int rc = async_data_write_accept((void **) &opts, true, 0, 0, 0, NULL);
-	
+
 	if (rc != EOK) {
 		async_answer_0(rid, rc);
@@ -986,5 +988,5 @@
 	/* get the buffer with the boot sector */
 	bs = block_bb_get(devmap_handle);
-	
+
 	if (BPS(bs) != BS_SIZE) {
 		block_fini(devmap_handle);
@@ -998,4 +1000,11 @@
 		block_fini(devmap_handle);
 		async_answer_0(rid, rc);
+		return;
+	}
+
+	/* Return NOT SUPPORTED if try to mount FAT32  */
+	if (!FAT_IS_FAT12(bs) && !FAT_IS_FAT16(bs)) {
+		block_fini(devmap_handle);
+		async_answer_0(rid, ENOTSUP);
 		return;
 	}
@@ -1061,5 +1070,5 @@
 	rootp->bp = rfn;
 	rfn->data = rootp;
-	
+
 	fibril_mutex_unlock(&ridxp->lock);
 
@@ -1095,5 +1104,5 @@
 		return;
 	}
-	
+
 	/*
 	 * Put the root node and force it to the FAT free node list.
@@ -1276,5 +1285,5 @@
 	int flags = BLOCK_FLAGS_NONE;
 	int rc;
-	
+
 	rc = fat_node_get(&fn, devmap_handle, index);
 	if (rc != EOK) {
@@ -1287,5 +1296,5 @@
 	}
 	nodep = FAT_NODE(fn);
-	
+
 	ipc_callid_t callid;
 	size_t len;
@@ -1304,10 +1313,10 @@
 	 * but this one greatly simplifies fat_write(). Note that we can afford
 	 * to do this because the client must be ready to handle the return
-	 * value signalizing a smaller number of bytes written. 
-	 */ 
+	 * value signalizing a smaller number of bytes written.
+	 */
 	bytes = min(len, BPS(bs) - pos % BPS(bs));
 	if (bytes == BPS(bs))
 		flags |= BLOCK_FLAGS_NOREAD;
-	
+
 	boundary = ROUND_UP(nodep->size, BPC(bs));
 	if (pos < boundary) {
@@ -1355,6 +1364,6 @@
 		 */
 		unsigned nclsts;
-		fat_cluster_t mcl, lcl; 
- 
+		fat_cluster_t mcl, lcl;
+
 		nclsts = (ROUND_UP(pos + bytes, BPC(bs)) - boundary) / BPC(bs);
 		/* create an independent chain of nclsts clusters in all FATs */
@@ -1452,5 +1461,5 @@
 		nodep->size = size;
 		nodep->dirty = true;		/* need to sync node */
-		rc = EOK;	
+		rc = EOK;
 	} else {
 		/*
@@ -1473,5 +1482,5 @@
 		nodep->size = size;
 		nodep->dirty = true;		/* need to sync node */
-		rc = EOK;	
+		rc = EOK;
 	}
 out:
@@ -1529,5 +1538,5 @@
 	devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
 	fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request);
-	
+
 	fs_node_t *fn;
 	int rc = fat_node_get(&fn, devmap_handle, index);
@@ -1540,10 +1549,10 @@
 		return;
 	}
-	
+
 	fat_node_t *nodep = FAT_NODE(fn);
-	
+
 	nodep->dirty = true;
 	rc = fat_node_sync(nodep);
-	
+
 	fat_node_put(fn);
 	async_answer_0(rid, rc);
