change log for rtems (2010-04-30)

rtems-vc at rtems.org rtems-vc at rtems.org
Fri Apr 30 09:12:04 UTC 2010


 *sh*:
2010-04-30	Sebastian Huber <sebastian.huber at embedded-brains.de>

	* posix/src/alarm.c, posix/src/psignal.c, posix/src/ualarm.c:
	Moved watchdog control objects to reduce dependencies.

M 1.2282  cpukit/ChangeLog
M   1.16  cpukit/posix/src/alarm.c
M   1.67  cpukit/posix/src/psignal.c
M   1.12  cpukit/posix/src/ualarm.c

diff -u rtems/cpukit/ChangeLog:1.2281 rtems/cpukit/ChangeLog:1.2282
--- rtems/cpukit/ChangeLog:1.2281	Thu Apr 29 07:24:55 2010
+++ rtems/cpukit/ChangeLog	Fri Apr 30 03:37:26 2010
@@ -1,3 +1,8 @@
+2010-04-30	Sebastian Huber <sebastian.huber at embedded-brains.de>
+
+	* posix/src/alarm.c, posix/src/psignal.c, posix/src/ualarm.c:
+	Moved watchdog control objects to reduce dependencies.
+
 2010-04-29	Sebastian Huber <sebastian.huber at embedded-brains.de>
 
 	PR 1507/filesystem

diff -u rtems/cpukit/posix/src/alarm.c:1.15 rtems/cpukit/posix/src/alarm.c:1.16
--- rtems/cpukit/posix/src/alarm.c:1.15	Sun Oct 11 17:37:38 2009
+++ rtems/cpukit/posix/src/alarm.c	Fri Apr 30 03:37:26 2010
@@ -22,8 +22,6 @@
 #include <rtems/posix/pthread.h>
 #include <rtems/posix/psignal.h>
 
-Watchdog_Control _POSIX_signals_Alarm_timer;
-
 /*PAGE
  *
  *  _POSIX_signals_Alarm_TSR

diff -u rtems/cpukit/posix/src/psignal.c:1.66 rtems/cpukit/posix/src/psignal.c:1.67
--- rtems/cpukit/posix/src/psignal.c:1.66	Sun Oct  4 17:08:43 2009
+++ rtems/cpukit/posix/src/psignal.c	Fri Apr 30 03:37:26 2010
@@ -89,6 +89,9 @@
 Chain_Control _POSIX_signals_Inactive_siginfo;
 Chain_Control _POSIX_signals_Siginfo[ SIG_ARRAY_MAX ];
 
+Watchdog_Control _POSIX_signals_Alarm_timer;
+Watchdog_Control _POSIX_signals_Ualarm_timer;
+
 /*PAGE
  *
  *  XXX - move these

diff -u rtems/cpukit/posix/src/ualarm.c:1.11 rtems/cpukit/posix/src/ualarm.c:1.12
--- rtems/cpukit/posix/src/ualarm.c:1.11	Mon Nov 30 09:44:21 2009
+++ rtems/cpukit/posix/src/ualarm.c	Fri Apr 30 03:37:27 2010
@@ -23,8 +23,6 @@
 #include <rtems/posix/psignal.h>
 #include <rtems/posix/time.h>
 
-Watchdog_Control _POSIX_signals_Ualarm_timer;
-
 /*PAGE
  *
  *  _POSIX_signals_Ualarm_TSR


 *sh*:
2010-04-30	Sebastian Huber <sebastian.huber at embedded-brains.de>

	* sapi/inline/rtems/chain.inl: Added missing functions.

M 1.2283  cpukit/ChangeLog
M    1.8  cpukit/sapi/inline/rtems/chain.inl

diff -u rtems/cpukit/ChangeLog:1.2282 rtems/cpukit/ChangeLog:1.2283
--- rtems/cpukit/ChangeLog:1.2282	Fri Apr 30 03:37:26 2010
+++ rtems/cpukit/ChangeLog	Fri Apr 30 03:39:14 2010
@@ -1,5 +1,9 @@
 2010-04-30	Sebastian Huber <sebastian.huber at embedded-brains.de>
 
+	* sapi/inline/rtems/chain.inl: Added missing functions.
+
+2010-04-30	Sebastian Huber <sebastian.huber at embedded-brains.de>
+
 	* posix/src/alarm.c, posix/src/psignal.c, posix/src/ualarm.c:
 	Moved watchdog control objects to reduce dependencies.
 

diff -u rtems/cpukit/sapi/inline/rtems/chain.inl:1.7 rtems/cpukit/sapi/inline/rtems/chain.inl:1.8
--- rtems/cpukit/sapi/inline/rtems/chain.inl:1.7	Thu Oct  8 02:07:36 2009
+++ rtems/cpukit/sapi/inline/rtems/chain.inl	Fri Apr 30 03:39:15 2010
@@ -385,6 +385,16 @@
 }
 
 /**
+ * @brief See _Chain_Get_unprotected().
+ */
+RTEMS_INLINE_ROUTINE rtems_chain_node *rtems_chain_get_unprotected(
+  rtems_chain_control *the_chain
+)
+{
+  return _Chain_Get_unprotected( the_chain );
+}
+
+/**
  *  @brief Insert a node on a chain
  *
  *  This routine inserts @a the_node on a chain immediately following
@@ -402,6 +412,17 @@
 }
 
 /**
+ * @brief See _Chain_Insert_unprotected().
+ */
+RTEMS_INLINE_ROUTINE void rtems_chain_insert_unprotected(
+  rtems_chain_node *after_node,
+  rtems_chain_node *the_node
+)
+{
+  _Chain_Insert_unprotected( after_node, the_node );
+}
+
+/**
  *  @brief Append a node on the end of a chain
  *
  *  This routine appends @a the_node onto the end of @a the_chain.


 *sh*:
2010-04-30	Sebastian Huber <sebastian.huber at embedded-brains.de>

	* libblock/src/bdpart.c: Removed file.
	* libblock/src/bdpart-create.c, libblock/src/bdpart-dump.c,
	libblock/src/bdpart-mount.c, libblock/src/bdpart-read.c,
	libblock/src/bdpart-register.c, libblock/src/bdpart-sort.c,
	libblock/src/bdpart-write.c: New files.
	* libblock/include/rtems/bdpart.h: Moved some definitions from bdpart.c.
	* libblock/Makefile.am: Update for file changes.

M 1.2284  cpukit/ChangeLog
M   1.38  cpukit/libblock/Makefile.am
M    1.3  cpukit/libblock/include/rtems/bdpart.h
A    1.1  cpukit/libblock/src/bdpart-create.c
A    1.1  cpukit/libblock/src/bdpart-dump.c
A    1.1  cpukit/libblock/src/bdpart-mount.c
A    1.1  cpukit/libblock/src/bdpart-read.c
A    1.1  cpukit/libblock/src/bdpart-register.c
A    1.1  cpukit/libblock/src/bdpart-sort.c
A    1.1  cpukit/libblock/src/bdpart-write.c

diff -u rtems/cpukit/ChangeLog:1.2283 rtems/cpukit/ChangeLog:1.2284
--- rtems/cpukit/ChangeLog:1.2283	Fri Apr 30 03:39:14 2010
+++ rtems/cpukit/ChangeLog	Fri Apr 30 03:42:11 2010
@@ -1,5 +1,15 @@
 2010-04-30	Sebastian Huber <sebastian.huber at embedded-brains.de>
 
+	* libblock/src/bdpart.c: Removed file.
+	* libblock/src/bdpart-create.c, libblock/src/bdpart-dump.c,
+	libblock/src/bdpart-mount.c, libblock/src/bdpart-read.c,
+	libblock/src/bdpart-register.c, libblock/src/bdpart-sort.c,
+	libblock/src/bdpart-write.c: New files.
+	* libblock/include/rtems/bdpart.h: Moved some definitions from bdpart.c.
+	* libblock/Makefile.am: Update for file changes.
+
+2010-04-30	Sebastian Huber <sebastian.huber at embedded-brains.de>
+
 	* sapi/inline/rtems/chain.inl: Added missing functions.
 
 2010-04-30	Sebastian Huber <sebastian.huber at embedded-brains.de>

diff -u rtems/cpukit/libblock/Makefile.am:1.37 rtems/cpukit/libblock/Makefile.am:1.38
--- rtems/cpukit/libblock/Makefile.am:1.37	Fri Oct 16 03:44:50 2009
+++ rtems/cpukit/libblock/Makefile.am	Fri Apr 30 03:42:12 2010
@@ -13,7 +13,13 @@
     src/ide_part_table.c \
     src/nvdisk.c \
     src/nvdisk-sram.c \
-    src/bdpart.c \
+    src/bdpart-create.c \
+    src/bdpart-dump.c \
+    src/bdpart-mount.c \
+    src/bdpart-read.c \
+    src/bdpart-register.c \
+    src/bdpart-sort.c \
+    src/bdpart-write.c \
     include/rtems/bdbuf.h include/rtems/blkdev.h \
     include/rtems/diskdevs.h include/rtems/flashdisk.h \
     include/rtems/ramdisk.h include/rtems/nvdisk.h include/rtems/nvdisk-sram.h \

diff -u rtems/cpukit/libblock/include/rtems/bdpart.h:1.2 rtems/cpukit/libblock/include/rtems/bdpart.h:1.3
--- rtems/cpukit/libblock/include/rtems/bdpart.h:1.2	Fri May 15 07:52:12 2009
+++ rtems/cpukit/libblock/include/rtems/bdpart.h	Fri Apr 30 03:42:12 2010
@@ -7,7 +7,7 @@
  */
 
 /*
- * Copyright (c) 2009
+ * Copyright (c) 2009, 2010
  * embedded brains GmbH
  * Obere Lagerstr. 30
  * D-82178 Puchheim
@@ -355,6 +355,50 @@
 
 /** @} */
 
+#define RTEMS_BDPART_MBR_CYLINDER_SIZE 63
+
+#define RTEMS_BDPART_NUMBER_SIZE 4
+
+#define RTEMS_BDPART_BLOCK_SIZE 512
+
+#define RTEMS_BDPART_MBR_TABLE_ENTRY_SIZE 16
+
+#define RTEMS_BDPART_MBR_OFFSET_TABLE_0 446
+
+#define RTEMS_BDPART_MBR_OFFSET_TABLE_1 \
+  (RTEMS_BDPART_MBR_OFFSET_TABLE_0 + RTEMS_BDPART_MBR_TABLE_ENTRY_SIZE)
+
+#define RTEMS_BDPART_MBR_OFFSET_DISK_ID 440
+
+#define RTEMS_BDPART_MBR_OFFSET_SIGNATURE_0 510
+
+#define RTEMS_BDPART_MBR_OFFSET_SIGNATURE_1 511
+
+#define RTEMS_BDPART_MBR_SIGNATURE_0 0x55U
+
+#define RTEMS_BDPART_MBR_SIGNATURE_1 0xaaU
+
+#define RTEMS_BDPART_MBR_OFFSET_BEGIN 8
+
+#define RTEMS_BDPART_MBR_OFFSET_SIZE 12
+
+#define RTEMS_BDPART_MBR_OFFSET_TYPE 4
+
+#define RTEMS_BDPART_MBR_OFFSET_FLAGS 0
+
+static inline uint8_t rtems_bdpart_mbr_partition_type(
+  const uuid_t type
+)
+{
+  return type [0];
+}
+
+rtems_status_code rtems_bdpart_get_disk_data(
+  const char *disk_name,
+  dev_t *disk,
+  rtems_blkdev_bnum *disk_end
+);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */

