From 850816f8174feed3013564828cc940e0a33d637e Mon Sep 17 00:00:00 2001 From: patacongo Date: Sun, 10 Aug 2008 14:50:27 +0000 Subject: [PATCH] Added mkfatfs() test git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@806 7fd9a85b-ad96-42d3-883c-3090e2eb8679 --- nuttx/COPYING | 44 ++++++++++ nuttx/ChangeLog | 1 + nuttx/Documentation/NuttX.html | 3 +- nuttx/examples/README.txt | 23 ++++- nuttx/examples/mount/Makefile | 2 +- nuttx/examples/mount/mount.h | 92 ++++++++++++++++++++ nuttx/examples/mount/mount_main.c | 72 +++++++++------- nuttx/examples/mount/ramdisk.c | 138 ++++++++++++++++++++++++++++++ nuttx/fs/fat/fs_configfat.c | 35 ++++++-- nuttx/fs/fat/fs_mkfatfs.c | 4 +- nuttx/fs/fs_closeblockdriver.c | 2 +- nuttx/include/nuttx/mkfatfs.h | 8 +- 12 files changed, 375 insertions(+), 49 deletions(-) create mode 100755 nuttx/COPYING create mode 100644 nuttx/examples/mount/mount.h create mode 100644 nuttx/examples/mount/ramdisk.c diff --git a/nuttx/COPYING b/nuttx/COPYING new file mode 100755 index 000000000..0fa6c256c --- /dev/null +++ b/nuttx/COPYING @@ -0,0 +1,44 @@ +/************************************************************************* + * * + * COPYING -- Describes the terms under which Nuttx is distributed. A * + * copy of the BSD-style licensing is included in this file. In my * + * words -- I believe that you should free to use NuttX in any * + * environmnet, private, private, commercial, open, closed, etc. * + * provided only that you repect the modest copyright notices as * + * described in license (below). Please feel free to contact me if you * + * have any licensing concerns. * + * * + ************************************************************************* + * * + * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. * + * Author: Gregory Nutt * + * * + * Redistribution and use in source and binary forms, with or without * + * modification, are permitted provided that the following conditions * + * are met: * + * * + * 1. Redistributions of source code must retain the above copyright * + * notice, this list of conditions and the following disclaimer. * + * 2. Redistributions in binary form must reproduce the above copyright * + * notice, this list of conditions and the following disclaimer in * + * the documentation and/or other materials provided with the * + * distribution. * + * 3. Neither the name NuttX nor the names of its contributors may be * + * used to endorse or promote products derived from this software * + * without specific prior written permission. * + * * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * + * POSSIBILITY OF SUCH DAMAGE. * + * * + *************************************************************************/ + diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 7eea38726..9e2e4347b 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -389,4 +389,5 @@ * Moved all FAT related files from fs to fs/fat * Implemented mkfatfs(), a non-standard API to create a FAT filesystem on a block device (not yet tested). + * Added a test for mkfatfs() on a RAM disk in examples/mount diff --git a/nuttx/Documentation/NuttX.html b/nuttx/Documentation/NuttX.html index 0de2ec94d..fc53f66ef 100644 --- a/nuttx/Documentation/NuttX.html +++ b/nuttx/Documentation/NuttX.html @@ -8,7 +8,7 @@

NuttX RTOS

-

Last Updated: August 9, 2008

+

Last Updated: August 10, 2008

