fstat(): Rethink procfs fstat(). If write method is supported, then should report file s writeable.

This commit is contained in:
Gregory Nutt
2017-02-15 09:32:42 -06:00
parent 1474300276
commit bae367c7c4
3 changed files with 29 additions and 13 deletions
-1
View File
@@ -250,7 +250,6 @@ static int _inode_search(FAR struct inode_search_s *desc)
DEBUGASSERT(desc != NULL && desc->path != NULL);
name = desc->path;
DEBUGASSERT(*name == '/');
if (*name != '/')
{
return -EINVAL;
+22 -6
View File
@@ -474,16 +474,32 @@ static int procfs_dup(FAR const struct file *oldp, FAR struct file *newp)
static int procfs_fstat(FAR const struct file *filep, FAR struct stat *buf)
{
/* This is trivially simple in the current implementation. The procfs
* file system contains only directory and read-only data file entries.
* Therefore, the return buf always has the same fixed values.
*
* REVISIT: This, of course, will need to change if read-write procfs
* entries are to be supported.
FAR struct procfs_file_s *handler;
finfo("buf=%p\n", buf);
/* Recover our private data from the struct file instance */
handler = (FAR struct procfs_file_s *)filep->f_priv;
DEBUGASSERT(handler);
/* The procfs file system contains only directory and data file entries.
* Since the file has been opened, we know that this is a data file and,
* at a minimum, readable.
*/
memset(buf, 0, sizeof(struct stat));
buf->st_mode = S_IFREG | S_IROTH | S_IRGRP | S_IRUSR;
/* If the write method is provided, then let's also claim that the file is
* writable.
*/
if (handler->procfsentry->ops->write != NULL)
{
buf->st_mode |= S_IWOTH | S_IWGRP | S_IWUSR;
}
return OK;
}