From 7866c38227f42969d228bd62ac6f51a6623102e7 Mon Sep 17 00:00:00 2001 From: patacongo Date: Wed, 10 Sep 2008 19:29:24 +0000 Subject: [PATCH] ROMFS filesystem support git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@903 7fd9a85b-ad96-42d3-883c-3090e2eb8679 --- nuttx/ChangeLog | 1 + nuttx/Documentation/NuttShell.html | 32 ++++++++----- nuttx/Documentation/NuttX.html | 12 ++++- nuttx/Documentation/NuttxPortingGuide.html | 13 +++++ nuttx/arch/sim/src/up_blockdevice.c | 2 +- nuttx/configs/ntosd-dm320/nsh/defconfig | 2 + nuttx/configs/sim/mount/defconfig | 2 + nuttx/configs/sim/nettest/defconfig | 4 +- nuttx/configs/sim/ostest/defconfig | 4 +- nuttx/configs/sim/pashello/defconfig | 4 +- nuttx/drivers/ramdisk.c | 56 ++++++++++++++++------ nuttx/examples/mount/mount.h | 3 ++ nuttx/examples/mount/ramdisk.c | 2 +- nuttx/examples/nsh/README.txt | 28 ++++++----- nuttx/examples/nsh/nsh.h | 16 ++++--- nuttx/examples/nsh/nsh_fscmds.c | 26 +++++----- nuttx/examples/nsh/nsh_main.c | 18 +++---- nuttx/fs/Makefile | 7 +-- nuttx/fs/fs_internal.h | 30 +++++++++--- nuttx/fs/fs_mount.c | 8 +++- nuttx/include/nuttx/ramdisk.h | 13 +++-- nuttx/tools/mkconfig.c | 34 +++++++++++-- 22 files changed, 227 insertions(+), 90 deletions(-) diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index ccb4e4e36..eb05614ae 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -463,3 +463,4 @@ random access to large files. 0.3.15 2008-xx-xx Gregory Nutt + * Add support for ROMFS filesystem (initial checkin untested) diff --git a/nuttx/Documentation/NuttShell.html b/nuttx/Documentation/NuttShell.html index bedb624f8..d25d6d8c4 100644 --- a/nuttx/Documentation/NuttShell.html +++ b/nuttx/Documentation/NuttShell.html @@ -8,7 +8,7 @@

NuttShell (NSH)

-

Last Updated: September 5, 2008

+

Last Updated: September 10, 2008

@@ -1485,7 +1485,7 @@ nsh> cd - !CONFIG_DISABLE_ENVIRON && CONFIG_NFILE_DESCRIPTORS > 0 + !CONFIG_DISABLE_ENVIRON && CONFIG_NFILE_DESCRIPTORS > 0 cp @@ -1530,11 +1530,11 @@ nsh> mkdir - !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 + !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_WRITABLE4 mkfatfs - !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_FAT + !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_FAT mkfifo @@ -1542,11 +1542,11 @@ nsh> mkrd - !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_FAT + !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_WRITABLE4 mount - !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_FAT + !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_READABLE3 ping @@ -1569,11 +1569,11 @@ nsh> rm - !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 + !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_WRITABLE4 rmdir - !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 + !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_WRITABLE4 set @@ -1593,7 +1593,7 @@ nsh> umount - !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_FAT + !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_READABLE3 unset @@ -1606,10 +1606,18 @@ nsh>

1 - Because of hardware padding, the actual required packet size may be larger

-

2 + Because of hardware padding, the actual required packet size may be larger
+ 2 Special TFTP server start-up optionss will probably be required to permit - creation of files for the correct operation of the put command.

+ creation of files for the correct operation of the put command.
+ 3 + CONFIG_FS_READABLE is not a user configuration but is set automatically + if any readable filesystem is selected. At present, this is either CONFIG_FS_FAT + or CONFIG_FS_ROMFS.
+ 4 + CONFIG_FS_WRITABLE is not a user configuration but is set automatically + if any writable filesystem is selected. At present, this is only CONFIG_FS_FAT.
+

diff --git a/nuttx/Documentation/NuttX.html b/nuttx/Documentation/NuttX.html index 2e8aa1106..9dc58d909 100644 --- a/nuttx/Documentation/NuttX.html +++ b/nuttx/Documentation/NuttX.html @@ -8,7 +8,7 @@

