Skip to content

Commit

Permalink
Rename st_*timespec fields to st_*tim for POSIX 2008 compliance.
Browse files Browse the repository at this point in the history
A nice thing about POSIX 2008 is that it finally standardizes a way to
obtain file access/modification/change times in sub-second precision,
namely using struct timespec, which we already have for a very long
time. Unfortunately POSIX uses different names.

This commit adds compatibility macros, so existing code should still
build properly. Also change all source code in the kernel to work
without any of the compatibility macros. This makes it all a less
ambiguous.

I am also renaming st_birthtime to st_birthtim, even though it was a
local extension anyway. It seems Cygwin also has a st_birthtim.
  • Loading branch information
ed authored and ed committed Mar 28, 2010
1 parent 9eaa28f commit 4f08ecd
Show file tree
Hide file tree
Showing 18 changed files with 140 additions and 159 deletions.
28 changes: 17 additions & 11 deletions lib/libc/sys/stat.2
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ fields together identify the file uniquely within the system.
The time-related fields of
.Vt "struct stat"
are as follows:
.Bl -tag -width ".Va st_birthtime"
.It Va st_atime
.Bl -tag -width ".Va st_birthtim"
.It Va st_atim
Time when file data last accessed.
Changed by the
.Xr mknod 2 ,
Expand All @@ -159,7 +159,7 @@ Changed by the
and
.Xr readv 2
system calls.
.It Va st_mtime
.It Va st_mtim
Time when file data last modified.
Changed by the
.Xr mkdir 2 ,
Expand All @@ -170,7 +170,7 @@ Changed by the
and
.Xr writev 2
system calls.
.It Va st_ctime
.It Va st_ctim
Time when file status was last changed (inode data modification).
Changed by the
.Xr chflags 2 ,
Expand All @@ -191,18 +191,24 @@ Changed by the
and
.Xr writev 2
system calls.
.It Va st_birthtime
.It Va st_birthtim
Time when the inode was created.
.El
.Pp
If
.Dv _POSIX_SOURCE
is not defined, the time-related fields are defined as:
The following time-related macros are defined for compatibility:
.Bd -literal
#define st_atime st_atim.tv_sec
#define st_mtime st_mtim.tv_sec
#define st_ctime st_ctim.tv_sec
#ifndef _POSIX_SOURCE
#define st_birthtime st_birthtim.tv_sec
#endif