diff -u /dev/null rtems/cpukit/libblock/src/bdpart-create.c:1.1
--- /dev/null	Fri Apr 30 04:12:03 2010
+++ rtems/cpukit/libblock/src/bdpart-create.c	Fri Apr 30 03:42:12 2010
@@ -0,0 +1,160 @@
+/**
+ * @file
+ *
+ * @ingroup rtems_bdpart
+ *
+ * Block device partition management.
+ */
+
+/*
+ * Copyright (c) 2009, 2010
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * D-82178 Puchheim
+ * Germany
+ * <rtems at embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/bdpart.h>
+
+rtems_status_code rtems_bdpart_create(
+  const char *disk_name,
+  const rtems_bdpart_format *format,
+  rtems_bdpart_partition *pt,
+  const unsigned *dist,
+  size_t count
+)
+{
+  rtems_status_code sc = RTEMS_SUCCESSFUL;
+  bool dos_compatibility = format != NULL
+    && format->type == RTEMS_BDPART_FORMAT_MBR
+    && format->mbr.dos_compatibility;
+  rtems_blkdev_bnum disk_end = 0;
+  rtems_blkdev_bnum pos = 0;
+  rtems_blkdev_bnum dist_sum = 0;
+  rtems_blkdev_bnum record_space =
+    dos_compatibility ? RTEMS_BDPART_MBR_CYLINDER_SIZE : 1;
+  rtems_blkdev_bnum overhead = 0;
+  rtems_blkdev_bnum free_space = 0;
+  dev_t disk = 0;
+  size_t i = 0;
+
+  /* Check if we have something to do */
+  if (count == 0) {
+    /* Nothing to do */
+    return RTEMS_SUCCESSFUL;
+  }
+
+  /* Check parameter */
+  if (format == NULL || pt == NULL || dist == NULL) {
+    return RTEMS_INVALID_ADDRESS;
+  }
+
+  /* Get disk data */
+  sc = rtems_bdpart_get_disk_data( disk_name, &disk, &disk_end);
+  if (sc != RTEMS_SUCCESSFUL) {
+    return sc;
+  }
+
+  /* Get distribution sum and check for overflow */
+  for (i = 0; i < count; ++i) {
+    unsigned prev_sum = dist_sum;
+
+    dist_sum += dist [i];
+
+    if (dist_sum < prev_sum) {
+      return RTEMS_INVALID_NUMBER;
+    }
+
+    if (dist [i] == 0) {
+      return RTEMS_INVALID_NUMBER;
+    }
+  }
+
+  /* Check format */
+  if (format->type != RTEMS_BDPART_FORMAT_MBR) {
+    return RTEMS_NOT_IMPLEMENTED;
+  }
+
+  /* Align end of disk on cylinder boundary if necessary */
+  if (dos_compatibility) {
+    disk_end -= (disk_end % record_space);
+  }
+
+  /*
+   * We need at least space for the MBR and the compatibility space for the
+   * first primary partition.
+   */
+  overhead += record_space;
+
+  /*
+   * In case we need an extended partition and logical partitions we have to
+   * account for the space of each EBR.
+   */
+  if (count > 4) {
+    overhead += (count - 3) * record_space;
+  }
+
+  /*
+   * Account space to align every partition on cylinder boundaries if
+   * necessary.
+   */
+  if (dos_compatibility) {
+    overhead += (count - 1) * record_space;
+  }
+
+  /* Check disk space */
+  if ((overhead + count) > disk_end) {
+    return RTEMS_IO_ERROR;
+  }
+
+  /* Begin of first primary partition */
+  pos = record_space;
+
+  /* Space for partitions */
+  free_space = disk_end - overhead;
+
+  for (i = 0; i < count; ++i) {
+    rtems_bdpart_partition *p = pt + i;
+
+    /* Partition size */
+    rtems_blkdev_bnum s = free_space * dist [i];
+    if (s < free_space || s < dist [i]) {
+      /* TODO: Calculate without overflow */
+      return RTEMS_INVALID_NUMBER;
+    }
+    s /= dist_sum;
+
+    /* Ensure that the partition is not empty */
+    if (s == 0) {
+      s = 1;
+    }
+
+    /* Align partition upwards */
+    s += record_space - (s % record_space);
+
+    /* Partition begin and end */
+    p->begin = pos;
+    pos += s;
+    p->end = pos;
+
+    /* Reserve space for the EBR if necessary */
+    if (count > 4 && i > 2) {
+      p->begin += record_space;
+    }
+  }
+
+  /* Expand the last partition to the disk end */
+  pt [count - 1].end = disk_end;
+
+  return RTEMS_SUCCESSFUL;
+}

diff -u /dev/null rtems/cpukit/libblock/src/bdpart-dump.c:1.1
--- /dev/null	Fri Apr 30 04:12:03 2010
+++ rtems/cpukit/libblock/src/bdpart-dump.c	Fri Apr 30 03:42:12 2010
@@ -0,0 +1,97 @@
+/**
+ * @file
+ *
+ * @ingroup rtems_bdpart
+ *
+ * Block device partition management.
+ */
+
+/*
+ * Copyright (c) 2009, 2010
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * D-82178 Puchheim
+ * Germany
+ * <rtems at embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <inttypes.h>
+
+#include <rtems.h>
+#include <rtems/bdpart.h>
+
+static void rtems_bdpart_type_to_string(
+  const uuid_t type,
+  char str [37]
+)
+{
+  uuid_unparse_lower( type, str);
+}
+
+void rtems_bdpart_dump( const rtems_bdpart_partition *pt, size_t count)
+{
+  size_t i = 0;
+
+  printf(
+    "-------------------------------------------------------------------------------\n"
+    "                                PARTITION TABLE\n"
+    "------------+------------+-----------------------------------------------------\n"
+    " BEGIN      | END        | TYPE\n"
+    "------------+------------+-----------------------------------------------------\n"
+  );
+
+  for (i = 0; i < count; ++i) {
+    const rtems_bdpart_partition *p = pt + i;
+    const char *type = NULL;
+    char type_buffer [52];
+    uint8_t type_mbr = 0;
+
+    if (rtems_bdpart_to_mbr_partition_type( p->type, &type_mbr)) {
+      switch (type_mbr) {
+        case RTEMS_BDPART_MBR_FAT_12:
+          type = "FAT 12";
+          break;
+        case RTEMS_BDPART_MBR_FAT_16:
+          type = "FAT 16";
+          break;
+        case RTEMS_BDPART_MBR_FAT_16_LBA:
+          type = "FAT 16 LBA";
+          break;
+        case RTEMS_BDPART_MBR_FAT_32:
+          type = "FAT 32";
+          break;
+        case RTEMS_BDPART_MBR_FAT_32_LBA:
+          type = "FAT 32 LBA";
+          break;
+        case RTEMS_BDPART_MBR_DATA:
+          type = "DATA";
+          break;
+        default:
+          snprintf( type_buffer, sizeof( type_buffer), "0x%02" PRIx8, type_mbr);
+          type = type_buffer;
+          break;
+      }
+    } else {
+      rtems_bdpart_type_to_string( p->type, type_buffer);
+      type = type_buffer;
+    }
+
+    printf(
+      " %10" PRIu32 " | %10" PRIu32 " |%52s\n",
+      p->begin,
+      p->end,
+      type
+    );
+  }
+
+  puts( "------------+------------+-----------------------------------------------------");
+}

diff -u /dev/null rtems/cpukit/libblock/src/bdpart-mount.c:1.1
--- /dev/null	Fri Apr 30 04:12:03 2010
+++ rtems/cpukit/libblock/src/bdpart-mount.c	Fri Apr 30 03:42:12 2010
@@ -0,0 +1,185 @@
+/**
+ * @file
+ *
+ * @ingroup rtems_bdpart
+ *
+ * Block device partition management.
+ */
+
+/*
+ * Copyright (c) 2009, 2010
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * D-82178 Puchheim
+ * Germany
+ * <rtems at embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <rtems.h>
+#include <rtems/bdpart.h>
+#include <rtems/dosfs.h>
+#include <rtems/fsmount.h>
+
+rtems_status_code rtems_bdpart_mount(
+  const char *disk_name,
+  const rtems_bdpart_partition *pt __attribute__((unused)),
+  size_t count,
+  const char *mount_base
+)
+{
+  rtems_status_code esc = RTEMS_SUCCESSFUL;
+  const char *disk_file_name = strrchr( disk_name, '/');
+  char *logical_disk_name = NULL;
+  char *logical_disk_marker = NULL;
+  char *mount_point = NULL;
+  char *mount_marker = NULL;
+  size_t disk_file_name_size = 0;
+  size_t disk_name_size = strlen( disk_name);
+  size_t mount_base_size = strlen( mount_base);
+  size_t i = 0;
+
+  /* Create logical disk name base */
+  logical_disk_name = malloc( disk_name_size + RTEMS_BDPART_NUMBER_SIZE);
+  if (logical_disk_name == NULL) {
+    return RTEMS_NO_MEMORY;
+  }
+  strncpy( logical_disk_name, disk_name, disk_name_size);
+
+  /* Get disk file name */
+  if (disk_file_name != NULL) {
+    disk_file_name += 1;
+    disk_file_name_size = strlen( disk_file_name);
+  } else {
+    disk_file_name = disk_name;
+    disk_file_name_size = disk_name_size;
+  }
+
+  /* Create mount point base */
+  mount_point = malloc( mount_base_size + 1 + disk_file_name_size + RTEMS_BDPART_NUMBER_SIZE);
+  if (mount_point == NULL) {
+    esc = RTEMS_NO_MEMORY;
+    goto cleanup;
+  }
+  strncpy( mount_point, mount_base, mount_base_size);
+  mount_point [mount_base_size] = '/';
+  strncpy( mount_point + mount_base_size + 1, disk_file_name, disk_file_name_size);
+
+  /* Markers */
+  logical_disk_marker = logical_disk_name + disk_name_size;
+  mount_marker = mount_point + mount_base_size + 1 + disk_file_name_size;
+
+  /* Mount supported file systems for each partition */
+  for (i = 0; i < count; ++i) {
+    /* Create logical disk name */
+    int rv = snprintf( logical_disk_marker, RTEMS_BDPART_NUMBER_SIZE, "%zu", i + 1);
+    if (rv >= RTEMS_BDPART_NUMBER_SIZE) {
+      esc = RTEMS_INVALID_NAME;
+      goto cleanup;
+    }
+
+    /* Create mount point */
+    strncpy( mount_marker, logical_disk_marker, RTEMS_BDPART_NUMBER_SIZE);
+    rv = rtems_fsmount_create_mount_point( mount_point);
+    if (rv != 0) {
+      esc = RTEMS_IO_ERROR;
+      goto cleanup;
+    }
+
+    /* Mount */
+    rv = mount(
+      NULL,
+      &msdos_ops,
+      0,
+      logical_disk_name,
+      mount_point
+    );
+    if (rv != 0) {
+      rmdir( mount_point);
+    }
+  }
+
+cleanup:
+
+  free( logical_disk_name);
+  free( mount_point);
+
+  return esc;
+}
+
+rtems_status_code rtems_bdpart_unmount(
+  const char *disk_name,
+  const rtems_bdpart_partition *pt __attribute__((unused)),
+  size_t count,
+  const char *mount_base
+)
+{
+  rtems_status_code esc = RTEMS_SUCCESSFUL;
+  const char *disk_file_name = strrchr( disk_name, '/');
+  char *mount_point = NULL;
+  char *mount_marker = NULL;
+  size_t disk_file_name_size = 0;
+  size_t disk_name_size = strlen( disk_name);
+  size_t mount_base_size = strlen( mount_base);
+  size_t i = 0;
+
+  /* Get disk file name */
+  if (disk_file_name != NULL) {
+    disk_file_name += 1;
+    disk_file_name_size = strlen( disk_file_name);
+  } else {
+    disk_file_name = disk_name;
+    disk_file_name_size = disk_name_size;
+  }
+
+  /* Create mount point base */
+  mount_point = malloc( mount_base_size + 1 + disk_file_name_size + RTEMS_BDPART_NUMBER_SIZE);
+  if (mount_point == NULL) {
+    esc = RTEMS_NO_MEMORY;
+    goto cleanup;
+  }
+  strncpy( mount_point, mount_base, mount_base_size);
+  mount_point [mount_base_size] = '/';
+  strncpy( mount_point + mount_base_size + 1, disk_file_name, disk_file_name_size);
+
+  /* Marker */
+  mount_marker = mount_point + mount_base_size + 1 + disk_file_name_size;
+
+  /* Mount supported file systems for each partition */
+  for (i = 0; i < count; ++i) {
+    /* Create mount point */
+    int rv = snprintf( mount_marker, RTEMS_BDPART_NUMBER_SIZE, "%zu", i + 1);
+    if (rv >= RTEMS_BDPART_NUMBER_SIZE) {
+      esc = RTEMS_INVALID_NAME;
+      goto cleanup;
+    }
+
+    /* Unmount */
+    rv = unmount( mount_point);
+    if (rv == 0) {
+      /* Remove mount point */
+      rv = rmdir( mount_point);
+      if (rv != 0) {
+        esc = RTEMS_IO_ERROR;
+        goto cleanup;
+      }
+    }
+  }
+
+cleanup:
+
+  free( mount_point);
+
+  return esc;
+}

