Index: uspace/drv/bus/isa/isa.ma
===================================================================
--- uspace/drv/bus/isa/isa.ma	(revision 04aaed8fb5f0d84ef06af90fda9391a41bdae192)
+++ uspace/drv/bus/isa/isa.ma	(revision db8a034e8369ef62950d379332e1cee26f14027e)
@@ -1,1 +1,1 @@
-9 	pci/ven=8086&dev=7000
+9 pci/ven=8086&dev=7000
Index: uspace/drv/bus/usb/ehci/ehci.ma
===================================================================
--- uspace/drv/bus/usb/ehci/ehci.ma	(revision 04aaed8fb5f0d84ef06af90fda9391a41bdae192)
+++ uspace/drv/bus/usb/ehci/ehci.ma	(revision db8a034e8369ef62950d379332e1cee26f14027e)
@@ -1,39 +1,1 @@
-10 pci/ven=1002&dev=4345
-10 pci/ven=1002&dev=4386
-10 pci/ven=1002&dev=4396
-10 pci/ven=1002&dev=4373
-10 pci/ven=1022&dev=7463
-10 pci/ven=1022&dev=7808
-10 pci/ven=102f&dev=01b5
-10 pci/ven=10cf&dev=1415
-10 pci/ven=10de&dev=00e8
-10 pci/ven=10de&dev=055f
-10 pci/ven=10de&dev=056a
-10 pci/ven=10de&dev=077c
-10 pci/ven=10de&dev=077e
-10 pci/ven=10de&dev=0aa6
-10 pci/ven=10de&dev=0aa9
-10 pci/ven=10de&dev=0aaa
-10 pci/ven=10de&dev=0d9d
-10 pci/ven=1166&dev=0414
-10 pci/ven=1166&dev=0416
-10 pci/ven=1414&dev=5805
-10 pci/ven=1414&dev=5807
-10 pci/ven=15ad&dev=0770
-10 pci/ven=17a0&dev=8084
-10 pci/ven=8086&dev=24cd
-10 pci/ven=8086&dev=24dd
-10 pci/ven=8086&dev=265c
-10 pci/ven=8086&dev=268c
-10 pci/ven=8086&dev=27cc
-10 pci/ven=8086&dev=2836
-10 pci/ven=8086&dev=283a
-10 pci/ven=8086&dev=293a
-10 pci/ven=8086&dev=293c
-10 pci/ven=8086&dev=3a3a
-10 pci/ven=8086&dev=3a3c
-10 pci/ven=8086&dev=3a6a
-10 pci/ven=8086&dev=3a6c
-10 pci/ven=8086&dev=8117
-10 pci/ven=8086&dev=8807
-10 pci/ven=8086&dev=880f
+10 pci/class=0c&subclass=03&progif=20
Index: uspace/drv/bus/usb/ohci/ohci.ma
===================================================================
--- uspace/drv/bus/usb/ohci/ohci.ma	(revision 04aaed8fb5f0d84ef06af90fda9391a41bdae192)
+++ uspace/drv/bus/usb/ohci/ohci.ma	(revision db8a034e8369ef62950d379332e1cee26f14027e)
@@ -1,15 +1,1 @@
-10 pci/ven=106b&dev=0026
-10 pci/ven=106b&dev=003f
-10 pci/ven=10de&dev=0aa5
-
-10 pci/ven=1002&dev=4374
-10 pci/ven=1002&dev=4375
-
-10 pci/ven=1002&dev=4387
-10 pci/ven=1002&dev=4388
-10 pci/ven=1002&dev=4389
-10 pci/ven=1002&dev=438a
-10 pci/ven=1002&dev=438b
-10 pci/ven=1002&dev=4397
-10 pci/ven=1002&dev=4398
-10 pci/ven=1002&dev=4399
+10 pci/class=0c&subclass=03&progif=10
Index: uspace/drv/bus/usb/uhci/uhci.ma
===================================================================
--- uspace/drv/bus/usb/uhci/uhci.ma	(revision 04aaed8fb5f0d84ef06af90fda9391a41bdae192)
+++ uspace/drv/bus/usb/uhci/uhci.ma	(revision db8a034e8369ef62950d379332e1cee26f14027e)
@@ -1,29 +1,1 @@
-10 pci/ven=8086&dev=7020
-10 pci/ven=8086&dev=7112
-
-10 pci/ven=8086&dev=27c8
-10 pci/ven=8086&dev=27c9
-10 pci/ven=8086&dev=27ca
-10 pci/ven=8086&dev=27cb
-
-10 pci/ven=8086&dev=2830
-10 pci/ven=8086&dev=2831
-10 pci/ven=8086&dev=2832
-10 pci/ven=8086&dev=2834
-10 pci/ven=8086&dev=2835
-
-10 pci/ven=8086&dev=2934
-10 pci/ven=8086&dev=2935
-10 pci/ven=8086&dev=2936
-10 pci/ven=8086&dev=2937
-10 pci/ven=8086&dev=2938
-10 pci/ven=8086&dev=2939
-
-10 pci/ven=8086&dev=24c2
-10 pci/ven=8086&dev=24c4
-10 pci/ven=8086&dev=24c7
-
-10 pci/ven=8086&dev=2688
-10 pci/ven=8086&dev=2689
-10 pci/ven=8086&dev=268a
-10 pci/ven=8086&dev=268b
+10 pci/class=0c&subclass=03&progif=00
Index: uspace/drv/bus/usb/vhc/vhc.ma
===================================================================
--- uspace/drv/bus/usb/vhc/vhc.ma	(revision 04aaed8fb5f0d84ef06af90fda9391a41bdae192)
+++ uspace/drv/bus/usb/vhc/vhc.ma	(revision db8a034e8369ef62950d379332e1cee26f14027e)
@@ -1,2 +1,1 @@
 10 usb&hc=vhc
