From 4bf87cef2238b9f5aa2a865cc875f632ff45b3d6 Mon Sep 17 00:00:00 2001 From: patacongo Date: Sun, 27 May 2007 20:40:01 +0000 Subject: 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 --- nuttx/ChangeLog | 1 + nuttx/Documentation/NuttX.html | 1 + nuttx/fs/Makefile | 2 +- nuttx/fs/fs_fat32.c | 1 + nuttx/fs/fs_fat32.h | 12 --- nuttx/fs/fs_fat32attrib.c | 194 +++++++++++++++++++++++++++++++++++++++++ nuttx/fs/fs_fat32util.c | 1 + nuttx/include/nuttx/fat.h | 90 +++++++++++++++++++ nuttx/include/sys/statfs.h | 138 +++++++++++++++++++++++++++++ nuttx/include/sys/vfs.h | 57 ++++++++++++ 10 files changed, 484 insertions(+), 13 deletions(-) create mode 100644 nuttx/fs/fs_fat32attrib.c create mode 100644 nuttx/include/nuttx/fat.h create mode 100644 nuttx/include/sys/statfs.h create mode 100644 nuttx/include/sys/vfs.h (limited to 'nuttx') diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 56ea043b7..e7dba2db7 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -153,5 +153,6 @@ * Added stat() to fs layer * Added stat() supported to FAT * Fixed reference counting errors associated with mounted filesystems + * Added fat_getattrib() and fat_setattrib() * Started m68322 diff --git a/nuttx/Documentation/NuttX.html b/nuttx/Documentation/NuttX.html index 96b9e8221..0706b2f4c 100644 --- a/nuttx/Documentation/NuttX.html +++ b/nuttx/Documentation/NuttX.html @@ -587,6 +587,7 @@ Other memory: * Added stat() to fs layer * Added stat() supported to FAT * Fixed reference counting errors associated with mounted filesystems + * Added fat_getattrib() and fat_setattrib() * Started m68322 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 #include +#include #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 + * + * 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 +#include +#include + +#include +#include + +#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 #include +#include #include "fs_internal.h" #include "fs_fat32.h" diff --git a/nuttx/include/nuttx/fat.h b/nuttx/include/nuttx/fat.h new file mode 100644 index 000000000..db9a4a902 --- /dev/null +++ b/nuttx/include/nuttx/fat.h @@ -0,0 +1,90 @@ +/************************************************************ + * nuttx/fat.h + * + * Copyright (C) 2007 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 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. + * + ************************************************************/ + +#ifndef __SYS_FAT_H +#define __SYS_FAT_H + +/************************************************************ + * Included Files + ************************************************************/ + +#include + +/************************************************************ + * Type Definitions + ************************************************************/ + +/* 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) + +/************************************************************ + * Type Definitions + ************************************************************/ + +typedef ubyte fat_attrib_t; + +/************************************************************ + * Public Function Prototypes + ************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" { +#else +#define EXTERN extern +#endif + +/* Non-standard functions to get and set FAT fire/directgory + * attributes + */ + +EXTERN int fat_getattrib(const char *path, fat_attrib_t *attrib); +EXTERN int fat_setattrib(const char *path, fat_attrib_t setbits, fat_attrib_t clearbits); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* __SYS_FAT_H */ diff --git a/nuttx/include/sys/statfs.h b/nuttx/include/sys/statfs.h new file mode 100644 index 000000000..7baf4be6f --- /dev/null +++ b/nuttx/include/sys/statfs.h @@ -0,0 +1,138 @@ +/************************************************************ + * sys/statfs.h + * + * Copyright (C) 2007 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 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. + * + ************************************************************/ + +#ifndef __SYS_STATFS_H +#define __SYS_STATFS_H + +/************************************************************ + * Included Files + ************************************************************/ + +#include +#include + +/************************************************************ + * Definitions + ************************************************************/ + +/* struct statfs file system types. */ + +#define ADFS_SUPER_MAGIC 0xadf5 +#define AFFS_SUPER_MAGIC 0xADFF +#define BEFS_SUPER_MAGIC 0x42465331 +#define BFS_MAGIC 0x1BADFACE +#define CIFS_MAGIC_NUMBER 0xFF534D42 +#define CODA_SUPER_MAGIC 0x73757245 +#define COH_SUPER_MAGIC 0x012FF7B7 +#define CRAMFS_MAGIC 0x28cd3d45 +#define DEVFS_SUPER_MAGIC 0x1373 +#define EFS_SUPER_MAGIC 0x00414A53 +#define EXT_SUPER_MAGIC 0x137D +#define EXT2_OLD_SUPER_MAGIC 0xEF51 +#define EXT2_SUPER_MAGIC 0xEF53 +#define EXT3_SUPER_MAGIC 0xEF53 +#define HFS_SUPER_MAGIC 0x4244 +#define HPFS_SUPER_MAGIC 0xF995E849 +#define HUGETLBFS_MAGIC 0x958458f6 +#define ISOFS_SUPER_MAGIC 0x9660 +#define JFFS2_SUPER_MAGIC 0x72b6 +#define JFS_SUPER_MAGIC 0x3153464a +#define MINIX_SUPER_MAGIC 0x137F /* orig. minix */ +#define MINIX_SUPER_MAGIC2 0x138F /* 30 char minix */ +#define MINIX2_SUPER_MAGIC 0x2468 /* minix V2 */ +#define MINIX2_SUPER_MAGIC2 0x2478 /* minix V2, 30 char names */ +#define MSDOS_SUPER_MAGIC 0x4d44 +#define NCP_SUPER_MAGIC 0x564c +#define NFS_SUPER_MAGIC 0x6969 +#define NTFS_SB_MAGIC 0x5346544e +#define OPENPROM_SUPER_MAGIC 0x9fa1 +#define PROC_SUPER_MAGIC 0x9fa0 +#define QNX4_SUPER_MAGIC 0x002f +#define REISERFS_SUPER_MAGIC 0x52654973 +#define ROMFS_MAGIC 0x7275 +#define SMB_SUPER_MAGIC 0x517B +#define SYSV2_SUPER_MAGIC 0x012FF7B6 +#define SYSV4_SUPER_MAGIC 0x012FF7B5 +#define TMPFS_MAGIC 0x01021994 +#define UDF_SUPER_MAGIC 0x15013346 +#define UFS_MAGIC 0x00011954 +#define USBDEVICE_SUPER_MAGIC 0x9fa2 +#define VXFS_SUPER_MAGIC 0xa501FCF5 +#define XENIX_SUPER_MAGIC 0x012FF7B4 +#define XFS_SUPER_MAGIC 0x58465342 +#define _XIAFS_SUPER_MAGIC 0x012FD16D + +/************************************************************ + * Type Definitions + ************************************************************/ + +struct statfs +{ + uint32 f_type; /* Type of filesystem (see definitions above) */ + size_t f_bsize; /* Optimal block size for transfers */ + size_t f_blocks; /* Totat 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 f_namelen; /* Maximum length of filenames */ +}; + +/************************************************************ + * Public Function Prototypes + ************************************************************/ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" { +#else +#define EXTERN extern +#endif + +/* Inspired by Linux statfs() which was, in turn, inspired by + * the BSD statfs(). None of these implementations agree in the + * form of the struct statfs. + */ + +EXTERN int statfs(const char *path, struct statfs *buf); +EXTERN int fstatfs(int fd, struct statfs *buf); + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __SYS_STATFS_H */ diff --git a/nuttx/include/sys/vfs.h b/nuttx/include/sys/vfs.h new file mode 100644 index 000000000..d1633f5ec --- /dev/null +++ b/nuttx/include/sys/vfs.h @@ -0,0 +1,57 @@ +/************************************************************ + * sys/vfs.h + * + * Copyright (C) 2007 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 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. + * + ************************************************************/ + +#ifndef __SYS_VFS_H +#define __SYS_VFS_H + +/************************************************************ + * Included Files + ************************************************************/ + +/* sys/vfs.h is just an alternative location for the + * information in sys/statfs.h. + */ + +#include + +/************************************************************ + * Type Definitions + ************************************************************/ + +/************************************************************ + * Public Function Prototypes + ************************************************************/ + +#endif /* __SYS_VFS_H */ -- cgit v1.2.3