+ else
+ DEST="${SNAP_OUTPUT}"
+ fi
+}
+
+Validate_input ()
+{
+ case "${SNAP_TYPE}" in
+ cpio|squashfs|jffs2|ext2|ext3|ext4|whole_partition)
+ ;;
+
+ *)
+ Error "invalid filesystem type \"${SNAP_TYPE}\""
+ ;;
+ esac
+
+ if [ ! -d "${SNAP_COW}" ]
+ then
+ Error "${SNAP_COW} is not a directory"
+ fi
+
+ if [ "$(id -u)" -ne 0 ]
+ then
+ Error "you are not root"
+ fi
+}
+
+Mount_device ()
+{
+ case "${SNAP_DEV}" in
+ "")
+ # create a temp
+ mount -t tmpfs -o rw tmpfs "${MOUNTP}"
+ ;;
+
+ *)
+ if [ -b "${SNAP_DEV}" ]
+ then
+ try_mount "${SNAP_DEV}" "${MOUNTP}" rw
+ fi
+ ;;
+ esac
+}
+
+Entry_is_modified ()
+{
+ # Returns true if file exists and it is also present in "cow" directory
+ # This means it is modified in respect to read-only media, so it deserve
+ # to be saved
+
+ entry="${1}"
+
+ if [ -e "${entry}" ] || [ -L "${entry}" ]
+ then
+ if [ -e "${SNAP_COW}/${entry}" ] || [ -L "${SNAP_COW}/${entry}" ]
+ then
+ return 0
+ fi
+ fi
+ return 1
+}
+
+Do_filelist ()
+{
+ # BUGS: does not handle deleted files yet
+ TMP_FILELIST=$1
+
+ if [ -f "${SNAP_LIST}" ]
+ then
+ # if SNAP_COW == /live/overlay/home, SNAP_RW = /home
+ SNAP_RW=$(echo "${SNAP_COW}" | sed -e "s|${DEF_SNAP_COW}||g")
+ if [ -z "${SNAP_RW}" ]
+ then
+ SNAP_RW="/"
+ fi
+
+ cd "${SNAP_RW}"
+ # Generate include list removing empty and commented lines
+ # and transforming paths to relatives
+ for entry in $(sed -e '/^ *$/d' -e '/^#.*$/d' -e 's#^.*$#./&#' -e 's#/\+#/#g' "${SNAP_LIST}")
+ do
+ if [ -d "${entry}" ]
+ then
+ find "${entry}" | while read line
+ do
+ if Entry_is_modified "${line}"
+ then
+ printf "%s\000" "${line}" >> "${TMP_FILELIST}"
+ fi
+ done
+ elif Entry_is_modified "${entry}"
+ then
+ # if file exists and it is modified
+ printf "%s\000" "${entry}" >> "${TMP_FILELIST}"
+ fi
+ done
+ cd "${OLDPWD}"
+
+ # echo Working dir
+ echo "${SNAP_RW}"
+ else
+ cd "${SNAP_COW}"
+ # removing whiteouts from list
+ find . -path '*.wh.*' -prune -o -print0 >> "${TMP_FILELIST}"
+ cd "${OLDPWD}"
+ # echo Working dir
+ echo "${SNAP_COW}"