NuttX RTOS

-

Last Updated: September 8, 2008

+

Last Updated: September 10, 2008

@@ -379,10 +379,17 @@

-

  • VFAT filesystem support.
  • +
  • FAT12/16/32 filesystem support.
  • + +
    + +

    +

  • ROMFS filesystem support.
  • +

    + @@ -1090,6 +1097,7 @@ buildroot-0.1.0 2007-03-09 <spudmonkey@racsa.co.cr>
      nuttx-0.3.15 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> + * Add support for ROMFS filesystem (initial checkin untested) pascal-0.1.3 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> diff --git a/nuttx/Documentation/NuttxPortingGuide.html b/nuttx/Documentation/NuttxPortingGuide.html index 2f29e0b01..d9bb8a662 100644 --- a/nuttx/Documentation/NuttxPortingGuide.html +++ b/nuttx/Documentation/NuttxPortingGuide.html @@ -1515,6 +1515,19 @@ The system can be re-made subsequently by just typing make.
    +

    File Systems

    +
      +
    • + CONFIG_FS_FAT: Enable FAT filesystem support. +
    • +
    • + CONFIG_FAT_SECTORSIZE: Max supported sector size. +
    • +
    • + CONFIG_FS_ROMFS: Enable ROMFS filesystem support +
    • +
    +

    Network Support

    TCP/IP and UDP support via uIP

      diff --git a/nuttx/arch/sim/src/up_blockdevice.c b/nuttx/arch/sim/src/up_blockdevice.c index 1146e4182..d91d121ac 100644 --- a/nuttx/arch/sim/src/up_blockdevice.c +++ b/nuttx/arch/sim/src/up_blockdevice.c @@ -83,5 +83,5 @@ void up_registerblockdevice(void) { - rd_register(0, (ubyte*)up_deviceimage(), NSECTORS, LOGICAL_SECTOR_SIZE, TRUE); + ramdisk_register(0, (ubyte*)up_deviceimage(), NSECTORS, LOGICAL_SECTOR_SIZE, TRUE); } diff --git a/nuttx/configs/ntosd-dm320/nsh/defconfig b/nuttx/configs/ntosd-dm320/nsh/defconfig index f8e1d831d..737135103 100644 --- a/nuttx/configs/ntosd-dm320/nsh/defconfig +++ b/nuttx/configs/ntosd-dm320/nsh/defconfig @@ -253,7 +253,9 @@ CONFIG_PREALLOC_TIMERS=8 # FAT filesystem configuration # CONFIG_FS_FAT - Enable FAT filesystem support # CONFIG_FAT_SECTORSIZE - Max supported sector size +# CONFIG_FS_ROMFS - Enable ROMFS filesystem support CONFIG_FS_FAT=n +CONFIG_FS_ROMFS=n # # TCP/IP and UDP support via uIP diff --git a/nuttx/configs/sim/mount/defconfig b/nuttx/configs/sim/mount/defconfig index 979615652..16b7cd741 100644 --- a/nuttx/configs/sim/mount/defconfig +++ b/nuttx/configs/sim/mount/defconfig @@ -208,7 +208,9 @@ CONFIG_PREALLOC_TIMERS=8 # FAT filesystem configuration # CONFIG_FS_FAT - Enable FAT filesystem support # CONFIG_FAT_SECTORSIZE - Max supported sector size +# CONFIG_FS_ROMFS - Enable ROMFS filesystem support CONFIG_FS_FAT=y +CONFIG_FS_ROMFS=n # # TCP/IP and UDP support via uIP diff --git a/nuttx/configs/sim/nettest/defconfig b/nuttx/configs/sim/nettest/defconfig index 73b2ae3f8..e774a6713 100644 --- a/nuttx/configs/sim/nettest/defconfig +++ b/nuttx/configs/sim/nettest/defconfig @@ -1,5 +1,5 @@ ############################################################################ -# sim/nettest/defconfig +# configs/sim/nettest/defconfig # # Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. # Author: Gregory Nutt @@ -208,7 +208,9 @@ CONFIG_PREALLOC_TIMERS=8 # FAT filesystem configuration # CONFIG_FS_FAT - Enable FAT filesystem support # CONFIG_FAT_SECTORSIZE - Max supported sector size +# CONFIG_FS_ROMFS - Enable ROMFS filesystem support CONFIG_FS_FAT=y +CONFIG_FS_ROMFS=n # # TCP/IP and UDP support via uIP diff --git a/nuttx/configs/sim/ostest/defconfig b/nuttx/configs/sim/ostest/defconfig index 7acf0ef78..66def7eec 100644 --- a/nuttx/configs/sim/ostest/defconfig +++ b/nuttx/configs/sim/ostest/defconfig @@ -1,5 +1,5 @@ ############################################################################ -# sim/defconfig +# configs/sim/ostest/defconfig # # Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. # Author: Gregory Nutt @@ -209,7 +209,9 @@ CONFIG_PREALLOC_TIMERS=8 # FAT filesystem configuration # CONFIG_FS_FAT - Enable FAT filesystem support # CONFIG_FAT_SECTORSIZE - Max supported sector size +# CONFIG_FS_ROMFS - Enable ROMFS filesystem support CONFIG_FS_FAT=y +CONFIG_FS_ROMFS=n # # TCP/IP and UDP support via uIP diff --git a/nuttx/configs/sim/pashello/defconfig b/nuttx/configs/sim/pashello/defconfig index 5c694d5b5..3f0ac8bd6 100644 --- a/nuttx/configs/sim/pashello/defconfig +++ b/nuttx/configs/sim/pashello/defconfig @@ -1,5 +1,5 @@ ############################################################################ -# configs/sim/defconfig +# configs/sim/pashello/defconfig # # Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. # Author: Gregory Nutt @@ -208,7 +208,9 @@ CONFIG_PREALLOC_TIMERS=8 # FAT filesystem configuration # CONFIG_FS_FAT - Enable FAT filesystem support # CONFIG_FAT_SECTORSIZE - Max supported sector size +# CONFIG_FS_ROMFS - Enable ROMFS filesystem support CONFIG_FS_FAT=y +CONFIG_FS_ROMFS=n # # TCP/IP and UDP support via uIP diff --git a/nuttx/drivers/ramdisk.c b/nuttx/drivers/ramdisk.c index 48c969030..3f261943e 100644 --- a/nuttx/drivers/ramdisk.c +++ b/nuttx/drivers/ramdisk.c @@ -59,10 +59,14 @@ struct rd_struct_s { - uint32 rd_nsectors; /* Number of sectors on device */ - uint16 rd_sectsize; /* The size of one sector */ - boolean rd_writeenabled; /* TRUE: can write to ram disk */ - ubyte *rd_buffer; /* RAM disk backup memory */ + uint32 rd_nsectors; /* Number of sectors on device */ + uint16 rd_sectsize; /* The size of one sector */ +#ifdef CONFIG_FS_WRITABLE + boolean rd_writeenabled; /* TRUE: can write to ram disk */ + ubyte *rd_buffer; /* RAM disk backup memory */ +#else + const ubyte *rd_buffer; /* ROM disk backup memory */ +#endif }; /**************************************************************************** @@ -73,8 +77,10 @@ static int rd_open(FAR struct inode *inode); static int rd_close(FAR struct inode *inode); static ssize_t rd_read(FAR struct inode *inode, unsigned char *buffer, size_t start_sector, unsigned int nsectors); +#ifdef CONFIG_FS_WRITABLE static ssize_t rd_write(FAR struct inode *inode, const unsigned char *buffer, size_t start_sector, unsigned int nsectors); +#endif static int rd_geometry(FAR struct inode *inode, struct geometry *geometry); /**************************************************************************** @@ -86,7 +92,11 @@ static const struct block_operations g_bops = rd_open, /* open */ rd_close, /* close */ rd_read, /* read */ +#ifdef CONFIG_FS_WRITABLE rd_write, /* write */ +#else + NULL, /* write */ +#endif rd_geometry, /* geometry */ NULL /* ioctl */ }; @@ -153,6 +163,7 @@ static ssize_t rd_read(FAR struct inode *inode, unsigned char *buffer, * ****************************************************************************/ +#ifdef CONFIG_FS_WRITABLE static ssize_t rd_write(FAR struct inode *inode, const unsigned char *buffer, size_t start_sector, unsigned int nsectors) { @@ -160,18 +171,25 @@ static ssize_t rd_write(FAR struct inode *inode, const unsigned char *buffer, if (inode) { dev = (struct rd_struct_s *)inode->i_private; - if (dev && - start_sector < dev->rd_nsectors && - start_sector + nsectors <= dev->rd_nsectors) + if (dev) { - memcpy(&dev->rd_buffer[start_sector * dev->rd_sectsize], - buffer, - nsectors * dev->rd_sectsize); - return nsectors; + if (!dev->rd_writeenabled) + { + return -EACCES; + } + else if (start_sector < dev->rd_nsectors && + start_sector + nsectors <= dev->rd_nsectors) + { + memcpy(&dev->rd_buffer[start_sector * dev->rd_sectsize], + buffer, + nsectors * dev->rd_sectsize); + return nsectors; + } } } return -EINVAL; } +#endif /**************************************************************************** * Name: rd_geometry @@ -188,7 +206,11 @@ static int rd_geometry(FAR struct inode *inode, struct geometry *geometry) dev = (struct rd_struct_s *)inode->i_private; geometry->geo_available = TRUE; geometry->geo_mediachanged = FALSE; +#ifdef CONFIG_FS_WRITABLE geometry->geo_writeenabled = dev->rd_writeenabled; +#else + geometry->geo_writeenabled = FALSE; +#endif geometry->geo_nsectors = dev->rd_nsectors; geometry->geo_sectorsize = dev->rd_sectsize; return OK; @@ -201,14 +223,18 @@ static int rd_geometry(FAR struct inode *inode, struct geometry *geometry) ****************************************************************************/ /**************************************************************************** - * Name: rd_register + * Name: ramdisk_register * * Description: Register the a ramdisk ****************************************************************************/ -int rd_register(int minor, ubyte *buffer, uint32 nsectors, uint16 sectsize, - boolean writeenabled) +#ifdef CONFIG_FS_WRITABLE +int ramdisk_register(int minor, ubyte *buffer, uint32 nsectors, uint16 sectsize, + boolean writeenabled) +#else +int romdisk_register(int minor, ubyte *buffer, uint32 nsectors, uint16 sectsize) +#endif { struct rd_struct_s *dev; char devname[16]; @@ -232,7 +258,9 @@ int rd_register(int minor, ubyte *buffer, uint32 nsectors, uint16 sectsize, dev->rd_nsectors = nsectors; /* Number of sectors on device */ dev->rd_sectsize = sectsize; /* The size of one sector */ +#ifdef CONFIG_FS_WRITABLE dev->rd_writeenabled = writeenabled; /* TRUE: can write to ram disk */ +#endif dev->rd_buffer = buffer; /* RAM disk backup memory */ /* Create a ramdisk device name */ diff --git a/nuttx/examples/mount/mount.h b/nuttx/examples/mount/mount.h index 5a2ab61cd..68a03674d 100644 --- a/nuttx/examples/mount/mount.h +++ b/nuttx/examples/mount/mount.h @@ -49,6 +49,9 @@ /* Configure the test */ #if defined(CONFIG_EXAMPLES_MOUNT_DEVNAME) +# if !defined(CONFIG_FS_WRITABLE) +# error "Writable filesystem required in this configuration" +# endif # undef CONFIG_EXAMPLES_MOUNT_NSECTORS # undef CONFIG_EXAMPLES_MOUNT_SECTORSIZE # undef CONFIG_EXAMPLES_MOUNT_RAMDEVNO diff --git a/nuttx/examples/mount/ramdisk.c b/nuttx/examples/mount/ramdisk.c index 905c56492..ca3846053 100644 --- a/nuttx/examples/mount/ramdisk.c +++ b/nuttx/examples/mount/ramdisk.c @@ -112,7 +112,7 @@ int create_ramdisk(void) /* Register a RAMDISK device to manage this RAM image */ - ret = rd_register(CONFIG_EXAMPLES_MOUNT_RAMDEVNO, + ret = ramdisk_register(CONFIG_EXAMPLES_MOUNT_RAMDEVNO, pbuffer, CONFIG_EXAMPLES_MOUNT_NSECTORS, CONFIG_EXAMPLES_MOUNT_SECTORSIZE, diff --git a/nuttx/examples/nsh/README.txt b/nuttx/examples/nsh/README.txt index 69187f1a3..31ec155cd 100644 --- a/nuttx/examples/nsh/README.txt +++ b/nuttx/examples/nsh/README.txt @@ -589,36 +589,42 @@ Command Dependencies on Configuration Settings echo -- exec -- exit -- - get CONFIG_NET && CONFIG_NET_UDP && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NET_BUFSIZE >= 558* + get CONFIG_NET && CONFIG_NET_UDP && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NET_BUFSIZE >= 558 (see note 1) help -- ifconfig CONFIG_NET ls CONFIG_NFILE_DESCRIPTORS > 0 mb,mh,mw --- mem --- - mkdir !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 + mkdir !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_WRITABLE (see note 4) mkfatfs !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_FAT mkfifo CONFIG_NFILE_DESCRIPTORS > 0 - mkrd !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_FAT - mount !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_FAT + mkrd !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_WRITABLE (see note 4) + mount !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_READABLE (see note 3) ping CONFIG_NET && CONFIG_NET_ICMP && CONFIG_NET_ICMP_PING && !CONFIG_DISABLE_CLOCK && !CONFIG_DISABLE_SIGNALS ps -- - put CONFIG_NET && CONFIG_NET_UDP && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NET_BUFSIZE >= 558* + put CONFIG_NET && CONFIG_NET_UDP && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NET_BUFSIZE >= 558 (see note 1,2) pwd !CONFIG_DISABLE_ENVIRON && CONFIG_NFILE_DESCRIPTORS > 0 - rm !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 - rmdir !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 + rm !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_WRITABLE (see note 4) + rmdir !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_WRITABLE (see note 4) set !CONFIG_DISABLE_ENVIRON sh CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0 && !CONFIG_EXAMPLES_NSH_DISABLESCRIPT sleep !CONFIG_DISABLE_SIGNALS test !CONFIG_EXAMPLES_NSH_DISABLESCRIPT - umount !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_FAT + umount !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_READABLE unset !CONFIG_DISABLE_ENVIRON usleep !CONFIG_DISABLE_SIGNALS xd --- * NOTES: - - Because of hardware padding, the actual required size may be larger. - - Special TFTP server start-up optionss will probably be required to permit - creation of file for the correct operation of the put command. + 1. Because of hardware padding, the actual required for put and get + operations size may be larger. + 2. Special TFTP server start-up optionss will probably be required to permit + creation of file for the correct operation of the put command. + 3. CONFIG_FS_READABLE is not a user configuration but is set automatically + if any readable filesystem is selected. At present, this is either CONFIG_FS_FAT + and CONFIG_FS_ROMFS. + 4. CONFIG_FS_WRITABLE is not a user configuration but is set automatically + if any writable filesystem is selected. At present, this is only CONFIG_FS_FAT. NSH-Specific Configuration Settings ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/nuttx/examples/nsh/nsh.h b/nuttx/examples/nsh/nsh.h index d8d18a72a..e35084ead 100644 --- a/nuttx/examples/nsh/nsh.h +++ b/nuttx/examples/nsh/nsh.h @@ -288,15 +288,19 @@ extern int cmd_lbracket(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); extern int cmd_sh(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); # endif /* CONFIG_NFILE_STREAMS && !CONFIG_EXAMPLES_NSH_DISABLESCRIPT */ # ifndef CONFIG_DISABLE_MOUNTPOINT - extern int cmd_mkdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); extern int cmd_mkfifo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); - extern int cmd_mkrd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); - extern int cmd_rm(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); - extern int cmd_rmdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# ifdef CONFIG_FS_FAT - extern int cmd_mkfatfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# ifdef CONFIG_FS_READABLE extern int cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); extern int cmd_umount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# ifdef CONFIG_FS_WRITABLE + extern int cmd_mkdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); + extern int cmd_mkrd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); + extern int cmd_rm(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); + extern int cmd_rmdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif /* CONFIG_FS_WRITABLE */ +# endif /* CONFIG_FS_READABLE */ +# ifdef CONFIG_FS_FAT + extern int cmd_mkfatfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); # endif /* CONFIG_FS_FAT */ # endif /* !CONFIG_DISABLE_MOUNTPOINT */ # if !defined(CONFIG_DISABLE_ENVIRON) diff --git a/nuttx/examples/nsh/nsh_fscmds.c b/nuttx/examples/nsh/nsh_fscmds.c index 43ef483a6..d38d9b720 100644 --- a/nuttx/examples/nsh/nsh_fscmds.c +++ b/nuttx/examples/nsh/nsh_fscmds.c @@ -44,11 +44,13 @@ # include # include # if !defined(CONFIG_DISABLE_MOUNTPOINT) -# ifdef CONFIG_FS_FAT /* Need at least one filesytem in configuration */ +# ifdef CONFIG_FS_READABLE /* Need at least one filesytem in configuration */ # include +# include +# endif +# ifdef CONFIG_FS_FAT # include # endif -# include #endif #endif @@ -711,7 +713,7 @@ int cmd_ls(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) * Name: cmd_mkdir ****************************************************************************/ -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 +#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_WRITABLE) int cmd_mkdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { char *fullpath = nsh_getfullpath(vtbl, argv[1]); @@ -781,7 +783,7 @@ int cmd_mkfifo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) * Name: cmd_mkrd ****************************************************************************/ -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 +#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_WRITABLE) int cmd_mkrd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { const char *fmt; @@ -860,10 +862,10 @@ int cmd_mkrd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) /* Then register the ramdisk */ - ret = rd_register(minor, buffer, nsectors, sectsize, TRUE); + ret = ramdisk_register(minor, buffer, nsectors, sectsize, TRUE); if (ret < 0) { - nsh_output(vtbl, g_fmtcmdfailed, argv[0], "rd_register", NSH_ERRNO_OF(-ret)); + nsh_output(vtbl, g_fmtcmdfailed, argv[0], "ramdisk_register", NSH_ERRNO_OF(-ret)); free(buffer); return ERROR; } @@ -879,8 +881,7 @@ errout_with_fmt: * Name: cmd_mount ****************************************************************************/ -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 -#ifdef CONFIG_FS_FAT /* Need at least one filesytem in configuration */ +#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_READABLE) int cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { char *source; @@ -953,13 +954,12 @@ int cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) return ret; } #endif -#endif /**************************************************************************** * Name: cmd_rm ****************************************************************************/ -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 +#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_WRITABLE) int cmd_rm(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { char *fullpath = nsh_getfullpath(vtbl, argv[1]); @@ -982,7 +982,7 @@ int cmd_rm(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) * Name: cmd_rmdir ****************************************************************************/ -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 +#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_WRITABLE) int cmd_rmdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { char *fullpath = nsh_getfullpath(vtbl, argv[1]); @@ -1070,8 +1070,7 @@ int cmd_sh(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) * Name: cmd_umount ****************************************************************************/ -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 -#ifdef CONFIG_FS_FAT /* Need at least one filesytem in configuration */ +#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_READABLE) int cmd_umount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { char *fullpath = nsh_getfullpath(vtbl, argv[1]); @@ -1091,4 +1090,3 @@ int cmd_umount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) return ret; } #endif -#endif diff --git a/nuttx/examples/nsh/nsh_main.c b/nuttx/examples/nsh/nsh_main.c index 68de85285..c893d2902 100644 --- a/nuttx/examples/nsh/nsh_main.c +++ b/nuttx/examples/nsh/nsh_main.c @@ -157,19 +157,21 @@ static const struct cmdmap_s g_cmdmap[] = #endif { "mb", cmd_mb, 2, 3, "[=][ ]" }, { "mem", cmd_mem, 1, 1, NULL }, -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 +#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_WRITABLE) { "mkdir", cmd_mkdir, 2, 2, "" }, -#ifdef CONFIG_FS_FAT +#endif +#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_FAT) { "mkfatfs", cmd_mkfatfs, 2, 2, "" }, #endif +#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 { "mkfifo", cmd_mkfifo, 2, 2, "" }, +#endif +#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_WRITABLE) { "mkrd", cmd_mkrd, 2, 6, "[-m ] [-s ] " }, #endif { "mh", cmd_mh, 2, 3, "[=][ ]" }, -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 -#ifdef CONFIG_FS_FAT /* Need at least one filesytem in configuration */ +#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_READABLE) { "mount", cmd_mount, 4, 5, "-t " }, -#endif #endif { "mw", cmd_mw, 2, 3, "[=][ ]" }, { "ps", cmd_ps, 1, 1, NULL }, @@ -183,7 +185,7 @@ static const struct cmdmap_s g_cmdmap[] = #if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_ENVIRON) { "pwd", cmd_pwd, 1, 1, NULL }, #endif -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 +#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_WRITABLE) { "rm", cmd_rm, 2, 2, "" }, { "rmdir", cmd_rmdir, 2, 2, "" }, #endif @@ -199,10 +201,8 @@ static const struct cmdmap_s g_cmdmap[] = #ifndef CONFIG_EXAMPLES_NSH_DISABLESCRIPT { "test", cmd_test, 3, NSH_MAX_ARGUMENTS, "" }, #endif -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 -# ifdef CONFIG_FS_FAT /* Need at least one filesytem in configuration */ +#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_READABLE) { "umount", cmd_umount, 2, 2, "" }, -# endif #endif #ifndef CONFIG_DISABLE_ENVIRON { "unset", cmd_unset, 2, 2, "" }, diff --git a/nuttx/fs/Makefile b/nuttx/fs/Makefile index 14a618803..0d08c84ab 100644 --- a/nuttx/fs/Makefile +++ b/nuttx/fs/Makefile @@ -57,6 +57,7 @@ CSRCS += fs_registerblockdriver.c fs_unregisterblockdriver.c \ fs_fsync.c fs_unlink.c fs_rename.c \ fs_mkdir.c fs_rmdir.c include fat/Make.defs +include romfs/Make.defs endif endif @@ -67,8 +68,8 @@ OBJS = $(AOBJS) $(COBJS) BIN = libfs$(LIBEXT) -SUBDIRS = fat -VPATH = fat +SUBDIRS = fat romfs +VPATH = fat:romfs all: $(BIN) @@ -84,7 +85,7 @@ $(BIN): $(OBJS) done ; ) .depend: Makefile $(SRCS) - @$(MKDEP) --dep-path . --dep-path fat $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep + @$(MKDEP) --dep-path . --dep-path fat --dep-path romfs $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep @touch $@ depend: .depend diff --git a/nuttx/fs/fs_internal.h b/nuttx/fs/fs_internal.h index c09716943..3ebf3f210 100644 --- a/nuttx/fs/fs_internal.h +++ b/nuttx/fs/fs_internal.h @@ -94,19 +94,34 @@ struct fs_psuedodir_s struct inode *fd_next; /* The inode for the next call to readdir() */ }; -#if defined(CONFIG_FS_FAT) && !defined(CONFIG_DISABLE_MOUNTPOINT) -/* For fat, we need to retun the start cluster, current cluster, current +#ifndef CONFIG_DISABLE_MOUNTPOINT +#ifdef CONFIG_FS_FAT +/* For fat, we need to return the start cluster, current cluster, current * sector and current directory index. */ struct fs_fatdir_s { - uint32 fd_startcluster; /* Start cluster number of the directory*/ - uint32 fd_currcluster; /* Current cluster number being read*/ - size_t fd_currsector; /* Current sector being read*/ + uint32 fd_startcluster; /* Start cluster number of the directory */ + uint32 fd_currcluster; /* Current cluster number being read */ + size_t fd_currsector; /* Current sector being read */ unsigned int fd_index; /* Current index of the directory entry to read */ }; -#endif +#endif /* CONFIG_FS_FAT */ + +#ifdef CONFIG_FS_ROMFS +/* For ROMFS, we need to return the offset to the current and start positions + * of the directory entry being read + */ + +struct fs_romfsdir_s +{ + uint32 fr_diroffset; /* Offset to the directory entry */ + uint32 fr_firstoffset; /* Offset to the first entry */ + uint32 fr_curroffset; /* Current offset into the directory contents */ +}; +#endif /* CONFIG_FS_ROMFS */ +#endif /* CONFIG_DISABLE_MOUNTPOINT */ struct internal_dir_s { @@ -148,6 +163,9 @@ struct internal_dir_s #ifdef CONFIG_FS_FAT struct fs_fatdir_s fat; #endif +#ifdef CONFIG_FS_ROMFS + struct fs_romfsdir_s romfs; +#endif #endif } u; diff --git a/nuttx/fs/fs_mount.c b/nuttx/fs/fs_mount.c index 0de22ac5a..d0806ba7d 100644 --- a/nuttx/fs/fs_mount.c +++ b/nuttx/fs/fs_mount.c @@ -53,7 +53,7 @@ * every configured filesystem. */ -#ifdef CONFIG_FS_FAT +#ifdef CONFIG_FS_READABLE /**************************************************************************** * Definitions @@ -76,11 +76,17 @@ struct fsmap_t #ifdef CONFIG_FS_FAT extern const struct mountpt_operations fat_operations; #endif +#ifdef CONFIG_FS_ROMFS +extern const struct mountpt_operations romfs_operations; +#endif static const struct fsmap_t g_fsmap[] = { #ifdef CONFIG_FS_FAT { "vfat", &fat_operations }, +#endif +#ifdef CONFIG_FS_ROMFS + { "romfs", &romfs_operations }, #endif { NULL, NULL }, }; diff --git a/nuttx/include/nuttx/ramdisk.h b/nuttx/include/nuttx/ramdisk.h index 839855633..0e34db960 100644 --- a/nuttx/include/nuttx/ramdisk.h +++ b/nuttx/include/nuttx/ramdisk.h @@ -40,6 +40,7 @@ * Included Files ****************************************************************************/ +#include #include /**************************************************************************** @@ -62,7 +63,7 @@ extern "C" { #define EXTERN extern #endif -/* Non-standard function to register a ramdisk +/* Non-standard function to register a ramdisk or a romdisk * * minor: Selects suffix of device named /dev/ramN, N={1,2,3...} * nsectors: Number of sectors on device @@ -71,8 +72,14 @@ extern "C" { * buffer: RAM disk backup memory */ -EXTERN int rd_register(int minor, ubyte *buffer, uint32 nsectors, - uint16 sectize, boolean writeenabled); +#ifdef CONFIG_FS_WRITABLE +EXTERN int ramdisk_register(int minor, ubyte *buffer, uint32 nsectors, + uint16 sectize, boolean writeenabled); +#define romdisk_register(m,b,n,s) ramdisk_register(m,b,n,s,0) +#else +EXTERN int romdisk_register(int minor, ubyte *buffer, uint32 nsectors, + uint16 sectize); +#endif #undef EXTERN #ifdef __cplusplus diff --git a/nuttx/tools/mkconfig.c b/nuttx/tools/mkconfig.c index c1653f308..695b45298 100644 --- a/nuttx/tools/mkconfig.c +++ b/nuttx/tools/mkconfig.c @@ -1,7 +1,7 @@ -/************************************************************ +/**************************************************************************** * mkconfig.c * - * Copyright (C) 2007 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -14,7 +14,7 @@ * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. - * 3. Neither the name Gregory Nutt nor the names of its contributors may be + * 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. * @@ -31,7 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************/ + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ #include #include @@ -41,9 +45,17 @@ #include #include +/**************************************************************************** + * Definitions + ****************************************************************************/ + #define DEFCONFIG ".config" #define LINESIZE ( PATH_MAX > 256 ? PATH_MAX : 256 ) +/**************************************************************************** + * Private Functions + ****************************************************************************/ + static char line[LINESIZE+1]; static char *skip_space(char *ptr) @@ -167,6 +179,10 @@ static void show_usage(const char *progname) exit(1); } +/**************************************************************************** + * Public Functions + ****************************************************************************/ + int main(int argc, char **argv, char **envp) { char *filepath; @@ -245,6 +261,16 @@ int main(int argc, char **argv, char **envp) printf("/* If mountpoint support in not included, then no filesystem can be supported */\n\n"); printf("#ifdef CONFIG_DISABLE_MOUNTPOINT\n"); printf("# undef CONFIG_FS_FAT\n"); + printf("# undef CONFIG_FS_ROMFS\n"); + printf("#endif\n\n"); + printf("/* Check if any readable and writable filesystem is supported */\n\n"); + printf("#undef CONFIG_FS_READABLE\n"); + printf("#undef CONFIG_FS_WRITABLE\n"); + printf("#if defined(CONFIG_FS_FAT) || defined(CONFIG_FS_ROMFS)\n"); + printf("# define CONFIG_FS_READABLE 1\n"); + printf("#endif\n\n"); + printf("#if defined(CONFIG_FS_FAT)\n"); + printf("# define CONFIG_FS_WRITABLE 1\n"); printf("#endif\n\n"); printf("/* There can be no network support with no socket descriptors */\n\n"); printf("#if CONFIG_NSOCKET_DESCRIPTORS <= 0\n");