# File lib/fusefs/metadir.rb, line 148
        def rename(from_path,to_path,to_fusefs = self)

            from_base,from_rest = split_path(from_path)

            case
            when !from_base
                # Shouldn't ever happen.
                raise Errno::EACCES.new("Can't move root")
            when !from_rest
                # So now we have a file or directory to move
                if @files.has_key?(from_base)
                    return false unless can_delete?(from_base) && to_fusefs.can_write?(to_path)
                    to_fusefs.write_to(to_path,@files[from_base])
                    to_fusefs.xattr(to_path).merge!(@xattr[from_base])
                    @xattr.delete(from_base)
                    @files.delete(from_base)
                elsif @subdirs.has_key?(from_base)
                    # we don't check can_rmdir? because that would prevent us 
                    # moving non empty directories
                    return false unless mount_user? && to_fusefs.can_mkdir?(to_path)
                    begin
                        to_fusefs.mkdir(to_path,@subdirs[from_base])
                        to_fusefs.xattr(to_path).merge!(@xattr[from_base])
                        @xattr.delete(from_base)
                        @subdirs.delete(from_base)
                        @stats.adjust(0,-1)
                        return true
                    rescue ArgumentError
                        # to_rest does not support mkdir with an arbitrary object
                        return false
                    end
                else
                    #We shouldn't get this either
                    return false
                end
            when @subdirs.has_key?(from_base)
                begin
                    if to_fusefs != self
                        #just keep recursing..
                        return @subdirs[from_base].rename(from_rest,to_path,to_fusefs)
                    else
                        to_base,to_rest = split_path(to_path)
                        if from_base == to_base
                            #mv within a subdir, just pass it on
                            return @subdirs[from_base].rename(from_rest,to_rest)
                        else
                            #OK, this is the tricky part, we want to move something further down
                            #our tree into something in another part of the tree.
                            #from this point on we keep a reference to the fusefs that owns
                            #to_path (ie us) and pass it down, but only if the eventual path
                            #is writable anyway!
                            if (file?(to_path))
                                return false unless can_write?(to_path)
                            else
                                return false unless can_mkdir?(to_path)
                            end

                            return @subdirs[from_base].rename(from_rest,to_path,self)
                        end
                    end
                rescue NoMethodError
                    #sub dir doesn't support rename
                    return false
                rescue ArgumentError
                    #sub dir doesn't support rename with additional to_fusefs argument
                    return false
                end
            else
                return false
            end
        end