refs #1166 add ogExtendFs()
parent
410f47fba2
commit
9a78f9f2c7
|
@ -1,3 +1,12 @@
|
|||
#/**
|
||||
#@file FileSystem.lib
|
||||
#@brief Librería o clase FileSystem
|
||||
#@class FileSystem
|
||||
#@brief Funciones para gestión de sistemas de archivos.
|
||||
#@version 1.1.0
|
||||
#@warning License: GNU GPLv3+
|
||||
#*/
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
import os.path
|
||||
|
@ -8,6 +17,20 @@ import DiskLib
|
|||
import CacheLib
|
||||
import FileSystemLib
|
||||
|
||||
|
||||
#/**
|
||||
# ogCheckFs int_ndisk int_nfilesys
|
||||
#@brief Comprueba el estado de un sistema de archivos.
|
||||
#@param int_ndisk nº de orden del disco
|
||||
#@param int_nfilesys nº de orden del sistema de archivos
|
||||
#@return (nada)
|
||||
#@exception OG_ERR_FORMAT Formato incorrecto.
|
||||
#@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo.
|
||||
#@exception OG_ERR_PARTITION Partición desconocida o no accesible.
|
||||
#@note Requisitos: *fsck*
|
||||
#@warning No se comprueban sistemas de archivos montados o bloqueados.
|
||||
#@todo Definir salidas.
|
||||
#*/ ##
|
||||
def ogCheckFs(int_ndisk, int_nfilesys):
|
||||
|
||||
if len(sys.argv) != 3:
|
||||
|
@ -119,97 +142,84 @@ def ogCheckFs(int_ndisk, int_nfilesys):
|
|||
ogUnlock(int_ndisk, int_nfilesys)
|
||||
return ERRCODE
|
||||
|
||||
def ogExtendFs():
|
||||
|
||||
# Error si no se reciben 2 parámetros.
|
||||
if len(sys.argv) != 3:
|
||||
SystemLib.ogRaiseError(
|
||||
"session",
|
||||
ogGlobals.OG_ERR_FORMAT,
|
||||
f"Not enough arguments"
|
||||
)
|
||||
return
|
||||
#/**
|
||||
# ogExtendFs int_ndisk int_nfilesys
|
||||
#@brief Extiende un sistema de archivos al tamaño de su partición.
|
||||
#@param int_ndisk nº de orden del disco
|
||||
#@param int_nfilesys nº de orden del sistema de archivos
|
||||
#@return (nada)
|
||||
#@exception OG_ERR_FORMAT Formato incorrecto.
|
||||
#@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo.
|
||||
#@exception OG_ERR_PARTITION Partición desconocida o no accesible.
|
||||
#@note Requisitos: *resize*
|
||||
#*/ ##
|
||||
def ogExtendFs (disk, par):
|
||||
PART = DiskLib.ogDiskToDev (disk, par)
|
||||
if not PART: return
|
||||
|
||||
# Obtener partición.
|
||||
PART = DiskLib.ogDiskToDev(int(sys.argv[1]), int(sys.argv[2]))
|
||||
if not PART:
|
||||
return
|
||||
data = {
|
||||
'EXT2': { 'prog': 'resize2fs', 'params': '-f', },
|
||||
'EXT3': { 'prog': 'resize2fs', 'params': '-f', },
|
||||
'EXT4': { 'prog': 'resize2fs', 'params': '-f', },
|
||||
'BTRFS': { 'prog': 'btrfs', 'params': 'filesystem resize max', 'domount': True },
|
||||
'REISERFS': { 'prog': 'resize_reiserfs', 'params': '-f', },
|
||||
'REISER4': { 'prog': 'resize_reiserfs', 'params': '-f', },
|
||||
'NTFS': { 'prog': 'ntfsresize', 'params': '-f', 'input': 'y' },
|
||||
'F2FS': { 'unsupported': True },
|
||||
'JFS': { 'unsupported': True },
|
||||
'NILFS2': { 'unsupported': True }, # try "nilfs-resize"
|
||||
'XFS': { 'unsupported': True },
|
||||
'EXFAT': { 'unsupported': True },
|
||||
'FAT32': { 'unsupported': True }, # try "fatresize"
|
||||
'FAT16': { 'unsupported': True }, # try "fatresize"
|
||||
'HFS': { 'unsupported': True },
|
||||
'HFSPLUS': { 'unsupported': True },
|
||||
'UFS': { 'unsupported': True },
|
||||
}
|
||||
|
||||
# Redimensionar al tamaño máximo según el tipo de partición.
|
||||
TYPE = ogGetFsType(int(sys.argv[1]), int(sys.argv[2]))
|
||||
if TYPE == "EXT[234]":
|
||||
PROG = "resize2fs"
|
||||
PARAMS = "-f"
|
||||
elif TYPE == "BTRFS":
|
||||
PROG = "btrfs"
|
||||
PARAMS = "filesystem resize max"
|
||||
DOMOUNT = True # Debe estar montado.
|
||||
elif TYPE == "REISERFS" or TYPE == "REISER4":
|
||||
PROG = "resize_reiserfs"
|
||||
PARAMS = "-f"
|
||||
elif TYPE == "F2FS" or TYPE == "JFS" or TYPE == "NILFS2" or TYPE == "XFS" or TYPE == "EXFAT" or TYPE == "FAT32" or TYPE == "FAT16" or TYPE == "HFS" or TYPE == "HFSPLUS" or TYPE == "UFS":
|
||||
return # No se reduce (por el momento).
|
||||
elif TYPE == "NTFS":
|
||||
PROG = "ntfsresize"
|
||||
PARAMS = "<<<\"y\" -f"
|
||||
type = ogGetFsType (disk, par)
|
||||
if type in data:
|
||||
prog = data[type]['prog'] if 'prog' in data[type] else None
|
||||
params = data[type]['params'] if 'params' in data[type] else None
|
||||
domount = data[type]['domount'] if 'domount' in data[type] else False
|
||||
input = data[type]['input'] if 'input' in data[type] else None
|
||||
else:
|
||||
SystemLib.ogRaiseError(
|
||||
"session",
|
||||
ogGlobals.OG_ERR_PARTITION,
|
||||
f"{int(sys.argv[1])} {int(sys.argv[2])} {TYPE}"
|
||||
)
|
||||
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_PARTITION, f'{disk} {par} {type}')
|
||||
return
|
||||
|
||||
# Salida normal si no se va a aplicar la operación.
|
||||
if not PROG:
|
||||
return
|
||||
if not prog: return
|
||||
|
||||
# Error si el sistema de archivos no se queda en el estado de montaje adecuado.
|
||||
if DOMOUNT:
|
||||
PART = ogMount(int(sys.argv[1]), int(sys.argv[2]))
|
||||
if not PART:
|
||||
return
|
||||
if domount:
|
||||
PART = ogMount (disk, par)
|
||||
if not PART: return
|
||||
else:
|
||||
ogUnmount(int(sys.argv[1]), int(sys.argv[2]))
|
||||
if ogIsMounted(int(sys.argv[1]), int(sys.argv[2])):
|
||||
SystemLib.ogRaiseError(
|
||||
"session",
|
||||
ogGlobals.OG_ERR_PARTITION,
|
||||
f"{int(sys.argv[1])} {int(sys.argv[2])}"
|
||||
)
|
||||
ogUnmount (disk, par)
|
||||
if ogIsMounted (disk, par):
|
||||
SystemLib.ogRaiseError([], ogGlobals.OG_ERR_PARTITION, f'{disk} {par}')
|
||||
return
|
||||
|
||||
# Error si el sistema de archivos está bloqueado.
|
||||
if ogIsLocked(int(sys.argv[1]), int(sys.argv[2])):
|
||||
SystemLib.ogRaiseError(
|
||||
"session",
|
||||
ogGlobals.OG_ERR_LOCKED,
|
||||
f"{int(sys.argv[1])} {int(sys.argv[2])}"
|
||||
)
|
||||
# Error si el sistema de archivos está bloqueado.
|
||||
if ogIsLocked (disk, par):
|
||||
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_LOCKED, f'{disk} {par}')
|
||||
return
|
||||
|
||||
# Redimensionar en modo uso exclusivo.
|
||||
ogLock(int(sys.argv[1]), int(sys.argv[2]))
|
||||
# Redimensionar en modo uso exclusivo.
|
||||
ogLock (disk, par)
|
||||
try:
|
||||
subprocess.run([PROG, PARAMS, PART], capture_output=True)
|
||||
ERRCODE = 0
|
||||
if input:
|
||||
rc = subprocess.run ([prog] + params.split() + [PART], input=input, text=True).returncode
|
||||
else:
|
||||
rc = subprocess.run ([prog] + params.split() + [PART]).returncode
|
||||
except FileNotFoundError:
|
||||
SystemLib.ogRaiseError(
|
||||
"session",
|
||||
ogGlobals.OG_ERR_NOTEXEC,
|
||||
PROG
|
||||
)
|
||||
ERRCODE = ogGlobals.OG_ERR_NOTEXEC
|
||||
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTEXEC, prog)
|
||||
rc = ogGlobals.OG_ERR_NOTEXEC
|
||||
except:
|
||||
SystemLib.ogRaiseError(
|
||||
"session",
|
||||
ogGlobals.OG_ERR_PARTITION,
|
||||
f"{int(sys.argv[1])} {int(sys.argv[2])}"
|
||||
)
|
||||
ERRCODE = ogGlobals.OG_ERR_PARTITION
|
||||
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_PARTITION, f'{disk} {par}')
|
||||
rc = ogGlobals.OG_ERR_PARTITION
|
||||
|
||||
ogUnlock(int(sys.argv[1]), int(sys.argv[2]))
|
||||
return ERRCODE
|
||||
ogUnlock (disk, par)
|
||||
return not rc ## reverse to indicate success
|
||||
|
||||
|
||||
#/**
|
||||
|
@ -608,6 +618,13 @@ def ogMount(*args):
|
|||
elif 2 == len (args):
|
||||
return ogMountFs(args[0], args[1])
|
||||
|
||||
|
||||
#/**
|
||||
# ogMountFirstFs int_ndisk
|
||||
#@brief Monta el primer sistema de archivos disponible en el disco.
|
||||
#@param int_ndisk nº de orden del disco
|
||||
#@return Punto de montaje del primer sistema de archivos detectado
|
||||
#*/ ##
|
||||
def ogMountFirstFs(int_ndisk):
|
||||
# Obtener número de particiones del disco.
|
||||
NPARTS = DiskLib.ogGetPartitionsNumber(int_ndisk)
|
||||
|
@ -737,6 +754,20 @@ def ogMountCdrom():
|
|||
return
|
||||
return MNTDIR
|
||||
|
||||
|
||||
#/**
|
||||
# ogReduceFs int_ndisk int_nfilesys
|
||||
#@brief Reduce el tamaño del sistema de archivos, sin tener en cuenta el espacio libre.
|
||||
#@param int_ndisk nº de orden del disco
|
||||
#@param int_nfilesys nº de orden del sistema de archivos
|
||||
#@return int_tamañoKB - tamaño en KB
|
||||
#@exception OG_ERR_FORMAT Formato incorrecto.
|
||||
#@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo.
|
||||
#@exception OG_ERR_PARTITION Partición desconocida o no accesible.
|
||||
#@warning En Windows, se borran los ficheros de hiberanción y de paginación.
|
||||
#@warning El sistema de archivos se amplía al mínimo + 10%.
|
||||
#@note Requisitos: *resize*
|
||||
#*/ ##
|
||||
def ogReduceFs(int_ndisk, int_nfilesys):
|
||||
|
||||
# Error si no se reciben 2 parámetros.
|
||||
|
@ -906,6 +937,15 @@ def ogUnmountAll(int_ndisk):
|
|||
if ogGetFsType(int_ndisk, PART) != "CACHE":
|
||||
ogUnmount(int_ndisk, PART)
|
||||
|
||||
|
||||
#/**
|
||||
# ogUnsetDirtyBit int_ndisk int_npart
|
||||
#@brief Inhabilita el Dirty Bit del sistema de ficheros NTFS para evitar un CHKDSK en el primer arranque
|
||||
#@param int_ndisk nº de orden del disco
|
||||
#@param int_npart nº de orden de partición
|
||||
#@return Nada
|
||||
#@exception OG_ERR_FORMAT Formato incorrecto.
|
||||
#*/ ##
|
||||
def ogUnsetDirtyBit(int_ndisk, int_nfilesys):
|
||||
|
||||
# Error si no se reciben 2 parámetros.
|
||||
|
|
|
@ -55,7 +55,7 @@ def ogGetOsType(disk, partition):
|
|||
if os_version:
|
||||
return os_version.split(":", 1)[0]
|
||||
else:
|
||||
return "Unknown"
|
||||
return None
|
||||
except Exception as e:
|
||||
print(f"Error en ogGetOsType: {e}")
|
||||
return "Unknown"
|
||||
|
|
Loading…
Reference in New Issue