-
Index: uspace/drv/nic/lo/lo.ma
===================================================================
--- uspace/drv/nic/lo/lo.ma	(revision 04aaed8fb5f0d84ef06af90fda9391a41bdae192)
+++ uspace/drv/nic/lo/lo.ma	(revision db8a034e8369ef62950d379332e1cee26f14027e)
Index: uspace/drv/nic/ne2k/ne2k.ma
===================================================================
--- uspace/drv/nic/ne2k/ne2k.ma	(revision 04aaed8fb5f0d84ef06af90fda9391a41bdae192)
+++ uspace/drv/nic/ne2k/ne2k.ma	(revision db8a034e8369ef62950d379332e1cee26f14027e)
Index: uspace/lib/c/generic/ddi.c
===================================================================
--- uspace/lib/c/generic/ddi.c	(revision 04aaed8fb5f0d84ef06af90fda9391a41bdae192)
+++ uspace/lib/c/generic/ddi.c	(revision db8a034e8369ef62950d379332e1cee26f14027e)
@@ -53,22 +53,24 @@
 }
 
-/** Map piece of physical memory to task.
+/** Map a piece of physical memory to task.
  *
  * Caller of this function must have the CAP_MEM_MANAGER capability.
  *
- * @param pf		Physical address of the starting frame.
- * @param vp		Virtual address of the starting page.
- * @param pages		Number of pages to map.
- * @param flags		Flags for the new address space area.
+ * @param pf    Physical address of the starting frame.
+ * @param vp    Virtual address of the starting page.
+ * @param pages Number of pages to map.
+ * @param flags Flags for the new address space area.
  *
- * @return 		0 on success, EPERM if the caller lacks the
- *			CAP_MEM_MANAGER capability, ENOENT if there is no task
- *			with specified ID and ENOMEM if there was some problem
- *			in creating address space area.
+ * @return EOK on success
+ * @return EPERM if the caller lacks the CAP_MEM_MANAGER capability
+ * @return ENOENT if there is no task with specified ID
+ * @return ENOMEM if there was some problem in creating
+ *         the address space area.
+ *
  */
