code: function validateAndMaskMode(value, def, callback) {
    if(typeof def === 'function') {
      callback = def;
      def = undefined;
    }
  
    if (isUint32(value)) {
      return value & FULL_READ_WRITE_EXEC_PERMISSIONS;
    }
  
    if (typeof value === 'number') {
      if (!Number.isInteger(value)) {
        callback(new Errors.EINVAL('mode not a valid an integer value', value));
        return false;
      } else {
        // 2 ** 32 === 4294967296
        callback(new Errors.EINVAL('mode not a valid an integer value', value));
        return false;
      }
    }
  
    if (typeof value === 'string') {
      if (!octalReg.test(value)) {
        callback(new Errors.EINVAL('mode not a valid octal string', value));
        return false;
      }
      var parsed = parseInt(value, 8);
      return parsed & FULL_READ_WRITE_EXEC_PERMISSIONS;
    }
  
    // TODO(BridgeAR): Only return `def` in case `value === null`
    if (def !== undefined) {
      return def;
    }
  
    callback(new Errors.EINVAL('mode not valid', value));
    return false;
  }
docs: Validator for mode_t (the S_* constants). Valid numbers or octal strings will be masked with 0o777 to be consistent with the behavior in POSIX APIs.