Fix AVR warnings; FAT FS needs to use off_t instead of size_t

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3728 42af7a65-404d-4744-a932-0658087f49c3
diff --git a/ChangeLog b/ChangeLog
index f1fa7b5..259b994 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1824,4 +1824,7 @@
 	  check-in.
 	* configs/teensy: Adds a board configuration for the PJRC Teensy++ 2.0 boar
 	  that features an Atmel AT90USB1286 MCU.
-
+	* fs/fat: Offsets, sector numbers, etc. need to be off_t, not size_t.  size_t
+	  is intended to be the maximum size of a memory object, not a file offset. This
+	  does not make any difference except on systems (like the AVR) where size_t
+	  is only 16-bits.
diff --git a/configs/teensy/usbstorage/defconfig b/configs/teensy/usbstorage/defconfig
index 1441285..7034c66 100755
--- a/configs/teensy/usbstorage/defconfig
+++ b/configs/teensy/usbstorage/defconfig
@@ -274,7 +274,7 @@
 CONFIG_GREGORIAN_TIME=n
 CONFIG_JULIAN_TIME=n
 CONFIG_DEV_CONSOLE=y
-CONFIG_DEV_LOWCONSOLE=n
+CONFIG_DEV_LOWCONSOLE=y
 CONFIG_MUTEX_TYPES=n
 CONFIG_PRIORITY_INHERITANCE=n
 CONFIG_SEM_PREALLOCHOLDERS=0