diff -u /dev/null rtems/cpukit/libblock/src/bdpart-read.c:1.1
--- /dev/null	Fri Apr 30 04:12:03 2010
+++ rtems/cpukit/libblock/src/bdpart-read.c	Fri Apr 30 03:42:13 2010
@@ -0,0 +1,348 @@
+/**
+ * @file
+ *
+ * @ingroup rtems_bdpart
+ *
+ * Block device partition management.
+ */
+
+/*
+ * Copyright (c) 2009, 2010
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * D-82178 Puchheim
+ * Germany
+ * <rtems at embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/bdbuf.h>
+#include <rtems/bdpart.h>
+#include <rtems/endian.h>
+
+#define RTEMS_BDPART_MBR_PARTITION_TYPE( type) \
+  { \
+    (type), 0xa2U, 0x2eU, 0x38U, \
+    0x38U, 0xb5U, 0xdeU, 0x11U, \
+    0xbcU, 0x13U, 0x00U, 0x1dU, \
+    0x09U, 0xb0U, 0x5fU, 0xa4U \
+  }
+
+static const uuid_t RTEMS_BDPART_MBR_MASTER_TYPE =
+  RTEMS_BDPART_MBR_PARTITION_TYPE( RTEMS_BDPART_MBR_EMPTY);
+
+void rtems_bdpart_to_partition_type( uint8_t mbr_type, uuid_t type)
+{
+  type [0] = mbr_type;
+  memcpy( type + 1, RTEMS_BDPART_MBR_MASTER_TYPE + 1, sizeof( uuid_t) - 1);
+}
+
+bool rtems_bdpart_to_mbr_partition_type(
+  const uuid_t type,
+  uint8_t *mbr_type
+)
+{
+  *mbr_type = rtems_bdpart_mbr_partition_type( type);
+
+  return memcmp(
+    type + 1,
+    RTEMS_BDPART_MBR_MASTER_TYPE + 1,
+    sizeof( uuid_t) - 1
+  ) == 0;
+}
+
+/*
+ * FIXME: This code should the deviceio interface and not the bdbug interface.
+ */
+rtems_status_code rtems_bdpart_get_disk_data(
+  const char *disk_name,
+  dev_t *disk,
+  rtems_blkdev_bnum *disk_end
+)
+{
+  rtems_status_code sc = RTEMS_SUCCESSFUL;
+  int rv = 0;
+  rtems_blkdev_bnum disk_begin = 0;
+  rtems_blkdev_bnum block_size = 0;
+  rtems_disk_device *dd = NULL;
+  struct stat st;
+
+  /* Get disk handle */
+  rv = stat( disk_name, &st);
+  if (rv != 0) {
+    return RTEMS_INVALID_NAME;
+  }
+  *disk = st.st_rdev;
+
+  /* Get disk begin, end and block size */
+  dd = rtems_disk_obtain( *disk);
+  if (dd == NULL) {
+    return RTEMS_INVALID_NAME;
+  }
+  disk_begin = dd->start;
+  *disk_end = dd->size;
+  block_size = dd->block_size;
+  sc = rtems_disk_release( dd);
+  if (sc != RTEMS_SUCCESSFUL) {
+    return sc;
+  }
+
+  /* Check block size */
+  if (block_size < RTEMS_BDPART_BLOCK_SIZE) {
+    return RTEMS_IO_ERROR;
+  }
+
+  /* Check that we have do not have a logical disk */
+  if (disk_begin != 0) {
+    return RTEMS_IO_ERROR;
+  }
+
+  return RTEMS_SUCCESSFUL;
+}
+
+static bool rtems_bdpart_is_valid_record( const uint8_t *data)
+{
+  return data [RTEMS_BDPART_MBR_OFFSET_SIGNATURE_0]
+      == RTEMS_BDPART_MBR_SIGNATURE_0
+    && data [RTEMS_BDPART_MBR_OFFSET_SIGNATURE_1]
+      == RTEMS_BDPART_MBR_SIGNATURE_1;
+}
+
+static rtems_blkdev_bnum rtems_bdpart_next_ebr( const uint8_t *data)
+{
+  rtems_blkdev_bnum begin =
+    rtems_uint32_from_little_endian( data + RTEMS_BDPART_MBR_OFFSET_BEGIN);
+  uint8_t type = data [RTEMS_BDPART_MBR_OFFSET_TYPE];
+
+  if (type == RTEMS_BDPART_MBR_EXTENDED) {
+    return begin;
+  } else {
+    return 0;
+  }
+}
+
+static rtems_status_code rtems_bdpart_read_mbr_partition(
+  const uint8_t *data,
+  rtems_bdpart_partition **p,
+  const rtems_bdpart_partition *p_end,
+  rtems_blkdev_bnum *ep_begin
+)
+{
+  rtems_blkdev_bnum begin =
+    rtems_uint32_from_little_endian( data + RTEMS_BDPART_MBR_OFFSET_BEGIN);
+  rtems_blkdev_bnum size =
+    rtems_uint32_from_little_endian( data + RTEMS_BDPART_MBR_OFFSET_SIZE);
+  rtems_blkdev_bnum end = begin + size;
+  uint8_t type = data [RTEMS_BDPART_MBR_OFFSET_TYPE];
+
+  if (type == RTEMS_BDPART_MBR_EMPTY) {
+    return RTEMS_SUCCESSFUL;
+  } else if (*p == p_end) {
+    return RTEMS_TOO_MANY;
+  } else if (begin >= end) {
+    return RTEMS_IO_ERROR;
+  } else if (type == RTEMS_BDPART_MBR_EXTENDED) {
+    if (ep_begin != NULL) {
+      *ep_begin = begin;
+    }
+  } else {
+    /* Increment partition index */
+    ++(*p);
+
+    /* Clear partition */
+    memset( *p, 0, sizeof( rtems_bdpart_partition));
+
+    /* Set values */
+    (*p)->begin = begin;
+    (*p)->end = end;
+    rtems_bdpart_to_partition_type( type, (*p)->type);
+    (*p)->flags = data [RTEMS_BDPART_MBR_OFFSET_FLAGS];
+  }
+
+  return RTEMS_SUCCESSFUL;
+}
+
+static rtems_status_code rtems_bdpart_read_record(
+  dev_t disk,
+  rtems_blkdev_bnum index,
+  rtems_bdbuf_buffer **block
+)
+{
+  rtems_status_code sc = RTEMS_SUCCESSFUL;
+
+  /* Release previous block if necessary */
+  if (*block != NULL) {
+    sc = rtems_bdbuf_release( *block);
+    if (sc != RTEMS_SUCCESSFUL) {
+      return sc;
+    }
+  }
+
+  /* Read the record block */
+  sc = rtems_bdbuf_read( disk, index, block);
+  if (sc != RTEMS_SUCCESSFUL) {
+    return sc;
+  }
+
+  /* just in case block did not get filled in */
+  if ( *block == NULL ) {
+    return RTEMS_INVALID_ADDRESS;
+  }
+
+  /* Check MBR signature */
+  if (!rtems_bdpart_is_valid_record( (*block)->buffer)) {
+    return RTEMS_IO_ERROR;
+  }
+
+  return RTEMS_SUCCESSFUL;
+}
+
+rtems_status_code rtems_bdpart_read(
+  const char *disk_name,
+  rtems_bdpart_format *format,
+  rtems_bdpart_partition *pt,
+  size_t *count
+)
+{
+  rtems_status_code sc = RTEMS_SUCCESSFUL;
+  rtems_status_code esc = RTEMS_SUCCESSFUL;
+  rtems_bdbuf_buffer *block = NULL;
+  rtems_bdpart_partition *p = pt - 1;
+  const rtems_bdpart_partition *p_end = pt + (count != NULL ? *count : 0);
+  rtems_blkdev_bnum ep_begin = 0; /* Extended partition begin */
+  rtems_blkdev_bnum ebr = 0; /* Extended boot record block index */
+  rtems_blkdev_bnum disk_end = 0;
+  dev_t disk = 0;
+  size_t i = 0;
+  const uint8_t *data = NULL;
+
+  /* Check parameter */
+  if (format == NULL || pt == NULL || count == NULL) {
+    return RTEMS_INVALID_ADDRESS;
+  }
+
+  /* Set count to a save value */
+  *count = 0;
+
+  /* Get disk data */
+  sc = rtems_bdpart_get_disk_data( disk_name, &disk, &disk_end);
+  if (sc != RTEMS_SUCCESSFUL) {
+    return sc;
+  }
+
+  /* Read MBR */
+  sc = rtems_bdpart_read_record( disk, 0, &block);
+  if (sc != RTEMS_SUCCESSFUL) {
+    esc = sc;
+    goto cleanup;
+  }
+
+  /* Read the first partition entry */
+  data = block->buffer + RTEMS_BDPART_MBR_OFFSET_TABLE_0;
+  sc = rtems_bdpart_read_mbr_partition( data, &p, p_end, &ep_begin);
+  if (sc != RTEMS_SUCCESSFUL) {
+    esc = sc;
+    goto cleanup;
+  }
+
+  /* Determine if we have a MBR or GPT format */
+  if (rtems_bdpart_mbr_partition_type( p->type) == RTEMS_BDPART_MBR_GPT) {
+    esc = RTEMS_NOT_IMPLEMENTED;
+    goto cleanup;
+  }
+
+  /* Set format */
+  format->type = RTEMS_BDPART_FORMAT_MBR;
+  format->mbr.disk_id = rtems_uint32_from_little_endian(
+    block->buffer + RTEMS_BDPART_MBR_OFFSET_DISK_ID
+  );
+  format->mbr.dos_compatibility = true;
+
+  /* Iterate through the rest of the primary partition table */
+  for (i = 1; i < 4; ++i) {
+    data += RTEMS_BDPART_MBR_TABLE_ENTRY_SIZE;
+
+    sc = rtems_bdpart_read_mbr_partition( data, &p, p_end, &ep_begin);
+    if (sc != RTEMS_SUCCESSFUL) {
+      esc = sc;
+      goto cleanup;
+    }
+  }
+
+  /* Iterate through the logical partitions within the extended partition */
+  ebr = ep_begin;
+  while (ebr != 0) {
+    rtems_blkdev_bnum tmp = 0;
+
+    /* Read EBR */
+    sc = rtems_bdpart_read_record( disk, ebr, &block);
+    if (sc != RTEMS_SUCCESSFUL) {
+      esc = sc;
+      goto cleanup;
+    }
+
+    /* Read first partition entry */
+    sc = rtems_bdpart_read_mbr_partition(
+      block->buffer + RTEMS_BDPART_MBR_OFFSET_TABLE_0,
+      &p,
+      p_end,
+      NULL
+    );
+    if (sc != RTEMS_SUCCESSFUL) {
+      esc = sc;
+      goto cleanup;
+    }
+
+    /* Adjust partition begin */
+    tmp = p->begin + ebr;
+    if (tmp > p->begin) {
+      p->begin = tmp;
+    } else {
+      esc = RTEMS_IO_ERROR;
+      goto cleanup;
+    }
+
+    /* Adjust partition end */
+    tmp = p->end + ebr;
+    if (tmp > p->end) {
+      p->end = tmp;
+    } else {
+      esc = RTEMS_IO_ERROR;
+      goto cleanup;
+    }
+
+    /* Read second partition entry for next EBR block */
+    ebr = rtems_bdpart_next_ebr(
+      block->buffer + RTEMS_BDPART_MBR_OFFSET_TABLE_1
+    );
+    if (ebr != 0) {
+      /* Adjust partition EBR block index */
+      tmp = ebr + ep_begin;
+      if (tmp > ebr) {
+        ebr = tmp;
+      } else {
+        esc = RTEMS_IO_ERROR;
+        goto cleanup;
+      }
+    }
+  }
+
+  /* Return partition count */
+  *count = (size_t) (p - pt + 1);
+
+cleanup:
+
+  if (block != NULL) {
+    rtems_bdbuf_release( block);
+  }
+
+  return esc;
+}

