HashMap doDotDotDR(ISO9660Directory dir) throws HandlerException {
    long position = streamHandler.mark();
    HashMap memory = super.doDotDotDR(dir);
    ISO9660Directory parentDir = dir.getParentDirectory();

    if (RRIPFactory.MKISOFS_COMPATIBILITY) {
      // RR: Recorded Fields
      int flags = RRIPFactory.RR_PX_RECORDED | RRIPFactory.RR_TF_RECORDED;
      if (dir.isMoved()) {
        flags |= RRIPFactory.RR_PL_RECORDED;
      }
      rripFactory.doRREntry(flags);
    }

    if (dir.isMoved()) {
      // PL: Real Parent of this relocated directory
      parentLocationFixups.put(dir, rripFactory.doPLEntry());
    }

    // PX: POSIX File Attributes
    POSIXFileMode fileMode = getPOSIXFileModeForObject(dir);
    int fileModes = fileMode.getFileMode();
    int fileLinks = 2 + parentDir.getDirectories().size();
    rripFactory.doPXEntry(fileModes, fileLinks, 0, 0, 1);

    // TF: Timestamp
    ISO9660ShortDateDataReference date =
        new ISO9660ShortDateDataReference(parentDir.lastModified());
    rripFactory.doTFEntry(RRIPFactory.TF_MODIFY, date);

    // Update Directory Record Length
    return finalizeDR(memory, helper.getDifferenceTo(position));
  }
  HashMap doDR(ISO9660File file) throws HandlerException {
    long position = streamHandler.mark();
    HashMap memory = super.doDR(file);

    if (RRIPFactory.MKISOFS_COMPATIBILITY) {
      // RR: Recorded Fields
      int flags =
          RRIPFactory.RR_PX_RECORDED | RRIPFactory.RR_TF_RECORDED | RRIPFactory.RR_NM_RECORDED;
      rripFactory.doRREntry(flags);
    }

    // PX: POSIX File Attributes
    POSIXFileMode fileMode = getPOSIXFileModeForObject(file);
    int fileModes = fileMode.getFileMode();
    rripFactory.doPXEntry(fileModes, 1, 0, 0, 1);

    // TF: Timestamp
    ISO9660ShortDateDataReference date = new ISO9660ShortDateDataReference(file.lastModified());
    rripFactory.doTFEntry(RRIPFactory.TF_MODIFY, date);

    // Compute length up to here
    int length = helper.getDifferenceTo(position);

    // NM: Alternate Name
    length = doNM(helper.getFilenameDataReference(file), length);

    // Update Directory Record Length
    return finalizeDR(memory, length);
  }
  private POSIXFileMode getPOSIXFileModeForObject(ISO9660HierarchyObject ho) {
    final POSIXFileMode ret = new POSIXFileMode();

    // Try to see if we can match the object name against one of the matchers
    for (String pattern : fileModesMap.keySet()) {
      Pattern p = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
      Matcher m = p.matcher(ho.getName());
      if (m.matches()) {
        POSIXFileMode mode = new POSIXFileMode();
        mode.setDefault(ho instanceof ISO9660Directory);
        mode.setPermission(fileModesMap.get(pattern));
        return mode;
      }
    }

    // If not, return the default mode object
    ret.setDefault(ho instanceof ISO9660Directory);
    return ret;
  }
  HashMap doDotDR(ISO9660Directory dir) throws HandlerException {
    long position = streamHandler.mark();
    HashMap memory = super.doDotDR(dir);

    if (dir == root) {
      // SP: SUSP Indicator
      rripFactory.doSPEntry(0);
    }

    if (RRIPFactory.MKISOFS_COMPATIBILITY) {
      // RR: Recorded Fields
      int flags = RRIPFactory.RR_PX_RECORDED | RRIPFactory.RR_TF_RECORDED;
      rripFactory.doRREntry(flags);
    }

    // PX: POSIX File Attributes
    POSIXFileMode fileMode = getPOSIXFileModeForObject(dir);
    int fileModes = fileMode.getFileMode();
    int fileLinks = 2 + dir.getDirectories().size();
    rripFactory.doPXEntry(fileModes, fileLinks, 0, 0, 1);

    // TF: Timestamp
    ISO9660ShortDateDataReference date = new ISO9660ShortDateDataReference(dir.lastModified());
    rripFactory.doTFEntry(RRIPFactory.TF_MODIFY, date);

    if (dir == root) {
      // CE: Continuation Area for RRIP ER
      HashMap ceMemory = rripFactory.doCEEntry();
      volumeFixups.put("rripERLocationFixup", ceMemory.get("ceLocationFixup"));
      volumeFixups.put("rripERLengthFixup", ceMemory.get("ceLengthFixup"));

      // Write and close ER Offset Fixup
      Fixup rripEROffsetFixup = (Fixup) ceMemory.get("ceOffsetFixup");
      rripEROffsetFixup.data(new BothWordDataReference(0));
      rripEROffsetFixup.close();
    }

    // Update Directory Record Length
    return finalizeDR(memory, helper.getDifferenceTo(position));
  }