-int physmem_map(void *pf, void *vp, unsigned long pages, int flags)
+int physmem_map(void *pf, void *vp, size_t pages, unsigned int flags)
 {
-	return __SYSCALL4(SYS_PHYSMEM_MAP, (sysarg_t) pf, (sysarg_t) vp, pages,
-	    flags);
+	return __SYSCALL4(SYS_PHYSMEM_MAP, (sysarg_t) pf, (sysarg_t) vp,
+	    pages, flags);
 }
 
Index: uspace/lib/c/include/ddi.h
===================================================================
--- uspace/lib/c/include/ddi.h	(revision 04aaed8fb5f0d84ef06af90fda9391a41bdae192)
+++ uspace/lib/c/include/ddi.h	(revision db8a034e8369ef62950d379332e1cee26f14027e)
@@ -41,5 +41,5 @@
 
 extern int device_assign_devno(void);
-extern int physmem_map(void *, void *, unsigned long, int);
+extern int physmem_map(void *, void *, size_t, unsigned int);
 extern int iospace_enable(task_id_t, void *, unsigned long);
 extern int pio_enable(void *, size_t, void **);
Index: uspace/lib/minix/minix.h
===================================================================
--- uspace/lib/minix/minix.h	(revision 04aaed8fb5f0d84ef06af90fda9391a41bdae192)
+++ uspace/lib/minix/minix.h	(revision db8a034e8369ef62950d379332e1cee26f14027e)
@@ -39,9 +39,9 @@
 #define S_ISDIR(m)		(((m) & S_IFMT) == S_IFDIR)
 #define S_ISREG(m)		(((m) & S_IFMT) == S_IFREG)
-#define S_IFDIR			0040000		/*Directory*/
-#define S_IFREG			0100000		/*Regular file*/
+#define S_IFDIR			0040000		/* Directory */
+#define S_IFREG			0100000		/* Regular file */
 #define S_IFMT			00170000
 
-/*The following block sizes are valid only on V3 filesystem*/
+/* The following block sizes are valid only on V3 filesystem */
 #define MFS_MIN_BLOCKSIZE	1024
 #define MFS_MAX_BLOCKSIZE	4096
@@ -88,19 +88,19 @@
 #define MFS_ERROR_FS		0x0002
 
-/*MFS V1/V2 superblock data on disk*/
+/* MFS V1/V2 superblock data on disk */
 struct mfs_superblock {
-	/*Total number of inodes on the device*/
+	/* Total number of inodes on the device */
 	uint16_t	s_ninodes;
-	/*Total number of zones on the device*/
+	/* Total number of zones on the device */
 	uint16_t	s_nzones;
-	/*Number of inode bitmap blocks*/
+	/* Number of inode bitmap blocks */
 	uint16_t	s_ibmap_blocks;
-	/*Number of zone bitmap blocks*/
+	/* Number of zone bitmap blocks */
 	uint16_t	s_zbmap_blocks;
-	/*First data zone on device*/
+	/* First data zone on device */
 	uint16_t	s_first_data_zone;
-	/*Base 2 logarithm of the zone to block ratio*/
+	/* Base 2 logarithm of the zone to block ratio */
 	uint16_t	s_log2_zone_size;
-	/*Maximum file size expressed in bytes*/
+	/* Maximum file size expressed in bytes */
 	uint32_t	s_max_file_size;
 	/*
@@ -109,28 +109,28 @@
 	 */
 	uint16_t	s_magic;
-	/*Flag used to detect FS errors*/
+	/* Flag used to detect FS errors*/
 	uint16_t	s_state;
-	/*Total number of zones on the device (V2 only)*/
+	/* Total number of zones on the device (V2 only) */
 	uint32_t	s_nzones2;
 } __attribute__ ((packed));
 
 
