Last active
February 6, 2025 20:42
-
-
Save enorrmann/c419a77bddc0ec4fb26e97cc96ac1d8f to your computer and use it in GitHub Desktop.
ls -s like for fat filesystems
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Validación de argumentos | |
if [ "$#" -ne 3 ]; then | |
echo "Uso: $0 dispositivo origen destino" | |
echo "Ejemplo: $0 /dev/sda1 /ROLAND/GROOVEBOX/SAMPLE/L_SAMPLE /R_SAMPLE" | |
echo "Similar a: ln -s origen destino" | |
exit 1 | |
fi | |
# Parámetros | |
DEVICE="$1" | |
DESTINO="$2" | |
ORIGEN="$3" | |
# Función para obtener el cluster de un directorio | |
get_cluster() { | |
local path="$1" | |
local cluster=$(fatcat "$DEVICE" -l "$path" | grep "c=" | sed 's/.*c=\([0-9]*\).*/\1/') | |
echo "$cluster" | |
} | |
# Función para crear directorio si no existe | |
create_directory() { | |
local path="$1" | |
if ! fatcat "$DEVICE" -l "$path" &>/dev/null; then | |
echo "Creando directorio: $path" | |
# Crear directorio padre primero si es necesario | |
local parent_dir=$(dirname "$path") | |
if [ "$parent_dir" != "/" ] && ! fatcat "$DEVICE" -l "$parent_dir" &>/dev/null; then | |
create_directory "$parent_dir" | |
fi | |
fatcat "$DEVICE" -m "$path" | |
if [ $? -ne 0 ]; then | |
echo "Error: No se pudo crear el directorio $path" | |
exit 1 | |
fi | |
fi | |
} | |
# Validar que fatcat está instalado | |
if ! command -v fatcat &> /dev/null; then | |
echo "Error: fatcat no está instalado" | |
exit 1 | |
fi | |
# Validar que el dispositivo existe y es un block device | |
if [ ! -b "$DEVICE" ]; then | |
echo "Error: $DEVICE no es un dispositivo válido" | |
exit 1 | |
fi | |
# Obtener el cluster del directorio origen | |
if ! fatcat "$DEVICE" -l "$ORIGEN" &>/dev/null; then | |
echo "Error: El directorio origen no existe" | |
exit 1 | |
fi | |
CLUSTER_ORIGEN=$(get_cluster "$ORIGEN") | |
if [ -z "$CLUSTER_ORIGEN" ]; then | |
echo "Error: No se pudo obtener el cluster del directorio origen" | |
exit 1 | |
fi | |
# Crear directorios intermedios del destino si no existen | |
DESTINO_DIR=$(dirname "$DESTINO") | |
if [ "$DESTINO_DIR" != "/" ]; then | |
create_directory "$DESTINO_DIR" | |
fi | |
# Crear el enlace usando fatcat | |
echo "Creando enlace desde $DESTINO hacia $ORIGEN (cluster $CLUSTER_ORIGEN)" | |
if fatcat "$DEVICE" -e "$DESTINO" -c "$CLUSTER_ORIGEN"; then | |
echo "Enlace creado exitosamente" | |
else | |
echo "Error al crear el enlace" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment