private static int pwd() {
        int rc, dot, dotdot;
        int child = 0;
        String relPath = ".";
        List<String> path = new LinkedList<String>();
        byte[] buf = new byte[blockSize];
        for (;;) {
            rc = Library.readdir(relPath, buf);
            if (rc != 0) {
                out.printf("pwd:  cannot read directory \"%s\"\n", relPath);
                return -1;
            }
            dot = dirSearch(buf, ".");
            if (dot == 0) {
                out.printf("pwd: bad directory \"%s\": no . entry\n",
                            relPath);
                return -1;
            }
            if (child != 0) {
                String cname = dirSearch(buf, child);
                if (cname == null) {
                    out.printf("pwd: bad directory \"%s\": "
                                + " no entry for %d\n", relPath, child);
                    return -1;
                }
                path.add(0, cname);
            }
            dotdot = dirSearch(buf, "..");
            if (dotdot == 0) {
                out.printf("pwd: bad directory \"%s\": no .. entry\n",
                            relPath);
                return -1;
            }
            if (dot == dotdot) {
                break;
            }
            child = dot;
            relPath += "/..";
        }
        if (path.size() == 0) {
            out.printf("/");
        } else {
            for (String s : path) {
                out.printf("/%s", s);
            }
        }
        out.printf("\n");
        return 0;
    } // pwd()