2005-07-12 Marcus Brinkmann * magic.c (magic_getroot): Deallocate DOTDOT if processing here. (magic_open): Do not allocate and deallocate DOTDOT, just consume the reference given to us. (magic_peropen_destroy): New function. (main): If in directory mode, install magic_peropen_destroy hook. Index: trans/magic.c =================================================================== RCS file: /cvsroot/hurd/hurd/trans/magic.c,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- hurd/trans/magic.c 6 Mar 2003 02:24:53 -0000 1.17 +++ hurd/trans/magic.c 12 Jul 2005 15:25:49 -0000 1.18 @@ -150,6 +150,7 @@ retry_type *do_retry, char *retry_name, mach_port_t *node, mach_msg_type_name_t *node_type) { + error_t err; struct magic *const m = cntl->hook; if (m->directory) @@ -159,6 +160,10 @@ *do_retry = FS_RETRY_MAGICAL; *node = MACH_PORT_NULL; *node_type = MACH_MSG_TYPE_COPY_SEND; + + err = mach_port_deallocate (mach_task_self (), dotdot); + assert_perror (err); + return 0; } @@ -178,18 +183,21 @@ error_t err = trivfs_open (cntl, user, flags, realnode, cred); if (!err) { + /* We consume the reference for DOTDOT. */ (*cred)->po->hook = (void *) dotdot; - err = mach_port_mod_refs (mach_task_self (), dotdot, - MACH_PORT_RIGHT_SEND, +1); - assert_perror (err); - err = mach_port_deallocate (mach_task_self (), dotdot); - assert_perror (err); struct magic *const m = cntl->hook; m->nusers++; } return err; } +static void +magic_peropen_destroy (struct trivfs_peropen *po) +{ + mach_port_deallocate (mach_task_self (), (mach_port_t) po->hook); +} + + /* We have this hook only for simple tracking of the live user ports. */ static void magic_protid_destroy (struct trivfs_protid *cred) @@ -467,6 +475,8 @@ trivfs_getroot_hook = &magic_getroot; trivfs_open_hook = &magic_open; trivfs_protid_destroy_hook = &magic_protid_destroy; + if (m->directory) + trivfs_peropen_destroy_hook = &magic_peropen_destroy; /* Reply to our parent */ err = trivfs_startup (bootstrap, 0, 0, 0, 0, 0, &fsys);