summaryrefslogtreecommitdiffstats
path: root/src/utils/fs.py
Commit message (Collapse)AuthorAgeFilesLines
* fs: fix bug when ntfsresize reports nothing to doJose M. Guisado2023-06-131-0/+3
| | | | | | | | There is a corner case in which a target NTFS filesystem is already shrunken. When this happens ntfsresize text output parsing breaks. Check when ntfsresize reports nothing to do, warn the user about this and stop the dry-run ntfsresize loop.
* fs: fix typo inside _extend_resize2fsJose M. Guisado2023-06-131-4/+4
| | | | | | | | | | _extend_ntfsresize contains an incorrect variable name inside subprocess.run referring the resize command value. Simplify this variable name inside each specific _extend_* function: s/cmd_resize2fs/cmd s/cmd_ntfsresize/cmd
* utils: add umount_all functionJose M. Guisado2023-05-091-0/+9
| | | | | | | | Add utility function to unmount any mountpoint present in the /mnt folder. This function is a simplified version of the legacy bash function ogUnmountAll used in several operations.
* utils: rewrite ogExtendFsJose M. Guisado2023-05-091-7/+28
| | | | | | | | | | | | | | | | | | | | Drop subprocess call to bash function ogExtendFs. Use a native python solution with subprocess calls to the required underlying tools. Use get_filesystem_type to get the present filesystem from a partition and call the corresponding filesystem grow function. Filesystem specific functions are declared "_extend_{filesystem}" and should not be imported elsewhere. Each filesystem specific function wraps a subprocess call to the required underlying program: - NTFS filesystems: "ntfsresize -f [partition]" - ext4 filesystems: "resize2fs -f [partition]" Set NTFS related subprocess stdin to 'y' because human input cannot be unset with other ntfsresize parameters.
* utils: rewrite ogReduceFsJose M. Guisado2023-05-021-9/+52
| | | | | | | | | | | | | | | | | | | | | | | | | | Drop subprocess call to bash function ogReduceFs. Use a native python solution with subprocess calls to the required underlying tools. Use get_filesystem_type to get the filesystem from a partition and call the corresponding supported filesystem shrink function. Filesystem specific functions are declared "_reduce_{filesystem}" and should not be imported elsewhere. In case of NTFS filesystems, the output of 'ntfsresize' is processed directly. This is dirty, but we can expect no changes to the output strings if we read the following comment in the nftsresize.c source code: https://github.com/tuxera/ntfs-3g/blob/edge/ntfsprogs/ntfsresize.c#L12 ntfsresize requires to do previous dry-run executions to confirm that the resizing is possible. If a dry-run fails but a 10% increase in size is still smaller than original filesystem then retry the operation until dry-run reports sucess or the size increase is bigger than original. If resizing to a smaller ntfs filesystem is not possible then ogReduceFs will do nothing.
* utils: add get_filesystem_type functionJose M. Guisado2023-04-251-0/+12
| | | | | Retrieve filesystem type from a partition using get_filesystem_type. Encapsulates a subprocess call to blkid.
* utils: add fs.pyJose M. Guisado2023-02-081-1/+66
| | | | | | | | | | | Adds utility module which wraps several mkfs.* calls as a subprocess. The main utility function is mkfs(fs, disk, partition, label), which subsequently calls the corresponding mkfs_*(partition_device) function. mkfs() supports specifying a drive label where supported. Other modules using fs.py should call mkfs() only.
* utils: minor fix for ogReduceFs and ogExtendFsJose M. Guisado2022-09-141-10/+10
| | | | | | | | | | Do not return the subprocess result for ogReduceFs/ogExtendFs. ogReduceFs works with or without the target filesystem mounted. ogExtendFs requires the target filesystem to be mounted. 'ogMount' legacy script invocation should be replaced by a better mount/umount wrapper.
* image_create: partial integration into pythonv1.2.2Jose M. Guisado2022-08-241-1/+27
| | | | | | | | | | | Integrates some parts of this operation into native code, eg: the md5 checksum computation. Wraps non native processes and commands using the subprocess module. For example, legacy.py stores bash commands pending integration. Supports python >=3.6, expected until more modern ogLives are put into production environments.
* utils: mount_mkdir success if target is a mountpointJose M. Guisado2022-06-011-0/+6
| | | | | | | | Returns true if target is already a mountpoint. Does not call mount. It's possible that another device might be mounted in the target mountpoint. A future check between the source and target for equal device major:minor must be added.
* probe: detect 64 bit operating systemsJose M. Guisado2022-05-091-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | OpenGnsys partition images store OS information, including the OS name appended with "64 bits" when the OS is meant for 64 bit machines. The detected OS name when probing (refresh) is important, if it differs from what's stored in the DB OpenGnsys will wipe last image restored information when running a refresh. See actualizaConfiguracion from legacy ogserver (ogAdmServer.c) code: dato = dbi_result_get_uint(result, "idnombreso"); if (idsoi == dato) { swu = false; } ... if (swu) { result_update = dbi_conn_queryf(dbi->conn, "UPDATE ordenadores_particiones SET " " codpar=0x%s," " tamano=%s," " uso=%s," " idsistemafichero=%d," " idnombreso=%d," " idimagen=0," " idperfilsoft=0," " fechadespliegue=NULL" " WHERE idordenador=%d AND numdisk=%s AND numpar=%s",
* Add utils modulesJose M. Guisado2022-04-211-0/+60
* disk.py Disk discovery * fs.py Uses psutil to fetch fs usage information * menu.py ogBrowser menu generation * net.py: gets nic status information IP address, MAC address and ethernet speed. * probe.py: probes mountpoints for operating systems Uses hivexget command to try fetching Windows installation information. Looks for /etc/os-release for probing linux systems.