Index: uspace/srv/fs/fat/fat_fat.c
===================================================================
--- uspace/srv/fs/fat/fat_fat.c	(revision 97bc3ee99b9182a255fcba5caf3fc118a0f767c1)
+++ uspace/srv/fs/fat/fat_fat.c	(revision d260a95d5be9ef2379607364e7848009c9d4dab9)
@@ -81,8 +81,7 @@
 {
 	uint16_t clusters = 0;
-	fat_cluster_t clst = firstc;
-	int rc;
-        uint16_t clst_last1 = FATTYPE(bs) == 16 ? FAT16_CLST_LAST1 : FAT12_CLST_LAST1;
-        uint16_t clst_bad   = FATTYPE(bs) == 16 ? FAT16_CLST_BAD : FAT12_CLST_BAD;
+	fat_cluster_t clst = firstc, clst_last1 = FAT_CLST_LAST1(bs);
+	fat_cluster_t clst_bad = FAT_CLST_BAD(bs);
+	int rc;
 
 	if (firstc == FAT_CLST_RES0) {
@@ -100,12 +99,11 @@
 			*lastc = clst;	/* remember the last cluster number */
 
-                /* read FAT1 */
-                rc = fat_get_cluster(bs, devmap_handle, FAT1, clst, &clst);
-                if (rc != EOK)
-                        return rc;
-
-                assert(clst != clst_bad);
-
-                clusters++;
+		/* read FAT1 */
+		rc = fat_get_cluster(bs, devmap_handle, FAT1, clst, &clst);
+		if (rc != EOK)
+			return rc;
+
+		assert(clst != clst_bad);
+		clusters++;
 	}
 
@@ -298,59 +296,60 @@
 {
 	block_t *b, *b1;
-        aoff64_t offset;
-	int rc;
-
-        assert(fatno < FATCNT(bs));
-
-        if (FATTYPE(bs) == 16)
-            offset = (clst * 2);
-        else
-            offset = (clst + clst/2);
-
-        rc = block_get(&b, devmap_handle, RSCNT(bs) + SF(bs) * fatno +
-                       offset / BPS(bs), BLOCK_FLAGS_NONE);
-        if (rc != EOK)
-                return rc;
-
-        /* This cluster access spans a sector boundary. Check only for FAT12 */
-        if (FATTYPE(bs) == 12 && (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 */
-                block_put(b);
-                return ERANGE;
-            }
-        }
-        else
-            *value = *(fat_cluster_t *)(b->data + offset % BPS(bs));
-
-        if (FATTYPE(bs) == 12) {
-            if (clst & 0x0001)
-                *value = (*value) >> 4;
-            else
-                *value = (*value) & 0x0fff;
-        }
-
-        *value = uint16_t_le2host(*value);
+	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 +
+	    offset / BPS(bs), BLOCK_FLAGS_NONE);
+	if (rc != EOK)
+		return rc;
+
+	/* 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);
 
@@ -373,77 +372,78 @@
 {
 	block_t *b, *b1;
-        aoff64_t offset;
-        fat_cluster_t *cp, temp;
-	int rc;
-        int spans = 0;
-
-        assert(fatno < FATCNT(bs));
-
-        if (FATTYPE(bs) == 16)
-            offset = (clst * sizeof(fat_cluster_t));
-        else
-            offset = (clst + clst/2);
-
-        rc = block_get(&b, devmap_handle, RSCNT(bs) + SF(bs) * fatno +
-                       offset / BPS(bs), BLOCK_FLAGS_NONE);
+	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 +
+	    offset / BPS(bs), BLOCK_FLAGS_NONE);
 	if (rc != EOK)
 		return rc;
 
-        /* This cluster access spans a sector boundary. Check only for FAT12 */
-        if (FATTYPE(bs) == 12 && (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 */
-                block_put(b);
-                return ERANGE;
-            }
-        }
-        else
-            cp = (fat_cluster_t *)(b->data + offset % BPS(bs));
-
-        value = host2uint16_t_le(value);
-        if (FATTYPE(bs) == 12) {
-            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 */
+	/* 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;
@@ -464,7 +464,6 @@
 	uint8_t fatno;
 	unsigned c;
-	int rc;
-        uint16_t clst_last1 = FATTYPE(bs) == 16 ? FAT16_CLST_LAST1 :
-                                                  FAT12_CLST_LAST1;
+	fat_cluster_t clst_last1 = FAT_CLST_LAST1(bs);
+	int rc;
 
 	for (fatno = FAT1 + 1; fatno < bs->fatcnt; fatno++) {
@@ -501,61 +500,58 @@
     fat_cluster_t *mcl, fat_cluster_t *lcl)
 {
-        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;
-        int rc = EOK;
-        uint16_t clst_last1 = FATTYPE(bs) == 16 ? FAT16_CLST_LAST1 :
-                                                  FAT12_CLST_LAST1;
-
-        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 (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);
-                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);
-            }
-        }
-
-        free(lifo);
-        fibril_mutex_unlock(&fat_alloc_lock);
-        return ENOSPC;
+	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 (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);
+			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);
+		}
+	}
+
+	free(lifo);
+	fibril_mutex_unlock(&fat_alloc_lock);
+	return ENOSPC;
 }
 
@@ -572,13 +568,9 @@
 {
 	unsigned fatno;
-	fat_cluster_t nextc;
-	int rc;
-        uint16_t clst_last1 = FATTYPE(bs) == 16 ? FAT16_CLST_LAST1 :
-                                                  FAT12_CLST_LAST1;
-        uint16_t clst_bad =   FATTYPE(bs) == 16 ? FAT16_CLST_BAD :
-                                                  FAT12_CLST_BAD;
+	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 < clst_last1) {
+	while (firstc < FAT_CLST_LAST1(bs)) {
 		assert(firstc >= FAT_CLST_FIRST && firstc < clst_bad);
 		rc = fat_get_cluster(bs, devmap_handle, FAT1, firstc, &nextc);
@@ -632,6 +624,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;
@@ -657,8 +649,7 @@
 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;
-        uint16_t clst_last1 = FATTYPE(bs) == 16 ? FAT16_CLST_LAST1 :
-                                                  FAT12_CLST_LAST1;
 
 	/*
@@ -790,5 +781,5 @@
 		 * set to one.
 		 */
-                if (FATTYPE(bs)!=12 && ((e0 >> 8) != 0xff || e1 != 0xffff))
+                if (!FAT_IS_FAT12(bs) && ((e0 >> 8) != 0xff || e1 != 0xffff))
 			return ENOTSUP;
 	}
Index: uspace/srv/fs/fat/fat_fat.h
===================================================================
--- uspace/srv/fs/fat/fat_fat.h	(revision 97bc3ee99b9182a255fcba5caf3fc118a0f767c1)
+++ uspace/srv/fs/fat/fat_fat.h	(revision d260a95d5be9ef2379607364e7848009c9d4dab9)
@@ -51,4 +51,7 @@
 #define FAT16_CLST_LAST8  0xffff
 
+#define FAT12_CLST_MAX    4085
+#define FAT16_CLST_MAX    65525
+
 /* internally used to mark root directory's parent */
 #define FAT_CLST_ROOTPAR	FAT_CLST_RES0
@@ -60,10 +63,20 @@
  * 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 FATTYPE(bs)     (bs)->reserved
+#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 97bc3ee99b9182a255fcba5caf3fc118a0f767c1)
+++ uspace/srv/fs/fat/fat_ops.c	(revision d260a95d5be9ef2379607364e7848009c9d4dab9)
@@ -1002,21 +1002,15 @@
 	}
 
-        /* Storing FAT type (12, 16, 32) in reserved field (bs->reserved) */
-        if (CC(bs) < 4085) {
-        /* Volume is FAT12 */
-            printf("Found FAT12 filesystem\n");
-            (bs)->reserved = 12;
-        } else if (CC(bs) < 65525) {
-        /* Volume is FAT16 */
-            printf("Found FAT16 filesystem\n");
-            (bs)->reserved = 16;
-        } else {
-        /* Volume is FAT32 */
-            printf("FAT32 filesystem is not supported by FAT server. Sorry.\n");
-            block_fini(devmap_handle);
-            async_answer_0(rid, ENOTSUP);
-            return;
-
-        }
+	/* Determining type of FAT  */
+	if (FAT_IS_FAT12(bs)) {
+		printf("Found FAT12 filesystem\n");
+	} else if (FAT_IS_FAT16(bs)) {
+		printf("Found FAT16 filesystem\n");
+	} else {
+		printf("FAT32 filesystem is not supported by FAT server.\n");
+		block_fini(devmap_handle);
+		async_answer_0(rid, ENOTSUP);
+		return;
+	}
 
 	/* Do some simple sanity checks on the file system. */
