Index: uspace/srv/fs/exfat/exfat_ops.c
===================================================================
--- uspace/srv/fs/exfat/exfat_ops.c	(revision 81d773ff1795cc203f65be169f30df86914ba559)
+++ uspace/srv/fs/exfat/exfat_ops.c	(revision a86e4f868defa19b207816ca4f2affe09149903b)
@@ -40,4 +40,5 @@
 #include "exfat_fat.h"
 #include "exfat_dentry.h"
+#include "exfat_directory.h"
 #include "../../vfs/vfs.h"
 #include <libfs.h>
@@ -237,4 +238,18 @@
 }
 
+static int exfat_node_get_new_by_pos(exfat_node_t **nodepp, 
+    devmap_handle_t devmap_handle, exfat_cluster_t pfc, unsigned pdi)
+{
+	exfat_idx_t *idxp = exfat_idx_get_by_pos(devmap_handle, pfc, pdi);
+	if (!idxp)
+		return ENOMEM;
+	if (exfat_node_get_new(nodepp) != EOK)
+		return ENOMEM;
+	(*nodepp)->idx = idxp;
+	idxp->nodep = *nodepp;
+	return EOK;
+}
+
+
 /** Internal version of exfat_node_get().
  *
@@ -368,5 +383,6 @@
 	return exfat_node_get(rfn, devmap_handle, EXFAT_BITMAP_IDX);
 }
-
+*/
+/*
 int exfat_uctable_get(fs_node_t **rfn, devmap_handle_t devmap_handle)
 {
@@ -505,7 +521,35 @@
  */
 
+/* Print debug info */
+static void exfat_fsinfo(exfat_bs_t *bs, devmap_handle_t devmap_handle)
+{
+	printf("exFAT file system mounted\n");
+	printf("Version: %d.%d\n", bs->version.major, bs->version.minor);
+	printf("Volume serial: %d\n", uint32_t_le2host(bs->volume_serial));
+	printf("Volume first sector: %lld\n", VOL_FS(bs));
+	printf("Volume sectors: %lld\n", VOL_CNT(bs));
+	printf("FAT first sector: %d\n", FAT_FS(bs));
+	printf("FAT sectors: %d\n", FAT_CNT(bs));
+	printf("Data first sector: %d\n", DATA_FS(bs));
+	printf("Data sectors: %d\n", DATA_CNT(bs));
+	printf("Root dir first cluster: %d\n", ROOT_FC(bs));
+	printf("Bytes per sector: %d\n", BPS(bs));
+	printf("Sectors per cluster: %d\n", SPC(bs));
+	printf("KBytes per cluster: %d\n", SPC(bs)*BPS(bs)/1024);
+	
+	int i, rc;
+	exfat_cluster_t clst;
+	for (i=0; i<6; i++) {
+		rc = fat_get_cluster(bs, devmap_handle, i, &clst);
+		if (rc != EOK)
+			return;
+		printf("Clst %d: %x\n", i, clst);
+	}
+}
+
 void exfat_mounted(ipc_callid_t rid, ipc_call_t *request)
 {
 	devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);
+	exfat_node_t *rootp=NULL, *bitmapp=NULL, *uctablep=NULL;
 	enum cache_mode cmode;
 	exfat_bs_t *bs;
@@ -545,9 +589,7 @@
 	/* get the buffer with the boot sector */
 	bs = block_bb_get(devmap_handle);
-	
-	(void) bs;
 
 	/* Initialize the block cache */
