+#include "devfs.h"
+
+#if FDESC
+#include "fdesc.h"
+#endif /* FDESC */
+
+static int devfs_update(struct vnode *vp, struct timeval *access,
+ struct timeval *modify);
+void devfs_rele_node(devnode_t *);
+static void devfs_consider_time_update(devnode_t *dnp, uint32_t just_changed_flags);
+static boolean_t devfs_update_needed(long now_s, long last_s);
+void dn_times_locked(devnode_t * dnp, struct timeval *t1, struct timeval *t2, struct timeval *t3, uint32_t just_changed_flags);
+void dn_times_now(devnode_t *dnp, uint32_t just_changed_flags);
+void dn_mark_for_delayed_times_update(devnode_t *dnp, uint32_t just_changed_flags);
+
+void
+dn_times_locked(devnode_t * dnp, struct timeval *t1, struct timeval *t2, struct timeval *t3, uint32_t just_changed_flags)
+{
+
+ lck_mtx_assert(&devfs_attr_mutex, LCK_MTX_ASSERT_OWNED);
+
+ if (just_changed_flags & DEVFS_UPDATE_ACCESS) {
+ dnp->dn_atime.tv_sec = t1->tv_sec;
+ dnp->dn_atime.tv_nsec = t1->tv_usec * 1000;
+ dnp->dn_access = 0;
+ } else if (dnp->dn_access) {
+ dnp->dn_atime.tv_sec = MIN(t1->tv_sec, dnp->dn_atime.tv_sec + DEVFS_LAZY_UPDATE_SECONDS);
+ dnp->dn_atime.tv_nsec = t1->tv_usec * 1000;
+ dnp->dn_access = 0;
+ }
+
+ if (just_changed_flags & DEVFS_UPDATE_MOD) {
+ dnp->dn_mtime.tv_sec = t2->tv_sec;
+ dnp->dn_mtime.tv_nsec = t2->tv_usec * 1000;
+ dnp->dn_update = 0;
+ } else if (dnp->dn_update) {
+ dnp->dn_mtime.tv_sec = MIN(t2->tv_sec, dnp->dn_mtime.tv_sec + DEVFS_LAZY_UPDATE_SECONDS);
+ dnp->dn_mtime.tv_nsec = t2->tv_usec * 1000;
+ dnp->dn_update = 0;
+ }
+
+ if (just_changed_flags & DEVFS_UPDATE_CHANGE) {
+ dnp->dn_ctime.tv_sec = t3->tv_sec;
+ dnp->dn_ctime.tv_nsec = t3->tv_usec * 1000;
+ dnp->dn_change = 0;
+ } else if (dnp->dn_change) {
+ dnp->dn_ctime.tv_sec = MIN(t3->tv_sec, dnp->dn_ctime.tv_sec + DEVFS_LAZY_UPDATE_SECONDS);
+ dnp->dn_ctime.tv_nsec = t3->tv_usec * 1000;
+ dnp->dn_change = 0;
+ }
+}
+
+void
+dn_mark_for_delayed_times_update(devnode_t *dnp, uint32_t just_changed_flags)
+{
+ if (just_changed_flags & DEVFS_UPDATE_CHANGE) {
+ dnp->dn_change = 1;
+ }
+ if (just_changed_flags & DEVFS_UPDATE_ACCESS) {
+ dnp->dn_access = 1;
+ }
+ if (just_changed_flags & DEVFS_UPDATE_MOD) {
+ dnp->dn_update = 1;
+ }
+}
+
+/*
+ * Update times based on pending updates and optionally a set of new changes.
+ */
+void
+dn_times_now(devnode_t * dnp, uint32_t just_changed_flags)
+{
+ struct timeval now;