1
0
Fork 0
forked from nuttx/nuttx-update

fs: Move umask to task_info_s

and implement the related semantic correctly

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I0587341e2c505e41b5e24e55dba039ed200d65f2
This commit is contained in:
Xiang Xiao 2021-07-11 17:44:25 +08:00 committed by Alan Carvalho de Assis
parent 0148e1d501
commit a0f2f6c362
7 changed files with 36 additions and 16 deletions

View file

@ -24,6 +24,7 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <sys/stat.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
@ -188,6 +189,8 @@ static int file_mq_vopen(FAR struct file *mq, FAR const char *mq_name,
attr = va_arg(ap, FAR struct mq_attr *); attr = va_arg(ap, FAR struct mq_attr *);
} }
mode &= ~getumask();
/* Skip over any leading '/'. All message queue paths are relative to /* Skip over any leading '/'. All message queue paths are relative to
* CONFIG_FS_MQUEUE_MPATH. * CONFIG_FS_MQUEUE_MPATH.
*/ */

View file

@ -24,6 +24,7 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <sys/stat.h>
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdarg.h> #include <stdarg.h>
@ -86,7 +87,7 @@
* *
****************************************************************************/ ****************************************************************************/
FAR sem_t *sem_open (FAR const char *name, int oflags, ...) FAR sem_t *sem_open(FAR const char *name, int oflags, ...)
{ {
FAR struct inode *inode; FAR struct inode *inode;
FAR struct nsem_inode_s *nsem; FAR struct nsem_inode_s *nsem;
@ -174,7 +175,7 @@ FAR sem_t *sem_open (FAR const char *name, int oflags, ...)
*/ */
va_start(ap, oflags); va_start(ap, oflags);
mode = va_arg(ap, mode_t); mode = va_arg(ap, mode_t) & ~getumask();
value = va_arg(ap, unsigned); value = va_arg(ap, unsigned);
va_end(ap); va_end(ap);

View file

@ -63,6 +63,8 @@ int mkdir(const char *pathname, mode_t mode)
int errcode; int errcode;
int ret; int ret;
mode &= ~getumask();
/* Find the inode that includes this path */ /* Find the inode that includes this path */
SETUP_SEARCH(&desc, pathname, false); SETUP_SEARCH(&desc, pathname, false);

View file

@ -25,6 +25,7 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h>
#include <stdbool.h> #include <stdbool.h>
#include <fcntl.h> #include <fcntl.h>
#include <sched.h> #include <sched.h>
@ -69,6 +70,8 @@ static int file_vopen(FAR struct file *filep,
{ {
mode = va_arg(ap, mode_t); mode = va_arg(ap, mode_t);
} }
mode &= ~getumask();
#endif #endif
/* Get an inode for this file */ /* Get an inode for this file */

View file

@ -63,15 +63,14 @@
struct task_info_s struct task_info_s
{ {
sem_t ta_sem; sem_t ta_sem;
mode_t ta_umask; /* File mode creation mask */
#if CONFIG_TLS_NELEM > 0 #if CONFIG_TLS_NELEM > 0
tls_ndxset_t ta_tlsset; /* Set of TLS indexes allocated */ tls_ndxset_t ta_tlsset; /* Set of TLS indexes allocated */
tls_dtor_t ta_tlsdtor[CONFIG_TLS_NELEM]; /* List of TLS destructors */ tls_dtor_t ta_tlsdtor[CONFIG_TLS_NELEM]; /* List of TLS destructors */
#endif #endif
#ifndef CONFIG_BUILD_KERNEL #ifndef CONFIG_BUILD_KERNEL
struct getopt_s ta_getopt; /* Globals used by getopt() */ struct getopt_s ta_getopt; /* Globals used by getopt() */
#endif #endif
}; };

View file

@ -166,6 +166,7 @@ int fchmod(int fd, mode_t mode);
int futimens(int fd, const struct timespec times[2]); int futimens(int fd, const struct timespec times[2]);
mode_t umask(mode_t mask); mode_t umask(mode_t mask);
mode_t getumask(void);
#undef EXTERN #undef EXTERN
#if defined(__cplusplus) #if defined(__cplusplus)

View file

@ -23,12 +23,7 @@
****************************************************************************/ ****************************************************************************/
#include <sys/stat.h> #include <sys/stat.h>
#include <nuttx/tls.h>
/****************************************************************************
* Private Data
****************************************************************************/
static mode_t g_mask;
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
@ -50,8 +45,24 @@ static mode_t g_mask;
mode_t umask(mode_t mask) mode_t umask(mode_t mask)
{ {
mode_t prev = g_mask; FAR struct task_info_s *info;
mode_t prev;
info = task_get_info();
prev = info->ta_umask;
info->ta_umask = mask;
g_mask = mask & 0777;
return prev; return prev;
} }
/****************************************************************************
* Name: getumask
****************************************************************************/
mode_t getumask(void)
{
FAR struct task_info_s *info;
info = task_get_info();
return info->ta_umask;
}