summaryrefslogtreecommitdiffstats
path: root/fs/inode.c
diff options
context:
space:
mode:
authorDeepa Dinamani <deepa.kernel@gmail.com>2018-04-22 23:18:46 -0400
committerDeepa Dinamani <deepa.kernel@gmail.com>2018-05-25 18:31:09 -0400
commit8efd6894ff089adeeac7cb9f32125b85d963d1bc (patch)
treeba9af4e1fa02f46279683236e1a5c9407d12d6d0 /fs/inode.c
parent771c577c23bac90597c685971d7297ea00f99d11 (diff)
fs: add timespec64_truncate()
As vfs moves to using struct timespec64 to represent times, update the argument to timespec_truncate() to use struct timespec64. Also change the name of the function. The rest of the implementation logic is the same. Move this to fs/inode.c instead of kernel/time/time.c as all the users of this api are filesystems. Signed-off-by: Deepa Dinamani <deepa.kernel@gmail.com> Cc: <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/inode.c')
-rw-r--r--fs/inode.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/fs/inode.c b/fs/inode.c
index 13ceb98c3bd3..93af998ee290 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -2111,6 +2111,30 @@ void inode_nohighmem(struct inode *inode)
2111EXPORT_SYMBOL(inode_nohighmem); 2111EXPORT_SYMBOL(inode_nohighmem);
2112 2112
2113/** 2113/**
2114 * timespec64_trunc - Truncate timespec64 to a granularity
2115 * @t: Timespec64
2116 * @gran: Granularity in ns.
2117 *
2118 * Truncate a timespec64 to a granularity. Always rounds down. gran must
2119 * not be 0 nor greater than a second (NSEC_PER_SEC, or 10^9 ns).
2120 */
2121struct timespec64 timespec64_trunc(struct timespec64 t, unsigned gran)
2122{
2123 /* Avoid division in the common cases 1 ns and 1 s. */
2124 if (gran == 1) {
2125 /* nothing */
2126 } else if (gran == NSEC_PER_SEC) {
2127 t.tv_nsec = 0;
2128 } else if (gran > 1 && gran < NSEC_PER_SEC) {
2129 t.tv_nsec -= t.tv_nsec % gran;
2130 } else {
2131 WARN(1, "illegal file time granularity: %u", gran);
2132 }
2133 return t;
2134}
2135EXPORT_SYMBOL(timespec64_trunc);
2136
2137/**
2114 * current_time - Return FS time 2138 * current_time - Return FS time
2115 * @inode: inode. 2139 * @inode: inode.
2116 * 2140 *