VFS: The inode unlink method should not be support if operations on the root pseudo-filesystem are disabled.

This commit is contained in:
Gregory Nutt
2015-02-18 09:34:58 -06:00
parent e2336a07bb
commit 63ab39b274
10 changed files with 73 additions and 2 deletions
+2
View File
@@ -121,7 +121,9 @@ static const struct rtc_ops_s g_rtc_ops =
#ifdef CONFIG_RTC_IOCTL
.ioctl = NULL,
#endif
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
.destroy = NULL,
#endif
};
/* STM32 RTC device state */
+2
View File
@@ -77,7 +77,9 @@ static const struct file_operations fifo_fops =
#ifndef CONFIG_DISABLE_POLL
pipecommon_poll, /* poll */
#endif
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
pipecommon_unlink /* unlink */
#endif
};
/****************************************************************************
+2
View File
@@ -86,7 +86,9 @@ static const struct file_operations pipe_fops =
#ifndef CONFIG_DISABLE_POLL
pipecommon_poll, /* poll */
#endif
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
pipecommon_unlink /* unlink */
#endif
};
static sem_t g_pipesem = SEM_INITIALIZER(1);
+4
View File
@@ -350,6 +350,7 @@ int pipecommon_close(FAR struct file *filep)
dev->d_refs = 0;
dev->d_nwriters = 0;
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
/* If, in addition, we have been unlinked, then also need to free the
* device structure as well to prevent a memory leak.
*/
@@ -359,6 +360,7 @@ int pipecommon_close(FAR struct file *filep)
pipecommon_freedev(dev);
return OK;
}
#endif
}
sem_post(&dev->d_bfsem);
@@ -707,6 +709,7 @@ int pipecommon_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
* Name: pipecommon_unlink
****************************************************************************/
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
int pipecommon_unlink(FAR struct inode *inode)
{
FAR struct pipe_dev_s *dev;
@@ -736,5 +739,6 @@ int pipecommon_unlink(FAR struct inode *inode)
return OK;
}
#endif
#endif /* CONFIG_DEV_PIPE_SIZE > 0 */
+2
View File
@@ -148,7 +148,9 @@ int pipecommon_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
int pipecommon_poll(FAR struct file *filep, FAR struct pollfd *fds,
bool setup);
#endif
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
int pipecommon_unlink(FAR struct inode *priv);
#endif
#undef EXTERN
#ifdef __cplusplus
+25
View File
@@ -79,7 +79,9 @@ struct rd_struct_s
{
uint32_t rd_nsectors; /* Number of sectors on device */
uint16_t rd_sectsize; /* The size of one sector */
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
uint8_t rd_crefs; /* Open reference count */
#endif
uint8_t rd_flags; /* See RDFLAG_* definitions */
#ifdef CONFIG_FS_WRITABLE
FAR uint8_t *rd_buffer; /* RAM disk backup memory */
@@ -92,10 +94,13 @@ struct rd_struct_s
* Private Function Prototypes
****************************************************************************/
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
static void rd_destroy(FAR struct rd_struct_s *dev);
static int rd_open(FAR struct inode *inode);
static int rd_close(FAR struct inode *inode);
#endif
static ssize_t rd_read(FAR struct inode *inode, FAR unsigned char *buffer,
size_t start_sector, unsigned int nsectors);
#ifdef CONFIG_FS_WRITABLE
@@ -107,7 +112,10 @@ static int rd_geometry(FAR struct inode *inode,
FAR struct geometry *geometry);
static int rd_ioctl(FAR struct inode *inode, int cmd,
unsigned long arg);
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
static int rd_unlink(FAR struct inode *inode);
#endif
/****************************************************************************
* Private Data
@@ -115,8 +123,13 @@ static int rd_unlink(FAR struct inode *inode);
static const struct block_operations g_bops =
{
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
rd_open, /* open */
rd_close, /* close */
#else
0, /* open */
0, /* close */
#endif
rd_read, /* read */
#ifdef CONFIG_FS_WRITABLE
rd_write, /* write */
@@ -125,7 +138,9 @@ static const struct block_operations g_bops =
#endif
rd_geometry, /* geometry */
rd_ioctl, /* ioctl */
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
rd_unlink /* unlink */
#endif
};
/****************************************************************************
@@ -140,6 +155,7 @@ static const struct block_operations g_bops =
*
****************************************************************************/
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
static void rd_destroy(FAR struct rd_struct_s *dev)
{
fvdbg("Destroying RAM disk\n");
@@ -159,6 +175,7 @@ static void rd_destroy(FAR struct rd_struct_s *dev)
kmm_free(dev);
}
#endif
/****************************************************************************
* Name: rd_open
@@ -167,6 +184,7 @@ static void rd_destroy(FAR struct rd_struct_s *dev)
*
****************************************************************************/
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
static int rd_open(FAR struct inode *inode)
{
FAR struct rd_struct_s *dev;
@@ -182,6 +200,7 @@ static int rd_open(FAR struct inode *inode)
fvdbg("rd_crefs: %d\n", dev->rd_crefs);
return OK;
}
#endif
/****************************************************************************
* Name: rd_close
@@ -190,6 +209,7 @@ static int rd_open(FAR struct inode *inode)
*
****************************************************************************/
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
static int rd_close(FAR struct inode *inode)
{
FAR struct rd_struct_s *dev;
@@ -203,6 +223,7 @@ static int rd_close(FAR struct inode *inode)
dev->rd_crefs--;
fvdbg("rd_crefs: %d\n", dev->rd_crefs);
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
/* Was that the last open reference to the RAM disk? */
if (dev->rd_crefs == 0)
@@ -216,9 +237,11 @@ static int rd_close(FAR struct inode *inode)
rd_destroy(dev);
}
}
#endif
return OK;
}
#endif
/****************************************************************************
* Name: rd_read
@@ -370,6 +393,7 @@ static int rd_ioctl(FAR struct inode *inode, int cmd, unsigned long arg)
*
****************************************************************************/
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
static int rd_unlink(FAR struct inode *inode)
{
FAR struct rd_struct_s *dev;
@@ -392,6 +416,7 @@ static int rd_unlink(FAR struct inode *inode)
return OK;
}
#endif
/****************************************************************************
* Public Functions
+29 -1
View File
@@ -56,8 +56,10 @@
struct rtc_upperhalf_s
{
FAR struct rtc_lowerhalf_s *lower; /* Contained lower half driver */
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
uint8_t crefs; /* Number of open references */
bool unlinked; /* True if the driver has been unlinked */
#endif
};
/****************************************************************************
@@ -66,17 +68,25 @@ struct rtc_upperhalf_s
/* Internal logic */
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
static void rtc_destroy(FAR struct rtc_upperhalf_s *upper);
#endif
/* Character driver methods */
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
static int rtc_open(FAR struct file *filep);
static int rtc_close(FAR struct file *filep);
#endif
static ssize_t rtc_read(FAR struct file *filep, FAR char *, size_t);
static ssize_t rtc_write(FAR struct file *filep, FAR const char *buffer,
size_t buflen);
static int rtc_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
static int rtc_unlink(FAR struct inode *inode);
#endif
/****************************************************************************
* Private Data
@@ -84,8 +94,13 @@ static int rtc_unlink(FAR struct inode *inode);
static const struct file_operations rtc_fops =
{
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
rtc_open, /* open */
rtc_close, /* close */
#else
0, /* open */
0, /* close */
#endif
rtc_read, /* read */
rtc_write, /* write */
0, /* seek */
@@ -93,7 +108,9 @@ static const struct file_operations rtc_fops =
#ifndef CONFIG_DISABLE_POLL
0, /* poll */
#endif
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
rtc_unlink /* unlink */
#endif
};
/****************************************************************************
@@ -101,9 +118,10 @@ static const struct file_operations rtc_fops =
****************************************************************************/
/****************************************************************************
* Name: rtc_read
* Name: rtc_destory
****************************************************************************/
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
static void rtc_destroy(FAR struct rtc_upperhalf_s *upper)
{
/* If the lower half driver provided a destroy method, then call that
@@ -121,11 +139,13 @@ static void rtc_destroy(FAR struct rtc_upperhalf_s *upper)
kmm_free(upper);
}
#endif
/****************************************************************************
* Name: rtc_open
****************************************************************************/
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
static int rtc_open(FAR struct file *filep)
{
FAR struct inode *inode;
@@ -146,11 +166,13 @@ static int rtc_open(FAR struct file *filep)
DEBUGASSERT(upper->crefs > 0);
return OK;
}
#endif
/****************************************************************************
* Name: rtc_close
****************************************************************************/
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
static int rtc_close(FAR struct file *filep)
{
FAR struct inode *inode;
@@ -181,6 +203,7 @@ static int rtc_close(FAR struct file *filep)
return OK;
}
#endif
/****************************************************************************
* Name: rtc_read
@@ -526,6 +549,7 @@ static int rtc_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
* Name: rtc_unlink
****************************************************************************/
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
static int rtc_unlink(FAR struct inode *inode)
{
FAR struct rtc_upperhalf_s *upper;
@@ -552,6 +576,7 @@ static int rtc_unlink(FAR struct inode *inode)
return OK;
}
#endif
/****************************************************************************
* Public Functions
@@ -593,8 +618,11 @@ int rtc_initialize(int minor, FAR struct rtc_lowerhalf_s *lower)
/* Initialize the upper half container */
upper->lower = lower; /* Contain lower half driver */
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
upper->crefs = 0; /* No open references */
upper->unlinked = false; /* Driver is not unlinked */
#endif
/* Create the driver name. There is space for the a minor number up to 6
* characters
+4
View File
@@ -99,7 +99,9 @@ struct file_operations
#ifndef CONFIG_DISABLE_POLL
int (*poll)(FAR struct file *filep, struct pollfd *fds, bool setup);
#endif
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
int (*unlink)(FAR struct inode *inode);
#endif
};
/* This structure provides information about the state of a block driver */
@@ -131,7 +133,9 @@ struct block_operations
size_t start_sector, unsigned int nsectors);
int (*geometry)(FAR struct inode *inode, FAR struct geometry *geometry);
int (*ioctl)(FAR struct inode *inode, int cmd, unsigned long arg);
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
int (*unlink)(FAR struct inode *inode);
#endif
};
/* This structure is provided by a filesystem to describe a mount point.
+2
View File
@@ -423,11 +423,13 @@ struct rtc_ops_s
unsigned long arg);
#endif
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
/* The driver has been unlinked and there are no further open references
* to the driver.
*/
CODE int (*destroy)(FAR struct rtc_lowerhalf_s *lower);
#endif
};
/* When the RTC driver is instantiated, a reference to struct
+1 -1
View File
@@ -4,7 +4,7 @@
#
menu "Unix Domain Socket Support"
depends on NET
depends on NET && !DISABLE_PSEUDOFS_OPERATIONS
config NET_LOCAL
bool "Unix domain (local) sockets"