diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2014-02-19 10:30:50 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2014-02-19 10:30:50 -0600 |
commit | d0a866fa54292a387ae72ac785943a62ea380dbe (patch) | |
tree | 32a8528d52150a376c4775bc2398293ef2123093 | |
parent | 9277eac1a8e6fb401e77e0802cb1d38a37f7530c (diff) | |
download | nuttx-d0a866fa54292a387ae72ac785943a62ea380dbe.tar.gz nuttx-d0a866fa54292a387ae72ac785943a62ea380dbe.tar.bz2 nuttx-d0a866fa54292a387ae72ac785943a62ea380dbe.zip |
mkdir can now be used to create empty directories in the pseudo-filesystem.
-rw-r--r-- | apps/ChangeLog.txt | 3 | ||||
-rw-r--r-- | apps/nshlib/README.txt | 4 | ||||
-rw-r--r-- | apps/nshlib/nsh.h | 6 | ||||
-rw-r--r-- | apps/nshlib/nsh_command.c | 2 | ||||
-rw-r--r-- | apps/nshlib/nsh_fscmds.c | 2 | ||||
-rw-r--r-- | nuttx/ChangeLog | 5 | ||||
-rw-r--r-- | nuttx/fs/Makefile | 12 | ||||
-rw-r--r-- | nuttx/fs/fs_mkdir.c | 82 |
8 files changed, 76 insertions, 40 deletions
diff --git a/apps/ChangeLog.txt b/apps/ChangeLog.txt index 018dd72ff..c5c513d02 100644 --- a/apps/ChangeLog.txt +++ b/apps/ChangeLog.txt @@ -828,3 +828,6 @@ * apps/nshilib: rmdir can now be used in the pseudo-filesystem. Hence, the command needs to be available even if there are no write-able filesystem enabled (2014-2-19). + * apps/nshilib: mkdir can now be used in the pseudo-filesystem. Hence, + the command needs to be available even if there are no write-able + filesystem enabled (2014-2-19). diff --git a/apps/nshlib/README.txt b/apps/nshlib/README.txt index 082d8dcc6..6e112846f 100644 --- a/apps/nshlib/README.txt +++ b/apps/nshlib/README.txt @@ -972,7 +972,7 @@ Command Dependencies on Configuration Settings ls CONFIG_NFILE_DESCRIPTORS > 0 md5 CONFIG_NETUTILS_CODECS && CONFIG_CODECS_HASH_MD5 mb,mh,mw --- - mkdir !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_WRITABLE (see note 4) + mkdir CONFIG_NFILE_DESCRIPTORS > 0 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_WRITABLE (see note 4) @@ -984,7 +984,7 @@ Command Dependencies on Configuration Settings 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 && CONFIG_FS_WRITABLE (see note 4) - rmdir !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_WRITABLE (see note 4) + rmdir CONFIG_NFILE_DESCRIPTORS > 0 set !CONFIG_DISABLE_ENVIRON sh CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0 && !CONFIG_NSH_DISABLESCRIPT sleep !CONFIG_DISABLE_SIGNALS diff --git a/apps/nshlib/nsh.h b/apps/nshlib/nsh.h index 78a5ea538..97afc430f 100644 --- a/apps/nshlib/nsh.h +++ b/apps/nshlib/nsh.h @@ -717,6 +717,9 @@ void nsh_usbtrace(void); # ifndef CONFIG_NSH_DISABLE_LS int cmd_ls(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); # endif +# ifndef CONFIG_NSH_DISABLE_MKDIR + int cmd_mkdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif # ifndef CONFIG_NSH_DISABLE_RMDIR int cmd_rmdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); # endif @@ -746,9 +749,6 @@ void nsh_usbtrace(void); int cmd_umount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); # endif # ifdef CONFIG_FS_WRITABLE -# ifndef CONFIG_NSH_DISABLE_MKDIR - int cmd_mkdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif # ifndef CONFIG_NSH_DISABLE_MKRD int cmd_mkrd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); # endif diff --git a/apps/nshlib/nsh_command.c b/apps/nshlib/nsh_command.c index 996383694..447036bc1 100644 --- a/apps/nshlib/nsh_command.c +++ b/apps/nshlib/nsh_command.c @@ -252,7 +252,7 @@ static const struct cmdmap_s g_cmdmap[] = # endif #endif -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_WRITABLE) +#if CONFIG_NFILE_DESCRIPTORS > 0 # ifndef CONFIG_NSH_DISABLE_MKDIR { "mkdir", cmd_mkdir, 2, 2, "<path>" }, # endif diff --git a/apps/nshlib/nsh_fscmds.c b/apps/nshlib/nsh_fscmds.c index fd4cac222..ccd831949 100644 --- a/apps/nshlib/nsh_fscmds.c +++ b/apps/nshlib/nsh_fscmds.c @@ -995,7 +995,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 && defined(CONFIG_FS_WRITABLE) +#if CONFIG_NFILE_DESCRIPTORS > 0 #ifndef CONFIG_NSH_DISABLE_MKDIR int cmd_mkdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index b8f92e787..437134ea4 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -6610,7 +6610,8 @@ * fs/fs_opendir.c, fs_readdir.c, et al: Modified so that errors will not be reported if you attempt to list a empty pseudo-directory (2014-2-19). - * fs/fs_rmdir.c: rmdir can be used to removed empty directories in + * fs/fs_rmdir.c: rmdir can now be used to remove empty directories in the pseudo-filesystem such as might be left after umounting a file system (2014-2-19). - + * fs/fs_mkdir.c: mkdir can now be used to create empty directories in + the pseudo-filesystem (2014-2-19). diff --git a/nuttx/fs/Makefile b/nuttx/fs/Makefile index 206d038a7..828535cfe 100644 --- a/nuttx/fs/Makefile +++ b/nuttx/fs/Makefile @@ -62,13 +62,15 @@ else # Common file/socket descriptor support CSRCS += fs_close.c fs_closedir.c fs_dup.c fs_dup2.c fs_fcntl.c -CSRCS += fs_filedup.c fs_filedup2.c fs_ioctl.c fs_lseek.c fs_open.c -CSRCS += fs_opendir.c fs_poll.c fs_read.c fs_readdir.c fs_rewinddir.c -CSRCS += fs_rmdir.c fs_seekdir.c fs_stat.c fs_statfs.c fs_select.c -CSRCS += fs_write.c +CSRCS += fs_filedup.c fs_filedup2.c fs_ioctl.c fs_lseek.c fs_mkdir.c +CSRCS += fs_open.c fs_opendir.c fs_poll.c fs_read.c fs_readdir.c +CSRCS += fs_rewinddir.c fs_rmdir.c fs_seekdir.c fs_stat.c fs_statfs.c +CSRCS += fs_select.c fs_write.c + CSRCS += fs_files.c fs_foreachinode.c fs_inode.c fs_inodeaddref.c CSRCS += fs_inodefind.c fs_inoderelease.c fs_inoderemove.c CSRCS += fs_inodereserve.c + CSRCS += fs_registerdriver.c fs_unregisterdriver.c CSRCS += fs_registerblockdriver.c fs_unregisterblockdriver.c CSRCS += fs_findblockdriver.c fs_openblockdriver.c fs_closeblockdriver.c @@ -102,7 +104,7 @@ endif ifneq ($(CONFIG_DISABLE_MOUNTPOINT),y) -CSRCS += fs_fsync.c fs_mkdir.c fs_mount.c fs_rename.c fs_umount.c +CSRCS += fs_fsync.c fs_mount.c fs_rename.c fs_umount.c CSRCS += fs_unlink.c CSRCS += fs_foreachmountpoint.c diff --git a/nuttx/fs/fs_mkdir.c b/nuttx/fs/fs_mkdir.c index 6e201ce34..b99e00133 100644 --- a/nuttx/fs/fs_mkdir.c +++ b/nuttx/fs/fs_mkdir.c @@ -1,7 +1,7 @@ /**************************************************************************** * fs/fs_mkdir.c * - * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2008, 2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <gnutt@nuttx.org> * * Redistribution and use in source and binary forms, with or without @@ -76,55 +76,85 @@ int mkdir(const char *pathname, mode_t mode) { FAR struct inode *inode; const char *relpath = NULL; + int errcode; int ret; - /* Get an inode for this file */ + /* Find the inode that includes this path */ inode = inode_find(pathname, &relpath); - if (!inode) + if (inode) { - /* There is no mountpoint that includes in this path */ + /* An inode was found that includes this path and possibly refers to a + * mountpoint. + */ - ret = ENOENT; - goto errout; - } +#ifndef CONFIG_DISABLE_MOUNTPOINT + /* Check if the inode is a valid mountpoint. */ - /* Verify that the inode is a valid mountpoint. */ + if (!INODE_IS_MOUNTPT(inode) || !inode->u.i_mops) + { + /* The inode is not a mountpoint */ - if (!INODE_IS_MOUNTPT(inode) || !inode->u.i_mops) - { - ret = ENXIO; - goto errout_with_inode; + errcode = ENXIO; + goto errout_with_inode; + } + + /* Perform the mkdir operation using the relative path + * at the mountpoint. + */ + + if (inode->u.i_mops->mkdir) + { + ret = inode->u.i_mops->mkdir(inode, relpath, mode); + if (ret < 0) + { + errcode = -ret; + goto errout_with_inode; + } + } + else + { + errcode = ENOSYS; + goto errout_with_inode; + } + + /* Release our reference on the inode */ + + inode_release(inode); +#else + /* But mountpoints are not supported in this configuration */ + + errocode = EEXIST; + goto errout_with_inode; +#endif } - /* Perform the mkdir operation using the relative path - * at the mountpoint. + /* No inode exists that contains this path. Create a new inode in the + * pseudo-filesystem at this location. */ - if (inode->u.i_mops->mkdir) + else { - ret = inode->u.i_mops->mkdir(inode, relpath, mode); + /* Create an inode in the pseudo-filesystem at this path */ + + inode_semtake(); + ret = inode_reserve(pathname, &inode); + inode_semgive(); + if (ret < 0) { - ret = -ret; - goto errout_with_inode; + errcode = -ret; + goto errout; } } - else - { - ret = ENOSYS; - goto errout_with_inode; - } /* Directory successfully created */ - inode_release(inode); return OK; errout_with_inode: inode_release(inode); errout: - set_errno(ret); + set_errno(errcode); return ERROR; } - |