-
- printf("add_fsevent: watcher %s %p: rd %4d wr %4d q_size %4d flags 0x%x\n",
- watcher_table[ii]->proc_name,
- watcher_table[ii],
- watcher_table[ii]->rd, watcher_table[ii]->wr,
- watcher_table[ii]->eventq_size, watcher_table[ii]->flags);
- }
- unlock_watch_table();
-
- last_print = current_tv;
- if (junkptr) {
- zfree(event_zone, junkptr);
- }
- }
- }
-
- if (pathbuff) {
- release_pathbuff(pathbuff);
- pathbuff = NULL;
- }
- return ENOSPC;
- }
-
- memset(kfse, 0, sizeof(kfs_event));
- kfse->refcount = 1;
- OSBitOrAtomic16(KFSE_BEING_CREATED, &kfse->flags);
-
- last_event_ptr = kfse;
- kfse->type = type;
- kfse->abstime = now;
- kfse->pid = p->p_pid;
- if (type == FSE_RENAME || type == FSE_EXCHANGE || type == FSE_CLONE) {
- memset(kfse_dest, 0, sizeof(kfs_event));
- kfse_dest->refcount = 1;
- OSBitOrAtomic16(KFSE_BEING_CREATED, &kfse_dest->flags);
- kfse_dest->type = type;
- kfse_dest->pid = p->p_pid;
- kfse_dest->abstime = now;
-
- kfse->dest = kfse_dest;
- }
-
- num_events_outstanding++;
- if (kfse->type == FSE_RENAME) {
- num_pending_rename++;
- }
- LIST_INSERT_HEAD(&kfse_list_head, kfse, kevent_list);
-
- if (kfse->refcount < 1) {
- panic("add_fsevent: line %d: kfse recount %d but should be at least 1\n", __LINE__, kfse->refcount);
- }
-
- unlock_fs_event_list(); // at this point it's safe to unlock
-
- //
- // now process the arguments passed in and copy them into
- // the kfse
- //
-
- cur = kfse;
-
- if (type == FSE_DOCID_CREATED || type == FSE_DOCID_CHANGED) {
- uint64_t val;
-
- //
- // These events are special and not like the other events. They only
- // have a dev_t, src inode #, dest inode #, and a doc-id. We use the
- // fields that we can in the kfse but have to overlay the dest inode
- // number and the doc-id on the other fields.
- //
-
- // First the dev_t
- arg_type = va_arg(ap, int32_t);
- if (arg_type == FSE_ARG_DEV) {
- cur->dev = (dev_t)(va_arg(ap, dev_t));
- } else {
- cur->dev = (dev_t)0xbadc0de1;
- }
-
- // next the source inode #
- arg_type = va_arg(ap, int32_t);
- if (arg_type == FSE_ARG_INO) {
- cur->ino = (ino64_t)(va_arg(ap, ino64_t));
- } else {
- cur->ino = 0xbadc0de2;
- }
-
- // now the dest inode #
- arg_type = va_arg(ap, int32_t);
- if (arg_type == FSE_ARG_INO) {
- val = (ino64_t)(va_arg(ap, ino64_t));
- } else {
- val = 0xbadc0de2;
- }
- // overlay the dest inode number on the str/dest pointer fields
- memcpy(&cur->str, &val, sizeof(ino64_t));
-
-
- // and last the document-id
- arg_type = va_arg(ap, int32_t);
- if (arg_type == FSE_ARG_INT32) {
- val = (uint64_t)va_arg(ap, uint32_t);
- } else if (arg_type == FSE_ARG_INT64) {
- val = (uint64_t)va_arg(ap, uint64_t);
- } else {
- val = 0xbadc0de3;
- }
-
- // the docid is 64-bit and overlays the uid/gid fields
- memcpy(&cur->uid, &val, sizeof(uint64_t));
-
- goto done_with_args;
- }
-
- if (type == FSE_UNMOUNT_PENDING) {
-
- // Just a dev_t
- arg_type = va_arg(ap, int32_t);
- if (arg_type == FSE_ARG_DEV) {
- cur->dev = (dev_t)(va_arg(ap, dev_t));
- } else {
- cur->dev = (dev_t)0xbadc0de1;
- }
-
- goto done_with_args;
- }
-
- for(arg_type=va_arg(ap, int32_t); arg_type != FSE_ARG_DONE; arg_type=va_arg(ap, int32_t))
-
- switch(arg_type) {
- case FSE_ARG_VNODE: {
- // this expands out into multiple arguments to the client
- struct vnode *vp;
- struct vnode_attr va;
-
- if (kfse->str != NULL) {
- cur = kfse_dest;
- }
-
- vp = va_arg(ap, struct vnode *);
- if (vp == NULL) {
- panic("add_fsevent: you can't pass me a NULL vnode ptr (type %d)!\n",
- cur->type);
- }
-
- VATTR_INIT(&va);
- VATTR_WANTED(&va, va_fsid);
- VATTR_WANTED(&va, va_fileid);
- VATTR_WANTED(&va, va_mode);
- VATTR_WANTED(&va, va_uid);
- VATTR_WANTED(&va, va_gid);
- VATTR_WANTED(&va, va_nlink);
- if ((ret = vnode_getattr(vp, &va, vfs_context_kernel())) != 0) {
- // printf("add_fsevent: failed to getattr on vp %p (%d)\n", cur->fref.vp, ret);
- cur->str = NULL;
- error = EINVAL;
- goto clean_up;
- }
-
- cur->dev = dev = (dev_t)va.va_fsid;
- cur->ino = (ino64_t)va.va_fileid;
- cur->mode = (int32_t)vnode_vttoif(vnode_vtype(vp)) | va.va_mode;
- cur->uid = va.va_uid;
- cur->gid = va.va_gid;
- if (vp->v_flag & VISHARDLINK) {
- cur->mode |= FSE_MODE_HLINK;
- if ((vp->v_type == VDIR && va.va_dirlinkcount == 0) || (vp->v_type == VREG && va.va_nlink == 0)) {
- cur->mode |= FSE_MODE_LAST_HLINK;