summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2003-12-17 02:43:26 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2003-12-17 02:43:26 +0000
commitf359beedb0af9ed570c1644081be2805b66d0ad8 (patch)
tree64e25be32579c5137a5e64879b90c0e732c8d431 /sys
parentf06a6b6982576f2e6e39ee80c0ecc509fb27426c (diff)
add NOTE_EOF (return on EOF) and NOTE_TRUNCATE (vnode was truncated)
to kqueue from marius@monkey tested by brad@
Diffstat (limited to 'sys')
-rw-r--r--sys/sys/event.h4
-rw-r--r--sys/ufs/ufs/ufs_vnops.c19
2 files changed, 15 insertions, 8 deletions
diff --git a/sys/sys/event.h b/sys/sys/event.h
index 85886bd470f..826332fd639 100644
--- a/sys/sys/event.h
+++ b/sys/sys/event.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: event.h,v 1.7 2003/07/22 01:05:07 tedu Exp $ */
+/* $OpenBSD: event.h,v 1.8 2003/12/17 02:43:25 tedu Exp $ */
/*-
* Copyright (c) 1999,2000,2001 Jonathan Lemon <jlemon@FreeBSD.org>
@@ -79,6 +79,7 @@ struct kevent {
* data/hint flags for EVFILT_{READ|WRITE}, shared with userspace
*/
#define NOTE_LOWAT 0x0001 /* low water mark */
+#define NOTE_EOF 0x0002 /* return on EOF */
/*
* data/hint flags for EVFILT_VNODE, shared with userspace
@@ -90,6 +91,7 @@ struct kevent {
#define NOTE_LINK 0x0010 /* link count changed */
#define NOTE_RENAME 0x0020 /* vnode was renamed */
#define NOTE_REVOKE 0x0040 /* vnode access was revoked */
+#define NOTE_TRUNCATE 0x0080 /* vnode was truncated */
/*
* data/hint flags for EVFILT_PROC, shared with userspace
diff --git a/sys/ufs/ufs/ufs_vnops.c b/sys/ufs/ufs/ufs_vnops.c
index 65d1b713fd4..4169076450e 100644
--- a/sys/ufs/ufs/ufs_vnops.c
+++ b/sys/ufs/ufs/ufs_vnops.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ufs_vnops.c,v 1.52 2003/11/19 03:29:31 mickey Exp $ */
+/* $OpenBSD: ufs_vnops.c,v 1.53 2003/12/17 02:43:25 tedu Exp $ */
/* $NetBSD: ufs_vnops.c,v 1.18 1996/05/11 18:28:04 mycroft Exp $ */
/*
@@ -350,6 +350,8 @@ ufs_setattr(v)
struct ucred *cred = ap->a_cred;
struct proc *p = ap->a_p;
int error;
+ long hint = NOTE_ATTRIB;
+ u_quad_t oldsize;
/*
* Check for unsettable attributes.
@@ -395,6 +397,7 @@ ufs_setattr(v)
return (error);
}
if (vap->va_size != VNOVAL) {
+ oldsize = ip->i_ffs_size;
/*
* Disallow write attempts on read-only file systems;
* unless the file is a socket, fifo, or a block or
@@ -413,6 +416,8 @@ ufs_setattr(v)
}
if ((error = UFS_TRUNCATE(ip, vap->va_size, 0, cred)) != 0)
return (error);
+ if (vap->va_size < oldsize)
+ hint |= NOTE_TRUNCATE;
}
if (vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL) {
if (vp->v_mount->mnt_flag & MNT_RDONLY)
@@ -436,7 +441,7 @@ ufs_setattr(v)
return (EROFS);
error = ufs_chmod(vp, (int)vap->va_mode, cred, p);
}
- VN_KNOTE(vp, NOTE_ATTRIB);
+ VN_KNOTE(vp, hint);
return (error);
}
@@ -2215,10 +2220,14 @@ filt_ufsread(struct knote *kn, long hint)
}
kn->kn_data = ip->i_ffs_size - kn->kn_fp->f_offset;
+ if (kn->kn_data == 0 && kn->kn_sfflags & NOTE_EOF) {
+ kn->kn_fflags |= NOTE_EOF;
+ return (1);
+ }
+
return (kn->kn_data != 0);
}
-
int
filt_ufswrite(struct knote *kn, long hint)
{
@@ -2238,7 +2247,6 @@ filt_ufswrite(struct knote *kn, long hint)
int
filt_ufsvnode(struct knote *kn, long hint)
{
-
if (kn->kn_sfflags & hint)
kn->kn_fflags |= hint;
if (hint == NOTE_REVOKE) {
@@ -2247,6 +2255,3 @@ filt_ufsvnode(struct knote *kn, long hint)
}
return (kn->kn_fflags != 0);
}
-
-
-