diff -u /dev/null rtems/cpukit/libblock/src/bdpart-register.c:1.1
--- /dev/null	Fri Apr 30 04:12:03 2010
+++ rtems/cpukit/libblock/src/bdpart-register.c	Fri Apr 30 03:42:13 2010
@@ -0,0 +1,163 @@
+/**
+ * @file
+ *
+ * @ingroup rtems_bdpart
+ *
+ * Block device partition management.
+ */
+
+/*
+ * Copyright (c) 2009, 2010
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * D-82178 Puchheim
+ * Germany
+ * <rtems at embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <rtems.h>
+#include <rtems/bdpart.h>
+
+rtems_status_code rtems_bdpart_register(
+  const char *disk_name,
+  const rtems_bdpart_partition *pt,
+  size_t count
+)
+{
+  rtems_status_code sc = RTEMS_SUCCESSFUL;
+  rtems_status_code esc = RTEMS_SUCCESSFUL;
+  rtems_device_major_number major = 0;
+  rtems_device_minor_number minor = 0;
+  rtems_blkdev_bnum disk_end = 0;
+  dev_t disk = 0;
+  dev_t logical_disk = 0;
+  char *logical_disk_name = NULL;
+  char *logical_disk_marker = NULL;
+  size_t disk_name_size = strlen( disk_name);
+  size_t i = 0;
+
+  /* Get disk data */
+  sc = rtems_bdpart_get_disk_data( disk_name, &disk, &disk_end);
+  if (sc != RTEMS_SUCCESSFUL) {
+    return sc;
+  }
+
+  /* Get the disk device identifier */
+  rtems_filesystem_split_dev_t( disk, major, minor);
+
+  /* Create logical disk name */
+  logical_disk_name = malloc( disk_name_size + RTEMS_BDPART_NUMBER_SIZE);
+  if (logical_disk_name == NULL) {
+    return RTEMS_NO_MEMORY;
+  }
+  strncpy( logical_disk_name, disk_name, disk_name_size);
+  logical_disk_marker = logical_disk_name + disk_name_size;
+
+  /* Create a logical disk for each partition */
+  for (i = 0; i < count; ++i) {
+    const rtems_bdpart_partition *p = pt + i;
+    int rv = 0;
+
+    /* New minor number */
+    ++minor;
+
+    /* Create a new device identifier */
+    logical_disk = rtems_filesystem_make_dev_t( major, minor);
+
+    /* Set partition number for logical disk name */
+    rv = snprintf( logical_disk_marker, RTEMS_BDPART_NUMBER_SIZE, "%zu", i + 1);
+    if (rv >= RTEMS_BDPART_NUMBER_SIZE) {
+      esc = RTEMS_INVALID_NAME;
+      goto cleanup;
+    }
+
+    /* Create logical disk */
+    sc = rtems_disk_create_log(
+      logical_disk,
+      disk,
+      p->begin,
+      p->end - p->begin,
+      logical_disk_name
+    );
+    if (sc != RTEMS_SUCCESSFUL) {
+      esc = sc;
+      goto cleanup;
+    }
+  }
+
+cleanup:
+
+  free( logical_disk_name);
+
+  return esc;
+}
+
+rtems_status_code rtems_bdpart_register_from_disk( const char *disk_name)
+{
+  rtems_status_code sc = RTEMS_SUCCESSFUL;
+  rtems_bdpart_format format;
+  rtems_bdpart_partition pt [RTEMS_BDPART_PARTITION_NUMBER_HINT];
+  size_t count = RTEMS_BDPART_PARTITION_NUMBER_HINT;
+
+  /* Read partitions */
+  sc = rtems_bdpart_read( disk_name, &format, pt, &count);
+  if (sc != RTEMS_SUCCESSFUL) {
+    return sc;
+  }
+
+  /* Register partitions */
+  return rtems_bdpart_register( disk_name, pt, count);
+}
+
+rtems_status_code rtems_bdpart_unregister(
+  const char *disk_name,
+  const rtems_bdpart_partition *pt __attribute__((unused)),
+  size_t count
+)
+{
+  rtems_status_code sc = RTEMS_SUCCESSFUL;
+  rtems_device_major_number major = 0;
+  rtems_device_minor_number minor = 0;
+  rtems_blkdev_bnum disk_end = 0;
+  dev_t disk = 0;
+  dev_t logical_disk = 0;
+  size_t i = 0;
+
+  /* Get disk data */
+  sc = rtems_bdpart_get_disk_data( disk_name, &disk, &disk_end);
+  if (sc != RTEMS_SUCCESSFUL) {
+    return sc;
+  }
+
+  /* Get the disk device identifier */
+  rtems_filesystem_split_dev_t( disk, major, minor);
+
+  /* Create a logical disk for each partition */
+  for (i = 0; i < count; ++i) {
+    /* New minor number */
+    ++minor;
+
+    /* Get the device identifier */
+    logical_disk = rtems_filesystem_make_dev_t( major, minor);
+
+    /* Delete logical disk */
+    sc = rtems_disk_delete( logical_disk);
+    if (sc != RTEMS_SUCCESSFUL) {
+      return sc;
+    }
+  }
+
+  return RTEMS_SUCCESSFUL;
+}

