Index: cpukit/ChangeLog
===================================================================
--- cpukit/ChangeLog	(revision a290e72a5dbff53a5e4c8bb5e945bbe455ff9b00)
+++ cpukit/ChangeLog	(revision 1d539c05010b34013e49c5a8221702ebadae4406)
@@ -1,2 +1,13 @@
+2010-04-12	Chris Johns <chrisj@rtems.org>
+
+	libfs/src/rfs/rtems-rfs-buffer-bdbuf.c,
+	libfs/src/rfs/rtems-rfs-buffer.c, libfs/src/rfs/rtems-rfs-data.h,
+	libfs/src/rfs/rtems-rfs-dir.c,
+	libfs/src/rfs/rtems-rfs-file-system.c,
+	libfs/src/rfs/rtems-rfs-format.c, libfs/src/rfs/rtems-rfs-inode.h,
+	libfs/src/rfs/rtems-rfs-rtems.c, libfs/src/rfs/rtems-rfs-rtems.h,
+	libfs/src/rfs/rtems-rfs-shell.c: Fix for PR1502. Clean up problems
+	on 16bit targets.
+
 2010-04-10	Ralf CorsÃ©pius <ralf.corsepius@rtems.org>
 
Index: cpukit/libfs/src/rfs/rtems-rfs-buffer-bdbuf.c
===================================================================
--- cpukit/libfs/src/rfs/rtems-rfs-buffer-bdbuf.c	(revision a290e72a5dbff53a5e4c8bb5e945bbe455ff9b00)
+++ cpukit/libfs/src/rfs/rtems-rfs-buffer-bdbuf.c	(revision 1d539c05010b34013e49c5a8221702ebadae4406)
@@ -68,5 +68,5 @@
   if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_RELEASE))
     printf ("rtems-rfs: bdbuf-release: block=%lu bdbuf=%lu %s\n",
-            (rtems_rfs_buffer_block) buffer->user,
+            (rtems_rfs_buffer_block) ((intptr_t) buffer->user),
             buffer->block, modified ? "(modified)" : "");
 
Index: cpukit/libfs/src/rfs/rtems-rfs-buffer.c
===================================================================
--- cpukit/libfs/src/rfs/rtems-rfs-buffer.c	(revision a290e72a5dbff53a5e4c8bb5e945bbe455ff9b00)
+++ cpukit/libfs/src/rfs/rtems-rfs-buffer.c	(revision 1d539c05010b34013e49c5a8221702ebadae4406)
@@ -52,10 +52,11 @@
 
     if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_CHAINS))
-      printf ("%lu ", (rtems_rfs_buffer_block) buffer->user);
-
-    if (((rtems_rfs_buffer_block) buffer->user) == block)
+      printf ("%lu ", (rtems_rfs_buffer_block) ((intptr_t)(buffer->user)));
+
+    if (((rtems_rfs_buffer_block) ((intptr_t)(buffer->user))) == block)
     {
       if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_CHAINS))
-        printf (": found block=%lu\n", (rtems_rfs_buffer_block) buffer->user);
+        printf (": found block=%lu\n",
+                (rtems_rfs_buffer_block) ((intptr_t)(buffer->user)));
 
       (*count)--;
@@ -183,5 +184,5 @@
   fs->buffers_count++;
   
-  handle->buffer->user = (void*) block;
+  handle->buffer->user = (void*) ((intptr_t) block);
   handle->bnum = block;
   
Index: cpukit/libfs/src/rfs/rtems-rfs-data.h
===================================================================
--- cpukit/libfs/src/rfs/rtems-rfs-data.h	(revision a290e72a5dbff53a5e4c8bb5e945bbe455ff9b00)
+++ cpukit/libfs/src/rfs/rtems-rfs-data.h	(revision 1d539c05010b34013e49c5a8221702ebadae4406)
@@ -32,4 +32,10 @@
 
 /**
+ * Helper function to get the data shifted in the correctly sized type.
+ */
+#define rtems_rfs_data_get(_d, _t, _o, _s) \
+  (((_t)(rtems_rfs_data_ptr (_d)[_o])) << (_s))
+
+/**
  * RFS Read Unsigned 8bit Integer
  */
@@ -41,5 +47,6 @@
  */
 #define rtems_rfs_read_u16(_d) \
-  ((rtems_rfs_data_ptr (_d)[0] << 8) | (rtems_rfs_data_ptr (_d)[1]))
+  (rtems_rfs_data_get (_d, uint16_t, 0, 8) | \
+   rtems_rfs_data_get (_d, uint16_t, 1, 0))
 
 /**
@@ -47,6 +54,8 @@
  */
 #define rtems_rfs_read_u32(_d) \