#ifndef _POSIX_SOURCE
#define st_atime st_atimespec.tv_sec
#define st_mtime st_mtimespec.tv_sec
#define st_ctime st_ctimespec.tv_sec
#define st_atimespec st_atim
#define st_mtimespec st_mtim
#define st_ctimespec st_ctim
#define st_birthtimespec st_birthtim
#endif
.Ed
.Pp
Expand Down
18 changes: 9 additions & 9 deletions sys/amd64/linux32/linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ struct l_newstat {
l_ulong st_size;
l_ulong st_blksize;
l_ulong st_blocks;
struct l_timespec st_atimespec;
struct l_timespec st_mtimespec;
struct l_timespec st_ctimespec;
struct l_timespec st_atim;
struct l_timespec st_mtim;
struct l_timespec st_ctim;
l_ulong __unused4;
l_ulong __unused5;
} __packed;
Expand All @@ -219,9 +219,9 @@ struct l_stat {
l_ushort st_gid;
l_ushort st_rdev;
l_long st_size;
struct l_timespec st_atimespec;
struct l_timespec st_mtimespec;
struct l_timespec st_ctimespec;
struct l_timespec st_atim;
struct l_timespec st_mtim;
struct l_timespec st_ctim;
l_long st_blksize;
l_long st_blocks;
l_ulong st_flags;
Expand All @@ -242,9 +242,9 @@ struct l_stat64 {
l_ulong st_blksize;
l_ulong st_blocks;
l_ulong __pad4;
struct l_timespec st_atimespec;
struct l_timespec st_mtimespec;
struct l_timespec st_ctimespec;
struct l_timespec st_atim;
struct l_timespec st_mtim;
struct l_timespec st_ctim;
l_ulonglong st_ino;
} __packed;

Expand Down
8 changes: 4 additions & 4 deletions sys/compat/freebsd32/freebsd32.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,15 @@ struct stat32 {
uid_t st_uid;
gid_t st_gid;
dev_t st_rdev;
struct timespec32 st_atimespec;
struct timespec32 st_mtimespec;
struct timespec32 st_ctimespec;
struct timespec32 st_atim;
struct timespec32 st_mtim;
struct timespec32 st_ctim;
off_t st_size;
int64_t st_blocks;
u_int32_t st_blksize;
u_int32_t st_flags;
u_int32_t st_gen;
struct timespec32 st_birthtimespec;
struct timespec32 st_birthtim;
unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec32));
unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec32));
};
Expand Down
6 changes: 3 additions & 3 deletions sys/compat/freebsd32/freebsd32_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1634,9 +1634,9 @@ copy_stat( struct stat *in, struct stat32 *out)
CP(*in, *out, st_uid);
CP(*in, *out, st_gid);
CP(*in, *out, st_rdev);
TS_CP(*in, *out, st_atimespec);
TS_CP(*in, *out, st_mtimespec);
TS_CP(*in, *out, st_ctimespec);
TS_CP(*in, *out, st_atim);
TS_CP(*in, *out, st_mtim);
TS_CP(*in, *out, st_ctim);
CP(*in, *out, st_size);
CP(*in, *out, st_blocks);
CP(*in, *out, st_blksize);
Expand Down
27 changes: 18 additions & 9 deletions sys/compat/linux/linux_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,12 @@ newstat_copyout(struct stat *buf, void *ubuf)
tbuf.st_gid = buf->st_gid;
tbuf.st_rdev = buf->st_rdev;
tbuf.st_size = buf->st_size;
tbuf.st_atime = buf->st_atime;
tbuf.st_mtime = buf->st_mtime;
tbuf.st_ctime = buf->st_ctime;
tbuf.st_atim.tv_sec = buf->st_atim.tv_sec;
tbuf.st_atim.tv_nsec = buf->st_atim.tv_nsec;
tbuf.st_mtim.tv_sec = buf->st_mtim.tv_sec;
tbuf.st_mtim.tv_nsec = buf->st_mtim.tv_nsec;
tbuf.st_ctim.tv_sec = buf->st_ctim.tv_sec;
tbuf.st_ctim.tv_nsec = buf->st_ctim.tv_nsec;
tbuf.st_blksize = buf->st_blksize;
tbuf.st_blocks = buf->st_blocks;

Expand Down Expand Up @@ -260,9 +263,12 @@ stat_copyout(struct stat *buf, void *ubuf)
lbuf.st_size = buf->st_size;
else
lbuf.st_size = -2;
lbuf.st_atime = buf->st_atime;
lbuf.st_mtime = buf->st_mtime;
lbuf.st_ctime = buf->st_ctime;
lbuf.st_atim.tv_sec = buf->st_atim.tv_sec;
lbuf.st_atim.tv_nsec = buf->st_atim.tv_nsec;
lbuf.st_mtim.tv_sec = buf->st_mtim.tv_sec;
lbuf.st_mtim.tv_nsec = buf->st_mtim.tv_nsec;
lbuf.st_ctim.tv_sec = buf->st_ctim.tv_sec;
lbuf.st_ctim.tv_nsec = buf->st_ctim.tv_nsec;
lbuf.st_blksize = buf->st_blksize;
lbuf.st_blocks = buf->st_blocks;
lbuf.st_flags = buf->st_flags;
Expand Down Expand Up @@ -498,9 +504,12 @@ stat64_copyout(struct stat *buf, void *ubuf)
lbuf.st_gid = buf->st_gid;
lbuf.st_rdev = buf->st_rdev;
lbuf.st_size = buf->st_size;
lbuf.st_atime = buf->st_atime;
lbuf.st_mtime = buf->st_mtime;
lbuf.st_ctime = buf->st_ctime;
lbuf.st_atim.tv_sec = buf->st_atim.tv_sec;
lbuf.st_atim.tv_nsec = buf->st_atim.tv_nsec;
lbuf.st_mtim.tv_sec = buf->st_mtim.tv_sec;
lbuf.st_mtim.tv_nsec = buf->st_mtim.tv_nsec;
lbuf.st_ctim.tv_sec = buf->st_ctim.tv_sec;
lbuf.st_ctim.tv_nsec = buf->st_ctim.tv_nsec;
lbuf.st_blksize = buf->st_blksize;
lbuf.st_blocks = buf->st_blocks;