-/*MFS V3 superblock data on disk*/
+/* MFS V3 superblock data on disk */
 struct mfs3_superblock {
-	/*Total number of inodes on the device*/
+	/* Total number of inodes on the device */
 	uint32_t	s_ninodes;
 	uint16_t	s_pad0;
-	/*Number of inode bitmap blocks*/
+	/* Number of inode bitmap blocks */
 	int16_t		s_ibmap_blocks;
-	/*Number of zone bitmap blocks*/
+	/* Number of zone bitmap blocks */
 	int16_t		s_zbmap_blocks;
-	/*First data zone on device*/
+	/* First data zone on device */
 	uint16_t	s_first_data_zone;
-	/*Base 2 logarithm of the zone to block ratio*/
+	/* Base 2 logarithm of the zone to block ratio */
 	int16_t		s_log2_zone_size;
 	int16_t		s_pad1;
-	/*Maximum file size expressed in bytes*/
+	/* Maximum file size expressed in bytes */
 	uint32_t	s_max_file_size;
-	/*Total number of zones on the device*/
+	/* Total number of zones on the device */
 	uint32_t	s_nzones;
 	/*
@@ -140,11 +140,11 @@
 	int16_t		s_magic;
 	int16_t		s_pad2;
-	/*Filesystem block size expressed in bytes*/
+	/* Filesystem block size expressed in bytes */
 	uint16_t	s_block_size;
-	/*Filesystem disk format version*/
+	/* Filesystem disk format version */
 	int8_t		s_disk_version;
 } __attribute__ ((packed));
 
-/*MinixFS V1 inode structure as it is on disk*/
+/* MinixFS V1 inode structure as it is on disk */
 struct mfs_inode {
 	uint16_t	i_mode;
@@ -154,11 +154,11 @@
 	uint8_t		i_gid;
 	uint8_t		i_nlinks;
-	/*Block numbers for direct zones*/
+	/* Block numbers for direct zones */
 	uint16_t	i_dzone[V1_NR_DIRECT_ZONES];
-	/*Block numbers for indirect zones*/
+	/* Block numbers for indirect zones */
 	uint16_t	i_izone[V1_NR_INDIRECT_ZONES];
 } __attribute__ ((packed));
 
-/*MinixFS V2 inode structure as it is on disk (also valid for V3).*/
+/* MinixFS V2 inode structure as it is on disk (also valid for V3). */
 struct mfs2_inode {
 	uint16_t 	i_mode;
@@ -170,11 +170,11 @@
 	int32_t		i_mtime;
 	int32_t		i_ctime;
-	/*Block numbers for direct zones*/
+	/* Block numbers for direct zones */
 	uint32_t	i_dzone[V2_NR_DIRECT_ZONES];
-	/*Block numbers for indirect zones*/
+	/* Block numbers for indirect zones */
 	uint32_t	i_izone[V2_NR_INDIRECT_ZONES];
 } __attribute__ ((packed));
 
-/*MinixFS V1/V2 directory entry on-disk structure*/
+/* MinixFS V1/V2 directory entry on-disk structure */
 struct mfs_dentry {
 	uint16_t d_inum;
@@ -182,5 +182,5 @@
 };
 