-  ((rtems_rfs_data_ptr (_d)[0] << 24) | (rtems_rfs_data_ptr (_d)[1] << 16) | \
-   (rtems_rfs_data_ptr (_d)[2] << 8) | (rtems_rfs_data_ptr (_d)[3]))
+  (rtems_rfs_data_get (_d, uint32_t, 0, 24) | \
+   rtems_rfs_data_get (_d, uint32_t, 1, 16) | \
+   rtems_rfs_data_get (_d, uint32_t, 2, 8) | \
+   rtems_rfs_data_get (_d, uint32_t, 3, 0))
 
 /**
@@ -61,5 +70,5 @@
 #define rtems_rfs_write_u16(_d, _v) \
   do { \
-    rtems_rfs_data_ptr (_d)[0] = (uint8_t)((_v) >> 8); \
+    rtems_rfs_data_ptr (_d)[0] = (uint8_t)(((uint16_t)(_v)) >> 8); \
     rtems_rfs_data_ptr (_d)[1] = (uint8_t)((_v)); \
   } while (0)
@@ -70,8 +79,8 @@
 #define rtems_rfs_write_u32(_d, _v) \
   do { \
-    rtems_rfs_data_ptr (_d)[0] = (uint8_t)((_v) >> 24); \
-    rtems_rfs_data_ptr (_d)[1] = (uint8_t)((_v) >> 16); \
-    rtems_rfs_data_ptr (_d)[2] = (uint8_t)((_v) >> 8); \
-    rtems_rfs_data_ptr (_d)[3] = (uint8_t)((_v)); \
+    rtems_rfs_data_ptr (_d)[0] = (uint8_t)(((uint32_t)(_v)) >> 24); \
+    rtems_rfs_data_ptr (_d)[1] = (uint8_t)(((uint32_t)(_v)) >> 16); \
+    rtems_rfs_data_ptr (_d)[2] = (uint8_t)(((uint32_t)(_v)) >> 8);  \
+    rtems_rfs_data_ptr (_d)[3] = (uint8_t)((uint32_t)(_v)); \
   } while (0)
 
Index: cpukit/libfs/src/rfs/rtems-rfs-dir.c
===================================================================
--- cpukit/libfs/src/rfs/rtems-rfs-dir.c	(revision a290e72a5dbff53a5e4c8bb5e945bbe455ff9b00)
+++ cpukit/libfs/src/rfs/rtems-rfs-dir.c	(revision 1d539c05010b34013e49c5a8221702ebadae4406)
@@ -162,5 +162,5 @@
           if (rtems_rfs_trace (RTEMS_RFS_TRACE_DIR_LOOKUP_INO_CHECK))
             printf ("rtems-rfs: dir-lookup-ino: " \
-                    "checking entry for ino %ld: off=%04lx length:%d ino:%d\n",
+                    "checking entry for ino %ld: off=%04lx length:%d ino:%ld\n",
                     rtems_rfs_inode_ino (inode), map.bpos.boff,
                     elength, rtems_rfs_dir_entry_ino (entry));
@@ -610,5 +610,5 @@
       if (rtems_rfs_trace (RTEMS_RFS_TRACE_DIR_READ))
         printf ("rtems-rfs: dir-read: found off:%Ld ino:%ld name=%s\n",
-                dirent->d_off, dirent->d_ino, dirent->d_name);
+                (uint64_t) dirent->d_off, dirent->d_ino, dirent->d_name);
       break;
     }
Index: cpukit/libfs/src/rfs/rtems-rfs-file-system.c
===================================================================
--- cpukit/libfs/src/rfs/rtems-rfs-file-system.c	(revision a290e72a5dbff53a5e4c8bb5e945bbe455ff9b00)
+++ cpukit/libfs/src/rfs/rtems-rfs-file-system.c	(revision 1d539c05010b34013e49c5a8221702ebadae4406)
@@ -80,5 +80,5 @@
   {
     if (rtems_rfs_trace (RTEMS_RFS_TRACE_OPEN))
-      printf ("rtems-rfs: read-superblock: incompatible version: %08x (%08x)\n",
+      printf ("rtems-rfs: read-superblock: incompatible version: %08lx (%08x)\n",
               read_sb (RTEMS_RFS_SB_OFFSET_VERSION), RTEMS_RFS_VERSION_MASK);
     rtems_rfs_buffer_handle_close (fs, &handle);
@@ -89,5 +89,5 @@
   {
     if (rtems_rfs_trace (RTEMS_RFS_TRACE_OPEN))
-      printf ("rtems-rfs: read-superblock: inode size mismatch: fs:%d target:%d\n",
+      printf ("rtems-rfs: read-superblock: inode size mismatch: fs:%ld target:%d\n",
               read_sb (RTEMS_RFS_SB_OFFSET_VERSION), RTEMS_RFS_VERSION_MASK);
     rtems_rfs_buffer_handle_close (fs, &handle);
Index: cpukit/libfs/src/rfs/rtems-rfs-format.c
===================================================================
--- cpukit/libfs/src/rfs/rtems-rfs-format.c	(revision a290e72a5dbff53a5e4c8bb5e945bbe455ff9b00)
+++ cpukit/libfs/src/rfs/rtems-rfs-format.c	(revision 1d539c05010b34013e49c5a8221702ebadae4406)
@@ -34,5 +34,5 @@
  * Return the number of gigabytes.
  */
