private int writeAttributeInlineIntoDirectoryRecord(int attributesRecordId,
                                                      int fileId,
                                                      int attributeId,
                                                      byte[] newValueBuffer,
                                                      int newValueSize) throws IOException {
    assert newValueSize < INLINE_ATTRIBUTE_SMALLER_THAN : "Only small values could be stored in directory record";

    if (attributesRecordId == NON_EXISTENT_ATTRIBUTE_RECORD_ID) {
      //no directory record yet -> create new one:
      int directoryRecordSize = AttributesRecord.RECORD_HEADER_SIZE
                                + AttributeEntry.entrySizeForInlineValueSize(attributeId, newValueSize);
      return storage.writeToRecord(attributesRecordId, buffer -> {
        ByteBuffer writeTo = ensureLimit(buffer, directoryRecordSize);
        AttributesRecord.putDirectoryRecordHeader(writeTo, fileId);
        AttributeEntry.putInlineEntry(
          writeTo,
          attributeId, newValueBuffer, newValueSize
        );

        return writeTo;
      }, directoryRecordSize);
    }
    else {//modify already existing directory record:
      IntRef recordToDelete = new IntRef(NON_EXISTENT_ATTRIBUTE_RECORD_ID);
      int updatedAttributeRecordId = storage.writeToRecord(attributesRecordId, buffer -> {

        AttributesRecord record = new AttributesRecord(buffer);
        if (record.findAttributeInDirectoryRecord(attributeId)) {
          //overwrite existent attribute entry:
          AttributeEntry entryToOverwrite = record.currentEntry();
          if (!entryToOverwrite.isValueInlined()) {
            //delete dedicated record (later):
            recordToDelete.set(entryToOverwrite.dedicatedValueRecordId());
          }
          int newEntrySize = AttributeEntry.entrySizeForInlineValueSize(attributeId, newValueSize);
          ByteBuffer writeTo = resizeGap(buffer, entryToOverwrite.offset(),
                                         entryToOverwrite.entrySize(), newEntrySize);
          writeTo.position(entryToOverwrite.offset());
          AttributeEntry.putInlineEntry(
            writeTo,
            attributeId, newValueBuffer, newValueSize
          );

          return writeTo.position(writeTo.limit());
        }
        else {
          //no entry for attributeId -> append new entry to the end:
          int entrySize = AttributeEntry.entrySizeForInlineValueSize(attributeId, newValueSize);
          ByteBuffer writeTo = ensureLimitAndData(buffer, record.length + entrySize);

          writeTo.position(record.length);
          AttributeEntry.putInlineEntry(
            writeTo,
            attributeId, newValueBuffer, newValueSize
          );
          return writeTo;
        }
      });

      if (recordToDelete.get() != NON_EXISTENT_ATTRIBUTE_RECORD_ID) {
        deleteRecordInStorage(recordToDelete.get());
      }

      return updatedAttributeRecordId;
    }
  }
private int writeAttributeInlineIntoDirectoryRecord(int attributesRecordId,
                                                      int fileId,
                                                      int attributeId,
                                                      byte[] newValueBuffer,
                                                      int newValueSize)