Setting uid/gid when mounting exfat and vfat filesystems.

This commit is contained in:
Roland 2026-02-08 09:50:18 -07:00
parent f779369bb8
commit 3a1d366c5c
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
4 changed files with 187 additions and 11 deletions

View file

@ -4,7 +4,9 @@ Disk utilities for WROLPi Controller.
Provides disk detection, mounting, and WROLPi drive identification.
"""
import grp
import json
import pwd
import subprocess
import tempfile
from dataclasses import dataclass
@ -16,6 +18,21 @@ from controller.lib.config import get_config, is_docker_mode
SUPPORTED_FILESYSTEMS = {"ext4", "btrfs", "vfat", "exfat"}
def get_wrolpi_uid_gid() -> tuple[int, int]:
"""
Get uid and gid for the wrolpi user.
Returns:
Tuple of (uid, gid). Falls back to (1001, 1001) if wrolpi user/group doesn't exist.
"""
try:
uid = pwd.getpwnam("wrolpi").pw_uid
gid = grp.getgrnam("wrolpi").gr_gid
return uid, gid
except KeyError:
return 1001, 1001 # wrolpi user is typically created after the first user
@dataclass
class BlockDevice:
"""Represents a block device/partition."""
@ -149,6 +166,12 @@ def mount_drive(
# Create mount point if needed
Path(mount_point).mkdir(parents=True, exist_ok=True)
# For exfat/vfat, add uid/gid options to set ownership to wrolpi user
# These filesystems don't support POSIX permissions natively
if fstype in ("exfat", "vfat"):
uid, gid = get_wrolpi_uid_gid()
options = f"{options},uid={uid},gid={gid}"
# Build mount command
cmd = ["mount"]
if fstype:

View file

@ -9,7 +9,7 @@ import subprocess
from datetime import datetime
from pathlib import Path
from controller.lib.disks import get_uuid, validate_mount_point
from controller.lib.disks import get_uuid, get_wrolpi_uid_gid, validate_mount_point
from controller.lib.wrol_mode import require_normal_mode
FSTAB_PATH = Path("/etc/fstab")
@ -160,6 +160,12 @@ def add_fstab_entry(
# This ensures we don't get duplicates when remounting the same device to a different location
entries = _filter_entry_with_comment(entries, mount_point=mount_point, device=device_spec)
# For exfat/vfat, add uid/gid options to set ownership to wrolpi user
# These filesystems don't support POSIX permissions natively
if fstype in ("exfat", "vfat"):
uid, gid = get_wrolpi_uid_gid()
options = f"{options},uid={uid},gid={gid}"
# Build new entry line
new_entry = f"{device_spec} {mount_point} {fstype} {options} 0 2\n"