@@ -1038,6 +1038,7 @@ nuttx-0.3.12 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> * Moved all FAT related files from fs to fs/fat * Implemented mkfatfs(), a non-standard API to create a FAT filesystem on a block device (not yet tested). + * Added a test for mkfatfs() on a RAM disk in examples/mount pascal-0.1.3 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> diff --git a/nuttx/examples/README.txt b/nuttx/examples/README.txt index d7b46d924..3b09768d5 100644 --- a/nuttx/examples/README.txt +++ b/nuttx/examples/README.txt @@ -109,7 +109,22 @@ examples/mount This contains a simple test of filesystem mountpoints. * CONFIG_EXAMPLES_MOUNT_DEVNAME - The name of the device to mount. Default: "/dev/ram0" + The name of the user-provided block device to mount. + If CONFIG_EXAMPLES_MOUNT_DEVNAME is not provided, then + a RAM disk will be configured. + + * CONFIG_EXAMPLES_MOUNT_NSECTORS + The number of "sectors" in the RAM disk used when + CONFIG_EXAMPLES_MOUNT_DEVNAME is not defined. + + * CONFIG_EXAMPLES_MOUNT_SECTORSIZE + The size of each sectors in the RAM disk used when + CONFIG_EXAMPLES_MOUNT_DEVNAME is not defined. + + * CONFIG_EXAMPLES_MOUNT_RAMDEVNO + The RAM device minor number used to mount the RAM disk used + when CONFIG_EXAMPLES_MOUNT_DEVNAME is not defined. The + default is zero (meaning that "/dev/ram0" will be used). examples/null ^^^^^^^^^^^^^ @@ -144,6 +159,8 @@ examples/pashello examples/pipe ^^^^^^^^^^^^^ -A test of the mkfifo() and pipe() APIs. - + A test of the mkfifo() and pipe() APIs. + * CONFIG_EXAMPLES_PIPE_STACKSIZE + Sets the size of the stack to use when creating the child tasks. + The default size is 1024. diff --git a/nuttx/examples/mount/Makefile b/nuttx/examples/mount/Makefile index 71e75ed9b..084fc8fb6 100644 --- a/nuttx/examples/mount/Makefile +++ b/nuttx/examples/mount/Makefile @@ -38,7 +38,7 @@ ASRCS = AOBJS = $(ASRCS:.S=$(OBJEXT)) -CSRCS = mount_main.c +CSRCS = mount_main.c ramdisk.c COBJS = $(CSRCS:.c=$(OBJEXT)) SRCS = $(ASRCS) $(CSRCS) diff --git a/nuttx/examples/mount/mount.h b/nuttx/examples/mount/mount.h new file mode 100644 index 000000000..388a6200b --- /dev/null +++ b/nuttx/examples/mount/mount.h @@ -0,0 +1,92 @@ +/**************************************************************************** + * examples/mount/mount.h + * + * Copyright (C) 2008 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __EXAMPLES_MOUNT_MOUNT_H +#define __EXAMPLES_MOUNT_MOUNT_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/* Configure the test */ + +#if defined(CONFIG_EXAMPLES_MOUNT_DEVNAME) +# undef CONFIG_EXAMPLES_MOUNT_NSECTORS +# undef CONFIG_EXAMPLES_MOUNT_SECTORSIZE +# undef CONFIG_EXAMPLES_MOUNT_RAMDEVNO +# define MOUNT_DEVNAME CONFIG_EXAMPLES_MOUNT_DEVNAME +#else +# if !defined(CONFIG_FS_FAT) +# error "CONFIG_FS_FAT required in this configuration" +# endif +# if !defined(CONFIG_EXAMPLES_MOUNT_SECTORSIZE) +# define CONFIG_EXAMPLES_MOUNT_SECTORSIZE 512 +# endif +# if !defined(CONFIG_EXAMPLES_MOUNT_NSECTORS) +# define CONFIG_EXAMPLES_MOUNT_NSECTORS 2048 +# endif +# if !defined(CONFIG_EXAMPLES_MOUNT_RAMDEVNO) +# define CONFIG_EXAMPLES_MOUNT_RAMDEVNO 0 +# endif +# define MKMOUNT_DEVNAME(m) "/dev/ram" #m +# define MOUNT_DEVNAME MKMOUNT_DEVNAME(CONFIG_EXAMPLES_MOUNT_RAMDEVNO) +#endif + + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/**************************************************************************** + * Public Variables + ****************************************************************************/ + +extern const char g_source[]; /* Mount 'source' path */ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#ifndef CONFIG_EXAMPLES_MOUNT_DEVNAME +extern int create_ramdisk(void); +#endif + +#endif /* __EXAMPLES_MOUNT_MOUNT_H */ diff --git a/nuttx/examples/mount/mount_main.c b/nuttx/examples/mount/mount_main.c index bd792ee11..3959abefb 100644 --- a/nuttx/examples/mount/mount_main.c +++ b/nuttx/examples/mount/mount_main.c @@ -50,14 +50,12 @@ #include #include +#include "mount.h" + /**************************************************************************** * Definitions ****************************************************************************/ -#ifndef CONFIG_EXAMPLES_MOUNT_DEVNAME -# define CONFIG_EXAMPLES_MOUNT_DEVNAME "/dev/ram0" -#endif - #define TEST_USE_STAT 1 #define TEST_SHOW_DIRECTORIES 1 #define TEST_USE_STATFS 1 @@ -70,7 +68,6 @@ * Private Data ****************************************************************************/ -static const char g_source[] = CONFIG_EXAMPLES_MOUNT_DEVNAME; static const char g_mntdir[] = "/mnt"; static const char g_target[] = "/mnt/fs"; static const char g_filesystemtype[] = "vfat"; @@ -89,6 +86,12 @@ static int g_nerrors = 0; static char g_namebuffer[256]; +/**************************************************************************** + * Public Data + ****************************************************************************/ + + const char g_source[] = MOUNT_DEVNAME; + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -157,7 +160,7 @@ static void show_statfs(const char *path) else { printf("show_statfs: ERROR statfs(%s) failed with errno=%d\n", - path, *get_errno_ptr()); + path, errno); g_nerrors++; } } @@ -179,7 +182,8 @@ static void show_directories(const char *path, int indent) dirp = opendir(path); if ( !dirp ) { - printf("show_directories: ERROR opendir(\"%s\") failed with errno=%d\n", path, *get_errno_ptr()); + printf("show_directories: ERROR opendir(\"%s\") failed with errno=%d\n", + path, errno); g_nerrors++; return; } @@ -228,10 +232,10 @@ static void fail_read_open(const char *path, int expectederror) g_nerrors++; close(fd); } - else if (*get_errno_ptr() != expectederror) + else if (errno != expectederror) { printf("fail_read_open: ERROR open(%s) failed with errno=%d (expected %d)\n", - path, *get_errno_ptr(), expectederror); + path, errno, expectederror); g_nerrors++; } } @@ -254,7 +258,7 @@ static void read_test_file(const char *path) if (fd < 0) { printf("read_test_file: ERROR failed to open %s, errno=%d\n", - path, *get_errno_ptr()); + path, errno); g_nerrors++; } else @@ -264,7 +268,7 @@ static void read_test_file(const char *path) if (nbytes < 0) { printf("read_test_file: ERROR failed to read from %s, errno=%d\n", - path, *get_errno_ptr()); + path, errno); g_nerrors++; } else @@ -292,7 +296,7 @@ static void write_test_file(const char *path) if (fd < 0) { printf("write_test_file: ERROR failed to open %s for writing, errno=%d\n", - path, *get_errno_ptr()); + path, errno); g_nerrors++; } else @@ -301,7 +305,7 @@ static void write_test_file(const char *path) if (nbytes < 0) { printf("write_test_file: ERROR failed to write to %s, errno=%d\n", - path, *get_errno_ptr()); + path, errno); g_nerrors++; } else @@ -330,10 +334,10 @@ static void fail_mkdir(const char *path, int expectederror) printf("fail_mkdir: ERROR mkdir(%s) succeeded\n", path); g_nerrors++; } - else if (*get_errno_ptr() != expectederror) + else if (errno != expectederror) { printf("fail_mkdir: ERROR mkdir(%s) failed with errno=%d (expected %d)\n", - path, *get_errno_ptr(), expectederror); + path, errno, expectederror); g_nerrors++; } } @@ -352,7 +356,7 @@ static void succeed_mkdir(const char *path) if (ret != 0) { printf("succeed_mkdir: ERROR mkdir(%s) failed with errno=%d\n", - path, *get_errno_ptr()); + path, errno); g_nerrors++; } } @@ -375,10 +379,10 @@ static void fail_rmdir(const char *path, int expectederror) printf("fail_rmdir: ERROR rmdir(%s) succeeded\n", path); g_nerrors++; } - else if (*get_errno_ptr() != expectederror) + else if (errno != expectederror) { printf("fail_rmdir: ERROR rmdir(%s) failed with errno=%d (expected %d)\n", - path, *get_errno_ptr(), expectederror); + path, errno, expectederror); g_nerrors++; } } @@ -397,7 +401,7 @@ static void succeed_rmdir(const char *path) if (ret != 0) { printf("succeed_rmdir: ERROR rmdir(%s) failed with errno=%d\n", - path, *get_errno_ptr()); + path, errno); g_nerrors++; } } @@ -420,10 +424,10 @@ static void fail_unlink(const char *path, int expectederror) printf("fail_unlink: ERROR unlink(%s) succeeded\n", path); g_nerrors++; } - else if (*get_errno_ptr() != expectederror) + else if (errno != expectederror) { printf("fail_unlink: ERROR unlink(%s) failed with errno=%d (expected %d)\n", - path, *get_errno_ptr(), expectederror); + path, errno, expectederror); g_nerrors++; } } @@ -444,7 +448,7 @@ static void succeed_unlink(const char *path) if (ret != 0) { printf("succeed_unlink: ERROR unlink(%s) failed with errno=%d\n", - path, *get_errno_ptr()); + path, errno); g_nerrors++; } } @@ -468,10 +472,10 @@ static void fail_rename(const char *oldpath, const char *newpath, int expecteder oldpath, newpath); g_nerrors++; } - else if (*get_errno_ptr() != expectederror) + else if (errno != expectederror) { printf("fail_rename: ERROR rename(%s->%s) failed with errno=%d (expected %d)\n", - oldpath, newpath, *get_errno_ptr(), expectederror); + oldpath, newpath, errno, expectederror); g_nerrors++; } } @@ -490,7 +494,7 @@ static void succeed_rename(const char *oldpath, const char *newpath) if (ret != 0) { printf("succeed_rename: ERROR rename(%s->%s) failed with errno=%d\n", - oldpath, newpath, *get_errno_ptr()); + oldpath, newpath, errno); g_nerrors++; } } @@ -516,10 +520,10 @@ static void fail_stat(const char *path, int expectederror) show_stat(path, &buf); g_nerrors++; } - else if (*get_errno_ptr() != expectederror) + else if (errno != expectederror) { printf("fail_stat: ERROR stat(%s) failed with errno=%d (expected %d)\n", - path, *get_errno_ptr(), expectederror); + path, errno, expectederror); g_nerrors++; } } @@ -543,7 +547,7 @@ static void succeed_stat(const char *path) if (ret != 0) { printf("succeed_stat: ERROR stat(%s) failed with errno=%d\n", - path, *get_errno_ptr()); + path, errno); g_nerrors++; } else @@ -576,6 +580,16 @@ int user_start(int argc, char *argv[]) { int ret; +#ifndef CONFIG_EXAMPLES_MOUNT_DEVNAME + /* Create a RAM disk for the test */ + + ret = create_ramdisk(); + if (ret < 0) + { + printf("user_start: ERROR failed to create RAM disk\n"); + } +#endif + /* Mount the test file system (see arch/sim/src/up_deviceimage.c */ printf("user_start: mounting %s filesystem at target=%s with source=%s\n", @@ -722,7 +736,7 @@ int user_start(int argc, char *argv[]) ret = umount(g_target); if (ret != 0) { - printf("user_start: ERROR umount() failed, errno %d\n", *get_errno_ptr()); + printf("user_start: ERROR umount() failed, errno %d\n", errno); g_nerrors++; } diff --git a/nuttx/examples/mount/ramdisk.c b/nuttx/examples/mount/ramdisk.c new file mode 100644 index 000000000..47238e336 --- /dev/null +++ b/nuttx/examples/mount/ramdisk.c @@ -0,0 +1,138 @@ +/**************************************************************************** + * examples/mount/ramdisk.c + * + * Copyright (C) 2008 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include "mount.h" + +#ifndef CONFIG_EXAMPLES_MOUNT_DEVNAME + +/**************************************************************************** + * Private Definitions + ****************************************************************************/ + +#define BUFFER_SIZE (CONFIG_EXAMPLES_MOUNT_NSECTORS*CONFIG_EXAMPLES_MOUNT_SECTORSIZE) + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static struct fat_format_s g_fmt = FAT_FORMAT_INITIALIZER; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: create_ramdisk + * + * Description: + * Create a RAM disk of the specified size formatting with a FAT file + * system + * + * Input Parameters: + * None + * + * Return: + * Zero on success, a negated errno on failure. + * + ****************************************************************************/ + +int create_ramdisk(void) +{ + char *pbuffer; + int ret; + + /* Allocate a buffer to hold the file system image. */ + + pbuffer = (char*)malloc(BUFFER_SIZE); + if (!pbuffer) + { + dbg("Failed to allocate ramdisk of size %d\n", BUFFER_SIZE); + return -ENOMEM; + } + + /* Register a RAMDISK device to manage this RAM image */ + + ret = rd_register(CONFIG_EXAMPLES_MOUNT_RAMDEVNO, + pbuffer, + CONFIG_EXAMPLES_MOUNT_NSECTORS, + CONFIG_EXAMPLES_MOUNT_NSECTORS, + TRUE); + if (ret < 0) + { + dbg("Failed to register ramdisk at %s\n", g_source); + free(pbuffer); + return ret; + } + + /* Create a FAT filesystem on the ramdisk */ + + ret = mkfatfs(g_source, &g_fmt); + if (ret < 0) + { + dbg("Failed to create FAT filesystem on ramdisk at %s\n", g_source); + /* free(pbuffer); -- RAM disk is registered */ + return ret; + } + + return 0; +} +#endif /* !CONFIG_EXAMPLES_MOUNT_DEVNAME */ diff --git a/nuttx/fs/fat/fs_configfat.c b/nuttx/fs/fat/fs_configfat.c index d69c483ad..5177da5b6 100644 --- a/nuttx/fs/fat/fs_configfat.c +++ b/nuttx/fs/fat/fs_configfat.c @@ -136,8 +136,13 @@ static inline uint32 mkfatfs_nfatsect12(FAR struct fat_format_s *fmt, FAR struct fat_var_s *var, uint32 navailsects) { - uint32 denom ; +#ifdef CONFIG_HAVE_LONG_LONG + uint64 denom; + uint64 numer; +#else + uint32 denom; uint32 numer; +#endif /* For FAT12, the cluster number is held in a 12-bit number or 1.5 bytes per * cluster reference. So each FAT sector will hold sectorsize/1.5 cluster @@ -165,18 +170,24 @@ mkfatfs_nfatsect12(FAR struct fat_format_s *fmt, FAR struct fat_var_s *var, * navailsects > 0x55555555 - 2 * clustersize */ +#ifndef CONFIG_HAVE_LONG_LONG if (navailsects <= (0x55555555 - (1 << (fmt->ff_clustshift + 1)))) { +#endif + denom = (fmt->ff_nfats << 1) + fmt->ff_nfats + (var->fv_sectorsize << (fmt->ff_clustshift + 1)); numer = (navailsects << 1) + navailsects + (1 << (fmt->ff_clustshift + 2)) + (1 << (fmt->ff_clustshift + 1)); - return (numer + denom - 1) / denom; + return (uint32)((numer + denom - 1) / denom); + +#ifndef CONFIG_HAVE_LONG_LONG } else { return 0; } +#endif } /**************************************************************************** @@ -202,8 +213,13 @@ static inline uint32 mkfatfs_nfatsect16(FAR struct fat_format_s *fmt, FAR struct fat_var_s *var, uint32 navailsects) { +#ifdef CONFIG_HAVE_LONG_LONG + uint64 denom; + uint64 numer; +#else uint32 denom; uint32 numer; +#endif /* For FAT16, the cluster number is held in a 16-bit number or 2 bytes per * cluster reference. So each FAT sector will hold sectorsize/2 cluster @@ -237,7 +253,7 @@ mkfatfs_nfatsect16(FAR struct fat_format_s *fmt, FAR struct fat_var_s *var, denom = fmt->ff_nfats + (var->fv_sectorsize << (fmt->ff_clustshift - 1)); numer = navailsects + (1 << (fmt->ff_clustshift + 1)); } - return (numer + denom - 1) / denom; + return (uint32)((numer + denom - 1) / denom); } /**************************************************************************** @@ -263,8 +279,13 @@ static inline uint32 mkfatfs_nfatsect32(FAR struct fat_format_s *fmt, FAR struct fat_var_s *var, uint32 navailsects) { +#ifdef CONFIG_HAVE_LONG_LONG + uint64 denom; + uint64 numer; +#else uint32 denom; uint32 numer; +#endif /* For FAT32, the cluster number is held in a 32-bit number or 4 bytes per * cluster reference. So each FAT sector will hold sectorsize/4 cluster @@ -283,7 +304,7 @@ mkfatfs_nfatsect32(FAR struct fat_format_s *fmt, FAR struct fat_var_s *var, * nfatsects = (navailsects + 3 * clustersize) / * (nfats + sectorsize * clustersize / 4) * - * Overflow in the calculation of the numerator could occur if: + * Overflow in the 32-bit calculation of the numerator could occur if: * * navailsects > 0xffffffff - 3 * clustersize */ @@ -303,7 +324,7 @@ mkfatfs_nfatsect32(FAR struct fat_format_s *fmt, FAR struct fat_var_s *var, denom = fmt->ff_nfats + (var->fv_sectorsize << (fmt->ff_clustshift - 2)); numer = navailsects + (1 << (fmt->ff_clustshift + 1)) + (1 << fmt->ff_clustshift); } - return (numer + denom - 1) / denom; + return (uint32)((numer + denom - 1) / denom); } /**************************************************************************** @@ -885,7 +906,7 @@ int mkfatfs_configfatfs(FAR struct fat_format_s *fmt, if (fmt->ff_backupboot <= 1 || fmt->ff_backupboot >= fmt->ff_rsvdseccount) { - fdbg("Invalid backup boot sector: %d\n", fmt->ff_backupboot) + fdbg("Invalid backup boot sector: %d\n", fmt->ff_backupboot); fmt->ff_backupboot = 0; } @@ -922,7 +943,7 @@ int mkfatfs_configfatfs(FAR struct fat_format_s *fmt, fdbg("Sector size: %d bytes\n", var->fv_sectorsize); fdbg("Number of sectors: %d sectors\n", fmt->ff_nsectors); fdbg("FAT size: %d bits\n", var->fv_fattype); - fdbg("Number FATs: %d\n", fmt->ff_fats); + fdbg("Number FATs: %d\n", fmt->ff_nfats); fdbg("Sectors per cluster: %d sectors\n", 1 << fmt->ff_clustshift); fdbg("FS size: %d sectors\n", var->fv_nfatsects); fdbg(" %d clusters\n", var->fv_nclusters); diff --git a/nuttx/fs/fat/fs_mkfatfs.c b/nuttx/fs/fat/fs_mkfatfs.c index 9fd902b4b..ce467e8ab 100644 --- a/nuttx/fs/fat/fs_mkfatfs.c +++ b/nuttx/fs/fat/fs_mkfatfs.c @@ -104,7 +104,7 @@ static inline int mkfatfs_getgeometry(FAR struct fat_format_s *fmt, if (fmt->ff_nsectors > geometry.geo_nsectors) { fdbg("User maxblocks (%d) exceeds blocks on device (%d)\n", - mt->ff_maxblocks, geometry.geo_nsectors); + fmt->ff_nsectors, geometry.geo_nsectors); return -EINVAL; } } @@ -197,7 +197,7 @@ int mkfatfs(FAR const char *pathname, FAR struct fat_format_s *fmt) if (fmt->ff_nfats < 1 || fmt->ff_nfats > 4) { - fdbg("Invalid number of fats: %d\n", fmt->ff_fats); + fdbg("Invalid number of fats: %d\n", fmt->ff_nfats); ret = -EINVAL; goto errout; } diff --git a/nuttx/fs/fs_closeblockdriver.c b/nuttx/fs/fs_closeblockdriver.c index 62f1e991b..07c7cacca 100644 --- a/nuttx/fs/fs_closeblockdriver.c +++ b/nuttx/fs/fs_closeblockdriver.c @@ -87,7 +87,7 @@ int close_blockdriver(FAR struct inode *inode) if (!INODE_IS_BLOCK(inode)) { - fdbg("%s is not a block driver\n", pathname); + fdbg("inode is not a block driver\n"); ret = -ENOTBLK; goto errout; } diff --git a/nuttx/include/nuttx/mkfatfs.h b/nuttx/include/nuttx/mkfatfs.h index c5187a772..7f43c8673 100644 --- a/nuttx/include/nuttx/mkfatfs.h +++ b/nuttx/include/nuttx/mkfatfs.h @@ -47,7 +47,6 @@ * Definitions ****************************************************************************/ -#define MKFATFS_DEFAULT_BBCHECK FALSE /* FALSE: No bad block check */ #define MKFATFS_DEFAULT_NFATS 2 /* 2: Default number of FATs */ #define MKFATFS_DEFAULT_FATTYPE 0xff /* 0: Autoselect FAT size */ #define MKFATFS_DEFAULT_CLUSTSIZE 0 /* 0: Autoselect cluster size */ @@ -57,12 +56,11 @@ #define MKFATFS_DEFAULT_RSVDSECCOUNT 0 /* 0: Autoselect number reserved sectors (usually 32) */ #define MKFATFS_DEFAULT_HIDSEC 0 /* No hidden sectors */ #define MKFATFS_DEFAULT_VOLUMEID 0 /* No volume ID */ -#define MKFATFS_DEFAULT_MAXBLOCKS 0 /* 0: Use all blocks on device */ +#define MKFATFS_DEFAULT_NSECTORS 0 /* 0: Use all sectors on device */ #define FAT_FORMAT_INITIALIZER \ { \ - MKFATFS_DEFAULT_BBCHECK, \ - MKFATFS_DEFAULT_NFAT, \ + MKFATFS_DEFAULT_NFATS, \ MKFATFS_DEFAULT_FATTYPE, \ MKFATFS_DEFAULT_CLUSTSIZE, \ MKFATFS_DEFAULT_VOLUMELABEL, \ @@ -71,7 +69,7 @@ MKFATFS_DEFAULT_RSVDSECCOUNT, \ MKFATFS_DEFAULT_HIDSEC, \ MKFATFS_DEFAULT_VOLUMEID, \ - MKFATFS_DEFAULT_MAXBLOCKS \ + MKFATFS_DEFAULT_NSECTORS \ } /****************************************************************************