fs: Add utimens and lutimens
https://pubs.opengroup.org/onlinepubs/9699919799/functions/futimens.html https://www.daemon-systems.org/man/utimens.2.html Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
parent
50c49da078
commit
6c61d032db
@ -25,7 +25,6 @@
|
|||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/time.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@ -301,15 +300,15 @@ int lchown(FAR const char *path, uid_t owner, gid_t group)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: utimes
|
* Name: utimens
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* The utimes() function shall set the access and modification times of
|
* The utimens() function shall set the access and modification times of
|
||||||
* the file pointed to by the path argument to the value of the times
|
* the file pointed to by the path argument to the value of the times
|
||||||
* argument. utimes() function allows time specifications accurate to
|
* argument. utimens() function allows time specifications accurate to
|
||||||
* the microsecond.
|
* the microsecond.
|
||||||
*
|
*
|
||||||
* For utimes(), the times argument is an array of timeval structures.
|
* For utimens(), the times argument is an array of timeval structures.
|
||||||
* The first array member represents the date and time of last access,
|
* The first array member represents the date and time of last access,
|
||||||
* and the second member represents the date and time of last
|
* and the second member represents the date and time of last
|
||||||
* modification. The times in the timeval structure are measured in
|
* modification. The times in the timeval structure are measured in
|
||||||
@ -320,7 +319,7 @@ int lchown(FAR const char *path, uid_t owner, gid_t group)
|
|||||||
* times of the file shall be set to the current time. The effective
|
* times of the file shall be set to the current time. The effective
|
||||||
* user ID of the process shall match the owner of the file, has write
|
* user ID of the process shall match the owner of the file, has write
|
||||||
* access to the file or appropriate privileges to use this call in this
|
* access to the file or appropriate privileges to use this call in this
|
||||||
* manner. Upon completion, utimes() shall mark the time of the last
|
* manner. Upon completion, utimens() shall mark the time of the last
|
||||||
* file status change, st_ctime, for update.
|
* file status change, st_ctime, for update.
|
||||||
*
|
*
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
@ -334,14 +333,14 @@ int lchown(FAR const char *path, uid_t owner, gid_t group)
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int utimes(FAR const char *path, const struct timeval times[2])
|
int utimens(FAR const char *path, const struct timespec times[2])
|
||||||
{
|
{
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
|
|
||||||
if (times != NULL)
|
if (times != NULL)
|
||||||
{
|
{
|
||||||
TIMEVAL_TO_TIMESPEC(×[0], &buf.st_atim);
|
buf.st_atim = times[0];
|
||||||
TIMEVAL_TO_TIMESPEC(×[1], &buf.st_mtim);
|
buf.st_mtim = times[1];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -353,10 +352,10 @@ int utimes(FAR const char *path, const struct timeval times[2])
|
|||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: lutimes
|
* Name: lutimens
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* The lutimes() system call is similar to utimes() but does not follow
|
* The lutimens() system call is similar to utimens() but does not follow
|
||||||
* the symbolic links.
|
* the symbolic links.
|
||||||
*
|
*
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
@ -370,14 +369,14 @@ int utimes(FAR const char *path, const struct timeval times[2])
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int lutimes(FAR const char *path, const struct timeval times[2])
|
int lutimens(FAR const char *path, const struct timespec times[2])
|
||||||
{
|
{
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
|
|
||||||
if (times != NULL)
|
if (times != NULL)
|
||||||
{
|
{
|
||||||
TIMEVAL_TO_TIMESPEC(×[0], &buf.st_atim);
|
buf.st_atim = times[0];
|
||||||
TIMEVAL_TO_TIMESPEC(×[1], &buf.st_mtim);
|
buf.st_mtim = times[1];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -178,6 +178,8 @@ int fstat(int fd, FAR struct stat *buf);
|
|||||||
int chmod(FAR const char *path, mode_t mode);
|
int chmod(FAR const char *path, mode_t mode);
|
||||||
int lchmod(FAR const char *path, mode_t mode);
|
int lchmod(FAR const char *path, mode_t mode);
|
||||||
int fchmod(int fd, mode_t mode);
|
int fchmod(int fd, mode_t mode);
|
||||||
|
int utimens(FAR const char *path, const struct timespec times[2]);
|
||||||
|
int lutimens(FAR const char *path, const struct timespec times[2]);
|
||||||
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);
|
||||||
|
@ -254,8 +254,8 @@ SYSCALL_LOOKUP(fchmod, 2)
|
|||||||
SYSCALL_LOOKUP(chown, 3)
|
SYSCALL_LOOKUP(chown, 3)
|
||||||
SYSCALL_LOOKUP(lchown, 3)
|
SYSCALL_LOOKUP(lchown, 3)
|
||||||
SYSCALL_LOOKUP(fchown, 3)
|
SYSCALL_LOOKUP(fchown, 3)
|
||||||
SYSCALL_LOOKUP(utimes, 2)
|
SYSCALL_LOOKUP(utimens, 2)
|
||||||
SYSCALL_LOOKUP(lutimes, 2)
|
SYSCALL_LOOKUP(lutimens, 2)
|
||||||
SYSCALL_LOOKUP(futimens, 2)
|
SYSCALL_LOOKUP(futimens, 2)
|
||||||
|
|
||||||
#if defined(CONFIG_FS_RAMMAP)
|
#if defined(CONFIG_FS_RAMMAP)
|
||||||
|
@ -26,9 +26,9 @@ CSRCS += lib_getopt_longonly.c lib_getoptvars.c lib_getoptargp.c
|
|||||||
CSRCS += lib_getopterrp.c lib_getoptindp.c lib_getoptoptp.c lib_times.c
|
CSRCS += lib_getopterrp.c lib_getoptindp.c lib_getoptoptp.c lib_times.c
|
||||||
CSRCS += lib_alarm.c lib_fstatvfs.c lib_statvfs.c lib_sleep.c lib_nice.c
|
CSRCS += lib_alarm.c lib_fstatvfs.c lib_statvfs.c lib_sleep.c lib_nice.c
|
||||||
CSRCS += lib_usleep.c lib_seteuid.c lib_setegid.c lib_geteuid.c lib_getegid.c
|
CSRCS += lib_usleep.c lib_seteuid.c lib_setegid.c lib_geteuid.c lib_getegid.c
|
||||||
CSRCS += lib_setreuid.c lib_setregid.c lib_getrusage.c lib_utime.c
|
CSRCS += lib_setreuid.c lib_setregid.c lib_getrusage.c lib_utime.c lib_utimes.c
|
||||||
CSRCS += lib_setrlimit.c lib_getrlimit.c lib_setpriority.c lib_getpriority.c
|
CSRCS += lib_setrlimit.c lib_getrlimit.c lib_setpriority.c lib_getpriority.c
|
||||||
CSRCS += lib_futimes.c lib_gethostname.c lib_sethostname.c
|
CSRCS += lib_futimes.c lib_lutimes.c lib_gethostname.c lib_sethostname.c
|
||||||
|
|
||||||
ifneq ($(CONFIG_SCHED_USER_IDENTITY),y)
|
ifneq ($(CONFIG_SCHED_USER_IDENTITY),y)
|
||||||
CSRCS += lib_setuid.c lib_setgid.c lib_getuid.c lib_getgid.c
|
CSRCS += lib_setuid.c lib_setgid.c lib_getuid.c lib_getgid.c
|
||||||
|
47
libs/libc/unistd/lib_lutimes.c
Normal file
47
libs/libc/unistd/lib_lutimes.c
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* libs/libc/unistd/lib_lutimes.c
|
||||||
|
*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership. The
|
||||||
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the
|
||||||
|
* License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int lutimes(FAR const char *path, const struct timeval tv[2])
|
||||||
|
{
|
||||||
|
struct timespec times[2];
|
||||||
|
|
||||||
|
if (tv == NULL)
|
||||||
|
{
|
||||||
|
return lutimens(path, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
times[0].tv_sec = tv[0].tv_sec;
|
||||||
|
times[0].tv_nsec = tv[0].tv_usec * 1000;
|
||||||
|
times[1].tv_sec = tv[1].tv_sec;
|
||||||
|
times[1].tv_nsec = tv[1].tv_usec * 1000;
|
||||||
|
|
||||||
|
return lutimens(path, times);
|
||||||
|
}
|
47
libs/libc/unistd/lib_utimes.c
Normal file
47
libs/libc/unistd/lib_utimes.c
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* libs/libc/unistd/lib_utimes.c
|
||||||
|
*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership. The
|
||||||
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the
|
||||||
|
* License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int utimes(FAR const char *path, const struct timeval tv[2])
|
||||||
|
{
|
||||||
|
struct timespec times[2];
|
||||||
|
|
||||||
|
if (tv == NULL)
|
||||||
|
{
|
||||||
|
return utimens(path, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
times[0].tv_sec = tv[0].tv_sec;
|
||||||
|
times[0].tv_nsec = tv[0].tv_usec * 1000;
|
||||||
|
times[1].tv_sec = tv[1].tv_sec;
|
||||||
|
times[1].tv_nsec = tv[1].tv_usec * 1000;
|
||||||
|
|
||||||
|
return utimens(path, times);
|
||||||
|
}
|
@ -56,7 +56,7 @@
|
|||||||
"listen","sys/socket.h","defined(CONFIG_NET)","int","int","int"
|
"listen","sys/socket.h","defined(CONFIG_NET)","int","int","int"
|
||||||
"lseek","unistd.h","","off_t","int","off_t","int"
|
"lseek","unistd.h","","off_t","int","off_t","int"
|
||||||
"lstat","sys/stat.h","","int","FAR const char *","FAR struct stat *"
|
"lstat","sys/stat.h","","int","FAR const char *","FAR struct stat *"
|
||||||
"lutimes","sys/time.h","","int","FAR const char *","const struct timeval [2]|FAR const struct timeval *"
|
"lutimens","sys/stat.h","","int","FAR const char *","const struct timespec [2]|FAR const struct timespec *"
|
||||||
"mkdir","sys/stat.h","!defined(CONFIG_DISABLE_MOUNTPOINT)","int","FAR const char *","mode_t"
|
"mkdir","sys/stat.h","!defined(CONFIG_DISABLE_MOUNTPOINT)","int","FAR const char *","mode_t"
|
||||||
"mmap","sys/mman.h","","FAR void *","FAR void *","size_t","int","int","int","off_t"
|
"mmap","sys/mman.h","","FAR void *","FAR void *","size_t","int","int","int","off_t"
|
||||||
"modhandle","nuttx/module.h","defined(CONFIG_MODULE)","FAR void *","FAR const char *"
|
"modhandle","nuttx/module.h","defined(CONFIG_MODULE)","FAR void *","FAR const char *"
|
||||||
@ -189,7 +189,7 @@
|
|||||||
"unlink","unistd.h","!defined(CONFIG_DISABLE_MOUNTPOINT)","int","FAR const char *"
|
"unlink","unistd.h","!defined(CONFIG_DISABLE_MOUNTPOINT)","int","FAR const char *"
|
||||||
"unsetenv","stdlib.h","!defined(CONFIG_DISABLE_ENVIRON)","int","FAR const char *"
|
"unsetenv","stdlib.h","!defined(CONFIG_DISABLE_ENVIRON)","int","FAR const char *"
|
||||||
"up_assert","nuttx/arch.h","","void","FAR const char *","int"
|
"up_assert","nuttx/arch.h","","void","FAR const char *","int"
|
||||||
"utimes","sys/time.h","","int","FAR const char *","const struct timeval [2]|FAR const struct timeval *"
|
"utimens","sys/stat.h","","int","FAR const char *","const struct timespec [2]|FAR const struct timespec *"
|
||||||
"vfork","unistd.h","defined(CONFIG_SCHED_WAITPID) && defined(CONFIG_ARCH_HAVE_VFORK)","pid_t"
|
"vfork","unistd.h","defined(CONFIG_SCHED_WAITPID) && defined(CONFIG_ARCH_HAVE_VFORK)","pid_t"
|
||||||
"wait","sys/wait.h","defined(CONFIG_SCHED_WAITPID) && defined(CONFIG_SCHED_HAVE_PARENT)","pid_t","FAR int *"
|
"wait","sys/wait.h","defined(CONFIG_SCHED_WAITPID) && defined(CONFIG_SCHED_HAVE_PARENT)","pid_t","FAR int *"
|
||||||
"waitid","sys/wait.h","defined(CONFIG_SCHED_WAITPID) && defined(CONFIG_SCHED_HAVE_PARENT)","int","idtype_t","id_t"," FAR siginfo_t *","int"
|
"waitid","sys/wait.h","defined(CONFIG_SCHED_WAITPID) && defined(CONFIG_SCHED_HAVE_PARENT)","int","idtype_t","id_t"," FAR siginfo_t *","int"
|
||||||
|
Can't render this file because it has a wrong number of fields in line 2.
|
Loading…
x
Reference in New Issue
Block a user