@@ -241,7 +241,7 @@ func (c *Connection) beginOp(
241241 // should not record any state keyed on their ID.
242242 //
243243 // Cf. https://github.com/osxfuse/osxfuse/issues/208
244- if opCode != fusekernel .OpForget {
244+ if opCode != fusekernel .OpForget && opCode < 100 {
245245 var cancel func ()
246246 ctx , cancel = context .WithCancel (ctx )
247247 c .recordCancelFunc (fuseID , cancel )
@@ -411,6 +411,36 @@ func (c *Connection) ReadOp() (ctx context.Context, op interface{}, err error) {
411411 }
412412}
413413
414+ func (c * Connection ) SetNotifyContext (op interface {}) (context.Context , error ) {
415+
416+ outMsg := c .getOutMessage ()
417+
418+ err := c .buildNotify (outMsg , op )
419+ if err != nil {
420+ return nil , err
421+ }
422+
423+ ctx := context .Background ()
424+
425+ switch op .(type ) {
426+ case * fuseops.NotifyInvalInodeOp :
427+ ctx = c .beginOp (100 + uint32 (fusekernel .NotifyCodeInvalInode ), 0 )
428+
429+ case * fuseops.NotifyInvalEntryOp :
430+ ctx = c .beginOp (100 + uint32 (fusekernel .NotifyCodeInvalEntry ), 0 )
431+
432+ case * fuseops.NotifyDeleteOp :
433+ ctx = c .beginOp (100 + uint32 (fusekernel .NotifyCodeDelete ), 0 )
434+
435+ default :
436+ panic (fmt .Sprintf ("Unexpected op: %#v" , op ))
437+ }
438+
439+ ctx = context .WithValue (ctx , contextKey , opState {nil , outMsg , op })
440+ return ctx , nil
441+
442+ }
443+
414444// Skip errors that happen as a matter of course, since they spook users.
415445func (c * Connection ) shouldLogError (
416446 op interface {},
@@ -498,6 +528,29 @@ func (c *Connection) Reply(ctx context.Context, opErr error) {
498528 }
499529}
500530
531+ func (c * Connection ) NotifyKernel (ctx context.Context ) {
532+
533+ // we should get outmsg from context
534+ var key interface {} = contextKey
535+ foo := ctx .Value (key )
536+ state , ok := foo .(opState )
537+ if ! ok {
538+ panic (fmt .Sprintf ("Reply called with invalid context: %#v" , ctx ))
539+ }
540+
541+ outMsg := state .outMsg
542+ defer c .putOutMessage (outMsg )
543+
544+ c .debugLogger .Println ("dev fd is:unique:notifycode " , c .dev .Fd (), outMsg .OutHeader ().Unique , outMsg .OutHeader ().Error )
545+ err := c .writeMessage (outMsg .Bytes ())
546+ if err != nil && c .errorLogger != nil {
547+ c .errorLogger .Printf ("writeMessage: %v %v" , err , outMsg .Bytes ())
548+ // c.debugLogger.Println("%#v %v %v", ctx, err, outMsg.Bytes())
549+ // panic(fmt.Sprintf(" %#v %v %v", ctx, err, outMsg.Bytes()))
550+ }
551+
552+ }
553+
501554// Close the connection. Must not be called until operations that were read
502555// from the connection have been responded to.
503556func (c * Connection ) close () (err error ) {
0 commit comments