Добавлена поддержка early-microcode для initrd

legacy27
Mike Hiretsky 6 years ago
parent a1e8c27ad8
commit 91a6f2d412

@ -465,6 +465,16 @@ class typeFile(object):
"""Закрываем magic"""
self.magicObject.close()
def getMTypeBuf(self, buf):
try:
ret = self.magicObject.buffer(buf)
except UnicodeDecodeError:
try:
ret = self.magicObject.buffer(buf.decode('utf-8'))
except UnicodeDecodeError:
return None
return ret
def getMType(self, filename):
"""Информация о типе файла"""
try:

@ -17,12 +17,14 @@
import sys
import re
from os import path
from files import typeFile
from files import typeFile, process
from subprocess import Popen, PIPE
from calculate.lib.cl_lang import setLocalTranslate
setLocalTranslate('cl_lib3', sys.modules[__name__])
class InitrdFileError(Exception):
pass
class InitrdFile(object):
"""
@ -31,6 +33,8 @@ class InitrdFile(object):
re_kver_path = re.compile("/modules/([^/]+)/kernel")
def __init__(self, _file):
if not self.is_cpio(_file):
raise InitrdFileError("%s is not initrd file" % _file)
self._file = _file
def get_kernel_version(self):
@ -43,20 +47,43 @@ class InitrdFile(object):
break
return ""
@staticmethod
def skipcpio_data(fn):
skipcpio_cmd = "/usr/lib/dracut/skipcpio"
skipcpio = Popen([skipcpio_cmd, fn], stdout=PIPE, stderr=PIPE,
close_fds=True)
buf = skipcpio.stdout.read(1024*1024)
skipcpio.terminate()
skipcpio.poll()
return buf
@staticmethod
def is_cpio(fn):
buf = InitrdFile.skipcpio_data(fn)
if not buf:
return False
buftype = typeFile(magic=0x4).getMTypeBuf
return "ASCII cpio archive" in buftype(buf)
def get_names(self):
if not path.exists(self._file):
# raise IOError
open(self._file)
ftype = typeFile(magic=0x4).getMType
rdtype = ftype(self._file)
buftype = typeFile(magic=0x4).getMTypeBuf
rdtype = buftype(self.skipcpio_data(self._file))
if "LZ4" in rdtype:
arch_cmd = '/usr/bin/lz4'
elif "XZ" in rdtype:
arch_cmd = '/usr/bin/xz'
else:
arch_cmd = '/bin/gzip'
gz = Popen([arch_cmd, "-dc", self._file], stdout=PIPE, stderr=PIPE,
skipcpio_cmd = "/usr/lib/dracut/skipcpio"
skipcpio = Popen([skipcpio_cmd, self._file], stdout=PIPE, stderr=PIPE,
close_fds=True)
gz = Popen([arch_cmd, "-dc"], stdout=PIPE, stderr=PIPE,
stdin=skipcpio.stdout, close_fds=True)
cpio = Popen(["/bin/cpio", "-tf"], stdout=PIPE, stdin=gz.stdout,
stderr=PIPE, close_fds=True)
try:
@ -65,6 +92,7 @@ class InitrdFile(object):
finally:
cpio.terminate()
gz.terminate()
skipcpio.terminate()
def __iter__(self):
return iter(self.get_names())

Loading…
Cancel
Save