fs/: Check return of nxsem_wait_uninterruptible.

This commit is contained in:
Ouss4
2020-03-30 11:22:26 +01:00
committed by patacongo
parent 3d78be81d2
commit ba8bc4c80c
14 changed files with 849 additions and 330 deletions
+75 -17
View File
@@ -174,7 +174,12 @@ static int romfs_open(FAR struct file *filep, FAR const char *relpath,
/* Check if the mount is still healthy */
romfs_semtake(rm);
ret = romfs_semtake(rm);
if (ret < 0)
{
return ret;
}
ret = romfs_checkmount(rm);
if (ret != OK)
{
@@ -385,7 +390,12 @@ static ssize_t romfs_read(FAR struct file *filep, FAR char *buffer,
/* Make sure that the mount is still healthy */
romfs_semtake(rm);
ret = romfs_semtake(rm);
if (ret < 0)
{
return (ssize_t)ret;
}
ret = romfs_checkmount(rm);
if (ret != OK)
{
@@ -476,7 +486,8 @@ static ssize_t romfs_read(FAR struct file *filep, FAR char *buffer,
sector++;
}
finfo("Return %d bytes from sector offset %d\n", bytesread, sectorndx);
finfo("Return %d bytes from sector offset %d\n",
bytesread, sectorndx);
memcpy(userbuffer, &rf->rf_buffer[sectorndx], bytesread);
}
@@ -547,7 +558,12 @@ static off_t romfs_seek(FAR struct file *filep, off_t offset, int whence)
/* Make sure that the mount is still healthy */
romfs_semtake(rm);
ret = romfs_semtake(rm);
if (ret < 0)
{
return (off_t)ret;
}
ret = romfs_checkmount(rm);
if (ret != OK)
{
@@ -644,7 +660,12 @@ static int romfs_dup(FAR const struct file *oldp, FAR struct file *newp)
/* Check if the mount is still healthy */
romfs_semtake(rm);
ret = romfs_semtake(rm);
if (ret < 0)
{
return ret;
}
ret = romfs_checkmount(rm);
if (ret != OK)
{
@@ -737,7 +758,12 @@ static int romfs_fstat(FAR const struct file *filep, FAR struct stat *buf)
/* Check if the mount is still healthy */
romfs_semtake(rm);
ret = romfs_semtake(rm);
if (ret < 0)
{
return ret;
}
ret = romfs_checkmount(rm);
if (ret >= 0)
{
@@ -778,7 +804,12 @@ static int romfs_opendir(FAR struct inode *mountpt, FAR const char *relpath,
/* Make sure that the mount is still healthy */
romfs_semtake(rm);
ret = romfs_semtake(rm);
if (ret < 0)
{
return ret;
}
ret = romfs_checkmount(rm);
if (ret != OK)
{
@@ -846,7 +877,12 @@ static int romfs_readdir(FAR struct inode *mountpt,
/* Make sure that the mount is still healthy */
romfs_semtake(rm);
ret = romfs_semtake(rm);
if (ret < 0)
{
return ret;
}
ret = romfs_checkmount(rm);
if (ret != OK)
{
@@ -883,7 +919,8 @@ static int romfs_readdir(FAR struct inode *mountpt,
/* Save the filename */
ret = romfs_parsefilename(rm, dir->u.romfs.fr_curroffset, dir->fd_dir.d_name);
ret = romfs_parsefilename(rm, dir->u.romfs.fr_curroffset,
dir->fd_dir.d_name);
if (ret < 0)
{
ferr("ERROR: romfs_parsefilename failed: %d\n", ret);
@@ -938,7 +975,12 @@ static int romfs_rewinddir(FAR struct inode *mountpt,
/* Make sure that the mount is still healthy */
romfs_semtake(rm);
ret = romfs_semtake(rm);
if (ret < 0)
{
return ret;
}
ret = romfs_checkmount(rm);
if (ret == OK)
{
@@ -986,7 +1028,8 @@ static int romfs_bind(FAR struct inode *blkdriver, FAR const void *data,
/* Create an instance of the mountpt state structure */
rm = (FAR struct romfs_mountpt_s *)kmm_zalloc(sizeof(struct romfs_mountpt_s));
rm = (FAR struct romfs_mountpt_s *)
kmm_zalloc(sizeof(struct romfs_mountpt_s));
if (!rm)
{
ferr("ERROR: Failed to allocate mountpoint structure\n");
@@ -1064,7 +1107,12 @@ static int romfs_unbind(FAR void *handle, FAR struct inode **blkdriver,
/* Check if there are sill any files opened on the filesystem. */
romfs_semtake(rm);
ret = romfs_semtake(rm);
if (ret < 0)
{
return ret;
}
if (rm->rm_head)
{
/* We cannot unmount now.. there are open files */
@@ -1092,9 +1140,9 @@ static int romfs_unbind(FAR void *handle, FAR struct inode **blkdriver,
}
/* We hold a reference to the block driver but should
* not but mucking with inodes in this context. So, we will just return
* our contained reference to the block driver inode and let the umount
* logic dispose of it.
* not but mucking with inodes in this context. So, we will
* just return our contained reference to the block driver
* inode and let the umount logic dispose of it.
*/
if (blkdriver)
@@ -1144,7 +1192,12 @@ static int romfs_statfs(FAR struct inode *mountpt, FAR struct statfs *buf)
/* Check if the mount is still healthy */
romfs_semtake(rm);
ret = romfs_semtake(rm);
if (ret < 0)
{
return ret;
}
ret = romfs_checkmount(rm);
if (ret < 0)
{
@@ -1250,7 +1303,12 @@ static int romfs_stat(FAR struct inode *mountpt, FAR const char *relpath,
/* Check if the mount is still healthy */
romfs_semtake(rm);
ret = romfs_semtake(rm);
if (ret < 0)
{
return ret;
}
ret = romfs_checkmount(rm);
if (ret != OK)
{
+7 -6
View File
@@ -79,7 +79,8 @@
* to 16 byte boundary. */
/* Bits 0-3 of the rf_next offset provide mode information. These are the
* values specified in */
* values specified in
*/
#define RFNEXT_MODEMASK 7 /* Bits 0-2: Mode; bit 3: Executable */
#define RFNEXT_ALLMODEMASK 15 /* Bits 0-3: All mode bits */
@@ -129,9 +130,9 @@
* Public Types
****************************************************************************/
/* This structure represents the overall mountpoint state. An instance of this
* structure is retained as inode private data on each mountpoint that is
* mounted with a fat32 filesystem.
/* This structure represents the overall mountpoint state. An instance of
* this structure is retained as inode private data on each mountpoint that
* is mounted with a fat32 filesystem.
*/
struct romfs_file_s;
@@ -141,7 +142,7 @@ struct romfs_mountpt_s
struct romfs_file_s *rm_head; /* A list to all files opened on this mountpoint */
bool rm_mounted; /* true: The file system is ready */
uint16_t rm_hwsectorsize; /* HW: Sector size reported by block driver*/
uint16_t rm_hwsectorsize; /* HW: Sector size reported by block driver */
sem_t rm_sem; /* Used to assume thread-safe access */
uint32_t rm_rootoffset; /* Saved offset to the first root directory entry */
uint32_t rm_hwnsectors; /* HW: The number of sectors reported by the hardware */
@@ -202,7 +203,7 @@ extern "C"
* Public Function Prototypes
****************************************************************************/
void romfs_semtake(FAR struct romfs_mountpt_s *rm);
int romfs_semtake(FAR struct romfs_mountpt_s *rm);
void romfs_semgive(FAR struct romfs_mountpt_s *rm);
int romfs_hwread(FAR struct romfs_mountpt_s *rm, FAR uint8_t *buffer,
uint32_t sector, unsigned int nsectors);
+18 -18
View File
@@ -171,9 +171,9 @@ int16_t romfs_devcacheread(struct romfs_mountpt_s *rm, uint32_t offset)
uint32_t sector;
int ret;
/* rm->rm_cachesector holds the current sector that is buffer in or referenced
* by rm->tm_buffer. If the requested sector is the same as this sector,
* then we do nothing.
/* rm->rm_cachesector holds the current sector that is buffer in or
* referenced by rm->tm_buffer. If the requested sector is the same as this
* this then we do nothing.
*/
sector = SEC_NSECTORS(rm, offset);
@@ -330,9 +330,9 @@ static inline int romfs_searchdir(struct romfs_mountpt_s *rm,
* Name: romfs_semtake
****************************************************************************/
void romfs_semtake(struct romfs_mountpt_s *rm)
int romfs_semtake(struct romfs_mountpt_s *rm)
{
nxsem_wait_uninterruptible(&rm->rm_sem);
return nxsem_wait_uninterruptible(&rm->rm_sem);
}
/****************************************************************************
@@ -351,8 +351,8 @@ void romfs_semgive(struct romfs_mountpt_s *rm)
*
****************************************************************************/
int romfs_hwread(struct romfs_mountpt_s *rm, uint8_t *buffer, uint32_t sector,
unsigned int nsectors)
int romfs_hwread(struct romfs_mountpt_s *rm, uint8_t *buffer,
uint32_t sector, unsigned int nsectors)
{
int ret = OK;
@@ -415,9 +415,9 @@ int romfs_filecacheread(struct romfs_mountpt_s *rm, struct romfs_file_s *rf,
sector, rf->rf_cachesector, rm->rm_hwsectorsize,
rm->rm_xipbase, rf->rf_buffer);
/* rf->rf_cachesector holds the current sector that is buffer in or referenced
* by rf->rf_buffer. If the requested sector is the same as this sector,
* then we do nothing.
/* rf->rf_cachesector holds the current sector that is buffer in or
* referenced by rf->rf_buffer. If the requested sector is the same as this
* sector then we do nothing.
*/
if (rf->rf_cachesector != sector)
@@ -458,10 +458,10 @@ int romfs_filecacheread(struct romfs_mountpt_s *rm, struct romfs_file_s *rf,
* Name: romfs_hwconfigure
*
* Description:
* This function is called as part of the ROMFS mount operation It
* configures the ROMFS filestem for use on this block driver. This includes
* the accounting for the geometry of the device, setting up any XIP modes
* of operation, and/or allocating any cache buffers.
* This function is called as part of the ROMFS mount operation.
* It configures the ROMFS filestem for use on this block driver. This
* include the accounting for the geometry of the device, setting up any
* XIP modes of operation, and/or allocating any cache buffers.
*
****************************************************************************/
@@ -563,9 +563,9 @@ int romfs_hwconfigure(struct romfs_mountpt_s *rm)
*
* Description:
* This function is called as part of the ROMFS mount operation It
* sets up the mount structure to include configuration information contained
* in the ROMFS header. This is the place where we actually determine if
* the media contains a ROMFS filesystem.
* sets up the mount structure to include configuration information
* contained in the ROMFS header. This is the place where we actually
* determine if the media contains a ROMFS filesystem.
*
****************************************************************************/
@@ -575,7 +575,7 @@ int romfs_fsconfigure(struct romfs_mountpt_s *rm)
int16_t ndx;
/* Then get information about the ROMFS filesystem on the devices managed
* by this block driver. Read sector zero which contains the volume header.
* by this block driver. Read sector zero which contains the volume header.
*/
ndx = romfs_devcacheread(rm, 0);