diff --git a/drivers/bch/bchdev_driver.c b/drivers/bch/bchdev_driver.c
index 3ca97bd..c57a5cd 100644
--- a/drivers/bch/bchdev_driver.c
+++ b/drivers/bch/bchdev_driver.c
@@ -232,7 +232,7 @@
 
   if (cmd == DIOC_GETPRIV)
     {
-      FAR struct bchlib_s **bchr = (FAR struct bchlib_s **)arg;
+      FAR struct bchlib_s **bchr = (FAR struct bchlib_s **)((uintptr_t)arg);
 
       bchlib_semtake(bch);
       if (!bchr && bch->refs < 255)
diff --git a/drivers/bch/bchdev_unregister.c b/drivers/bch/bchdev_unregister.c
index d9172bc..c54b5b0 100644
--- a/drivers/bch/bchdev_unregister.c
+++ b/drivers/bch/bchdev_unregister.c
@@ -110,7 +110,7 @@
    * will hold a reference count on the state structure.
    */
 
-  ret = ioctl(fd, DIOC_GETPRIV, (unsigned long)&bch);
+  ret = ioctl(fd, DIOC_GETPRIV, (unsigned long)((uintptr_t)&bch));
   (void)close(fd);
 
   if (ret < 0)
diff --git a/drivers/ramdisk.c b/drivers/ramdisk.c
index 23b0737..b3f9916 100644
--- a/drivers/ramdisk.c
+++ b/drivers/ramdisk.c
@@ -251,7 +251,7 @@
 static int rd_ioctl(FAR struct inode *inode, int cmd, unsigned long arg)
 {
   struct rd_struct_s *dev ;
-  void **ppv = (void**)arg;
+  void **ppv = (void**)((uintptr_t)arg);
 
   fvdbg("Entry\n");
 
diff --git a/drivers/usbdev/usbdev_scsi.c b/drivers/usbdev/usbdev_scsi.c
index 3d52012..a0bbf8c 100644
--- a/drivers/usbdev/usbdev_scsi.c
+++ b/drivers/usbdev/usbdev_scsi.c
@@ -463,7 +463,7 @@
     {
       /* Get the Logical Block Address (LBA) from cdb[] as the starting sector */
 
-      priv->sector = (read6->mslba & SCSICMD_READ6_MSLBAMASK) << 16 | usbstrg_getbe16(read6->lslba);
+      priv->sector = (uint32_t)(read6->mslba & SCSICMD_READ6_MSLBAMASK) << 16 | (uint32_t)usbstrg_getbe16(read6->lslba);
 
       /* Verify that a block driver has been bound to the LUN */
 
@@ -519,7 +519,7 @@
     {
       /* Get the Logical Block Address (LBA) from cdb[] as the starting sector */
 
-      priv->sector = (write6->mslba & SCSICMD_WRITE6_MSLBAMASK) << 16 | usbstrg_getbe16(write6->lslba);
+      priv->sector = (uint32_t)(write6->mslba & SCSICMD_WRITE6_MSLBAMASK) << 16 | (uint32_t)usbstrg_getbe16(write6->lslba);
 
       /* Verify that a block driver has been bound to the LUN */
 
diff --git a/fs/fat/fs_fat32.c b/fs/fat/fs_fat32.c
index 4547d0b..a572f4a 100644
--- a/fs/fat/fs_fat32.c
+++ b/fs/fat/fs_fat32.c
@@ -342,7 +342,7 @@
 
   if ((oflags & (O_APPEND|O_WRONLY)) == (O_APPEND|O_WRONLY))
     {
-      ssize_t offset = (ssize_t)fat_seek(filep, ff->ff_size, SEEK_SET);
+      off_t offset = fat_seek(filep, ff->ff_size, SEEK_SET);
       if (offset < 0)
         {
           kfree(ff);
@@ -658,7 +658,7 @@
       goto errout_with_semaphore;
     }
 
-  /* Check if the file size would exceed the range of size_t */
+  /* Check if the file size would exceed the range of off_t */
 
   if (ff->ff_size + buflen < ff->ff_size)
     {
@@ -860,7 +860,7 @@
   struct fat_mountpt_s *fs;
   struct fat_file_s    *ff;
   int32_t               cluster;
-  ssize_t               position;
+  off_t                 position;
   unsigned int          clustersize;
   int                   ret;
 
@@ -1701,8 +1701,8 @@
   struct fat_dirinfo_s  dirinfo;
   uint8_t     *direntry;
   uint8_t     *direntry2;
-  size_t       parentsector;
-  ssize_t      dirsector;
+  off_t        parentsector;
+  off_t        dirsector;
   int32_t      dircluster;
   uint32_t     parentcluster;
   uint32_t     crtime;
@@ -1955,7 +1955,7 @@
 {
   struct fat_mountpt_s *fs;
   struct fat_dirinfo_s  dirinfo;
-  size_t                oldsector;
+  off_t                 oldsector;
   uint8_t              *olddirentry;
   uint8_t              *newdirentry;
   uint8_t               dirstate[32-11];
diff --git a/fs/fat/fs_fat32.h b/fs/fat/fs_fat32.h
index 7104177..59dbb1f 100644
--- a/fs/fat/fs_fat32.h
+++ b/fs/fat/fs_fat32.h
@@ -1,7 +1,7 @@
 /****************************************************************************
  * fs/fat/fs_fat32.h
  *
- *   Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
+ *   Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
  *   Author: Gregory Nutt <spudmonkey@racsa.co.cr>
  *
  * Redistribution and use in source and binary forms, with or without
@@ -516,13 +516,13 @@
   struct fat_file_s *fs_head;      /* A list to all files opened on this mountpoint */
 
   sem_t    fs_sem;                 /* Used to assume thread-safe access */
-  size_t   fs_hwsectorsize;        /* HW: Sector size reported by block driver*/
-  size_t   fs_hwnsectors;          /* HW: The number of sectors reported by the hardware */
-  size_t   fs_fatbase;             /* Logical block of start of filesystem (past resd sectors) */
-  size_t   fs_rootbase;            /* MBR: Cluster no. of 1st cluster of root dir */
-  size_t   fs_database;            /* Logical block of start data sectors */
-  size_t   fs_fsinfo;              /* MBR: Sector number of FSINFO sector */
-  size_t   fs_currentsector;       /* The sector number buffered in fs_buffer */
+  off_t    fs_hwsectorsize;        /* HW: Sector size reported by block driver*/
+  off_t    fs_hwnsectors;          /* HW: The number of sectors reported by the hardware */
+  off_t    fs_fatbase;             /* Logical block of start of filesystem (past resd sectors) */
+  off_t    fs_rootbase;            /* MBR: Cluster no. of 1st cluster of root dir */
+  off_t    fs_database;            /* Logical block of start data sectors */
+  off_t    fs_fsinfo;              /* MBR: Sector number of FSINFO sector */
+  off_t    fs_currentsector;       /* The sector number buffered in fs_buffer */
   uint32_t fs_nclusters;           /* Maximum number of data clusters */
   uint32_t fs_nfatsects;           /* MBR: Count of sectors occupied by one fat */
   uint32_t fs_fattotsec;           /* MBR: Total count of sectors on the volume */
@@ -554,11 +554,11 @@
   uint8_t  ff_sectorsincluster;    /* Sectors remaining in cluster */
   uint16_t ff_dirindex;            /* Index into ff_dirsector to directory entry */
   uint32_t ff_currentcluster;      /* Current cluster being accessed */
-  size_t   ff_dirsector;           /* Sector containing the directory entry */
+  off_t    ff_dirsector;           /* Sector containing the directory entry */
   off_t    ff_size;                /* Size of the file in bytes */
-  size_t   ff_startcluster;        /* Start cluster of file on media */
-  size_t   ff_currentsector;       /* Current sector being operated on */
-  size_t   ff_cachesector;         /* Current sector in the file buffer */
+  off_t    ff_startcluster;        /* Start cluster of file on media */
+  off_t    ff_currentsector;       /* Current sector being operated on */
+  off_t    ff_cachesector;         /* Current sector in the file buffer */
   uint8_t *ff_buffer;              /* File buffer (for partial sector accesses) */
 };
 
@@ -615,16 +615,16 @@
 /* low-level hardware access */
 
 EXTERN int    fat_hwread(struct fat_mountpt_s *fs, uint8_t *buffer,
-                         size_t sector, unsigned int nsectors);
+                         off_t sector, unsigned int nsectors);
 EXTERN int    fat_hwwrite(struct fat_mountpt_s *fs, uint8_t *buffer,
-                          size_t sector, unsigned int nsectors);
+                          off_t sector, unsigned int nsectors);
 
 /* Cluster / cluster chain access helpers */
 
-EXTERN ssize_t fat_cluster2sector(struct fat_mountpt_s *fs,  uint32_t cluster);
-EXTERN ssize_t fat_getcluster(struct fat_mountpt_s *fs, uint32_t clusterno);
+EXTERN off_t  fat_cluster2sector(struct fat_mountpt_s *fs,  uint32_t cluster);
+EXTERN off_t  fat_getcluster(struct fat_mountpt_s *fs, uint32_t clusterno);
 EXTERN int    fat_putcluster(struct fat_mountpt_s *fs, uint32_t clusterno,
-                             size_t startsector);
+                             off_t startsector);
 EXTERN int    fat_removechain(struct fat_mountpt_s *fs, uint32_t cluster);
 EXTERN int32_t fat_extendchain(struct fat_mountpt_s *fs, uint32_t cluster);
 
@@ -648,15 +648,15 @@
 /* Mountpoint and file buffer cache (for partial sector accesses) */
 
 EXTERN int    fat_fscacheflush(struct fat_mountpt_s *fs);
-EXTERN int    fat_fscacheread(struct fat_mountpt_s *fs, size_t sector);
+EXTERN int    fat_fscacheread(struct fat_mountpt_s *fs, off_t sector);
 EXTERN int    fat_ffcacheflush(struct fat_mountpt_s *fs, struct fat_file_s *ff);
-EXTERN int    fat_ffcacheread(struct fat_mountpt_s *fs, struct fat_file_s *ff, size_t sector);
+EXTERN int    fat_ffcacheread(struct fat_mountpt_s *fs, struct fat_file_s *ff, off_t sector);
 EXTERN int    fat_ffcacheinvalidate(struct fat_mountpt_s *fs, struct fat_file_s *ff);
 
 /* FSINFO sector support */
 
 EXTERN int    fat_updatefsinfo(struct fat_mountpt_s *fs);
-EXTERN int    fat_nfreeclusters(struct fat_mountpt_s *fs, size_t *pfreeclusters);
+EXTERN int    fat_nfreeclusters(struct fat_mountpt_s *fs, off_t *pfreeclusters);
 EXTERN int    fat_currentsector(struct fat_mountpt_s *fs, struct fat_file_s *ff, off_t position);
 
 #undef EXTERN
diff --git a/fs/fat/fs_fat32util.c b/fs/fat/fs_fat32util.c
index a37f8fa..5bd5431 100644
--- a/fs/fat/fs_fat32util.c
+++ b/fs/fat/fs_fat32util.c
@@ -792,7 +792,7 @@
  *
  ****************************************************************************/
 
-int fat_hwread(struct fat_mountpt_s *fs, uint8_t *buffer,  size_t sector,
+int fat_hwread(struct fat_mountpt_s *fs, uint8_t *buffer,  off_t sector,
                unsigned int nsectors)
 {
   int ret = -ENODEV;
@@ -823,7 +823,7 @@
  *
  ****************************************************************************/
 
-int fat_hwwrite(struct fat_mountpt_s *fs, uint8_t *buffer, size_t sector,
+int fat_hwwrite(struct fat_mountpt_s *fs, uint8_t *buffer, off_t sector,
                 unsigned int nsectors)
 {
   int ret = -ENODEV;
@@ -855,7 +855,7 @@
  *
  ****************************************************************************/
 
-ssize_t fat_cluster2sector(struct fat_mountpt_s *fs,  uint32_t cluster )
+off_t fat_cluster2sector(struct fat_mountpt_s *fs,  uint32_t cluster )
 {
   cluster -= 2;
   if (cluster >= fs->fs_nclusters - 2)
@@ -874,7 +874,7 @@
  *
  ****************************************************************************/
 
-ssize_t fat_getcluster(struct fat_mountpt_s *fs, uint32_t clusterno)
+off_t fat_getcluster(struct fat_mountpt_s *fs, uint32_t clusterno)
 {
   /* Verify that the cluster number is within range */
 
@@ -888,7 +888,7 @@
         {
           case FSTYPE_FAT12 :
             {
-              size_t       fatsector;
+              off_t        fatsector;
               unsigned int fatoffset;
               unsigned int cluster;
               unsigned int fatindex;
@@ -959,7 +959,7 @@
           case FSTYPE_FAT16 :
             {
               unsigned int fatoffset = 2 * clusterno;
-              size_t       fatsector = fs->fs_fatbase + SEC_NSECTORS(fs, fatoffset);
+              off_t        fatsector = fs->fs_fatbase + SEC_NSECTORS(fs, fatoffset);
               unsigned int fatindex  = fatoffset & SEC_NDXMASK(fs);
 
               if (fat_fscacheread(fs, fatsector) < 0)
@@ -973,7 +973,7 @@
           case FSTYPE_FAT32 :
             {
               unsigned int fatoffset = 4 * clusterno;
-              size_t       fatsector = fs->fs_fatbase + SEC_NSECTORS(fs, fatoffset);
+              off_t        fatsector = fs->fs_fatbase + SEC_NSECTORS(fs, fatoffset);
               unsigned int fatindex  = fatoffset & SEC_NDXMASK(fs);
 
               if (fat_fscacheread(fs, fatsector) < 0)
@@ -990,7 +990,7 @@
 
   /* There is no cluster information, or an error occured */
 
-  return (ssize_t)-EINVAL;
+  return (off_t)-EINVAL;
 }
 
 /****************************************************************************
@@ -1000,7 +1000,7 @@
  *
  ****************************************************************************/
 
-int fat_putcluster(struct fat_mountpt_s *fs, uint32_t clusterno, size_t nextcluster)
+int fat_putcluster(struct fat_mountpt_s *fs, uint32_t clusterno, off_t nextcluster)
 {
   /* Verify that the cluster number is within range.  Zero erases the cluster. */
 
@@ -1014,7 +1014,7 @@
         {
           case FSTYPE_FAT12 :
             {
-              size_t       fatsector;
+              off_t        fatsector;
               unsigned int fatoffset;
               unsigned int fatindex;
               uint8_t      value;
@@ -1101,7 +1101,7 @@
           case FSTYPE_FAT16 :
             {
               unsigned int fatoffset = 2 * clusterno;
-              size_t       fatsector = fs->fs_fatbase + SEC_NSECTORS(fs, fatoffset);
+              off_t        fatsector = fs->fs_fatbase + SEC_NSECTORS(fs, fatoffset);
               unsigned int fatindex  = fatoffset & SEC_NDXMASK(fs);
 
               if (fat_fscacheread(fs, fatsector) < 0)
@@ -1116,7 +1116,7 @@
           case FSTYPE_FAT32 :
             {
               unsigned int fatoffset = 4 * clusterno;
-              size_t       fatsector = fs->fs_fatbase + SEC_NSECTORS(fs, fatoffset);
+              off_t        fatsector = fs->fs_fatbase + SEC_NSECTORS(fs, fatoffset);
               unsigned int fatindex  = fatoffset & SEC_NDXMASK(fs);
 
               if (fat_fscacheread(fs, fatsector) < 0)
@@ -1202,7 +1202,7 @@
 
 int32_t fat_extendchain(struct fat_mountpt_s *fs, uint32_t cluster)
 {
-  ssize_t  startsector;
+  off_t    startsector;
   uint32_t newcluster;
   uint32_t startcluster;
   int      ret;
@@ -1448,7 +1448,7 @@
 int fat_finddirentry(struct fat_mountpt_s *fs, struct fat_dirinfo_s *dirinfo,
                      const char *path)
 {
-  size_t cluster;
+  off_t  cluster;
   uint8_t *direntry = NULL;
   char terminator;
   int ret;
@@ -1605,7 +1605,7 @@
 int fat_allocatedirentry(struct fat_mountpt_s *fs, struct fat_dirinfo_s *dirinfo)
 {
   int32_t cluster;
-  size_t  sector;
+  off_t   sector;
   uint8_t *direntry;
   uint8_t ch;
   int     ret;
@@ -1839,7 +1839,7 @@
 {
   unsigned int startcluster;
   uint32_t     writetime;
-  size_t       savesector;
+  off_t        savesector;
   int          ret;
 
   /* Get start cluster of the file to truncate */
@@ -1948,7 +1948,7 @@
 {
   struct fat_dirinfo_s dirinfo;
   uint32_t  dircluster;
-  size_t  dirsector;
+  off_t   dirsector;
   int     ret;
 
   /* Find the directory entry referring to the entry to be deleted */
@@ -2172,7 +2172,7 @@
  *
  ****************************************************************************/
 
-int fat_fscacheread(struct fat_mountpt_s *fs, size_t sector)
+int fat_fscacheread(struct fat_mountpt_s *fs, off_t sector)
 {
   int ret;
 
@@ -2251,7 +2251,7 @@
  *
  ****************************************************************************/
 
-int fat_ffcacheread(struct fat_mountpt_s *fs, struct fat_file_s *ff, size_t sector)
+int fat_ffcacheread(struct fat_mountpt_s *fs, struct fat_file_s *ff, off_t sector)
 {
   int ret;
 
@@ -2374,7 +2374,7 @@
  *
  ****************************************************************************/
 
-int fat_nfreeclusters(struct fat_mountpt_s *fs, size_t *pfreeclusters)
+int fat_nfreeclusters(struct fat_mountpt_s *fs, off_t *pfreeclusters)
 {
   uint32_t nfreeclusters;
 
@@ -2391,7 +2391,7 @@
   nfreeclusters = 0;
   if (fs->fs_type == FSTYPE_FAT12)
     {
-      size_t sector;
+      off_t sector;
 
       /* Examine every cluster in the fat */
 
@@ -2409,7 +2409,7 @@
   else
     {
       unsigned int cluster;
-      size_t       fatsector;
+      off_t        fatsector;
       unsigned int offset;
       int          ret;
 
diff --git a/fs/fat/fs_writefat.c b/fs/fat/fs_writefat.c
index 0d35baa..714ad38 100644
--- a/fs/fat/fs_writefat.c
+++ b/fs/fat/fs_writefat.c
@@ -1,7 +1,7 @@
 /****************************************************************************
  * fs/fat/fs_writefat.c
  *
- *   Copyright (C) 2008-2009 Gregory Nutt. All rights reserved.
+ *   Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved.
  *   Author: Gregory Nutt <spudmonkey@racsa.co.cr>
  *
  * Redistribution and use in source and binary forms, with or without
@@ -388,7 +388,7 @@
 static inline int mkfatfs_writefat(FAR struct fat_format_s *fmt,
                                    FAR struct fat_var_s *var)
 {
-  size_t offset = fmt->ff_rsvdseccount;
+  off_t offset = fmt->ff_rsvdseccount;
   int fatno;
   int sectno;
   int ret;
@@ -471,7 +471,7 @@
 static inline int mkfatfs_writerootdir(FAR struct fat_format_s *fmt,
                                        FAR struct fat_var_s *var)
 {
-  size_t offset = fmt->ff_rsvdseccount + fmt->ff_nfats * var->fv_nfatsects;
+  off_t offset = fmt->ff_rsvdseccount + fmt->ff_nfats * var->fv_nfatsects;
   int ret;
   int i;
 
diff --git a/fs/romfs/fs_romfs.c b/fs/romfs/fs_romfs.c
index b2ffffa..ca42093 100644
--- a/fs/romfs/fs_romfs.c
+++ b/fs/romfs/fs_romfs.c
@@ -469,7 +469,7 @@
 {
   struct romfs_mountpt_s *rm;
   struct romfs_file_s    *rf;
-  ssize_t                 position;
+  off_t                   position;
   int                     ret;
 
   fvdbg("Seek to offset: %d whence: %d\n", offset, whence);
diff --git a/include/sys/statfs.h b/include/sys/statfs.h
index 7f80902..d37b056 100644
--- a/include/sys/statfs.h
+++ b/include/sys/statfs.h
@@ -108,13 +108,13 @@
 struct statfs
 {
   uint32_t f_type;     /* Type of filesystem (see definitions above) */
+  size_t   f_namelen;  /* Maximum length of filenames */
   size_t   f_bsize;    /* Optimal block size for transfers */
-  size_t   f_blocks;   /* Total data blocks in the file system of this size */
-  size_t   f_bfree;    /* Free blocks in the file system */
-  size_t   f_bavail;   /* Free blocks avail to non-superuser */
-  size_t   f_files;    /* Total file nodes in the file system */
-  size_t   f_ffree;    /* Free file nodes in the file system */
-  uint32_t f_namelen;  /* Maximum length of filenames */
+  off_t    f_blocks;   /* Total data blocks in the file system of this size */
+  off_t    f_bfree;    /* Free blocks in the file system */
+  off_t    f_bavail;   /* Free blocks avail to non-superuser */
+  off_t    f_files;    /* Total file nodes in the file system */
+  off_t    f_ffree;    /* Free file nodes in the file system */
 };
 
 /****************************************************************************
diff --git a/include/sys/types.h b/include/sys/types.h
index 43731f1..5215982 100644
--- a/include/sys/types.h
+++ b/include/sys/types.h
@@ -121,7 +121,7 @@
 
 typedef unsigned int mode_t;
 
-/* size_t is used for sizes of objects.
+/* size_t is used for sizes of memory objects.
  * ssize_t is used for a count of bytes or an error indication.
  */
 
@@ -161,15 +161,23 @@
 /* blkcnt_t and off_t are signed integer types.
  *
  *   blkcnt_t is used for file block counts.
- *   off_t is used for file sizes.
+ *   off_t is used for file offsets and sizes.
+ *   fpos_t is used for file positions.
  *
- * Hence, both should be independent of processor architecture.
+ * Hence, all should be independent of processor architecture.
  */
 
 typedef uint32_t     blkcnt_t;
 typedef int32_t      off_t;
 typedef off_t        fpos_t;
 
+/* Large file versions */
+
+#ifdef CONFIG_HAVE_LONG_LONG
+typedef int64_t      off64_t;
+typedef int64_t      fpos64_t;
+#endif
+
 /* blksize_t is a signed integer value used for file block sizes */
 
 typedef int16_t      blksize_t;