diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-05-27 20:40:01 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-05-27 20:40:01 +0000 |
commit | 4bf87cef2238b9f5aa2a865cc875f632ff45b3d6 (patch) | |
tree | dec2bd4aed503cb9c17f96e353ed0e547372806e /nuttx/fs | |
parent | 70616853600900cb04a615ac620792553dbe1c7d (diff) | |
download | px4-nuttx-4bf87cef2238b9f5aa2a865cc875f632ff45b3d6.tar.gz px4-nuttx-4bf87cef2238b9f5aa2a865cc875f632ff45b3d6.tar.bz2 px4-nuttx-4bf87cef2238b9f5aa2a865cc875f632ff45b3d6.zip |
Added fat_getattrib.c and fat_setattrib.c
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@259 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/fs')
-rw-r--r-- | nuttx/fs/Makefile | 2 | ||||
-rw-r--r-- | nuttx/fs/fs_fat32.c | 1 | ||||
-rw-r--r-- | nuttx/fs/fs_fat32.h | 12 | ||||
-rw-r--r-- | nuttx/fs/fs_fat32attrib.c | 194 | ||||
-rw-r--r-- | nuttx/fs/fs_fat32util.c | 1 |
5 files changed, 197 insertions, 13 deletions
diff --git a/nuttx/fs/Makefile b/nuttx/fs/Makefile index a61d811d8..49fdce3a5 100644 --- a/nuttx/fs/Makefile +++ b/nuttx/fs/Makefile @@ -51,7 +51,7 @@ CSRCS += fs_registerblockdriver.c fs_unregisterblockdriver.c \ fs_mount.c fs_umount.c fs_unlink.c fs_mkdir.c fs_rmdir.c \ fs_rename.c ifeq ($(CONFIG_FS_FAT),y) -CSRCS += fs_fat32.c fs_fat32util.c +CSRCS += fs_fat32.c fs_fat32util.c fs_fat32attrib.c endif endif COBJS = $(CSRCS:.c=$(OBJEXT)) diff --git a/nuttx/fs/fs_fat32.c b/nuttx/fs/fs_fat32.c index 098353cd5..6aa58710f 100644 --- a/nuttx/fs/fs_fat32.c +++ b/nuttx/fs/fs_fat32.c @@ -55,6 +55,7 @@ #include <debug.h> #include <nuttx/fs.h> +#include <nuttx/fat.h> #include "fs_internal.h" #include "fs_fat32.h" diff --git a/nuttx/fs/fs_fat32.h b/nuttx/fs/fs_fat32.h index b654e0006..ff516be00 100644 --- a/nuttx/fs/fs_fat32.h +++ b/nuttx/fs/fs_fat32.h @@ -135,18 +135,6 @@ #define FATNTRES_LCNAME 0x08 /* Lower case in name */ #define FATNTRES_LCEXT 0x10 /* Lower case in extension */ -/* File attribute bits in FAT directory entry */ - -#define FATATTR_READONLY 0x01 -#define FATATTR_HIDDEN 0x02 -#define FATATTR_SYSTEM 0x04 -#define FATATTR_VOLUMEID 0x08 -#define FATATTR_DIRECTORY 0x10 -#define FATATTR_ARCHIVE 0x20 - -#define FATATTR_LONGNAME \ - (FATATTR_READONLY|FATATTR_HIDDEN|FATATTR_SYSTEM|FATATTR_VOLUMEID) - /* Directory indexing helper. Each directory entry is 32-bytes in length. * The number of directory entries in a sector then varies with the size * of the sector supported in hardware. diff --git a/nuttx/fs/fs_fat32attrib.c b/nuttx/fs/fs_fat32attrib.c new file mode 100644 index 000000000..6c7c8c6b3 --- /dev/null +++ b/nuttx/fs/fs_fat32attrib.c @@ -0,0 +1,194 @@ +/************************************************************ + * fs_fat32attrib.c + * + * Copyright (C) 2007 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * 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 Gregory Nutt 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. + * + ************************************************************/ + +/************************************************************ + * Compilation Switches + ************************************************************/ + +/************************************************************ + * Included Files + ************************************************************/ + +#include <nuttx/config.h> +#include <sys/types.h> +#include <errno.h> + +#include <nuttx/fs.h> +#include <nuttx/fat.h> + +#include "fs_internal.h" +#include "fs_fat32.h" + +#if defined(CONFIG_FS_FAT) && !defined(CONFIG_DISABLE_MOUNTPOUNT) + +/************************************************************ + * Private Functions + ************************************************************/ + +/************************************************************ + * Name: fat_attrib + ************************************************************/ + +static int fat_attrib(const char *path, fat_attrib_t *retattrib, + fat_attrib_t setbits, fat_attrib_t clearbits) +{ + struct fat_mountpt_s *fs; + struct fat_dirinfo_s dirinfo; + FAR struct inode *inode; + const char *relpath = NULL; + ubyte oldattributes; + ubyte newattributes; + int ret; + + /* Get an inode for this file */ + + inode = inode_find(path, &relpath); + if (!inode) + { + /* There is no mountpoint that includes in this path */ + + ret = ENOENT; + goto errout; + } + + /* Verify that the inode is a valid mountpoint. */ + + if (!INODE_IS_MOUNTPT(inode) || !inode->u.i_mops || !inode->i_private) + { + ret = ENXIO; + goto errout_with_inode; + } + + /* Get the mountpoint private data from the inode structure */ + + fs = inode->i_private; + + /* Check if the mount is still healthy */ + + fat_semtake(fs); + ret = fat_checkmount(fs); + if (ret != OK) + { + goto errout_with_semaphore; + } + + /* Find the file/directory entry for the oldrelpath */ + + ret = fat_finddirentry(fs, &dirinfo, relpath); + if (ret != OK) + { + /* Some error occurred -- probably -ENOENT */ + + goto errout_with_semaphore; + } + + /* Make sure that we found some valid file or directory */ + + if (!dirinfo.fd_entry) + { + /* Ooops.. we found the root directory */ + + ret = EACCES; + goto errout_with_semaphore; + } + + /* Get the current attributes */ + + oldattributes = DIR_GETATTRIBUTES(dirinfo.fd_entry); + newattributes = oldattributes; + + /* Set or clear any bits as requested */ + + newattributes &= ~(clearbits & (FATATTR_READONLY|FATATTR_HIDDEN|FATATTR_SYSTEM|FATATTR_ARCHIVE)); + newattributes |= (setbits & (FATATTR_READONLY|FATATTR_HIDDEN|FATATTR_SYSTEM|FATATTR_ARCHIVE)); + + /* Did any thingchange? */ + + if (newattributes != oldattributes) + { + DIR_PUTATTRIBUTES(dirinfo.fd_entry, newattributes); + fs->fs_dirty = TRUE; + ret = fat_updatefsinfo(fs); + if (ret != OK) + { + ret = -ret; + goto errout_with_semaphore; + } + } + + /* Success */ + + if (retattrib) + { + *retattrib = newattributes; + } + + fat_semgive(fs); + inode_release(inode); + return OK; + +errout_with_semaphore: + fat_semgive(fs); +errout_with_inode: + inode_release(inode); +errout: + *get_errno_ptr() = ret; + return ERROR; +} + +/************************************************************ + * Global Functions + ************************************************************/ + +/************************************************************ + * Name: fat_getattrib + ************************************************************/ + +int fat_getattrib(const char *path, fat_attrib_t *attrib) +{ + return fat_attrib(path, attrib, 0, 0); +} + +/************************************************************ + * Name: fat_setattrib + ************************************************************/ + +int fat_setattrib(const char *path, fat_attrib_t setbits, fat_attrib_t clearbits) +{ + return fat_attrib(path, NULL, setbits, clearbits); +} + +#endif /* CONFIG_FS_FAT && !CONFIG_DISABLE_MOUNTPOUNT */ + diff --git a/nuttx/fs/fs_fat32util.c b/nuttx/fs/fs_fat32util.c index be36d6f75..f68d4cf1b 100644 --- a/nuttx/fs/fs_fat32util.c +++ b/nuttx/fs/fs_fat32util.c @@ -53,6 +53,7 @@ #include <debug.h> #include <nuttx/fs.h> +#include <nuttx/fat.h> #include "fs_internal.h" #include "fs_fat32.h" |