diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-05-13 20:56:16 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-05-13 20:56:16 +0000 |
commit | 59443567767ebc201ff769eec21df238364d32ef (patch) | |
tree | 635daf8d49012f7919dcefdd3c10071540380231 /nuttx | |
parent | 499922dce09f07ab44e742c0f8f162c0e531d977 (diff) | |
download | px4-nuttx-59443567767ebc201ff769eec21df238364d32ef.tar.gz px4-nuttx-59443567767ebc201ff769eec21df238364d32ef.tar.bz2 px4-nuttx-59443567767ebc201ff769eec21df238364d32ef.zip |
Add FAT32 unmount; mountpoint open needs oflags+mode
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@220 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx')
-rw-r--r-- | nuttx/fs/fs_fat32.c | 93 | ||||
-rw-r--r-- | nuttx/fs/fs_open.c | 5 | ||||
-rw-r--r-- | nuttx/include/nuttx/fs.h | 3 |
3 files changed, 76 insertions, 25 deletions
diff --git a/nuttx/fs/fs_fat32.c b/nuttx/fs/fs_fat32.c index 0a98b87ac..35870b3ae 100644 --- a/nuttx/fs/fs_fat32.c +++ b/nuttx/fs/fs_fat32.c @@ -214,13 +214,16 @@ * Private Function Prototypes ****************************************************************************/ -static int fat_open(FAR struct file *filp, const char *rel_path); +static int fat_open(FAR struct file *filp, const char *rel_path, + int oflags, mode_t mode); static int fat_close(FAR struct file *filp); static ssize_t fat_read(FAR struct file *filp, char *buffer, size_t buflen); -static ssize_t fat_write(FAR struct file *filp, const char *buffer, size_t buflen); +static ssize_t fat_write(FAR struct file *filp, const char *buffer, + size_t buflen); static off_t fat_seek(FAR struct file *filp, off_t offset, int whence); static int fat_ioctl(FAR struct file *filp, int cmd, unsigned long arg); -static int fat_bind(FAR struct inode *blkdriver, const void *data, void **handle); +static int fat_bind(FAR struct inode *blkdriver, const void *data, + void **handle); static int fat_unbind(void *handle); /**************************************************************************** @@ -372,7 +375,10 @@ static int fat_checkmount(struct fat_mountpt_s *fs) { struct fat_file_s *file; - /* We still think the mount is healthy. Check an see if this is still the case */ + /* We still think the mount is healthy. Check an see if this is + * still the case + */ + if (fs->fs_blkdriver) { struct inode *inode = fs->fs_blkdriver; @@ -416,7 +422,8 @@ static int fat_bread(struct fat_mountpt_s *fs, size_t sector) struct inode *inode = fs->fs_blkdriver; if (inode && inode->u.i_bops && inode->u.i_bops->read) { - ssize_t nSectorsRead = inode->u.i_bops->read(inode, fs->fs_buffer, sector, 1); + ssize_t nSectorsRead = inode->u.i_bops->read(inode, fs->fs_buffer, + sector, 1); if (nSectorsRead == 1) { ret = OK; @@ -604,8 +611,9 @@ static int fat_mount(struct fat_mountpt_s *fs, boolean writeable) goto errout; } - /* Search FAT boot record on the drive. First check at sector zero. This could - * be either the boot record or a partition that refers to the boot record. + /* Search FAT boot record on the drive. First check at sector zero. This + * could be either the boot record or a partition that refers to the boot + * record. * * First read sector zero. This will be the first access to the drive and a * likely failure point. @@ -620,10 +628,11 @@ static int fat_mount(struct fat_mountpt_s *fs, boolean writeable) if (fat_checkbootrecord(fs) != OK) { - /* The contents of sector 0 is not a boot record. It could be a partition, - * however. Assume it is a partition and get the offset into the partition - * table. This table is at offset MBR_TABLE and is indexed by 16x the - * partition number. Here we support only parition 0. + /* The contents of sector 0 is not a boot record. It could be a + * partition, however. Assume it is a partition and get the offset + * into the partition table. This table is at offset MBR_TABLE and is + * indexed by 16x the partition number. Here we support only + * parition 0. */ ubyte *partition = &fs->fs_buffer[MBR_TABLE + 0]; @@ -683,7 +692,8 @@ static int fat_mount(struct fat_mountpt_s *fs, boolean writeable) * Name: fat_open ****************************************************************************/ -static int fat_open(FAR struct file *filp, const char *rel_path) +static int fat_open(FAR struct file *filp, const char *rel_path, + int oflags, mode_t mode) { struct fat_mountpt_s *fs = filp->f_priv; int ret; @@ -705,15 +715,11 @@ static int fat_open(FAR struct file *filp, const char *rel_path) static int fat_close(FAR struct file *filp) { struct fat_mountpt_s *fs = filp->f_priv; - int ret; - /* Make sure that the mount is still healthy */ + /* Do not check if the mount is healthy. We must support closing of + * the file even when there is healthy mount. + */ - ret = fat_checkmount(fs); - if (ret != OK) - { - return ret; - } return -ENOSYS; } @@ -740,7 +746,8 @@ static ssize_t fat_read(FAR struct file *filp, char *buffer, size_t buflen) * Name: fat_write ****************************************************************************/ -static ssize_t fat_write(FAR struct file *filp, const char *buffer, size_t buflen) +static ssize_t fat_write(FAR struct file *filp, const char *buffer, + size_t buflen) { struct fat_mountpt_s *fs = filp->f_priv; int ret; @@ -806,7 +813,8 @@ static int fat_ioctl(FAR struct file *filp, int cmd, unsigned long arg) * ****************************************************************************/ -static int fat_bind(FAR struct inode *blkdriver, const void *data, void **handle) +static int fat_bind(FAR struct inode *blkdriver, const void *data, + void **handle) { struct fat_mountpt_s *fs; int ret; @@ -850,7 +858,48 @@ static int fat_bind(FAR struct inode *blkdriver, const void *data, void **handle static int fat_unbind(void *handle) { - return -ENOSYS; + struct fat_mountpt_s *fs = (struct fat_mountpt_s*)handle; + int ret; + + if ( !fs ) + { + return -EINVAL; + } + + /* Check if there are sill any files opened on the filesystem. */ + + ret = OK; /* Assume success */ + fat_semtake(fs); + if (fs->fs_head) + { + /* We cannot unmount now.. there are open files */ + + ret = -EBUSY; + } + else + { + /* Unmount ... close the block driver */ + + if (fs->fs_blkdriver) + { + struct inode *inode = fs->fs_blkdriver; + if (inode && inode->u.i_bops && inode->u.i_bops->close) + { + (void)inode->u.i_bops->close(inode); + } + } + + /* Release the mountpoint private data */ + + if (fs->fs_buffer) + { + free(fs->fs_buffer); + } + free(fs); + } + + fat_semgive(fs); + return ret; } /**************************************************************************** diff --git a/nuttx/fs/fs_open.c b/nuttx/fs/fs_open.c index 3561d2be0..e954fb743 100644 --- a/nuttx/fs/fs_open.c +++ b/nuttx/fs/fs_open.c @@ -76,6 +76,7 @@ int open(const char *path, int oflags, ...) { struct filelist *list; FAR struct inode *inode; + mode_t mode = 0666; int status; int fd; @@ -90,7 +91,6 @@ int open(const char *path, int oflags, ...) #ifdef CONFIG_FILE_MODE # warning "File creation not implemented" - mode_t mode = 0; /* If the file is opened for creation, then get the mode bits */ @@ -153,7 +153,8 @@ int open(const char *path, int oflags, ...) { if (INODE_IS_MOUNTPT(inode)) { - status = inode->u.i_mops->open((FAR struct file*)&list->fl_files[fd], relpath); + status = inode->u.i_mops->open((FAR struct file*)&list->fl_files[fd], + relpath, oflags, mode); } else { diff --git a/nuttx/include/nuttx/fs.h b/nuttx/include/nuttx/fs.h index 19c7ba3be..f813a44a2 100644 --- a/nuttx/include/nuttx/fs.h +++ b/nuttx/include/nuttx/fs.h @@ -120,7 +120,8 @@ struct mountpt_operations * because it receives the relative path into the mountpoint. */ - int (*open)(FAR struct file *filp, const char *rel_path); + int (*open)(FAR struct file *filp, const char *rel_path, + int oflags, mode_t mode); /* The following methods must be identical in signature and position because * the struct file_operations and struct mountp_operations are treated like |