diff -u /dev/null rtems/cpukit/libblock/src/bdpart-sort.c:1.1
--- /dev/null	Fri Apr 30 04:12:03 2010
+++ rtems/cpukit/libblock/src/bdpart-sort.c	Fri Apr 30 03:42:13 2010
@@ -0,0 +1,48 @@
+/**
+ * @file
+ *
+ * @ingroup rtems_bdpart
+ *
+ * Block device partition management.
+ */
+
+/*
+ * Copyright (c) 2009, 2010
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * D-82178 Puchheim
+ * Germany
+ * <rtems at embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+
+#include <rtems.h>
+#include <rtems/bdpart.h>
+
+static int rtems_bdpart_partition_compare( const void *aa, const void *bb)
+{
+  const rtems_bdpart_partition *a = aa;
+  const rtems_bdpart_partition *b = bb;
+
+  if (a->begin < b->begin) {
+    return -1;
+  } else if (a->begin == b->begin) {
+    return 0;
+  } else {
+    return 1;
+  }
+}
+
+void rtems_bdpart_sort( rtems_bdpart_partition *pt, size_t count)
+{
+  qsort( pt, count, sizeof( *pt), rtems_bdpart_partition_compare);
+}

diff -u /dev/null rtems/cpukit/libblock/src/bdpart-write.c:1.1
--- /dev/null	Fri Apr 30 04:12:03 2010
+++ rtems/cpukit/libblock/src/bdpart-write.c	Fri Apr 30 03:42:13 2010
@@ -0,0 +1,302 @@
+/**
+ * @file
+ *
+ * @ingroup rtems_bdpart
+ *
+ * Block device partition management.
+ */
+
+/*
+ * Copyright (c) 2009, 2010
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * D-82178 Puchheim
+ * Germany
+ * <rtems at embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+
+#include <rtems.h>
+#include <rtems/bdbuf.h>
+#include <rtems/bdpart.h>
+#include <rtems/endian.h>
+
+static void rtems_bdpart_write_mbr_partition(
+  uint8_t *data,
+  uint32_t begin,
+  uint32_t size,
+  uint8_t type,
+  uint8_t flags
+)
+{
+  rtems_uint32_to_little_endian( begin, data + RTEMS_BDPART_MBR_OFFSET_BEGIN);
+  rtems_uint32_to_little_endian( size, data + RTEMS_BDPART_MBR_OFFSET_SIZE);
+  data [RTEMS_BDPART_MBR_OFFSET_TYPE] = type;
+  data [RTEMS_BDPART_MBR_OFFSET_FLAGS] = flags;
+}
+
+static rtems_status_code rtems_bdpart_new_record(
+  dev_t disk,
+  rtems_blkdev_bnum index,
+  rtems_bdbuf_buffer **block
+)
+{
+  rtems_status_code sc = RTEMS_SUCCESSFUL;
+
+  /* Synchronize previous block if necessary */
+  if (*block != NULL) {
+    sc = rtems_bdbuf_sync( *block);
+    if (sc != RTEMS_SUCCESSFUL) {
+      return sc;
+    }
+  }
+
+  /* Read the new record block (this accounts for disk block sizes > 512) */
+  sc = rtems_bdbuf_read( disk, index, block);
+  if (sc != RTEMS_SUCCESSFUL) {
+    return sc;
+  }
+
+  /* just in case block did not get filled in */
+  if ( *block == NULL ) {
+    return RTEMS_INVALID_ADDRESS;
+  }
+
+  /* Clear record */
+  memset( (*block)->buffer, 0, RTEMS_BDPART_BLOCK_SIZE);
+
+  /* Write signature */
+  (*block)->buffer [RTEMS_BDPART_MBR_OFFSET_SIGNATURE_0] =
+    RTEMS_BDPART_MBR_SIGNATURE_0;
+  (*block)->buffer [RTEMS_BDPART_MBR_OFFSET_SIGNATURE_1] =
+    RTEMS_BDPART_MBR_SIGNATURE_1;
+
+  return RTEMS_SUCCESSFUL;
+}
+
+rtems_status_code rtems_bdpart_write(
+  const char *disk_name,
+  const rtems_bdpart_format *format,
+  const rtems_bdpart_partition *pt,
+  size_t count
+)
+{
+  rtems_status_code sc = RTEMS_SUCCESSFUL;
+  rtems_status_code esc = RTEMS_SUCCESSFUL;
+  bool dos_compatibility = format != NULL
+    && format->type == RTEMS_BDPART_FORMAT_MBR
+    && format->mbr.dos_compatibility;
+  rtems_bdbuf_buffer *block = NULL;
+  rtems_blkdev_bnum disk_end = 0;
+  rtems_blkdev_bnum record_space =
+    dos_compatibility ? RTEMS_BDPART_MBR_CYLINDER_SIZE : 1;
+  dev_t disk = 0;
+  size_t ppc = 0; /* Primary partition count */
+  size_t i = 0;
+  uint8_t *data = NULL;
+
+  /* Check if we have something to do */
+  if (count == 0) {
+    /* Nothing to do */
+    return RTEMS_SUCCESSFUL;
+  }
+
+  /* Check parameter */
+  if (format == NULL || pt == NULL) {
+    return RTEMS_INVALID_ADDRESS;
+  }
+
+  /* Get disk data */
+  sc = rtems_bdpart_get_disk_data( disk_name, &disk, &disk_end);
+  if (sc != RTEMS_SUCCESSFUL) {
+    return sc;
+  }
+
+  /* Align end of disk on cylinder boundary if necessary */
+  if (dos_compatibility) {
+    disk_end -= (disk_end % record_space);
+  }
+
+  /* Check that we have a consistent partition table */
+  for (i = 0; i < count; ++i) {
+    const rtems_bdpart_partition *p = pt + i;
+
+    /* Check that begin and end are proper within the disk */
+    if (p->begin >= disk_end || p->end > disk_end) {
+      esc = RTEMS_INVALID_NUMBER;
+      goto cleanup;
+    }
+
+    /* Check that begin and end are valid */
+    if (p->begin >= p->end) {
+      esc = RTEMS_INVALID_NUMBER;
+      goto cleanup;
+    }
+
+    /* Check that partitions do not overlap */
+    if (i > 0 && pt [i - 1].end > p->begin) {
+      esc = RTEMS_INVALID_NUMBER;
+      goto cleanup;
+    }
+  }
+
+  /* Check format */
+  if (format->type != RTEMS_BDPART_FORMAT_MBR) {
+    esc = RTEMS_NOT_IMPLEMENTED;
+    goto cleanup;
+  }
+
+  /*
+   * Set primary partition count.  If we have more than four partitions we need
+   * an extended partition which will contain the partitions of number four and
+   * above as logical partitions.  If we have four or less partitions we can
+   * use the primary partition table.
+   */
+  ppc = count <= 4 ? count : 3;
+
+  /*
+   * Check that the first primary partition starts at head one and sector one
+   * under the virtual one head and 63 sectors geometry if necessary.
+   */
+  if (dos_compatibility && pt [0].begin != RTEMS_BDPART_MBR_CYLINDER_SIZE) {
+    esc = RTEMS_INVALID_NUMBER;
+    goto cleanup;
+  }
+
+  /*
+   * Check that we have enough space for the EBRs.  The partitions with number
+   * four and above are logical partitions if we have more than four partitions
+   * in total.  The logical partitions are contained in the extended partition.
+   * Each logical partition is described via one EBR preceding the partition.
+   * The space for the EBR and maybe some space which is needed for DOS
+   * compatibility resides between the partitions.  So there have to be gaps of
+   * the appropriate size between the partitions.
+   */
+  for (i = ppc; i < count; ++i) {
+    if ((pt [i].begin - pt [i - 1].end) < record_space) {
+      esc = RTEMS_INVALID_NUMBER;
+      goto cleanup;
+    }
+  }
+
+  /* Check that we can convert the parition descriptions to the MBR format */
+  for (i = 0; i < count; ++i) {
+    uint8_t type = 0;
+
+    const rtems_bdpart_partition *p = pt + i;
+
+    /* Check type */
+    if (!rtems_bdpart_to_mbr_partition_type( p->type, &type)) {
+      esc =  RTEMS_INVALID_ID;
+      goto cleanup;
+    }
+
+    /* Check flags */
+    if (p->flags > 0xffU) {
+      esc = RTEMS_INVALID_ID;
+      goto cleanup;
+    }
+
+    /* Check ID */
+    /* TODO */
+  }
+
+  /* New MBR */
+  sc = rtems_bdpart_new_record( disk, 0, &block);
+  if (sc != RTEMS_SUCCESSFUL) {
+    esc = sc;
+    goto cleanup;
+  }
+
+  /* Write disk ID */
+  rtems_uint32_to_little_endian(
+    format->mbr.disk_id,
+    block->buffer + RTEMS_BDPART_MBR_OFFSET_DISK_ID
+  );
+
+  /* Write primary partition table */
+  data = block->buffer + RTEMS_BDPART_MBR_OFFSET_TABLE_0;
+  for (i = 0; i < ppc; ++i) {
+    const rtems_bdpart_partition *p = pt + i;
+
+    /* Write partition entry */
+    rtems_bdpart_write_mbr_partition(
+      data,
+      p->begin,
+      p->end - p->begin,
+      rtems_bdpart_mbr_partition_type( p->type),
+      (uint8_t) p->flags
+    );
+
+    data += RTEMS_BDPART_MBR_TABLE_ENTRY_SIZE;
+  }
+
+  /* Write extended partition with logical partitions if necessary */
+  if (ppc != count) {
+    rtems_blkdev_bnum ebr = 0; /* Extended boot record block index */
+
+    /* Begin of extended partition */
+    rtems_blkdev_bnum ep_begin = pt [ppc].begin - record_space;
+
+    /* Write extended partition */
+    rtems_bdpart_write_mbr_partition(
+      data,
+      ep_begin,
+      disk_end - ep_begin,
+      RTEMS_BDPART_MBR_EXTENDED,
+      0
+    );
+
+    /* Write logical partitions */
+    for (i = ppc; i < count; ++i) {
+      const rtems_bdpart_partition *p = pt + i;
+
+      /* Write second partition entry */
+      if (i > ppc) {
+        rtems_blkdev_bnum begin = p->begin - record_space;
+
+        rtems_bdpart_write_mbr_partition(
+          block->buffer + RTEMS_BDPART_MBR_OFFSET_TABLE_1,
+          begin - ep_begin,
+          disk_end - begin,
+          RTEMS_BDPART_MBR_EXTENDED,
+          0
+        );
+      }
+
+      /* New EBR */
+      ebr = p->begin - record_space;
+      sc = rtems_bdpart_new_record( disk, ebr, &block);
+      if (sc != RTEMS_SUCCESSFUL) {
+        esc = sc;
+        goto cleanup;
+      }
+
+      /* Write first partition entry */
+      rtems_bdpart_write_mbr_partition(
+        block->buffer + RTEMS_BDPART_MBR_OFFSET_TABLE_0,
+        record_space,
+        p->end - p->begin,
+        rtems_bdpart_mbr_partition_type( p->type),
+        (uint8_t) p->flags
+      );
+    }
+  }
+
+cleanup:
+
+  if (block != NULL) {
+    rtems_bdbuf_sync( block);
+  }
+
+  return esc;
+}


 *sh*:
2010-04-30	Sebastian Huber <sebastian.huber at embedded-brains.de>

	* libfs/src/dosfs/msdos_format.c: Added missing va_end().

M 1.2285  cpukit/ChangeLog
M   1.17  cpukit/libfs/src/dosfs/msdos_format.c

diff -u rtems/cpukit/ChangeLog:1.2284 rtems/cpukit/ChangeLog:1.2285
--- rtems/cpukit/ChangeLog:1.2284	Fri Apr 30 03:42:11 2010
+++ rtems/cpukit/ChangeLog	Fri Apr 30 03:43:30 2010
@@ -1,5 +1,9 @@
 2010-04-30	Sebastian Huber <sebastian.huber at embedded-brains.de>
 
+	* libfs/src/dosfs/msdos_format.c: Added missing va_end().
+
+2010-04-30	Sebastian Huber <sebastian.huber at embedded-brains.de>
+
 	* libblock/src/bdpart.c: Removed file.
 	* libblock/src/bdpart-create.c, libblock/src/bdpart-dump.c,
 	libblock/src/bdpart-mount.c, libblock/src/bdpart-read.c,

diff -u rtems/cpukit/libfs/src/dosfs/msdos_format.c:1.16 rtems/cpukit/libfs/src/dosfs/msdos_format.c:1.17
--- rtems/cpukit/libfs/src/dosfs/msdos_format.c:1.16	Fri Mar 12 10:26:14 2010
+++ rtems/cpukit/libfs/src/dosfs/msdos_format.c	Fri Apr 30 03:43:31 2010
@@ -81,6 +81,7 @@
     vfprintf (stdout, format, args);
     fflush (stdout);
   }
