mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 12:32:40 +03:00
vfs: implement support for all known stat formats and centralize handling
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
This commit is contained in:
parent
c8e8f01faf
commit
eb1375b65d
@ -261,7 +261,7 @@ AC_CHECK_TYPE([major_t], [], [AC_DEFINE([major_t], [int], [Type of major device
|
|||||||
AC_CHECK_TYPE([minor_t], [], [AC_DEFINE([minor_t], [int], [Type of minor device numbers.])])
|
AC_CHECK_TYPE([minor_t], [], [AC_DEFINE([minor_t], [int], [Type of minor device numbers.])])
|
||||||
|
|
||||||
AC_STRUCT_ST_BLOCKS
|
AC_STRUCT_ST_BLOCKS
|
||||||
AC_CHECK_MEMBERS([struct stat.st_blksize, struct stat.st_rdev, struct stat.st_mtim])
|
AC_CHECK_MEMBERS([struct stat.st_blksize, struct stat.st_rdev, struct stat.st_mtim, struct stat.st_mtimespec, struct stat.st_mtimensec])
|
||||||
gl_STAT_SIZE
|
gl_STAT_SIZE
|
||||||
|
|
||||||
AH_TEMPLATE([sig_atomic_t],
|
AH_TEMPLATE([sig_atomic_t],
|
||||||
@ -387,14 +387,7 @@ AC_EGREP_CPP([yes],
|
|||||||
])
|
])
|
||||||
|
|
||||||
dnl utimensat is supported since glibc 2.6 and specified in POSIX.1-2008
|
dnl utimensat is supported since glibc 2.6 and specified in POSIX.1-2008
|
||||||
dnl utimensat() causes different timespec structures to cause failures on IBM i and AIX
|
|
||||||
case $host_os in
|
|
||||||
*os400 | aix*)
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
AC_CHECK_FUNCS([utimensat])
|
AC_CHECK_FUNCS([utimensat])
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
case $host_os in
|
case $host_os in
|
||||||
*os400)
|
*os400)
|
||||||
|
@ -113,13 +113,6 @@
|
|||||||
#define get_default_editor() "vi"
|
#define get_default_editor() "vi"
|
||||||
#define OS_SORT_CASE_SENSITIVE_DEFAULT TRUE
|
#define OS_SORT_CASE_SENSITIVE_DEFAULT TRUE
|
||||||
|
|
||||||
/* struct stat members */
|
|
||||||
#ifdef __APPLE__
|
|
||||||
#define st_atim st_atimespec
|
|
||||||
#define st_ctim st_ctimespec
|
|
||||||
#define st_mtim st_mtimespec
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*** enums ***************************************************************************************/
|
/*** enums ***************************************************************************************/
|
||||||
|
|
||||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
@ -1030,10 +1030,7 @@ vfs_s_default_stat (struct vfs_class *me, mode_t mode)
|
|||||||
#endif
|
#endif
|
||||||
st.st_size = 0;
|
st.st_size = 0;
|
||||||
|
|
||||||
st.st_mtime = st.st_atime = st.st_ctime = time (NULL);
|
vfs_zero_stat_times (&st);
|
||||||
#ifdef HAVE_STRUCT_STAT_ST_MTIM
|
|
||||||
st.st_atim.tv_nsec = st.st_mtim.tv_nsec = st.st_ctim.tv_nsec = 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
vfs_adjust_stat (&st);
|
vfs_adjust_stat (&st);
|
||||||
|
|
||||||
|
@ -796,15 +796,14 @@ vfs_parse_ls_lga (const char *p, struct stat *s, char **filename, char **linknam
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vfs_zero_stat_times (s);
|
||||||
|
|
||||||
idx = vfs_parse_filedate (idx, &s->st_mtime);
|
idx = vfs_parse_filedate (idx, &s->st_mtime);
|
||||||
if (idx == 0)
|
if (idx == 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
/* Use resulting time value */
|
/* Use resulting time value */
|
||||||
s->st_atime = s->st_ctime = s->st_mtime;
|
s->st_atime = s->st_ctime = s->st_mtime;
|
||||||
#ifdef HAVE_STRUCT_STAT_ST_MTIM
|
|
||||||
s->st_atim.tv_nsec = s->st_mtim.tv_nsec = s->st_ctim.tv_nsec = 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* s->st_dev and s->st_ino must be initialized by vfs_s_new_inode () */
|
/* s->st_dev and s->st_ino must be initialized by vfs_s_new_inode () */
|
||||||
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
|
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
|
||||||
|
@ -408,15 +408,70 @@ vfs_get_timespecs_from_timesbuf (mc_timesbuf_t *times, mc_timespec_t *atime, mc_
|
|||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
vfs_get_timesbuf_from_stat (const struct stat *sb, mc_timesbuf_t *times)
|
vfs_get_timesbuf_from_stat (const struct stat *s, mc_timesbuf_t *times)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_UTIMENSAT
|
#ifdef HAVE_UTIMENSAT
|
||||||
(*times)[0] = sb->st_atim;
|
#ifdef HAVE_STRUCT_STAT_ST_MTIM
|
||||||
(*times)[1] = sb->st_mtim;
|
/* POSIX IEEE Std 1003.1-2008 should be the preferred way
|
||||||
|
*
|
||||||
|
* AIX has internal type st_timespec_t conflicting with timespec, so assign per field, for details see:
|
||||||
|
* https://github.com/libuv/libuv/pull/4404
|
||||||
|
*/
|
||||||
|
(*times)[0].tv_sec = s->st_atim.tv_sec;
|
||||||
|
(*times)[0].tv_nsec = s->st_atim.tv_nsec;
|
||||||
|
(*times)[1].tv_sec = s->st_mtim.tv_sec;
|
||||||
|
(*times)[1].tv_nsec = s->st_mtim.tv_nsec;
|
||||||
|
#elif HAVE_STRUCT_STAT_ST_MTIMESPEC
|
||||||
|
/* Modern BSD solution */
|
||||||
|
(*times)[0] = s->st_atimespec;
|
||||||
|
(*times)[1] = s->st_mtimespec;
|
||||||
|
#elif HAVE_STRUCT_STAT_ST_MTIMENSEC
|
||||||
|
/* Legacy BSD solution */
|
||||||
|
(*times)[0].tv_sec = s->st_atime;
|
||||||
|
(*times)[0].tv_nsec = s->st_atimensec;
|
||||||
|
(*times)[1].tv_sec = s->st_mtime;
|
||||||
|
(*times)[1].tv_nsec = s->st_mtimensec;
|
||||||
#else
|
#else
|
||||||
times->actime = sb->st_atime;
|
#error "Found utimensat for nanosecond timestamps, but unsupported struct stat format!"
|
||||||
times->modtime = sb->st_mtime;
|
#endif
|
||||||
|
#else
|
||||||
|
times->actime = s->st_atime;
|
||||||
|
times->modtime = s->st_mtime;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
void
|
||||||
|
vfs_copy_stat_times (const struct stat *src, struct stat *dst)
|
||||||
|
{
|
||||||
|
dst->st_atime = src->st_atime;
|
||||||
|
dst->st_mtime = src->st_mtime;
|
||||||
|
dst->st_ctime = src->st_ctime;
|
||||||
|
|
||||||
|
#ifdef HAVE_STRUCT_STAT_ST_MTIM
|
||||||
|
dst->st_atim.tv_nsec = src->st_atim.tv_nsec;
|
||||||
|
dst->st_mtim.tv_nsec = src->st_mtim.tv_nsec;
|
||||||
|
dst->st_ctim.tv_nsec = src->st_ctim.tv_nsec;
|
||||||
|
#elif HAVE_STRUCT_STAT_ST_MTIMESPEC
|
||||||
|
dst->st_atimespec.tv_nsec = src->st_atimespec.tv_nsec;
|
||||||
|
dst->st_mtimespec.tv_nsec = src->st_mtimespec.tv_nsec;
|
||||||
|
dst->st_ctimespec.tv_nsec = src->st_ctimespec.tv_nsec;
|
||||||
|
#elif HAVE_STRUCT_STAT_ST_MTIMENSEC
|
||||||
|
dst->st_atimensec = src->st_atimensec;
|
||||||
|
dst->st_mtimensec = src->st_mtimensec;
|
||||||
|
dst->st_ctimensec = src->st_ctimensec;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
void
|
||||||
|
vfs_zero_stat_times (struct stat *s)
|
||||||
|
{
|
||||||
|
const struct stat empty = { 0 };
|
||||||
|
|
||||||
|
vfs_copy_stat_times (&empty, s);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
@ -63,7 +63,9 @@ int vfs_parse_filedate (int idx, time_t * t);
|
|||||||
int vfs_utime (const char *path, mc_timesbuf_t *times);
|
int vfs_utime (const char *path, mc_timesbuf_t *times);
|
||||||
void vfs_get_timespecs_from_timesbuf (mc_timesbuf_t *times, mc_timespec_t *atime,
|
void vfs_get_timespecs_from_timesbuf (mc_timesbuf_t *times, mc_timespec_t *atime,
|
||||||
mc_timespec_t *mtime);
|
mc_timespec_t *mtime);
|
||||||
void vfs_get_timesbuf_from_stat (const struct stat *sb, mc_timesbuf_t *times);
|
void vfs_get_timesbuf_from_stat (const struct stat *s, mc_timesbuf_t *times);
|
||||||
|
void vfs_copy_stat_times (const struct stat *src, struct stat *dst);
|
||||||
|
void vfs_zero_stat_times (struct stat *s);
|
||||||
|
|
||||||
/*** inline functions ****************************************************************************/
|
/*** inline functions ****************************************************************************/
|
||||||
|
|
||||||
|
@ -470,15 +470,8 @@ cpio_create_entry (struct vfs_class *me, struct vfs_s_super *super, struct stat
|
|||||||
entry->ino->st.st_mode = st->st_mode;
|
entry->ino->st.st_mode = st->st_mode;
|
||||||
entry->ino->st.st_uid = st->st_uid;
|
entry->ino->st.st_uid = st->st_uid;
|
||||||
entry->ino->st.st_gid = st->st_gid;
|
entry->ino->st.st_gid = st->st_gid;
|
||||||
#ifdef HAVE_STRUCT_STAT_ST_MTIM
|
|
||||||
entry->ino->st.st_atim = st->st_atim;
|
vfs_copy_stat_times (st, &entry->ino->st);
|
||||||
entry->ino->st.st_mtim = st->st_mtim;
|
|
||||||
entry->ino->st.st_ctim = st->st_ctim;
|
|
||||||
#else
|
|
||||||
entry->ino->st.st_atime = st->st_atime;
|
|
||||||
entry->ino->st.st_mtime = st->st_mtime;
|
|
||||||
entry->ino->st.st_ctime = st->st_ctime;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (name);
|
g_free (name);
|
||||||
@ -603,9 +596,9 @@ cpio_read_bin_head (struct vfs_class *me, struct vfs_s_super *super)
|
|||||||
st.st_rdev = u.buf.c_rdev;
|
st.st_rdev = u.buf.c_rdev;
|
||||||
#endif
|
#endif
|
||||||
st.st_size = ((off_t) u.buf.c_filesizes[0] << 16) | u.buf.c_filesizes[1];
|
st.st_size = ((off_t) u.buf.c_filesizes[0] << 16) | u.buf.c_filesizes[1];
|
||||||
#ifdef HAVE_STRUCT_STAT_ST_MTIM
|
|
||||||
st.st_atim.tv_nsec = st.st_mtim.tv_nsec = st.st_ctim.tv_nsec = 0;
|
vfs_zero_stat_times (&st);
|
||||||
#endif
|
|
||||||
st.st_atime = st.st_mtime = st.st_ctime =
|
st.st_atime = st.st_mtime = st.st_ctime =
|
||||||
((time_t) u.buf.c_mtimes[0] << 16) | u.buf.c_mtimes[1];
|
((time_t) u.buf.c_mtimes[0] << 16) | u.buf.c_mtimes[1];
|
||||||
|
|
||||||
@ -676,9 +669,8 @@ cpio_read_oldc_head (struct vfs_class *me, struct vfs_s_super *super)
|
|||||||
u.st.st_rdev = hd.c_rdev;
|
u.st.st_rdev = hd.c_rdev;
|
||||||
#endif
|
#endif
|
||||||
u.st.st_size = hd.c_filesize;
|
u.st.st_size = hd.c_filesize;
|
||||||
#ifdef HAVE_STRUCT_STAT_ST_MTIM
|
|
||||||
u.st.st_atim.tv_nsec = u.st.st_mtim.tv_nsec = u.st.st_ctim.tv_nsec = 0;
|
vfs_zero_stat_times (&u.st);
|
||||||
#endif
|
|
||||||
u.st.st_atime = u.st.st_mtime = u.st.st_ctime = hd.c_mtime;
|
u.st.st_atime = u.st.st_mtime = u.st.st_ctime = hd.c_mtime;
|
||||||
|
|
||||||
return cpio_create_entry (me, super, &u.st, name);
|
return cpio_create_entry (me, super, &u.st, name);
|
||||||
@ -757,9 +749,8 @@ cpio_read_crc_head (struct vfs_class *me, struct vfs_s_super *super)
|
|||||||
u.st.st_rdev = makedev (hd.c_rdev, hd.c_rdevmin);
|
u.st.st_rdev = makedev (hd.c_rdev, hd.c_rdevmin);
|
||||||
#endif
|
#endif
|
||||||
u.st.st_size = hd.c_filesize;
|
u.st.st_size = hd.c_filesize;
|
||||||
#ifdef HAVE_STRUCT_STAT_ST_MTIM
|
|
||||||
u.st.st_atim.tv_nsec = u.st.st_mtim.tv_nsec = u.st.st_ctim.tv_nsec = 0;
|
vfs_zero_stat_times (&u.st);
|
||||||
#endif
|
|
||||||
u.st.st_atime = u.st.st_mtime = u.st.st_ctime = hd.c_mtime;
|
u.st.st_atime = u.st.st_mtime = u.st.st_ctime = hd.c_mtime;
|
||||||
|
|
||||||
return cpio_create_entry (me, super, &u.st, name);
|
return cpio_create_entry (me, super, &u.st, name);
|
||||||
|
@ -1230,15 +1230,22 @@ extfs_closedir (void *data)
|
|||||||
static void
|
static void
|
||||||
extfs_stat_move (struct stat *buf, const struct vfs_s_inode *inode)
|
extfs_stat_move (struct stat *buf, const struct vfs_s_inode *inode)
|
||||||
{
|
{
|
||||||
|
const time_t atime = inode->st.st_atime;
|
||||||
|
const time_t mtime = inode->st.st_mtime;
|
||||||
|
const time_t ctime = inode->st.st_ctime;
|
||||||
|
|
||||||
*buf = inode->st;
|
*buf = inode->st;
|
||||||
|
|
||||||
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
|
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
|
||||||
buf->st_blksize = RECORDSIZE;
|
buf->st_blksize = RECORDSIZE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
vfs_adjust_stat (buf);
|
vfs_adjust_stat (buf);
|
||||||
#ifdef HAVE_STRUCT_STAT_ST_MTIM
|
vfs_zero_stat_times (buf);
|
||||||
buf->st_atim.tv_nsec = buf->st_mtim.tv_nsec = buf->st_ctim.tv_nsec = 0;
|
|
||||||
#endif
|
buf->st_atime = atime;
|
||||||
|
buf->st_mtime = mtime;
|
||||||
|
buf->st_ctime = ctime;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
|
|
||||||
#include "lib/global.h"
|
#include "lib/global.h"
|
||||||
#include "lib/util.h"
|
#include "lib/util.h"
|
||||||
|
#include "lib/vfs/utilvfs.h"
|
||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
|
||||||
@ -255,12 +256,10 @@ sftpfs_attr_to_stat (const LIBSSH2_SFTP_ATTRIBUTES *attrs, struct stat *s)
|
|||||||
|
|
||||||
if ((attrs->flags & LIBSSH2_SFTP_ATTR_ACMODTIME) != 0)
|
if ((attrs->flags & LIBSSH2_SFTP_ATTR_ACMODTIME) != 0)
|
||||||
{
|
{
|
||||||
|
vfs_zero_stat_times (s);
|
||||||
s->st_atime = attrs->atime;
|
s->st_atime = attrs->atime;
|
||||||
s->st_mtime = attrs->mtime;
|
s->st_mtime = attrs->mtime;
|
||||||
s->st_ctime = attrs->mtime;
|
s->st_ctime = attrs->mtime;
|
||||||
#ifdef HAVE_STRUCT_STAT_ST_MTIM
|
|
||||||
s->st_atim.tv_nsec = s->st_mtim.tv_nsec = s->st_ctim.tv_nsec = 0;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((attrs->flags & LIBSSH2_SFTP_ATTR_SIZE) != 0)
|
if ((attrs->flags & LIBSSH2_SFTP_ATTR_SIZE) != 0)
|
||||||
|
@ -860,12 +860,10 @@ shell_parse_ls (char *buffer, struct vfs_s_entry *ent)
|
|||||||
|
|
||||||
case 'd':
|
case 'd':
|
||||||
vfs_split_text (buffer);
|
vfs_split_text (buffer);
|
||||||
|
vfs_zero_stat_times (&ST);
|
||||||
if (vfs_parse_filedate (0, &ST.st_ctime) == 0)
|
if (vfs_parse_filedate (0, &ST.st_ctime) == 0)
|
||||||
break;
|
break;
|
||||||
ST.st_atime = ST.st_mtime = ST.st_ctime;
|
ST.st_atime = ST.st_mtime = ST.st_ctime;
|
||||||
#ifdef HAVE_STRUCT_STAT_ST_MTIM
|
|
||||||
ST.st_atim.tv_nsec = ST.st_mtim.tv_nsec = ST.st_ctim.tv_nsec = 0;
|
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'D':
|
case 'D':
|
||||||
@ -877,10 +875,8 @@ shell_parse_ls (char *buffer, struct vfs_s_entry *ent)
|
|||||||
if (sscanf (buffer, "%d %d %d %d %d %d", &tim.tm_year, &tim.tm_mon,
|
if (sscanf (buffer, "%d %d %d %d %d %d", &tim.tm_year, &tim.tm_mon,
|
||||||
&tim.tm_mday, &tim.tm_hour, &tim.tm_min, &tim.tm_sec) != 6)
|
&tim.tm_mday, &tim.tm_hour, &tim.tm_min, &tim.tm_sec) != 6)
|
||||||
break;
|
break;
|
||||||
|
vfs_zero_stat_times (&ST);
|
||||||
ST.st_atime = ST.st_mtime = ST.st_ctime = mktime (&tim);
|
ST.st_atime = ST.st_mtime = ST.st_ctime = mktime (&tim);
|
||||||
#ifdef HAVE_STRUCT_STAT_ST_MTIM
|
|
||||||
ST.st_atim.tv_nsec = ST.st_mtim.tv_nsec = ST.st_ctim.tv_nsec = 0;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -631,12 +631,12 @@ undelfs_stat_int (int inode_index, struct stat *buf)
|
|||||||
buf->st_uid = delarray[inode_index].uid;
|
buf->st_uid = delarray[inode_index].uid;
|
||||||
buf->st_gid = delarray[inode_index].gid;
|
buf->st_gid = delarray[inode_index].gid;
|
||||||
buf->st_size = delarray[inode_index].size;
|
buf->st_size = delarray[inode_index].size;
|
||||||
|
|
||||||
|
vfs_zero_stat_times (buf);
|
||||||
buf->st_atime = delarray[inode_index].dtime;
|
buf->st_atime = delarray[inode_index].dtime;
|
||||||
buf->st_ctime = delarray[inode_index].dtime;
|
buf->st_ctime = delarray[inode_index].dtime;
|
||||||
buf->st_mtime = delarray[inode_index].dtime;
|
buf->st_mtime = delarray[inode_index].dtime;
|
||||||
#ifdef HAVE_STRUCT_STAT_ST_MTIM
|
|
||||||
buf->st_atim.tv_nsec = buf->st_mtim.tv_nsec = buf->st_ctim.tv_nsec = 0;
|
|
||||||
#endif
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,10 +106,7 @@ message (int flags, const char *title, const char *text, ...)
|
|||||||
static void
|
static void
|
||||||
fill_stat_struct (struct stat *etalon_stat, int iterator)
|
fill_stat_struct (struct stat *etalon_stat, int iterator)
|
||||||
{
|
{
|
||||||
|
vfs_zero_stat_times (etalon_stat);
|
||||||
#ifdef HAVE_STRUCT_STAT_ST_MTIM
|
|
||||||
etalon_stat->st_atim.tv_nsec = etalon_stat->st_mtim.tv_nsec = etalon_stat->st_ctim.tv_nsec = 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
switch (iterator)
|
switch (iterator)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user