lib/ffi/devt.rb in ffi-libfuse-0.4.0 vs lib/ffi/devt.rb in ffi-libfuse-0.4.1

- old
+ new

@@ -1,9 +1,8 @@ # frozen_string_literal: true require 'ffi' - module FFI # Calculate major/minor device numbers for use with mknod etc.. # @see makedev(3) module Device extend FFI::Library @@ -25,14 +24,17 @@ # @!method minor(dev) # @param [Integer] dev # @return [Integer] the minor component of dev attach_function :minor, :"#{prefix}minor", [:int], :int rescue FFI::NotFoundError - case Platform::NAME - when 'x86_64-darwin' - # From https://github.com/golang/go/issues/8106 these functions are not defined on Darwin. - class << self + + class << self + # rubocop:disable Naming/MethodParameterName + case RUBY_PLATFORM + when 'x86_64-darwin' + # From https://github.com/golang/go/issues/8106 these functions are not defined on Darwin. + # define major(x) ((int32_t)(((u_int32_t)(x) >> 24) & 0xff)) def major(dev) (dev >> 24) & 0xff end @@ -43,11 +45,35 @@ # define makedev(x,y) ((dev_t)(((x) << 24) | (y))) def makedev(major, minor) (major << 24) | minor end + + when 'x86_64-linux-musl' # eg alpine linux + # #define major(x) \ + # ((unsigned)( (((x)>>31>>1) & 0xfffff000) | (((x)>>8) & 0x00000fff) )) + def major(x) + ((x >> 31 >> 1) & 0xfffff000) | ((x >> 8) & 0x00000fff) + end + + # #define minor(x) \ + # ((unsigned)( (((x)>>12) & 0xffffff00) | ((x) & 0x000000ff) )) + # + def minor(x) + ((x >> 12) & 0xffffff00) | (x & 0x000000ff) + end + + # #define makedev(x,y) ( \ + # (((x)&0xfffff000ULL) << 32) | \ + # (((x)&0x00000fffULL) << 8) | \ + # (((y)&0xffffff00ULL) << 12) | \ + # (((y)&0x000000ffULL)) ) + def makedev(x, y) + ((x & 0xfffff000) << 32) | ((x & 0x00000fff) << 8) | ((y & 0xffffff00) << 12) | (y & 0x000000ff) + end + else + raise end - else - raise + # rubocop:enable Naming/MethodParameterName end end end