+  va_end (args);
 }
 
 /*=========================================================================*\


 *sh*:
2010-04-30	Sebastian Huber <sebastian.huber at embedded-brains.de>

	* libnetworking/lib/ftpfs.c: Format changes.  Fixed pathname
	allocation in rtems_ftpfs_eval_path().  Send QUIT command during
	file close.

M 1.2286  cpukit/ChangeLog
M   1.27  cpukit/libnetworking/lib/ftpfs.c

diff -u rtems/cpukit/ChangeLog:1.2285 rtems/cpukit/ChangeLog:1.2286
--- rtems/cpukit/ChangeLog:1.2285	Fri Apr 30 03:43:30 2010
+++ rtems/cpukit/ChangeLog	Fri Apr 30 03:52:28 2010
@@ -1,5 +1,11 @@
 2010-04-30	Sebastian Huber <sebastian.huber at embedded-brains.de>
 
+	* libnetworking/lib/ftpfs.c: Format changes.  Fixed pathname
+	allocation in rtems_ftpfs_eval_path().  Send QUIT command during
+	file close.
+
+2010-04-30	Sebastian Huber <sebastian.huber at embedded-brains.de>
+
 	* libfs/src/dosfs/msdos_format.c: Added missing va_end().
 
 2010-04-30	Sebastian Huber <sebastian.huber at embedded-brains.de>

diff -u rtems/cpukit/libnetworking/lib/ftpfs.c:1.26 rtems/cpukit/libnetworking/lib/ftpfs.c:1.27
--- rtems/cpukit/libnetworking/lib/ftpfs.c:1.26	Mon Apr 12 07:50:25 2010
+++ rtems/cpukit/libnetworking/lib/ftpfs.c	Fri Apr 30 03:52:29 2010
@@ -5,7 +5,7 @@
  */
 
 /*
- * Copyright (c) 2009
+ * Copyright (c) 2009, 2010
  * embedded brains GmbH
  * Obere Lagerstr. 30
  * D-82178 Puchheim
@@ -59,9 +59,9 @@
 #include <rtems/seterr.h>
 
 #ifdef DEBUG
-  #define DEBUG_PRINTF( ...) printf( __VA_ARGS__)
+  #define DEBUG_PRINTF(...) printf(__VA_ARGS__)
 #else
-  #define DEBUG_PRINTF( ...)
+  #define DEBUG_PRINTF(...)
 #endif
 
 /**
@@ -103,7 +103,7 @@
 
 static const rtems_filesystem_file_handlers_r rtems_ftpfs_root_handlers;
 
-static bool rtems_ftpfs_use_timeout( const struct timeval *to)
+static bool rtems_ftpfs_use_timeout(const struct timeval *to)
 {
   return to->tv_sec != 0 || to->tv_usec != 0;
 }
@@ -113,15 +113,15 @@
   const struct timeval *to
 )
 {
-  if (rtems_ftpfs_use_timeout( to)) {
+  if (rtems_ftpfs_use_timeout(to)) {
     int rv = 0;
     
-    rv = setsockopt( socket, SOL_SOCKET, SO_SNDTIMEO, to, sizeof( *to));
+    rv = setsockopt(socket, SOL_SOCKET, SO_SNDTIMEO, to, sizeof(*to));
     if (rv != 0) {
       return EIO;
     }
 
-    rv = setsockopt( socket, SOL_SOCKET, SO_RCVTIMEO, to, sizeof( *to));
+    rv = setsockopt(socket, SOL_SOCKET, SO_RCVTIMEO, to, sizeof(*to));
     if (rv != 0) {
       return EIO;
     }
@@ -130,7 +130,7 @@
   return 0;
 }
 
-rtems_status_code rtems_ftpfs_mount( const char *mount_point)
+rtems_status_code rtems_ftpfs_mount(const char *mount_point)
 {
   int rv = 0;
 
@@ -138,7 +138,7 @@
     mount_point = RTEMS_FTPFS_MOUNT_POINT_DEFAULT;
   }
 
-  rv = mkdir( mount_point, S_IRWXU | S_IRWXG | S_IRWXO);
+  rv = mkdir(mount_point, S_IRWXU | S_IRWXG | S_IRWXO);
   if (rv != 0) {
     return RTEMS_IO_ERROR;
   }
@@ -172,19 +172,19 @@
     mount_point = RTEMS_FTPFS_MOUNT_POINT_DEFAULT;
   }
 
-  fd = open( mount_point, O_RDWR);
+  fd = open(mount_point, O_RDWR);
   if (fd < 0) {
     return RTEMS_INVALID_NAME;
   }
   
-  va_start( ap, req);
-  rv = ioctl( fd, req, va_arg( ap, void *));
-  va_end( ap);
+  va_start(ap, req);
+  rv = ioctl(fd, req, va_arg(ap, void *));
+  va_end(ap);
   if (rv != 0) {
     sc = RTEMS_INVALID_NUMBER;
   }
 
-  rv = close( fd);
+  rv = close(fd);
   if (rv != 0 && sc == RTEMS_SUCCESSFUL) {
     sc = RTEMS_IO_ERROR;
   }
@@ -192,7 +192,7 @@
   return sc;
 }
 
-rtems_status_code rtems_ftpfs_get_verbose( const char *mount_point, bool *verbose)
+rtems_status_code rtems_ftpfs_get_verbose(const char *mount_point, bool *verbose)
 {
   return rtems_ftpfs_do_ioctl(
     mount_point,
@@ -201,7 +201,7 @@
   );
 }
 
-rtems_status_code rtems_ftpfs_set_verbose( const char *mount_point, bool verbose)
+rtems_status_code rtems_ftpfs_set_verbose(const char *mount_point, bool verbose)
 {
   return rtems_ftpfs_do_ioctl(
     mount_point,
@@ -234,11 +234,11 @@
   );
 }
 
-int rtems_bsdnet_initialize_ftp_filesystem( void)
+int rtems_bsdnet_initialize_ftp_filesystem(void)
 {
   rtems_status_code sc = RTEMS_SUCCESSFUL;
 
-  sc = rtems_ftpfs_mount( NULL);
+  sc = rtems_ftpfs_mount(NULL);
 
   if (sc == RTEMS_SUCCESSFUL) {
     return 0;
@@ -290,7 +290,7 @@
   while (true) {
     /* Receive reply fragment from socket */
     ssize_t i = 0;
