protected Result attach (int fid, int afid, String uid, String aname, Credential cr) {
		// check for authentication fid
		if (afid != -1) {
			// get associated entry
			Entry e = assoc.get (afid);
			if (e instanceof AuthEntry) {
				// we have an authentication entry.
				AuthEntry auth = (AuthEntry) e;
				// check credential
				Credential newCr = auth.getCredential();
				if (newCr == null || !newCr.isAuthenticated())
					return new Result (Result.RC_NOT_AUTHENTICATED, auth);

				// overwrite current credential with
				// credential from authentication.
				auth.updateCredential (cr);
			} else
				// error condition
				return new Result (Result.RC_NO_AUTH_ENTRY, e);
		}
		// check for required authentication
		if (withAuth && !cr.isAuthenticated())
			// not authenticated
			return new Result (Result.RC_NOT_AUTHENTICATED, null);

		// if we have an empty credential (if no authentication
		// is required and performed), initialize it with
		// the user name specified in the attach call.
		if (!withAuth && cr.setUser (uid)) {
			// we need to fill an empty credential.
			cr.addGroup (uid);
		}
		
		// get associated namespace
		ns = nsHdlr.getUserNS (uid);
		if (ns == null)
			return new Result (Result.RC_NO_NAMESPACE_AVAIL, null);
		
		// get root directory of attached (mounted) namespace...
		Directory root = ns.getRoot();
		// ... and remember association with fid.
		assoc.put (fid, root);
		// return root directory.
		return new Result (Result.RC_OK, root);
	}