Expand Down
18 changes: 9 additions & 9 deletions sys/compat/svr4/svr4_stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ bsd_to_svr4_stat(st, st4)
st4->st_gid = st->st_gid;
st4->st_rdev = bsd_to_svr4_odev_t(st->st_rdev);
st4->st_size = st->st_size;
st4->st_atim = st->st_atimespec.tv_sec;
st4->st_mtim = st->st_mtimespec.tv_sec;
st4->st_ctim = st->st_ctimespec.tv_sec;
st4->st_atim = st->st_atim.tv_sec;
st4->st_mtim = st->st_mtim.tv_sec;
st4->st_ctim = st->st_ctim.tv_sec;
}
#endif

Expand All @@ -127,9 +127,9 @@ bsd_to_svr4_xstat(st, st4)
st4->st_gid = st->st_gid;
st4->st_rdev = bsd_to_svr4_dev_t(st->st_rdev);
st4->st_size = st->st_size;
st4->st_atim = st->st_atimespec;
st4->st_mtim = st->st_mtimespec;
st4->st_ctim = st->st_ctimespec;
st4->st_atim = st->st_atim;
st4->st_mtim = st->st_mtim;
st4->st_ctim = st->st_ctim;
st4->st_blksize = st->st_blksize;
st4->st_blocks = st->st_blocks;
strcpy(st4->st_fstype, "unknown");
Expand All @@ -150,9 +150,9 @@ bsd_to_svr4_stat64(st, st4)
st4->st_gid = st->st_gid;
st4->st_rdev = bsd_to_svr4_dev_t(st->st_rdev);
st4->st_size = st->st_size;
st4->st_atim = st->st_atimespec;
st4->st_mtim = st->st_mtimespec;
st4->st_ctim = st->st_ctimespec;
st4->st_atim = st->st_atim;
st4->st_mtim = st->st_mtim;
st4->st_ctim = st->st_ctim;
st4->st_blksize = st->st_blksize;
st4->st_blocks = st->st_blocks;
strcpy(st4->st_fstype, "unknown");
Expand Down
6 changes: 3 additions & 3 deletions sys/i386/ibcs2/ibcs2_stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ bsd_stat2ibcs_stat(st, st4)
st4->st_size = (ibcs2_off_t)st->st_size;
else
st4->st_size = -2;
st4->st_atim = (ibcs2_time_t)st->st_atime;
st4->st_mtim = (ibcs2_time_t)st->st_mtime;
st4->st_ctim = (ibcs2_time_t)st->st_ctime;
st4->st_atim = (ibcs2_time_t)st->st_atim.tv_sec;
st4->st_mtim = (ibcs2_time_t)st->st_mtim.tv_sec;
st4->st_ctim = (ibcs2_time_t)st->st_ctim.tv_sec;
}

