doc: switch links to https://, update or remove dead links
[midnight-commander.git] / src / vfs / extfs / helpers / iso9660.in
blob4fd6cb3f9dd3f971cef21174d1cc69377657df82
1 #! /bin/sh
2 # Midnight Commander - ISO9660 VFS for MC
3 # based on lslR by Tomas Novak <tnovak@ipex.cz> April 2000
5 # Copyright (C) 2000, 2003
6 # The Free Software Foundation, Inc.
8 # Written by:
9 # Michael Shigorin <mike@altlinux.org>,
10 # Grigory Milev <week@altlinux.org>,
11 # Kachalov Anton <mouse@linux.ru.net>, 2003
12 # Victor Ananjevsky <ananasik@gmail.com>, 2013
13 # slava zanko <slavazanko@gmail.com>, 2013
14 # slowpeek <slowpeek@users.noreply.github.com>, 2024
16 # This file is part of the Midnight Commander.
18 # The Midnight Commander is free software: you can redistribute it
19 # and/or modify it under the terms of the GNU General Public License as
20 # published by the Free Software Foundation, either version 3 of the License,
21 # or (at your option) any later version.
23 # The Midnight Commander is distributed in the hope that it will be useful,
24 # but WITHOUT ANY WARRANTY; without even the implied warranty of
25 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 # GNU General Public License for more details.
28 # You should have received a copy of the GNU General Public License
29 # along with this program. If not, see <https://www.gnu.org/licenses/>.
31 #*** include section (source functions, for example) *******************
33 #*** file scope functions **********************************************
35 XORRISO=`command -v xorriso 2>/dev/null`
37 # This snippet is used to undo xorriso's Text_shellsafe(). Pseudocode for the
38 # function:
40 # Text_shellsafe( s) {
41 # return q(') replace(q('), q('"'"'), s) q(')
42 # }
44 # Xorriso_ls() uses two formats for pathes:
45 # - generic: Text_shellsafe(path)
46 # - symlink: Text_shellsafe(link) q( -> ) Text_shellsafe(target)
48 # References in xorriso sources:
49 # - iso_tree.c:Xorriso_ls()
50 # - text_io.c:Xorriso_esc_filepath()
51 # - misc_funct.c:Text_shellsafe()
52 awk_xorriso_unesc=`cat <<'EOF'
54 # Start of the path part
55 i = index($0, "'")
57 s = substr($0, i)
58 # The path part with the wrapping quotes removed
59 s = substr(s, 2, length(s)-2)
61 if (substr($0, 1, 1) == "l") {
62 s1=s
63 if (gsub("->", "", s1) > 1) {
64 # Ambiguity: either the link or its target contains q(->) in
65 # addition to the link/target delimiter
66 next
69 j = index(s, "' -> '")
70 # link -> target with the wrapping quotes removed from both
71 s = substr(s, 1, j-1) " -> " substr(s, j+6)
72 } else if (index(s, "->")) {
73 # Ambiguity: not a symlink, but there is q(->)
74 next
77 gsub("'\"'\"'", "'", s)
78 print substr($0, 1, i-1) s
80 EOF
83 xorriso_list() (
84 if test -z "$XORRISO"; then
85 return 1
88 temp_ls=`mktemp "${MC_TMPDIR:-/tmp}"/mc-iso9660.XXXXXX` || return 1
90 # $XORRISO must be unquoted here to hook into the testing framework
91 $XORRISO -abort_on FATAL -dev stdio:"$1" -find / -exec lsdl 2>/dev/null >"$temp_ls"
92 r=$?
94 if [ "$r" != 0 ]; then
95 rm -f "$temp_ls"
96 return "$r"
99 # The first line is /, skip it
100 sed 1,1d "$temp_ls" |
101 # disk_ops.c:Xorriso_format_ls_l() prints the boot catalog file as of
102 # type "e". Make it a generic file
103 sed 's,^e,-,' |
104 @AWK@ "$awk_xorriso_unesc"
106 rm -f "$temp_ls"
109 xorriso_copyout() {
110 if test -z "$XORRISO"; then
111 return 1
113 $XORRISO -dev stdio:"$1" -osirrox on -extract "$2" "$3" >/dev/null 2>&1
116 xorriso_copyin() {
117 if test -z "$XORRISO"; then
118 return 1
120 $XORRISO -dev stdio:"$1" -cpr "$3" "$2" >/dev/null 2>&1
123 xorriso_mkdir() {
124 if test -z "$XORRISO"; then
125 return 1
127 $XORRISO -dev stdio:"$1" -mkdir "$2" >/dev/null 2>&1
130 xorriso_rmdir() {
131 if test -z "$XORRISO"; then
132 return 1
134 $XORRISO -dev stdio:"$1" -rmdir "$2" >/dev/null 2>&1
137 xorriso_rm() {
138 if test -z "$XORRISO"; then
139 return 1
141 $XORRISO -dev stdio:"$1" -rm "$2" >/dev/null 2>&1
144 # tested to comply with isoinfo 2.0's output
145 test_iso () {
146 ISOINFO=`command -v isoinfo 2>/dev/null`
147 if test -z "$ISOINFO"; then
148 echo "isoinfo not found" >&2
149 return 1
152 CHARSET=`locale charmap 2>/dev/null`
153 if test -z "$CHARSET"; then
154 CHARSET=`locale 2>/dev/null | grep LC_CTYPE | sed -n -e 's/.*\.\(.*\)"$/\1/p'`
156 if test -n "$CHARSET"; then
157 CHARSET=`echo "$CHARSET" | tr '[A-Z]' '[a-z]' | sed -e 's/^iso-/iso/'`
158 $ISOINFO -j $CHARSET -i /dev/null 2>&1 | grep "Iconv not yet supported\|Unknown charset" >/dev/null && CHARSET=
160 if test -n "$CHARSET"; then
161 JOLIET_OPT="-j $CHARSET -J"
162 else
163 JOLIET_OPT="-J"
166 ISOINFO_D_I=`$ISOINFO -d -i "$1" 2>/dev/null`
167 ISOINFO="$ISOINFO -R"
169 echo "$ISOINFO_D_I" | grep "UCS level 1\|NO Joliet" > /dev/null || ISOINFO="$ISOINFO $JOLIET_OPT"
171 if [ `echo "$ISOINFO_D_I" | grep "Joliet with UCS level 3 found" | wc -l` = 1 \
172 -a `echo "$ISOINFO_D_I" | grep "NO Rock Ridge" | wc -l` = 1 ] ; then
173 SEMICOLON="YES"
177 mcisofs_list () (
178 # left as a reminder to implement compressed image support =)
179 case "$1" in
180 *.lz) MYCAT="lzip -dc";;
181 *.lz4) MYCAT="lz4 -dc";;
182 *.lzma) MYCAT="lzma -dc";;
183 *.lzo) MYCAT="lzop -dc";;
184 *.xz) MYCAT="xz -dc";;
185 *.zst) MYCAT="zstd -dc";;
186 *.bz2) MYCAT="bzip2 -dc";;
187 *.gz) MYCAT="gzip -dc";;
188 *.z) MYCAT="gzip -dc";;
189 *.Z) MYCAT="gzip -dc";;
190 *) MYCAT="cat";;
191 esac
193 lsl=`$ISOINFO -l -i "$1" 2>/dev/null`
194 r=$?
195 test $r -gt 0 && return $r
197 echo "$lsl" | @AWK@ -v SEMICOLON=$SEMICOLON '
198 BEGIN {
199 dir="";
200 # Pattern to match 8 first fields.
201 rx = "[^ ]+[ ]+";
202 rx = "^" rx rx rx rx rx rx rx rx;
203 irx = "^\\[ *-?[0-9]* *[0-9]+\\] +";
205 /^$/ { next }
206 /^d---------/ { next }
207 /^Directory listing of [^ ].*$/ {
208 dir=substr($0, 23);
209 next;
211 { $11 != "" } {
212 name=$0
213 sub(rx, "", name)
214 attr=substr($0, 1, length($0)-length(name))
215 # strip inodes and extra dir entries; fix perms
216 sub(irx, "", name)
217 sub("^---------- 0 0 0", "-r--r--r-- 1 0 0 ", attr)
218 sub(" $", "", name)
219 # for Joliet UCS level 3
220 if (SEMICOLON == "YES") sub(";1$", "", name);
221 ## sub(";[0-9]+$", "", name) ## would break copyout
222 # skip . and ..
223 if (name == ".") next;
224 if (name == "..") next;
225 printf "%s%s%s\n", attr, dir, name
229 mcisofs_copyout () {
230 if [ "x$SEMICOLON" = "xYES" ]; then
231 $ISOINFO -i "$1" -x "/$2;1" 2>/dev/null > "$3"
232 else
233 $ISOINFO -i "$1" -x "/$2" 2>/dev/null > "$3"
237 #*** main code *********************************************************
239 LC_ALL=C
241 cmd="$1"
242 shift
244 case "$cmd" in
245 list)
246 if [ -n "${MC_TEST_EXTFS_LIST_CMD:-}" ]; then
247 case "${MC_TEST_EXTFS_ISO9660_TOOL}" in
248 xorriso)
249 XORRISO="$MC_TEST_EXTFS_LIST_CMD"
250 xorriso_list "$@" || exit 1
253 exit 1
255 esac
257 exit 0
260 xorriso_list "$@" || {
261 test_iso "$@" || exit 1
262 mcisofs_list "$@" || exit 1
264 exit 0
267 xorriso_rm "$@" || {
268 exit 1
270 exit 0
272 rmdir)
273 xorriso_rmdir "$@" || {
274 exit 1
276 exit 0
278 mkdir)
279 xorriso_mkdir "$@" || {
280 exit 1
282 exit 0
284 copyin)
285 xorriso_copyin "$@" || {
286 exit 1
288 exit 0
290 copyout)
291 xorriso_copyout "$@" || {
292 test_iso "$@" || exit 1
293 mcisofs_copyout "$@" || exit 1
295 exit 0
297 esac
298 exit 1