-	rc = block_cache_init(devmap_handle, BS_SIZE, 0 /* XXX */, cmode);
+	rc = block_cache_init(devmap_handle, BPS(bs), 0 /* XXX */, cmode);
 	if (rc != EOK) {
 		block_fini(devmap_handle);
@@ -574,6 +616,7 @@
 
 	/* Initialize the root node. */
-	fs_node_t *rfn = (fs_node_t *)malloc(sizeof(fs_node_t));
-	if (!rfn) {
+	rc = exfat_node_get_new_by_pos(&rootp, devmap_handle, EXFAT_ROOT_PAR, 
+	    EXFAT_ROOT_POS);
+	if (rc!=EOK) {
 		(void) block_cache_fini(devmap_handle);
 		block_fini(devmap_handle);
@@ -582,9 +625,53 @@
 		return;
 	}
-
-	fs_node_initialize(rfn);
-	exfat_node_t *rootp = (exfat_node_t *)malloc(sizeof(exfat_node_t));
-	if (!rootp) {
-		free(rfn);
+	assert(rootp->idx->index == EXFAT_ROOT_IDX);
+
+	rootp->type = EXFAT_DIRECTORY;
+	rootp->firstc = ROOT_FC(bs);
+	rootp->fragmented = true;
+	rootp->refcnt = 1;
+	rootp->lnkcnt = 0;	/* FS root is not linked */
+
+	uint32_t clusters;
+	rc = fat_clusters_get(&clusters, bs, devmap_handle, rootp->firstc);
+	if (rc != EOK) {
+		free(rootp);
+		(void) block_cache_fini(devmap_handle);
+		block_fini(devmap_handle);
+		exfat_idx_fini_by_devmap_handle(devmap_handle);
+		async_answer_0(rid, ENOTSUP);
+		return;
+	}
+	rootp->size = BPS(bs) * SPC(bs) * clusters;
+	fibril_mutex_unlock(&rootp->idx->lock);
+
+	/* Open root directory and looking for Bitmap and UC-Table */
+	exfat_directory_t di;
+	exfat_dentry_t *de;
+	rc = exfat_directory_open(rootp, &di);
+	if (rc != EOK) {
+		free(rootp);
+		(void) block_cache_fini(devmap_handle);
+		block_fini(devmap_handle);
+		exfat_idx_fini_by_devmap_handle(devmap_handle);
+		async_answer_0(rid, ENOTSUP);
+		return;
+	}
+
+	/* Initialize the bitmap node. */
+	rc = exfat_directory_find(&di, EXFAT_DENTRY_BITMAP, &de);
+	if (rc != EOK) {
+		free(rootp);
+		(void) block_cache_fini(devmap_handle);
+		block_fini(devmap_handle);
+		exfat_idx_fini_by_devmap_handle(devmap_handle);
+		async_answer_0(rid, ENOTSUP);
+		return;
+	}
+
+	rc = exfat_node_get_new_by_pos(&bitmapp, devmap_handle, rootp->firstc, 
+	    di.pos);
+	if (rc!=EOK) {
+		free(rootp);
 		(void) block_cache_fini(devmap_handle);
 		block_fini(devmap_handle);
@@ -593,11 +680,42 @@
 		return;
 	}
-
-	exfat_node_initialize(rootp);
-
-	exfat_idx_t *ridxp = exfat_idx_get_by_pos(devmap_handle, EXFAT_ROOT_PAR, 0);
-	if (!ridxp) {
-		free(rfn);
+	assert(bitmapp->idx->index == EXFAT_BITMAP_IDX);
+	fibril_mutex_unlock(&bitmapp->idx->lock);
+
+	bitmapp->type = EXFAT_BITMAP;
+	bitmapp->firstc = de->bitmap.firstc;
+	bitmapp->fragmented = true;
+	bitmapp->refcnt = 1;
+	bitmapp->lnkcnt = 0;
+	bitmapp->size = de->bitmap.size;
+
+	/* Initialize the uctable node. */
+	rc = exfat_directory_seek(&di, 0);
+	if (rc != EOK) {
 		free(rootp);
+		free(bitmapp);
+		(void) block_cache_fini(devmap_handle);
+		block_fini(devmap_handle);
+		exfat_idx_fini_by_devmap_handle(devmap_handle);
+		async_answer_0(rid, ENOTSUP);
+		return;
+	}
+
+	rc = exfat_directory_find(&di, EXFAT_DENTRY_UCTABLE, &de);
+	if (rc != EOK) {
+		free(rootp);
+		free(bitmapp);
+		(void) block_cache_fini(devmap_handle);
+		block_fini(devmap_handle);
+		exfat_idx_fini_by_devmap_handle(devmap_handle);
+		async_answer_0(rid, ENOTSUP);
+		return;
+	}
+
+	rc = exfat_node_get_new_by_pos(&uctablep, devmap_handle, rootp->firstc, 
+	    di.pos);
+	if (rc!=EOK) {
+		free(rootp);
+		free(bitmapp);
 		(void) block_cache_fini(devmap_handle);
 		block_fini(devmap_handle);
@@ -606,24 +724,30 @@
 		return;
 	}
-	assert(ridxp->index == 0);
-	/* ridxp->lock held */
-
-	rootp->type = EXFAT_DIRECTORY;
-	rootp->firstc = ROOT_ST(bs);
-	rootp->refcnt = 1;
-	rootp->lnkcnt = 0;	/* FS root is not linked */
-	rootp->idx = ridxp;
-	ridxp->nodep = rootp;
-	rootp->bp = rfn;
-	rfn->data = rootp;
-
-	fibril_mutex_unlock(&ridxp->lock);
-	
-	/* TODO */
-	/* We should intitalize bitmap and uctable nodes next to the root node */
-	/* HERE!!! */
-
-	/* async_answer_0(rid, EOK); */
-	async_answer_3(rid, EOK, ridxp->index, rootp->size, rootp->lnkcnt);
+	assert(uctablep->idx->index == EXFAT_UCTABLE_IDX);
+	fibril_mutex_unlock(&uctablep->idx->lock);
+
+	uctablep->type = EXFAT_UCTABLE;
+	uctablep->firstc = de->uctable.firstc;
+	uctablep->fragmented = true;
+	uctablep->refcnt = 1;
+	uctablep->lnkcnt = 0;
+	uctablep->size = de->uctable.size;
+
+	rc = exfat_directory_close(&di);
+	if (rc!=EOK) {
+		free(rootp);
+		free(bitmapp);
+		free(uctablep);
+		(void) block_cache_fini(devmap_handle);
+		block_fini(devmap_handle);
+		exfat_idx_fini_by_devmap_handle(devmap_handle);
+		async_answer_0(rid, ENOMEM);
+		return;
+	}
+
+	exfat_fsinfo(bs, devmap_handle);
+	printf("Root dir size: %lld\n", rootp->size);
+
+	async_answer_3(rid, EOK, rootp->idx->index, rootp->size, rootp->lnkcnt);
 }
 
@@ -681,4 +805,22 @@
 }
 
+/*
+int bitmap_is_allocated(exfat_bs_t *bs, devmap_handle_t devmap_handle,
+    exfat_cluster_t clst, bool *status)
+{
+	fs_node_t *fn;
+	exfat_node_t *bitmap;
+	int rc;
+
+	rc = exfat_bitmap_get(&fn, devmap_handle);
+	if (rc != EOK)
+		return rc;
+
+	nbitmap = EXFAT_NODE(fn);
+
+	
+	return EOK;
+}
+*/
 
 /**