-/*MinixFS V3 directory entry on-disk structure*/
+/* MinixFS V3 directory entry on-disk structure */
 struct mfs3_dentry {
 	uint32_t d_inum;
Index: uspace/srv/bd/rd/rd.c
===================================================================
--- uspace/srv/bd/rd/rd.c	(revision 04aaed8fb5f0d84ef06af90fda9391a41bdae192)
+++ uspace/srv/bd/rd/rd.c	(revision db8a034e8369ef62950d379332e1cee26f14027e)
@@ -55,6 +55,7 @@
 #include <ipc/bd.h>
 #include <macros.h>
-
-#define NAME "rd"
+#include <inttypes.h>
+
+#define NAME  "rd"
 
 /** Pointer to the ramdisk's image */
@@ -208,39 +209,42 @@
 static bool rd_init(void)
 {
-	int ret = sysinfo_get_value("rd.size", &rd_size);
-	if ((ret != EOK) || (rd_size == 0)) {
+	sysarg_t size;
+	int ret = sysinfo_get_value("rd.size", &size);
+	if ((ret != EOK) || (size == 0)) {
 		printf("%s: No RAM disk found\n", NAME);
 		return false;
 	}
 	
-	sysarg_t rd_ph_addr;
-	ret = sysinfo_get_value("rd.address.physical", &rd_ph_addr);
-	if ((ret != EOK) || (rd_ph_addr == 0)) {
+	sysarg_t addr_phys;
+	ret = sysinfo_get_value("rd.address.physical", &addr_phys);
+	if ((ret != EOK) || (addr_phys == 0)) {
 		printf("%s: Invalid RAM disk physical address\n", NAME);
 		return false;
 	}
 	
+	rd_size = ALIGN_UP(size, block_size);
 	rd_addr = as_get_mappable_page(rd_size);
 	
-	int flags = AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE;
-	int retval = physmem_map((void *) rd_ph_addr, rd_addr,
+	unsigned int flags =
+	    AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE;
+	ret = physmem_map((void *) addr_phys, rd_addr,
 	    ALIGN_UP(rd_size, PAGE_SIZE) >> PAGE_WIDTH, flags);
-	
-	if (retval < 0) {
+	if (ret < 0) {
 		printf("%s: Error mapping RAM disk\n", NAME);
 		return false;
 	}
 	
-	printf("%s: Found RAM disk at %p, %zu bytes\n", NAME,
-	    (void *) rd_ph_addr, rd_size);
-	
-	int rc = loc_server_register(NAME, rd_connection);
-	if (rc < 0) {
-		printf("%s: Unable to register driver (%d)\n", NAME, rc);
+	printf("%s: Found RAM disk at %p, %" PRIun " bytes\n", NAME,
+	    (void *) addr_phys, size);
+	
+	ret = loc_server_register(NAME, rd_connection);
+	if (ret < 0) {
+		printf("%s: Unable to register driver (%d)\n", NAME, ret);
 		return false;
 	}
 	
 	service_id_t service_id;
-	if (loc_service_register("bd/initrd", &service_id) != EOK) {
+	ret = loc_service_register("bd/initrd", &service_id);
+	if (ret != EOK) {
 		printf("%s: Unable to register device service\n", NAME);
 		return false;
Index: uspace/srv/fs/mfs/mfs.h
===================================================================
--- uspace/srv/fs/mfs/mfs.h	(revision 04aaed8fb5f0d84ef06af90fda9391a41bdae192)
+++ uspace/srv/fs/mfs/mfs.h	(revision db8a034e8369ef62950d379332e1cee26f14027e)
@@ -48,5 +48,5 @@
 #define NAME		"mfs"
 
-//#define DEBUG_MODE
+/* #define DEBUG_MODE */
 
 #define min(a, b)	((a) < (b) ? (a) : (b))
@@ -71,5 +71,5 @@
 } mfs_version_t;
 
-/*Generic MinixFS superblock*/
+/* Generic MinixFS superblock */
 struct mfs_sb_info {
 	uint32_t ninodes;
@@ -84,5 +84,5 @@
 	uint16_t state;
 
-	/*The following fields do not exist on disk but only in memory*/
+	/* The following fields do not exist on disk but only in memory */
 	unsigned long itable_size;
 	mfs_version_t fs_version;
@@ -97,5 +97,5 @@
 };
 
-/*Generic MinixFS inode*/
+/* Generic MinixFS inode */
 struct mfs_ino_info {
 	uint16_t	i_mode;
@@ -107,24 +107,24 @@
 	int32_t		i_mtime;
 	int32_t		i_ctime;
-	/*Block numbers for direct zones*/
+	/* Block numbers for direct zones */
 	uint32_t	i_dzone[V2_NR_DIRECT_ZONES];
-	/*Block numbers for indirect zones*/
+	/* Block numbers for indirect zones */
 	uint32_t	i_izone[V2_NR_INDIRECT_ZONES];
 
-	/*The following fields do not exist on disk but only in memory*/
+	/* The following fields do not exist on disk but only in memory */
 	bool dirty;
 	fs_index_t index;
 };
 
-/*Generic MFS directory entry*/
+/* Generic MFS directory entry */
 struct mfs_dentry_info {
 	uint32_t d_inum;
 	char d_name[MFS3_MAX_NAME_LEN + 1];
 
-	/*The following fields do not exist on disk but only in memory*/
-
-	/*Index of the dentry in the list*/
+	/* The following fields do not exist on disk but only in memory */
+
+	/* Index of the dentry in the list */
 	unsigned index;
-	/*Pointer to the node at witch the dentry belongs*/
+	/* Pointer to the node at witch the dentry belongs */
 	struct mfs_node *node;
 };
@@ -136,5 +136,5 @@
 };
 
-/*MinixFS node in core*/
+/* MinixFS node in core */
 struct mfs_node {
 	struct mfs_ino_info *ino_i;
@@ -145,5 +145,5 @@
 };
 
-/*mfs_ops.c*/
+/* mfs_ops.c */
 extern vfs_out_ops_t mfs_ops;
 extern libfs_ops_t mfs_libfs_ops;
@@ -152,8 +152,8 @@
 mfs_global_init(void);
 
-/*mfs_inode.c*/
+/* mfs_inode.c */
 extern int
 mfs_get_inode(struct mfs_instance *inst, struct mfs_ino_info **ino_i,
-	  fs_index_t index);
+    fs_index_t index);
 
 extern int
@@ -163,5 +163,5 @@
 mfs_inode_shrink(struct mfs_node *mnode, size_t size_shrink);
 
-/*mfs_rw.c*/
+/* mfs_rw.c */
 extern int
 mfs_read_map(uint32_t *b, const struct mfs_node *mnode, const uint32_t pos);
@@ -169,13 +169,13 @@
 extern int
 mfs_write_map(struct mfs_node *mnode, uint32_t pos, uint32_t new_zone,
-	  uint32_t *old_zone);
+    uint32_t *old_zone);
 
 extern int
 mfs_prune_ind_zones(struct mfs_node *mnode, size_t new_size);
 
-/*mfs_dentry.c*/
+/* mfs_dentry.c */
 extern int
 mfs_read_dentry(struct mfs_node *mnode,
-		     struct mfs_dentry_info *d_info, unsigned index);
+    struct mfs_dentry_info *d_info, unsigned index);
 
 extern int
@@ -188,5 +188,5 @@
 mfs_insert_dentry(struct mfs_node *mnode, const char *d_name, fs_index_t d_inum);
 
-/*mfs_balloc.c*/
+/* mfs_balloc.c */
 extern int
 mfs_alloc_inode(struct mfs_instance *inst, uint32_t *inum);
@@ -201,5 +201,5 @@
 mfs_free_zone(struct mfs_instance *inst, uint32_t zone);
 
-/*mfs_utils.c*/
+/* mfs_utils.c */
 extern uint16_t
 conv16(bool native, uint16_t n);
Index: uspace/srv/fs/mfs/mfs_balloc.c
===================================================================
--- uspace/srv/fs/mfs/mfs_balloc.c	(revision 04aaed8fb5f0d84ef06af90fda9391a41bdae192)
+++ uspace/srv/fs/mfs/mfs_balloc.c	(revision db8a034e8369ef62950d379332e1cee26f14027e)
@@ -198,5 +198,5 @@
 		limit = sbi->nzones - sbi->firstdatazone - 1;
 	} else {
-		/*bid == BMAP_INODE*/
+		/* bid == BMAP_INODE */
 		search = &sbi->isearch;
 		start_block = 2;
@@ -212,5 +212,5 @@
 	for (i = *search / bits_per_block; i < nblocks; ++i) {
 		r = block_get(&b, inst->service_id, i + start_block,
-			      BLOCK_FLAGS_NONE);
+		    BLOCK_FLAGS_NONE);
 
 		if (r != EOK)
Index: uspace/srv/fs/mfs/mfs_dentry.c
===================================================================
--- uspace/srv/fs/mfs/mfs_dentry.c	(revision 04aaed8fb5f0d84ef06af90fda9391a41bdae192)
+++ uspace/srv/fs/mfs/mfs_dentry.c	(revision db8a034e8369ef62950d379332e1cee26f14027e)
@@ -168,5 +168,5 @@
 		return ENAMETOOLONG;
 
-	/*Search the directory entry to be removed*/
+	/* Search the directory entry to be removed */
 	unsigned i;
 	for (i = 0; i < mnode->ino_i->i_size / sbi->dirsize ; ++i) {
Index: uspace/srv/fs/mfs/mfs_inode.c
===================================================================
--- uspace/srv/fs/mfs/mfs_inode.c	(revision 04aaed8fb5f0d84ef06af90fda9391a41bdae192)
+++ uspace/srv/fs/mfs/mfs_inode.c	(revision db8a034e8369ef62950d379332e1cee26f14027e)
@@ -235,6 +235,6 @@
 
 	r = block_get(&b, mnode->instance->service_id,
-		      itable_off + inum / sbi->ino_per_block,
-		      BLOCK_FLAGS_NONE);
+	    itable_off + inum / sbi->ino_per_block,
+	    BLOCK_FLAGS_NONE);
 
 	if (r != EOK)
@@ -278,6 +278,6 @@
 
 	r = block_get(&b, mnode->instance->service_id,
-		      itable_off + inum / sbi->ino_per_block,
-		      BLOCK_FLAGS_NONE);
+	    itable_off + inum / sbi->ino_per_block,
+	    BLOCK_FLAGS_NONE);
 
 	if (r != EOK)
Index: uspace/srv/fs/mfs/mfs_ops.c
===================================================================
--- uspace/srv/fs/mfs/mfs_ops.c	(revision 04aaed8fb5f0d84ef06af90fda9391a41bdae192)
+++ uspace/srv/fs/mfs/mfs_ops.c	(revision db8a034e8369ef62950d379332e1cee26f14027e)
@@ -664,4 +664,5 @@
 	struct mfs_node *child = cfn->data;
 	struct mfs_sb_info *sbi = parent->instance->sbi;
+	bool destroy_dentry = false;
 
 	mfsdebug("%s()\n", __FUNCTION__);
@@ -672,17 +673,24 @@
 	int r = mfs_insert_dentry(parent, name, child->ino_i->index);
 	if (r != EOK)
-		goto exit_error;
-
-	child->ino_i->i_nlinks++;
-	child->ino_i->dirty = true;
+		return r;
 
 	if (S_ISDIR(child->ino_i->i_mode)) {
+		if (child->ino_i->i_nlinks != 1) {
+			/* It's not possible to hardlink directories in MFS */
+			destroy_dentry = true;
+			r = EMLINK;
+			goto exit;
+		}
 		r = mfs_insert_dentry(child, ".", child->ino_i->index);
-		if (r != EOK)
-			goto exit_error;
+		if (r != EOK) {
+			destroy_dentry = true;
+			goto exit;
+		}
 
 		r = mfs_insert_dentry(child, "..", parent->ino_i->index);
-		if (r != EOK)
-			goto exit_error;
+		if (r != EOK) {
+			destroy_dentry = true;
+			goto exit;
+		}
 
 		parent->ino_i->i_nlinks++;
@@ -690,5 +698,13 @@
 	}
 
-exit_error:
+exit:
+	if (destroy_dentry) {
+		int r2 = mfs_remove_dentry(parent, name);
+		if (r2 != EOK)
+			r = r2;
+	} else {
+		child->ino_i->i_nlinks++;
+		child->ino_i->dirty = true;
+	}
 	return r;
 }
@@ -821,5 +837,5 @@
 found:
 		async_data_read_finalize(callid, d_info.d_name,
-					 str_size(d_info.d_name) + 1);
+		    str_size(d_info.d_name) + 1);
 		bytes = ((pos - spos) + 1);
 	} else {
Index: uspace/srv/fs/mfs/mfs_rw.c
===================================================================
--- uspace/srv/fs/mfs/mfs_rw.c	(revision 04aaed8fb5f0d84ef06af90fda9391a41bdae192)
+++ uspace/srv/fs/mfs/mfs_rw.c	(revision db8a034e8369ef62950d379332e1cee26f14027e)
@@ -147,5 +147,5 @@
 				ino_i->dirty = true;
 			} else {
-				/*Sparse block*/
+				/* Sparse block */
 				*b = 0;
 				return EOK;
@@ -233,5 +233,5 @@
 }
 
-/**Free unused indirect zones from a MINIX inode according to it's new size.
+/**Free unused indirect zones from a MINIX inode according to its new size.
  *
  * @param mnode		Pointer to a generic MINIX inode in memory.