-#define GIGS(_g) ((_g) * 1024 * 1024)
+#define GIGS(_g) (((uint64_t)(_g)) * 1024 * 1024)
 
 /**
Index: cpukit/libfs/src/rfs/rtems-rfs-inode.h
===================================================================
--- cpukit/libfs/src/rfs/rtems-rfs-inode.h	(revision a290e72a5dbff53a5e4c8bb5e945bbe455ff9b00)
+++ cpukit/libfs/src/rfs/rtems-rfs-inode.h	(revision 1d539c05010b34013e49c5a8221702ebadae4406)
@@ -340,5 +340,5 @@
                              uint16_t uid, uint16_t gid)
 {
-  rtems_rfs_write_u32 (&handle->node->owner, (gid << 16) | uid);
+  rtems_rfs_write_u32 (&handle->node->owner, (((uint32_t) gid) << 16) | uid);
   rtems_rfs_buffer_mark_dirty (&handle->buffer);
 }
Index: cpukit/libfs/src/rfs/rtems-rfs-rtems.c
===================================================================
--- cpukit/libfs/src/rfs/rtems-rfs-rtems.c	(revision a290e72a5dbff53a5e4c8bb5e945bbe455ff9b00)
+++ cpukit/libfs/src/rfs/rtems-rfs-rtems.c	(revision 1d539c05010b34013e49c5a8221702ebadae4406)
@@ -814,5 +814,5 @@
   if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_FCHMOD))
     printf ("rtems-rfs-rtems: fchmod: in: ino:%ld mode:%06o\n",
-            ino, mode);
+            ino, (unsigned int) mode);
   
   rtems_rfs_rtems_lock (fs);
Index: cpukit/libfs/src/rfs/rtems-rfs-rtems.h
===================================================================
--- cpukit/libfs/src/rfs/rtems-rfs-rtems.h	(revision a290e72a5dbff53a5e4c8bb5e945bbe455ff9b00)
+++ cpukit/libfs/src/rfs/rtems-rfs-rtems.h	(revision 1d539c05010b34013e49c5a8221702ebadae4406)
@@ -159,5 +159,5 @@
  */
 #define rtems_rfs_rtems_set_pathloc_ino(_loc, _ino) \
-  (_loc)->node_access = (void*)(_ino)
+  (_loc)->node_access = (void*)((intptr_t)(_ino))
 
 /**
@@ -177,5 +177,5 @@
  */
 #define rtems_rfs_rtems_set_pathloc_doff(_loc, _doff) \
-  (_loc)->node_access_2 = (void*)(_doff)
+  (_loc)->node_access_2 = (void*)((intptr_t)(_doff))
 
 /**
Index: cpukit/libfs/src/rfs/rtems-rfs-shell.c
===================================================================
--- cpukit/libfs/src/rfs/rtems-rfs-shell.c	(revision a290e72a5dbff53a5e4c8bb5e945bbe455ff9b00)
+++ cpukit/libfs/src/rfs/rtems-rfs-shell.c	(revision 1d539c05010b34013e49c5a8221702ebadae4406)
@@ -500,5 +500,5 @@
     length = elength - RTEMS_RFS_DIR_ENTRY_SIZE;
     
-    printf (" %5d: %04x inode=%-6u hash=%08x name[%03u]=",
+    printf (" %5d: %04x inode=%-6lu hash=%08lx name[%03u]=",
             entry, b,
             rtems_rfs_dir_entry_ino (data),