-    ssize_t rv = recv( socket, buf, sizeof( buf), 0);
+    ssize_t rv = recv(socket, buf, sizeof(buf), 0);
 
     if (rv <= 0) {
       return RTEMS_FTPFS_REPLY_ERROR;
@@ -298,12 +298,12 @@
 
     /* Be verbose if necessary */
     if (verbose) {
-      write( STDERR_FILENO, buf, (size_t) rv);
+      write(STDERR_FILENO, buf, (size_t) rv);
     }
 
     /* Invoke parser if necessary */
     if (parser != NULL) {
-      parser( buf, (size_t) rv, parser_arg);
+      parser(buf, (size_t) rv, parser_arg);
     }
 
     /* Parse reply fragment */
@@ -350,9 +350,9 @@
     /* Check reply */
     if (state == RTEMS_FTPFS_REPLY_SINGLE_LINE_DONE) {
       if (
-        isdigit( reply_first [0])
-          && isdigit( reply_first [1])
-          && isdigit( reply_first [2])
+        isdigit(reply_first [0])
+          && isdigit(reply_first [1])
+          && isdigit(reply_first [2])
       ) {
         break;
       } else {
@@ -364,7 +364,7 @@
       for (i = 0; i < RTEMS_FTPFS_REPLY_SIZE; ++i) {
         ok = ok
           && reply_first [i] == reply_last [i]
-          && isdigit( reply_first [i]);
+          && isdigit(reply_first [i]);
       }
 
       if (ok) {
@@ -389,36 +389,36 @@
   int rv = 0;
 
   /* Send command */
-  rv = send( socket, cmd, strlen( cmd), 0);
+  rv = send(socket, cmd, strlen(cmd), 0);
   if (rv < 0) {
     return RTEMS_FTPFS_REPLY_ERROR;
   }
   if (verbose) {
-    write( STDERR_FILENO, cmd, strlen( cmd));
+    write(STDERR_FILENO, cmd, strlen(cmd));
   }
 
   /* Send command argument if necessary */
   if (arg != NULL) {
-    rv = send( socket, arg, strlen( arg), 0);
+    rv = send(socket, arg, strlen(arg), 0);
     if (rv < 0) {
       return RTEMS_FTPFS_REPLY_ERROR;
     }
     if (verbose) {
-      write( STDERR_FILENO, arg, strlen( arg));
+      write(STDERR_FILENO, arg, strlen(arg));
     }
   }
 
   /* Send end of line */
-  rv = send( socket, eol, 2, 0);
+  rv = send(socket, eol, 2, 0);
   if (rv < 0) {
     return RTEMS_FTPFS_REPLY_ERROR;
   }
   if (verbose) {
-    write( STDERR_FILENO, &eol [1], 1);
+    write(STDERR_FILENO, &eol [1], 1);
   }
 
   /* Return reply */
-  return rtems_ftpfs_get_reply( socket, parser, parser_arg, verbose);
+  return rtems_ftpfs_get_reply(socket, parser, parser_arg, verbose);
 }
 
 static rtems_ftpfs_reply rtems_ftpfs_send_command(
@@ -459,7 +459,7 @@
 )
 {
   split_state state = STATE_USER_NAME;
-  size_t len = strlen( s);
+  size_t len = strlen(s);
   size_t i = 0;
 
   *user = s;
@@ -543,28 +543,29 @@
   unsigned short port
 )
 {
-  memset( sa, sizeof( *sa), 0);
+  memset(sa, sizeof(*sa), 0);
 
   sa->sin_family = AF_INET;
   sa->sin_addr.s_addr = address;
   sa->sin_port = port;
-  sa->sin_len = sizeof( *sa);
+  sa->sin_len = sizeof(*sa);
 
-  return sizeof( *sa);
+  return sizeof(*sa);
 }
 
-static int rtems_ftpfs_terminate( rtems_libio_t *iop, bool error)
+static int rtems_ftpfs_terminate(rtems_libio_t *iop, bool error)
 {
   int eno = 0;
   int rv = 0;
   rtems_ftpfs_entry *e = iop->data1;
   rtems_ftpfs_mount_entry *me = iop->pathinfo.mt_entry->fs_info;
   bool verbose = me->verbose;
+  rtems_ftpfs_reply reply = RTEMS_FTPFS_REPLY_ERROR;
 
   if (e != NULL) {
     /* Close data connection if necessary */
     if (e->data_socket >= 0) {
-      rv = close( e->data_socket);
+      rv = close(e->data_socket);
       if (rv != 0) {
         eno = EIO;
       }
@@ -575,9 +576,7 @@
           && (iop->flags & LIBIO_FLAGS_WRITE) != 0
           && !error
       ) {
-        rtems_ftpfs_reply reply =
-          rtems_ftpfs_get_reply( e->ctrl_socket, NULL, NULL, verbose);
-
+        reply = rtems_ftpfs_get_reply(e->ctrl_socket, NULL, NULL, verbose);
         if (reply != RTEMS_FTPFS_REPLY_2) {
           eno = EIO;
         }
@@ -586,14 +585,24 @@
 
     /* Close control connection if necessary */
     if (e->ctrl_socket >= 0) {
-      rv = close( e->ctrl_socket);
+      reply = rtems_ftpfs_send_command(
+        e->ctrl_socket,
+        "QUIT",
+        NULL,
+        verbose
+      );
+      if (reply != RTEMS_FTPFS_REPLY_2) {
+        eno = EIO;
+      }
+
+      rv = close(e->ctrl_socket);
       if (rv != 0) {
         eno = EIO;
       }
     }
 
     /* Free connection entry */
-    free( e);
+    free(e);
   }
 
   /* Invalidate IO entry */
@@ -620,46 +629,46 @@
   socklen_t size = 0;
 
   /* Create the socket for the control connection */
-  e->ctrl_socket = socket( AF_INET, SOCK_STREAM, 0);
+  e->ctrl_socket = socket(AF_INET, SOCK_STREAM, 0);
   if (e->ctrl_socket < 0) {
     return ENOMEM;
   }
 
   /* Set up the server address from the hostname */
-  if (hostname == NULL || strlen( hostname) == 0) {
+  if (hostname == NULL || strlen(hostname) == 0) {
     /* Default to BOOTP server address */
     address = rtems_bsdnet_bootp_server_address;
-  } else if (inet_aton( hostname, &address) == 0) {
+  } else if (inet_aton(hostname, &address) == 0) {
     /* Try to get the address by name */
-    struct hostent *he = gethostbyname( hostname);
+    struct hostent *he = gethostbyname(hostname);
 
     if (he != NULL) {
-      memcpy( &address, he->h_addr, sizeof( address));
+      memcpy(&address, he->h_addr, sizeof(address));
     } else {
       return ENOENT;
     }
   }
-  rtems_ftpfs_create_address( &sa, address.s_addr, htons( RTEMS_FTPFS_CTRL_PORT));
-  DEBUG_PRINTF( "server = %s\n", inet_ntoa( sa.sin_addr));
+  rtems_ftpfs_create_address(&sa, address.s_addr, htons(RTEMS_FTPFS_CTRL_PORT));
+  DEBUG_PRINTF("server = %s\n", inet_ntoa(sa.sin_addr));
 
   /* Open control connection */
   rv = connect(
     e->ctrl_socket,
     (struct sockaddr *) &sa,
-    sizeof( sa)
+    sizeof(sa)
   );
   if (rv != 0) {
     return ENOENT;
   }
 
   /* Set control connection timeout */
-  eno = rtems_ftpfs_set_connection_timeout( e->ctrl_socket, timeout);
+  eno = rtems_ftpfs_set_connection_timeout(e->ctrl_socket, timeout);
   if (eno != 0) {
     return eno;
   }
 
   /* Get client address */
-  size = rtems_ftpfs_create_address( &sa, INADDR_ANY, 0);
+  size = rtems_ftpfs_create_address(&sa, INADDR_ANY, 0);
   rv = getsockname(
     e->ctrl_socket,
     (struct sockaddr *) &sa,
@@ -668,17 +677,17 @@
   if (rv != 0) {
     return ENOMEM;
   }
-  *client_address = ntohl( sa.sin_addr.s_addr);
-  DEBUG_PRINTF( "client = %s\n", inet_ntoa( sa.sin_addr));
+  *client_address = ntohl(sa.sin_addr.s_addr);
+  DEBUG_PRINTF("client = %s\n", inet_ntoa(sa.sin_addr));
 
   /* Now we should get a welcome message from the server */
-  reply = rtems_ftpfs_get_reply( e->ctrl_socket, NULL, NULL, verbose);
+  reply = rtems_ftpfs_get_reply(e->ctrl_socket, NULL, NULL, verbose);
   if (reply != RTEMS_FTPFS_REPLY_2) {
     return ENOENT;
   }
 
   /* Send USER command */
-  reply = rtems_ftpfs_send_command( e->ctrl_socket, "USER ", user, verbose);
+  reply = rtems_ftpfs_send_command(e->ctrl_socket, "USER ", user, verbose);
   if (reply == RTEMS_FTPFS_REPLY_3) {
     /* Send PASS command */
     reply = rtems_ftpfs_send_command(
@@ -697,7 +706,7 @@
   }
 
   /* Send TYPE command to set binary mode for all data transfers */
-  reply = rtems_ftpfs_send_command( e->ctrl_socket, "TYPE I", NULL, verbose);
+  reply = rtems_ftpfs_send_command(e->ctrl_socket, "TYPE I", NULL, verbose);
   if (reply != RTEMS_FTPFS_REPLY_2) {
     return EIO;
   }
@@ -724,18 +733,18 @@
   uint16_t data_port = 0;
 
   /* Create port socket to establish a data data connection */
-  port_socket = socket( AF_INET, SOCK_STREAM, 0);
+  port_socket = socket(AF_INET, SOCK_STREAM, 0);
   if (port_socket < 0) {
     eno = ENOMEM;
     goto cleanup;
   }
 
   /* Bind port socket */
-  rtems_ftpfs_create_address( &sa, INADDR_ANY, 0);
+  rtems_ftpfs_create_address(&sa, INADDR_ANY, 0);
   rv = bind(
     port_socket,
     (struct sockaddr *) &sa,
-    sizeof( sa)
+    sizeof(sa)
   );
   if (rv != 0) {
     eno = EBUSY;
@@ -743,7 +752,7 @@
   }
 
   /* Get port number for data socket */
-  size = rtems_ftpfs_create_address( &sa, INADDR_ANY, 0);
+  size = rtems_ftpfs_create_address(&sa, INADDR_ANY, 0);
   rv = getsockname(
     port_socket,
     (struct sockaddr *) &sa,
@@ -753,12 +762,12 @@
     eno = ENOMEM;
     goto cleanup;
   }
-  data_port = ntohs( sa.sin_port);
+  data_port = ntohs(sa.sin_port);
 
   /* Send PORT command to set data connection port for server */
   snprintf(
     port_command,
-    sizeof( port_command),
+    sizeof(port_command),
     "PORT %lu,%lu,%lu,%lu,%lu,%lu",
     (client_address >> 24) & 0xffUL,
     (client_address >> 16) & 0xffUL,
@@ -779,7 +788,7 @@
   }
 
   /* Listen on port socket for incoming data connections */
-  rv = listen( port_socket, 1);
+  rv = listen(port_socket, 1);
   if (rv != 0) {
     eno = EBUSY;
     goto cleanup;
@@ -798,14 +807,14 @@
   }
 
   /* Wait for connect on data connection if necessary */
-  if (rtems_ftpfs_use_timeout( timeout)) {
+  if (rtems_ftpfs_use_timeout(timeout)) {
     struct timeval to = *timeout;
     fd_set fds;
 
-    FD_ZERO( &fds);
-    FD_SET( port_socket, &fds);
+    FD_ZERO(&fds);
+    FD_SET(port_socket, &fds);
 
-    rv = select( port_socket + 1, &fds, NULL, NULL, &to);
+    rv = select(port_socket + 1, &fds, NULL, NULL, &to);
     if (rv <= 0) {
       eno = EIO;
       goto cleanup;
@@ -813,7 +822,7 @@
   }
 
   /* Accept data connection  */
-  size = sizeof( sa);
+  size = sizeof(sa);
   e->data_socket = accept(
     port_socket,
     (struct sockaddr *) &sa,
@@ -828,7 +837,7 @@
 
   /* Close port socket if necessary */
   if (port_socket >= 0) {
-    rv = close( port_socket);
+    rv = close(port_socket);
     if (rv != 0) {
       eno = EIO;
     }
@@ -864,23 +873,23 @@
 
     switch (e->state) {
       case RTEMS_FTPFS_PASV_START:
-        if (!isdigit( c)) {
+        if (!isdigit(c)) {
           e->state = RTEMS_FTPFS_PASV_JUNK;
           e->index = 0;
         }
         break;
       case RTEMS_FTPFS_PASV_JUNK:
-        if (isdigit( c)) {
+        if (isdigit(c)) {
           e->state = RTEMS_FTPFS_PASV_DATA;
           e->data [e->index] = (uint8_t) (c - '0');
         }
         break;
       case RTEMS_FTPFS_PASV_DATA:
-        if (isdigit( c)) {
+        if (isdigit(c)) {
           e->data [e->index] = (uint8_t) (e->data [e->index] * 10 + c - '0');
         } else if (c == ',') {
           ++e->index;
-          if (e->index < sizeof( e->data)) {
+          if (e->index < sizeof(e->data)) {
             e->data [e->index] = 0;
           } else {
             e->state = RTEMS_FTPFS_PASV_DONE;
@@ -929,15 +938,15 @@
   data_address = ((uint32_t)(pe.data [0]) << 24) + ((uint32_t)(pe.data [1]) << 16)
     + ((uint32_t)(pe.data [2]) << 8) + ((uint32_t)(pe.data [3]));
   data_port = (uint16_t) ((pe.data [4] << 8) + pe.data [5]);
-  rtems_ftpfs_create_address( &sa, htonl( data_address), htons( data_port));
+  rtems_ftpfs_create_address(&sa, htonl(data_address), htons(data_port));
   DEBUG_PRINTF(
     "server data = %s:%u\n",
-    inet_ntoa( sa.sin_addr),
-    (unsigned) ntohs( sa.sin_port)
+    inet_ntoa(sa.sin_addr),
+    (unsigned) ntohs(sa.sin_port)
   );
 
   /* Create data socket */
-  e->data_socket = socket( AF_INET, SOCK_STREAM, 0);
+  e->data_socket = socket(AF_INET, SOCK_STREAM, 0);
   if (e->data_socket < 0) {
     return ENOMEM;
   }
@@ -946,7 +955,7 @@
   rv = connect(
     e->data_socket,
     (struct sockaddr *) &sa,
-    sizeof( sa)
+    sizeof(sa)
   );
   if (rv != 0) {
     return EIO;
@@ -994,7 +1003,7 @@
 
   /* Check location, it was allocated during path evaluation */
   if (location == NULL) {
-    rtems_set_errno_and_return_minus_one( ENOMEM);
+    rtems_set_errno_and_return_minus_one(ENOMEM);
   }
 
   /* Split location into parts */
@@ -1006,7 +1015,7 @@
       &filename
   );
   if (!ok) {
-    if (strlen( location) == 0) {
+    if (strlen(location) == 0) {
       /*
        * This is an access to the root node that will be used for file system
        * option settings.
@@ -1015,7 +1024,7 @@
 
       return 0;
     } else {
-      rtems_set_errno_and_return_minus_one( ENOENT);
+      rtems_set_errno_and_return_minus_one(ENOENT);
     }
   }
   DEBUG_PRINTF(
@@ -1030,13 +1039,13 @@
     (iop->flags & LIBIO_FLAGS_WRITE) != 0
       && (iop->flags & LIBIO_FLAGS_READ) != 0
   ) {
-    rtems_set_errno_and_return_minus_one( ENOTSUP);
+    rtems_set_errno_and_return_minus_one(ENOTSUP);
   }
 
   /* Allocate connection entry */
-  e = malloc( sizeof( *e));
+  e = malloc(sizeof(*e));
   if (e == NULL) {
-    rtems_set_errno_and_return_minus_one( ENOMEM);
+    rtems_set_errno_and_return_minus_one(ENOMEM);
   }
 
   /* Initialize connection entry */
@@ -1086,7 +1095,7 @@
   }
 
   /* Set data connection timeout */
-  eno = rtems_ftpfs_set_connection_timeout( e->data_socket, timeout);
+  eno = rtems_ftpfs_set_connection_timeout(e->data_socket, timeout);
 
 cleanup:
 
@@ -1094,9 +1103,9 @@
     return 0;
   } else {
     /* Free all resources if an error occured */
-    rtems_ftpfs_terminate( iop, true);
+    rtems_ftpfs_terminate(iop, true);
 
-    rtems_set_errno_and_return_minus_one( eno);
+    rtems_set_errno_and_return_minus_one(eno);
   }
 }
 
@@ -1117,12 +1126,12 @@
   }
 
   while (todo > 0) {
-    ssize_t rv = recv( e->data_socket, in, todo, 0);
+    ssize_t rv = recv(e->data_socket, in, todo, 0);
 
     if (rv <= 0) {
       if (rv == 0) {
         rtems_ftpfs_reply reply =
-          rtems_ftpfs_get_reply( e->ctrl_socket, NULL, NULL, verbose);
+          rtems_ftpfs_get_reply(e->ctrl_socket, NULL, NULL, verbose);
 
         if (reply == RTEMS_FTPFS_REPLY_2) {
           e->eof = true;
@@ -1130,7 +1139,7 @@
         }
       }
 
-      rtems_set_errno_and_return_minus_one( EIO);
+      rtems_set_errno_and_return_minus_one(EIO);
     }
 
     in += rv;
@@ -1151,13 +1160,13 @@
   size_t todo = count;
 
   while (todo > 0) {
-    ssize_t rv = send( e->data_socket, out, todo, 0);
+    ssize_t rv = send(e->data_socket, out, todo, 0);
 
     if (rv <= 0) {
       if (rv == 0) {
         break;
       } else {
-        rtems_set_errno_and_return_minus_one( EIO);
+        rtems_set_errno_and_return_minus_one(EIO);
       }
     }
 
@@ -1168,19 +1177,19 @@
   return (ssize_t) (count - todo);
 }
 
-static int rtems_ftpfs_close( rtems_libio_t *iop)
+static int rtems_ftpfs_close(rtems_libio_t *iop)
 {
-  int eno = rtems_ftpfs_terminate( iop, false);
+  int eno = rtems_ftpfs_terminate(iop, false);
 
   if (eno == 0) {
     return 0;
   } else {
-    rtems_set_errno_and_return_minus_one( eno);
+    rtems_set_errno_and_return_minus_one(eno);
   }
 }
 
-/* Dummy version to let fopen( *,"w") work properly */
-static int rtems_ftpfs_ftruncate( rtems_libio_t *iop, rtems_off64_t count)
+/* Dummy version to let fopen(*,"w") work properly */
+static int rtems_ftpfs_ftruncate(rtems_libio_t *iop, rtems_off64_t count)
 {
   return 0;
 }
@@ -1197,19 +1206,21 @@
    * We need to store this path here or otherwise we would have to do this job
    * again.  The path is used in rtems_ftpfs_open() via iop->file_info.
    */
-  pathloc->node_access = malloc(pathnamelen + 1);
-  if (pathloc->node_access) {
-    memset(pathloc->node_access, 0, pathnamelen + 1);
-    memcpy(pathloc->node_access, pathname, pathnamelen);
-  }    
-  pathloc->node_access = strdup( pathname);
+  char *pathname_dup = malloc(pathnamelen + 1);
+
+  if (pathname_dup != NULL) {
+    memcpy(pathname_dup, pathname, pathnamelen);
+    pathname_dup [pathnamelen] = '\0';
+  }
+
+  pathloc->node_access = pathname_dup;
 
   return 0;
 }
 
-static int rtems_ftpfs_free_node( rtems_filesystem_location_info_t *pathloc)
+static int rtems_ftpfs_free_node(rtems_filesystem_location_info_t *pathloc)
 {
-  free( pathloc->node_access);
+  free(pathloc->node_access);
 
   return 0;
 }
@@ -1225,12 +1236,12 @@
   rtems_filesystem_mount_table_entry_t *e
 )
 {
-  rtems_ftpfs_mount_entry *me = malloc( sizeof( rtems_ftpfs_mount_entry));
+  rtems_ftpfs_mount_entry *me = malloc(sizeof(rtems_ftpfs_mount_entry));
 
   /* Mount entry for FTP file system instance */
   e->fs_info = me;
   if (e->fs_info == NULL) {
-    rtems_set_errno_and_return_minus_one( ENOMEM);
+    rtems_set_errno_and_return_minus_one(ENOMEM);
   }
   me->verbose = false;
   me->timeout.tv_sec = 0;
@@ -1253,7 +1264,7 @@
   rtems_filesystem_mount_table_entry_t *e
 )
 {
-  free( e->fs_info);
+  free(e->fs_info);
 
   return 0;
 }
@@ -1269,7 +1280,7 @@
   struct timeval *timeout = arg;
 
   if (arg == NULL) {
-    rtems_set_errno_and_return_minus_one( EINVAL);
+    rtems_set_errno_and_return_minus_one(EINVAL);
   }
 
   switch (command) {
@@ -1305,11 +1316,11 @@
 {
   static unsigned ino = 0;
 
-  memset( st, 0, sizeof( *st));
+  memset(st, 0, sizeof(*st));
 
   /* FIXME */
   st->st_ino = ++ino;
-  st->st_dev = rtems_filesystem_make_dev_t( 0xcc494cd6U, 0x1d970b4dU);
+  st->st_dev = rtems_filesystem_make_dev_t(0xcc494cd6U, 0x1d970b4dU);
 
   st->st_mode = S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO;
 


 *sh*:
2010-04-30	Sebastian Huber <sebastian.huber at embedded-brains.de>

	* libcsupport/include/rtems/libio_.h, libcsupport/src/envlock.c,
	libcsupport/src/libio.c: Added and use rtems_libio_lock() and
	rtems_libio_unlock().  Cleaned up includes and declarations.  Do not
	use RTEMS_NO_PRIORITY for unused ceiling priority in
	rtems_semaphore_create().

M 1.2287  cpukit/ChangeLog
M   1.32  cpukit/libcsupport/include/rtems/libio_.h
M    1.5  cpukit/libcsupport/src/envlock.c
M   1.49  cpukit/libcsupport/src/libio.c

diff -u rtems/cpukit/ChangeLog:1.2286 rtems/cpukit/ChangeLog:1.2287
--- rtems/cpukit/ChangeLog:1.2286	Fri Apr 30 03:52:28 2010
+++ rtems/cpukit/ChangeLog	Fri Apr 30 03:55:38 2010
@@ -1,5 +1,13 @@
 2010-04-30	Sebastian Huber <sebastian.huber at embedded-brains.de>
 
+	* libcsupport/include/rtems/libio_.h, libcsupport/src/envlock.c,
+	libcsupport/src/libio.c: Added and use rtems_libio_lock() and
+	rtems_libio_unlock().  Cleaned up includes and declarations.  Do not
+	use RTEMS_NO_PRIORITY for unused ceiling priority in
+	rtems_semaphore_create().
+
+2010-04-30	Sebastian Huber <sebastian.huber at embedded-brains.de>
+
 	* libnetworking/lib/ftpfs.c: Format changes.  Fixed pathname
 	allocation in rtems_ftpfs_eval_path().  Send QUIT command during
 	file close.

diff -u rtems/cpukit/libcsupport/include/rtems/libio_.h:1.31 rtems/cpukit/libcsupport/include/rtems/libio_.h:1.32
--- rtems/cpukit/libcsupport/include/rtems/libio_.h:1.31	Wed Aug  5 13:17:11 2009
+++ rtems/cpukit/libcsupport/include/rtems/libio_.h	Fri Apr 30 03:55:40 2010
@@ -204,6 +204,16 @@
 rtems_status_code rtems_libio_set_private_env(void);
 rtems_status_code rtems_libio_share_private_env(rtems_id task_id) ;
 
+static inline void rtems_libio_lock( void )
+{
+  rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT );
+}
+
+static inline void rtems_libio_unlock( void )
+{
+  rtems_semaphore_release( rtems_libio_semaphore );
+}
+
 /*
  *  File Descriptor Routine Prototypes
  */

diff -u rtems/cpukit/libcsupport/src/envlock.c:1.4 rtems/cpukit/libcsupport/src/envlock.c:1.5
--- rtems/cpukit/libcsupport/src/envlock.c:1.4	Tue Sep 15 04:29:55 2009
+++ rtems/cpukit/libcsupport/src/envlock.c	Fri Apr 30 03:55:40 2010
@@ -97,12 +97,12 @@
 void
 __env_lock(struct _reent *r __attribute__((unused)))
 {
-  rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT );
+  rtems_libio_lock();
 }
 
 void
 __env_unlock(struct _reent *r __attribute__((unused)))
 {
-  rtems_semaphore_release( rtems_libio_semaphore );
+  rtems_libio_unlock();
 }
 #endif

diff -u rtems/cpukit/libcsupport/src/libio.c:1.48 rtems/cpukit/libcsupport/src/libio.c:1.49
--- rtems/cpukit/libcsupport/src/libio.c:1.48	Sun Nov 29 07:35:32 2009
+++ rtems/cpukit/libcsupport/src/libio.c	Fri Apr 30 03:55:41 2010
@@ -17,14 +17,15 @@
 #include "config.h"
 #endif
 
-#include <rtems/libio_.h>               /* libio_.h pulls in rtems */
-#include <rtems.h>
-#include <rtems/assoc.h>                /* assoc.h not included by rtems.h */
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
 
-#include <stdio.h>                      /* O_RDONLY, et.al. */
-#include <fcntl.h>                      /* O_RDONLY, et.al. */
-#include <assert.h>
-#include <errno.h>
+#include <rtems.h>
+#include <rtems/libio_.h>
+#include <rtems/assoc.h>
 
 /* define this to alias O_NDELAY to  O_NONBLOCK, i.e.,
  * O_NDELAY is accepted on input but fcntl(F_GETFL) returns
@@ -40,22 +41,6 @@
  */
 #undef ACCEPT_O_NDELAY_ALIAS
 
-#include <errno.h>
-#include <string.h>                     /* strcmp */
-#include <unistd.h>
-#include <stdlib.h>                     /* calloc() */
-
-#include <rtems/libio.h>                /* libio.h not pulled in by rtems */
-
-/*
- *  File descriptor Table Information
- */
-
-extern uint32_t       rtems_libio_number_iops;
-extern rtems_id       rtems_libio_semaphore;
-extern rtems_libio_t *rtems_libio_iops;
-extern rtems_libio_t *rtems_libio_iop_freelist;
-
 /*
  *  rtems_libio_fcntl_flags
  *
@@ -151,14 +136,14 @@
   rtems_status_code rc;
   rtems_id sema;
 
-  rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT );
+  rtems_libio_lock();
 
   if (rtems_libio_iop_freelist) {
     rc = rtems_semaphore_create(
       RTEMS_LIBIO_IOP_SEM(rtems_libio_iop_freelist - rtems_libio_iops),
       1,
       RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY,
-      RTEMS_NO_PRIORITY,
+      0,
       &sema
     );
     if (rc != RTEMS_SUCCESSFUL)
@@ -176,7 +161,7 @@
   iop = 0;
 
 done:
-  rtems_semaphore_release( rtems_libio_semaphore );
+  rtems_libio_unlock();
   return iop;
 }
 
@@ -191,7 +176,7 @@
   rtems_libio_t *iop
 )
 {
-  rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT );
+  rtems_libio_lock();
 
     if (iop->sem)
       rtems_semaphore_delete(iop->sem);
@@ -200,7 +185,7 @@
     iop->data1 = rtems_libio_iop_freelist;
     rtems_libio_iop_freelist = iop;
 
-  rtems_semaphore_release(rtems_libio_semaphore);
+  rtems_libio_unlock();
 }
 
 /*
@@ -222,7 +207,7 @@
   int                result = 0;
   uint32_t           i;
 
-  rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT );
+  rtems_libio_lock();
 
   /*
    *  Look for any active file descriptor entry.
@@ -244,7 +229,7 @@
     }
   }
 
-  rtems_semaphore_release( rtems_libio_semaphore );
+  rtems_libio_unlock();
 
   return result;
 }
@@ -266,7 +251,7 @@
   int                result=0;
   uint32_t           i;
 
-  rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT );
+  rtems_libio_lock();
 
   /*
    *  Look for any active file descriptor entry.
@@ -287,7 +272,7 @@
     }
   }
 
-  rtems_semaphore_release( rtems_libio_semaphore );
+  rtems_libio_unlock();
 
   return result;
 }



--

Generated by Deluxe Loginfo [http://www.codewiz.org/projects/index.html#loginfo] 2.122 by Bernardo Innocenti <bernie at develer.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/vc/attachments/20100430/5b9bc198/attachment.html>


More information about the vc mailing list