static int
Expand Down
18 changes: 9 additions & 9 deletions sys/i386/linux/linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ struct l_newstat {
l_ulong st_size;
l_ulong st_blksize;
l_ulong st_blocks;
struct l_timespec st_atimespec;
struct l_timespec st_mtimespec;
struct l_timespec st_ctimespec;
struct l_timespec st_atim;
struct l_timespec st_mtim;
struct l_timespec st_ctim;
l_ulong __unused4;
l_ulong __unused5;
};
Expand All @@ -194,9 +194,9 @@ struct l_stat {
l_ushort st_gid;
l_ushort st_rdev;
l_long st_size;
struct l_timespec st_atimespec;
struct l_timespec st_mtimespec;
struct l_timespec st_ctimespec;
struct l_timespec st_atim;
struct l_timespec st_mtim;
struct l_timespec st_ctim;
l_long st_blksize;
l_long st_blocks;
l_ulong st_flags;
Expand All @@ -217,9 +217,9 @@ struct l_stat64 {
l_ulong st_blksize;
l_ulong st_blocks;
l_ulong __pad4;
struct l_timespec st_atimespec;
struct l_timespec st_mtimespec;
struct l_timespec st_ctimespec;
struct l_timespec st_atim;
struct l_timespec st_mtim;
struct l_timespec st_ctim;
l_ulonglong st_ino;
};

Expand Down
6 changes: 3 additions & 3 deletions sys/kern/sys_pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -1428,9 +1428,9 @@ pipe_stat(fp, ub, active_cred, td)
else
ub->st_size = pipe->pipe_buffer.cnt;
ub->st_blocks = (ub->st_size + ub->st_blksize - 1) / ub->st_blksize;
ub->st_atimespec = pipe->pipe_atime;
ub->st_mtimespec = pipe->pipe_mtime;
ub->st_ctimespec = pipe->pipe_ctime;
ub->st_atim = pipe->pipe_atime;
ub->st_mtim = pipe->pipe_mtime;
ub->st_ctim = pipe->pipe_ctime;
ub->st_uid = fp->f_cred->cr_uid;
ub->st_gid = fp->f_cred->cr_gid;
/*
Expand Down
6 changes: 3 additions & 3 deletions sys/kern/tty_pts.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,9 +556,9 @@ ptsdev_stat(struct file *fp, struct stat *sb, struct ucred *active_cred,
#endif /* PTS_EXTERNAL */
sb->st_ino = sb->st_rdev = tty_udev(tp);

sb->st_atimespec = dev->si_atime;
sb->st_ctimespec = dev->si_ctime;
sb->st_mtimespec = dev->si_mtime;
sb->st_atim = dev->si_atime;
sb->st_ctim = dev->si_ctime;
sb->st_mtim = dev->si_mtime;
sb->st_uid = dev->si_uid;
sb->st_gid = dev->si_gid;
sb->st_mode = dev->si_mode | S_IFCHR;
Expand Down
8 changes: 4 additions & 4 deletions sys/kern/uipc_mqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -2447,10 +2447,10 @@ mqf_stat(struct file *fp, struct stat *st, struct ucred *active_cred,
struct mqfs_node *pn = fp->f_data;

bzero(st, sizeof *st);
st->st_atimespec = pn->mn_atime;
st->st_mtimespec = pn->mn_mtime;
st->st_ctimespec = pn->mn_ctime;
st->st_birthtimespec = pn->mn_birth;
st->st_atim = pn->mn_atime;
st->st_mtim = pn->mn_mtime;
st->st_ctim = pn->mn_ctime;
st->st_birthtim = pn->mn_birth;
st->st_uid = pn->mn_uid;
st->st_gid = pn->mn_gid;
st->st_mode = S_IFIFO | pn->mn_mode;
Expand Down
8 changes: 4 additions & 4 deletions sys/kern/uipc_sem.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,10 @@ ksem_stat(struct file *fp, struct stat *sb, struct ucred *active_cred,
bzero(sb, sizeof(*sb));
sb->st_mode = S_IFREG | ks->ks_mode; /* XXX */

sb->st_atimespec = ks->ks_atime;
sb->st_ctimespec = ks->ks_ctime;
sb->st_mtimespec = ks->ks_mtime;
sb->st_birthtimespec = ks->ks_birthtime;
sb->st_atim = ks->ks_atime;
sb->st_ctim = ks->ks_ctime;
sb->st_mtim = ks->ks_mtime;
sb->st_birthtim = ks->ks_birthtime;
sb->st_uid = ks->ks_uid;
sb->st_gid = ks->ks_gid;

Expand Down
8 changes: 4 additions & 4 deletions sys/kern/uipc_shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,10 @@ shm_stat(struct file *fp, struct stat *sb, struct ucred *active_cred,
sb->st_blksize = PAGE_SIZE;
sb->st_size = shmfd->shm_size;
sb->st_blocks = (sb->st_size + sb->st_blksize - 1) / sb->st_blksize;
sb->st_atimespec = shmfd->shm_atime;
sb->st_ctimespec = shmfd->shm_ctime;
sb->st_mtimespec = shmfd->shm_mtime;
sb->st_birthtimespec = shmfd->shm_birthtime;
sb->st_atim = shmfd->shm_atime;
sb->st_ctim = shmfd->shm_ctime;
sb->st_mtim = shmfd->shm_mtime;
sb->st_birthtim = shmfd->shm_birthtime;
sb->st_uid = shmfd->shm_uid;
sb->st_gid = shmfd->shm_gid;

Expand Down
14 changes: 7 additions & 7 deletions sys/kern/vfs_syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -2269,9 +2269,9 @@ cvtstat(st, ost)
ost->st_size = st->st_size;
else
ost->st_size = -2;
ost->st_atime = st->st_atime;
ost->st_mtime = st->st_mtime;
ost->st_ctime = st->st_ctime;
ost->st_atim = st->st_atim;
ost->st_mtim = st->st_mtim;
ost->st_ctim = st->st_ctim;
ost->st_blksize = st->st_blksize;
ost->st_blocks = st->st_blocks;
ost->st_flags = st->st_flags;
Expand Down Expand Up @@ -2431,15 +2431,15 @@ cvtnstat(sb, nsb)
nsb->st_uid = sb->st_uid;
nsb->st_gid = sb->st_gid;
nsb->st_rdev = sb->st_rdev;
nsb->st_atimespec = sb->st_atimespec;
nsb->st_mtimespec = sb->st_mtimespec;
nsb->st_ctimespec = sb->st_ctimespec;
nsb->st_atim = sb->st_atim;
nsb->st_mtim = sb->st_mtim;
nsb->st_ctim = sb->st_ctim;
nsb->st_size = sb->st_size;
nsb->st_blocks = sb->st_blocks;
nsb->st_blksize = sb->st_blksize;
nsb->st_flags = sb->st_flags;
nsb->st_gen = sb->st_gen;
nsb->st_birthtimespec = sb->st_birthtimespec;
nsb->st_birthtim = sb->st_birthtim;
}

#ifndef _SYS_SYSPROTO_H_
Expand Down
8 changes: 4 additions & 4 deletions sys/kern/vfs_vnops.c
Original file line number Diff line number Diff line change
Expand Up @@ -782,10 +782,10 @@ vn_stat(vp, sb, active_cred, file_cred, td)
if (vap->va_size > OFF_MAX)
return (EOVERFLOW);
sb->st_size = vap->va_size;
sb->st_atimespec = vap->va_atime;
sb->st_mtimespec = vap->va_mtime;
sb->st_ctimespec = vap->va_ctime;
sb->st_birthtimespec = vap->va_birthtime;
sb->st_atim = vap->va_atime;
sb->st_mtim = vap->va_mtime;
sb->st_ctim = vap->va_ctime;
sb->st_birthtim = vap->va_birthtime;

/*
* According to www.opengroup.org, the meaning of st_blksize is
Expand Down
Loading

0 comments on commit 4f08ecd

Please sign in to comment.