Files
webgui/sbin/in_use
Tom Mortensen f9ec00b488 repo reorg
2023-06-02 12:49:33 -07:00

20 lines
552 B
Bash
Executable File

#!/bin/bash
#Copyright 2005-2016, Lime Technology
#License: GPLv2 only
# usage: in_use <file>
# returns exit status 0 (success) if in-use, 1 if not
# used to check if a file is "in use", ie:
# - if any process has the file open, or
# - if file is loopback mounted
FILE=$1
# if file is on user share, check dereferenced file
if [[ "$FILE" == /mnt/user/* ]]; then
DISK=$(getfattr -n system.LOCATION --absolute-names --only-values "$FILE" 2>/dev/null)
FILE="${FILE/user/$DISK}"
fi
fuser -s "$FILE" && exit
[[ $(losetup -j "$FILE") ]] && exit
exit 1