File: File.pm

package info (click to toggle)
autopsy 2.24-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,644 kB
  • sloc: perl: 12,439; sh: 322; makefile: 32
file content (2310 lines) | stat: -rw-r--r-- 71,693 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
#
# File name layer functions
#
# Brian Carrier [carrier@sleuthkit.org]
# Copyright (c) 2001-2005 by Brian Carrier.  All rights reserved
#
# This file is part of the Autopsy Forensic Browser (Autopsy)
#
# Autopsy is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Autopsy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Autopsy; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR ANY PARTICULAR PURPOSE.
# IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA, OR PROFITS OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# Updated 1/15

package File;

# If the order of these views are changed, then the checks in main
# must be as well
$File::BLANK          = 0;
$File::FRAME          = 1;
$File::DIR_LIST       = 2;
$File::FILE_LIST_DIR  = 3;
$File::FILE_LIST_FILE = 4;
$File::FILE_LIST_DEL  = 5;
$File::FILE_LIST      = 6;
$File::CONT           = 7;
$File::CONT_FR        = 8;
$File::CONT_MENU      = 9;
$File::REPORT         = 10;
$File::EXPORT         = 11;
$File::MD5LIST        = 12;
$File::CONT_IMG       = 13;

$File::REC_NO  = 0;
$File::REC_YES = 1;

sub main {

    # By default, show the main frame
    $Args::args{'view'} = $Args::enc_args{'view'} = $File::FRAME
      unless (exists $Args::args{'view'});

    Args::check_view();
    my $view = Args::get_view();

    if ($view == $File::BLANK) {
        blank();
        return 0;
    }

    # Check Basic Args
    Args::check_vol('vol');

    # These windows don't need the meta data address
    if ($view < $File::FILE_LIST) {

        if ($view == $File::FRAME) {
            return frame();
        }

        Args::check_dir();
        if ($view == $File::DIR_LIST) {
            return dir_list();
        }
        elsif ($view == $File::FILE_LIST_DIR) {
            return file_list_dir();
        }
        elsif ($view == $File::FILE_LIST_DEL) {
            return file_list_del();
        }
        elsif ($view == $File::FILE_LIST_FILE) {
            return file_list_file();
        }
    }

    # These windows need the meta data address
    Args::check_dir();
    Args::check_meta('meta');

    if ($view < $File::REPORT) {
        if ($view == $File::FILE_LIST) {
            return file_list();
        }
        elsif ($view == $File::CONT) {
            return content();
        }
        elsif ($view == $File::CONT_FR) {
            return content_fr();
        }
        elsif ($view == $File::CONT_MENU) {
            return content_menu();
        }
    }
    else {
        if ($view == $File::REPORT) {
            return report();
        }
        elsif ($view == $File::EXPORT) {
            return export();
        }
        elsif ($view == $File::MD5LIST) {
            return md5list();
        }
        elsif ($view == $File::CONT_IMG) {
            return content_img();
        }
    }

    Print::print_check_err("Invalid File View");
}

# Sorting and display types
my $FIL_SORT_ASC = 0;
my $FIL_SORT_STR = 1;
my $FIL_SORT_HEX = 2;

# Methods of sorting the file listings
my $SORT_DTYPE = 0;    # type according to dentry
my $SORT_ITYPE = 1;    # type according to meta
my $SORT_NAME  = 2;
my $SORT_MOD   = 3;
my $SORT_ACC   = 4;
my $SORT_CHG   = 5;
my $SORT_CRT   = 6;
my $SORT_SIZE  = 7;
my $SORT_GID   = 8;
my $SORT_UID   = 9;
my $SORT_META  = 10;
my $SORT_DEL   = 11;

my $DIRMODE_SHOW   = 1;
my $DIRMODE_NOSHOW = 2;

#
# Make the three frames and fill them in
#
sub frame {
    my $vol = Args::get_vol('vol');
    my $mnt = $Caseman::vol2mnt{$vol};

    my $ftype = $Caseman::vol2ftype{$vol};

    # If we were not given the meta, then look up the root
    unless (exists $Args::args{'meta'}) {
        $Args::args{'meta'} = $Args::enc_args{'meta'} = $Fs::root_meta{$ftype};
    }

    unless (exists $Args::args{'dir'}) {
        $Args::enc_args{'dir'} = $Args::args{'dir'} = "/";
    }

    Args::check_meta('meta');
    Args::check_dir();

    my $meta = Args::get_meta('meta');
    my $dir  = Args::get_dir();

    Print::print_html_header_frameset("$mnt$dir on $Args::args{'vol'}");

    my $sort = $SORT_NAME;
    $sort = $Args::args{'sort'} if (exists $Args::args{'sort'});

    my $dirmode = $DIRMODE_NOSHOW;
    $dirmode = $Args::args{'dirmode'} if (exists $Args::args{'dirmode'});

    print "<frameset cols=\"175,*\">\n";

    # Directory Listing on Left
    my $url =
      "$::PROGNAME?$Args::baseargs&dir=$dir&" . "sort=$sort&dirmode=$dirmode";

    print "<frame src=\"$url&mod=$::MOD_FILE&view=$File::DIR_LIST\">\n";

    # File frameset on right
    print "<frameset rows=\"50%,50%\">\n";

    # File Listings on top
    print
      "<frame src=\"$url&mod=$::MOD_FILE&view=$File::FILE_LIST&meta=$meta\" "
      . "name=\"list\">\n";

    # File Contents
    print "<frame src=\"$::PROGNAME?mod=$::MOD_FILE&view=$File::BLANK&"
      . "$Args::baseargs\" name=\"content\">\n"
      . "</frameset>\n"
      . "</frameset>\n";

    Print::print_html_footer_frameset();
    return 0;
}

#
# Print the directory names for the lhs frame and other
# Search forms
#

sub dir_list {
    Args::check_sort();
    Args::check_dirmode();

    Print::print_html_header("");

    my $vol     = Args::get_vol('vol');
    my $ftype   = $Caseman::vol2ftype{$vol};
    my $sort    = Args::get_sort();
    my $dirmode = Args::get_dirmode();
    my $mnt     = $Caseman::vol2mnt{$vol};
    my $img     = $Caseman::vol2path{$vol};
    my $offset  = $Caseman::vol2start{$vol};
    my $imgtype = $Caseman::vol2itype{$vol};

    my $lcldir     = "";
    my $prev_plus  = "";    # previous number of '+' directory spacers
    my $prev_fname = "";
    my $prev_meta  = "";

    # Field to enter a directory into:
    print "<p><form action=\"$::PROGNAME\" method=\"get\" target=\"list\">\n"
      . "<center><b>Directory Seek</b></center><br>"
      . "Enter the name of a directory that you want to view.<br>"
      . "<tt>$mnt</tt>"
      . "<input type=\"text\" name=\"dir\" size=24 maxlength=100>\n"
      . "<input type=\"hidden\" name=\"mod\" value=\"$::MOD_FILE\">\n"
      . "<input type=\"hidden\" name=\"view\" value=\"$File::FILE_LIST_DIR\">\n"
      . "<input type=\"hidden\" name=\"vol\" value=\"$vol\">\n"
      . "<input type=\"hidden\" name=\"sort\" value=\"$Args::args{'sort'}\">\n"
      . "<input type=\"hidden\" name=\"dirmode\" value=\"$Args::args{'dirmode'}\">\n"
      . Args::make_hidden()
      .

      # View Button
      "<br><input type=\"image\" src=\"pict/but_view.jpg\" "
      . "width=45 height=22 alt=\"View\" border=\"0\"></form>\n";

    # Field to enter a name into:
    print
      "<hr><p><form action=\"$::PROGNAME\" method=\"get\" target=\"list\">\n"
      . "<center><b>File Name Search</b></center><br>"
      . "Enter a Perl regular expression for the file names you want to find.<br><br>\n"
      . "<input type=\"text\" name=\"dir\" size=24 maxlength=100>\n"
      . "<input type=\"hidden\" name=\"mod\" value=\"$::MOD_FILE\">\n"
      . "<input type=\"hidden\" name=\"view\" value=\"$File::FILE_LIST_FILE\">\n"
      . "<input type=\"hidden\" name=\"vol\" value=\"$Args::args{'vol'}\">\n"
      . "<input type=\"hidden\" name=\"sort\" value=\"$Args::args{'sort'}\">\n"
      . "<input type=\"hidden\" name=\"dirmode\" value=\"$Args::args{'dirmode'}\">\n"
      . Args::make_hidden()
      . "<br>\n"
      .

      # Search Button
      "<input type=\"image\" src=\"pict/but_search.jpg\" "
      . "width=61 height=22 alt=\"Search\" border=\"0\"></form>\n";

    print "<p><hr><p>\n";

    my $base_url = "$::PROGNAME?$Args::baseargs&sort=$sort";

    # All deleted files button
    print "<a href=\"$base_url&mod=$::MOD_FILE&view=$File::FILE_LIST_DEL&"
      . "dir=&dirmode=$dirmode\" target=\"list\">"
      . "<img border=\"0\" src=\"pict/file_b_alldel.jpg\" width=\"127\" "
      . "alt=\"Show All Deleted Files\">"
      . "</a><p>\n";

    # The dirmode arg shows if we should expand the whole directory listing
    # or not
    if ($dirmode == $DIRMODE_NOSHOW) {
        print "<a href=\"$base_url&mod=$::MOD_FILE&view=$File::FRAME&"
          . "dirmode=$DIRMODE_SHOW\" target=\"_parent\">"
          . "<img src=\"pict/file_b_expand.jpg\" alt=\"Expand All Directories\" "
          . "border=\"0\"></a><p><hr>\n";

        return;
    }
    else {
        print "<a href=\"$base_url&mod=$::MOD_FILE&view=$File::FRAME&"
          . "dirmode=$DIRMODE_NOSHOW\" target=\"_parent\">"
          . "<img src=\"pict/file_b_hide.jpg\" alt=\"Hide All Directories\" "
          . "border=\"0\"></a><p><hr>\n";
    }

    $base_url .= "&dirmode=$dirmode";

    Print::log_host_inv("$Args::args{'vol'}: List of all directories");

    # We need to maintain state to create dir and this is done by
    # counting the + marks.
    local *OUT;
    Exec::exec_pipe(*OUT,
        "'$::TSKDIR/fls' -f $ftype -ruD -o $offset -i $imgtype $img");

    # Print root
    my $url =
        "$base_url&mod=$::MOD_FILE&view=$File::FILE_LIST&"
      . "meta=$Fs::root_meta{$ftype}&dir=";
    print "<p><a href=\"$url\" target=\"list\">$mnt</a><br>\n";

    while ($_ = Exec::read_pipe_line(*OUT)) {
        if (
/^(\*)?(\+*)\s*[\-d]\/[\-d]\s*(\d+)\-?\d*\-?\d*\s*(\(realloc\))?:\t(.+)$/
          )
        {

            my $del   = $1;
            my $plus  = $2;
            my $meta  = $3;
            my $re    = $4;
            my $fname = $5;

            # Adjust the dir value using the '++' values to determine
            # how "deep" we are
            unless ($prev_plus eq $plus) {

                # are we in 1 more
                if ($plus eq $prev_plus . '+') {
                    $lcldir .= ($prev_fname . "/");
                }

                # we are back (at least one)
                elsif (defined $plus) {
                    my @dirs = split('/', $lcldir);
                    my $idx = -1;
                    $lcldir = "";

                    while (($idx = index($plus, '+', $idx + 1)) != -1) {
                        $lcldir .= ($dirs[$idx] . "/");
                    }
                }
            }

            $prev_plus  = $plus;
            $prev_fname = $fname;
            $prev_meta  = $meta;

            $url =
                "$base_url&mod=$::MOD_FILE&view=$File::FILE_LIST&"
              . "meta=$meta&dir="
              . Args::url_encode($lcldir . $fname . "/");

            print "<font color=\"$::DEL_COLOR[0]\">" if defined $del;
            print "+$plus<a href=\"$url\" target=\"list\"><tt>/"
              . Print::html_encode($fname)
              . "</tt></a><br>\n";
            print "</font>" if defined $del;
        }
    }
    close(OUT);
    Print::print_html_footer();
    return 0;

};    # end of FIL_DIR

# Print the files and directories for the upper rhs frame
# These can be sorted in any format
#
# We need to find a way to cache this data
#
sub file_list {
    Args::check_sort();
    Args::check_dirmode();

    my $vol     = Args::get_vol('vol');
    my $sort    = Args::get_sort();
    my $ftype   = $Caseman::vol2ftype{$vol};
    my $meta    = Args::get_meta('meta');
    my $mnt     = $Caseman::vol2mnt{$vol};
    my $img     = $Caseman::vol2path{$vol};
    my $offset  = $Caseman::vol2start{$vol};
    my $imgtype = $Caseman::vol2itype{$vol};

    my $fname = "$mnt$Args::args{'dir'}";
    $fname =~ s/\/\//\//g;

    my $sp = "&nbsp;&nbsp;";

    Print::print_html_header("Entries in $fname");

    my (@itype, @dtype, @name, @mod, @acc, @chg, @crt, @size, @gid, @uid,
        @meta);
    my (@dir, @entry, @del, @realloc, @meta_int);

    my $tz = "";
    $tz = "-z '$Caseman::tz'" unless ("$Caseman::tz" eq "");

    Print::log_host_inv(
        "$Caseman::vol2sname{$vol}: Directory listing of $fname ($meta)");

    local *OUT;

    # execute command
    Exec::exec_pipe(*OUT,
"'$::TSKDIR/fls' -f $ftype -la $tz -s $Caseman::ts -o $offset -i $imgtype $img $meta"
    );

    # Make the big table, small table, and start the current directory

    my $iurl =
"$::PROGNAME?$Args::baseargs&dirmode=$Args::enc_args{'dirmode'}&sort=$sort";

    # base number of columns in table
    my $cols = 15;
    $cols += 2 if ($Fs::has_ctime{$ftype});
    $cols += 2 if ($Fs::has_crtime{$ftype});
    $cols += 2 if ($Fs::has_mtime{$ftype});

    print <<EOF1;
<!-- Big Table -->
<table cellspacing=\"0\" cellpadding=\"2\" border=0>

<!-- Small Table -->
<tr>
  <td colspan=$cols>
    <table border=0 align=\"left\" cellspacing=\"0\" cellpadding=\"2\" width=500>
    <tr>
      <td colspan=2><b>Current Directory:</b> <tt>

        <a href=\"${iurl}&mod=$::MOD_FILE&view=$File::FILE_LIST&meta=$Fs::root_meta{$ftype}&dir=\">$mnt</a>&nbsp;

EOF1

    # Each file in the path will get its own link
    $iurl .= "&mod=$::MOD_FILE&view=$File::FILE_LIST_DIR";
    my $path = "";
    my @dir_split = split('/', $Args::args{'dir'});
    while (scalar @dir_split > 1) {
        my $d = shift @dir_split;

        next if ($d eq '');

        $path .= "$d/";
        print "        <a href=\"${iurl}&dir=$path\">/${d}/</a>&nbsp;\n";
    }
    print "        /$dir_split[0]/&nbsp;\n"
      if (scalar @dir_split == 1);

    print "      </tt></td>\n" . "    </tr>\n";

    # Add Note Button
    $iurl =
"&$Args::baseargs&dir=$Args::enc_args{'dir'}&meta=$Args::enc_args{'meta'}";
    if ($::USE_NOTES == 1) {

        print <<EOF2;
    <tr>
      <td width=\"100\" align=left>
        <a href=\"$::PROGNAME?mod=$::MOD_NOTES&view=$Notes::ENTER_FILE$iurl\" target=\"_blank\">
          <img border=\"0\" src=\"pict/but_addnote.jpg\" width=\"89\" height=20 alt=\"Add Note About Directory\">
         </a>
      </td>
EOF2

    }

    # Generate MD5 List Button
    print <<EOF3;

      <td width=\"206\" align=left>
        <a href=\"$::PROGNAME?mod=$::MOD_FILE&view=$File::MD5LIST$iurl\" target=\"_blank\">
          <img border=\"0\" src=\"pict/file_b_md5list.jpg\" width=\"206\" alt=\"Generate list of MD5 values\">
        </a>
      </td>
    </tr>
  <!-- END of Little Table -->
  </table>
  </td>
</tr>
<tr>
  <td colspan=$cols><hr></td>
</tr>

EOF3

    # Make the Table and Headers
    my $url =
        "$::PROGNAME?mod=$::MOD_FILE&view=$File::FRAME&"
      . "$Args::baseargs&meta=$Args::enc_args{'meta'}"
      . "&dir=$Args::enc_args{'dir'}&dirmode=$Args::enc_args{'dirmode'}";

    print "<tr valign=\"MIDDLE\" " . "background=\"$::YEL_PIX\">\n";

    # Print the Headers - If the sorting mode is set to it, then don't
    # make it a link and print a different button
    if ($sort == $SORT_DEL) {
        print "  <td align=\"left\" background=\"$::YEL_PIX\">"
          . "<img border=\"0\" "
          . "src=\"pict/file_h_del_cur.jpg\" "
          . "width=\"49\" height=20 "
          . "alt=\"Deleted Files\">"
          . "</td>\n";
    }
    else {
        $iurl = $url . "&sort=$SORT_DEL";
        print "  <td align=\"left\" background=\"$::YEL_PIX\">"
          . "<a href=\"$iurl\" target=\"_parent\">"
          . "<img border=\"0\" "
          . "src=\"pict/file_h_del_link.jpg\" "
          . "width=\"28\" height=20 "
          . "alt=\"Deleted Files\">"
          . "</a></td>\n";
    }

    # type only gets one column for two 'types'
    print "  <td background=\"$::YEL_PIX\">$sp</td>\n"
      . "  <th align=\"center\" background=\"$::YEL_PIX\">"
      . "&nbsp;&nbsp;Type&nbsp;&nbsp;<br>";

    if ($sort == $SORT_DTYPE) {
        print "dir";
    }
    else {
        $iurl = $url . "&sort=$SORT_DTYPE";
        print "<a href=\"$iurl\" target=\"_parent\">dir</a>";
    }

    print "&nbsp;/&nbsp;";

    if ($sort == $SORT_ITYPE) {
        print "in</th>\n";
    }
    else {
        $iurl = $url . "&sort=$SORT_ITYPE";
        print "<a href=\"$iurl\" target=\"_parent\">in</a></th>\n";
    }

    print "  <td background=\"$::YEL_PIX\">$sp</td>\n";

    if ($sort == $SORT_NAME) {
        print "  <td align=\"left\" background=\"$::YEL_PIX\">"
          . "<img border=\"0\" "
          . "src=\"pict/file_h_nam_cur.jpg\" "
          . "width=\"76\" height=20 "
          . "alt=\"File Name\">"
          . "</td>\n";
    }
    else {
        $iurl = $url . "&sort=$SORT_NAME";
        print "  <td align=\"left\" background=\"$::YEL_PIX\">"
          . "<a href=\"$iurl\" target=\"_parent\">"
          . "<img border=\"0\" "
          . "src=\"pict/file_h_nam_link.jpg\" "
          . "width=\"50\" height=20 "
          . "alt=\"File Name\">"
          . "</a></td>\n";
    }

    print "  <td background=\"$::YEL_PIX\">$sp</td>\n";

    # Modified / Written
    if ($Fs::has_mtime{$ftype}) {
        if ($sort == $SORT_MOD) {
            print "  <td align=\"left\" background=\"$::YEL_PIX\">"
              . "<img border=\"0\" "
              . "src=\"pict/file_h_wr_cur.jpg\" "
              . "width=\"89\" height=20 "
              . "alt=\"Modified/Written Time\">"
              . "</td>\n";
        }
        else {
            $iurl = $url . "&sort=$SORT_MOD";
            print "  <td align=\"left\" background=\"$::YEL_PIX\">"
              . "<a href=\"$iurl\" target=\"_parent\">"
              . "<img border=\"0\" "
              . "src=\"pict/file_h_wr_link.jpg\" "
              . "width=\"60\" height=20 "
              . "alt=\"Modified/Written Time\">"
              . "</a></td>\n";
        }
        print "  <td background=\"$::YEL_PIX\">$sp</td>\n";
    }

    # Accessed
    if ($sort == $SORT_ACC) {
        print "  <td align=\"left\" background=\"$::YEL_PIX\">"
          . "<img border=\"0\" "
          . "src=\"pict/file_h_acc_cur.jpg\" "
          . "width=\"90\" height=20 "
          . "alt=\"Access Time\">"
          . "</td>\n";
    }
    else {
        $iurl = $url . "&sort=$SORT_ACC";
        print "  <td align=\"left\" background=\"$::YEL_PIX\">"
          . "<a href=\"$iurl\" target=\"_parent\">"
          . "<img border=\"0\" "
          . "src=\"pict/file_h_acc_link.jpg\" "
          . "width=\"66\" height=20 "
          . "alt=\"Access Time\">"
          . "</a></td>\n";
    }

    print "  <td background=\"$::YEL_PIX\">$sp</td>\n";

    # Change
    if ($Fs::has_ctime{$ftype}) {
        if ($sort == $SORT_CHG) {
            print "  <td align=\"left\" background=\"$::YEL_PIX\">"
              . "<img border=\"0\" "
              . "src=\"pict/file_h_chg_cur.jpg\" "
              . "width=\"90\" height=20 "
              . "alt=\"Change Time\">"
              . "</td>\n";
        }
        else {
            $iurl = $url . "&sort=$SORT_CHG";
            print "  <td align=\"left\" background=\"$::YEL_PIX\">"
              . "<a href=\"$iurl\" target=\"_parent\">"
              . "<img border=\"0\" "
              . "src=\"pict/file_h_chg_link.jpg\" "
              . "width=\"62\" height=20 "
              . "alt=\"Change Time\">"
              . "</a></td>\n";
        }
        print "  <td background=\"$::YEL_PIX\">$sp</td>\n";
    }

    # Create
    if ($Fs::has_crtime{$ftype}) {
        if ($sort == $SORT_CRT) {
            print "  <td align=\"left\" background=\"$::YEL_PIX\">"
              . "<img border=\"0\" "
              . "src=\"pict/file_h_cre_cur.jpg\" "
              . "width=\"84\" height=20 "
              . "alt=\"Create Time\">"
              . "</td>\n";
        }
        else {
            $iurl = $url . "&sort=$SORT_CRT";
            print "  <td align=\"left\" background=\"$::YEL_PIX\">"
              . "<a href=\"$iurl\" target=\"_parent\">"
              . "<img border=\"0\" "
              . "src=\"pict/file_h_cre_link.jpg\" "
              . "width=\"59\" height=20 "
              . "alt=\"Create Time\">"
              . "</a></td>\n";
        }
        print "  <td background=\"$::YEL_PIX\">$sp</td>\n";
    }

    # Size
    if ($sort == $SORT_SIZE) {
        print "  <td align=\"left\" background=\"$::YEL_PIX\">"
          . "<img border=\"0\" "
          . "src=\"pict/file_h_siz_cur.jpg\" "
          . "width=\"53\" height=20 "
          . "alt=\"Size\">"
          . "</td>\n";
    }
    else {
        $iurl = $url . "&sort=$SORT_SIZE";
        print "  <td align=\"left\" background=\"$::YEL_PIX\">"
          . "<a href=\"$iurl\" target=\"_parent\">"
          . "<img border=\"0\" "
          . "src=\"pict/file_h_siz_link.jpg\" "
          . "width=\"31\" height=20 "
          . "alt=\"Size\">"
          . "</a></td>\n";
    }

    print "  <td background=\"$::YEL_PIX\">$sp</td>\n";

    # UID
    if ($sort == $SORT_UID) {
        print "  <td align=\"left\" background=\"$::YEL_PIX\">"
          . "<img border=\"0\" "
          . "src=\"pict/file_h_uid_cur.jpg\" "
          . "width=\"49\" height=20 "
          . "alt=\"UID\">"
          . "</td>\n";
    }
    else {
        $iurl = $url . "&sort=$SORT_UID";
        print "  <td align=\"left\" background=\"$::YEL_PIX\">"
          . "<a href=\"$iurl\" target=\"_parent\">"
          . "<img border=\"0\" "
          . "src=\"pict/file_h_uid_link.jpg\" "
          . "width=\"27\" height=20 "
          . "alt=\"UID\">"
          . "</a></td>\n";
    }

    print "  <td background=\"$::YEL_PIX\">$sp</td>\n";

    # GID
    if ($sort == $SORT_GID) {
        print "  <td align=\"left\" background=\"$::YEL_PIX\">"
          . "<img border=\"0\" "
          . "src=\"pict/file_h_gid_cur.jpg\" "
          . "width=\"49\" height=20 "
          . "alt=\"GID\">"
          . "</td>\n";
    }
    else {
        $iurl = $url . "&sort=$SORT_GID";
        print "  <td align=\"left\" background=\"$::YEL_PIX\">"
          . "<a href=\"$iurl\" target=\"_parent\">"
          . "<img border=\"0\" "
          . "src=\"pict/file_h_gid_link.jpg\" "
          . "width=\"28\" height=20 "
          . "alt=\"GID\">"
          . "</a></td>\n";
    }

    print "  <td background=\"$::YEL_PIX\">$sp</td>\n";

    # meta
    if ($sort == $SORT_META) {
        print "  <td align=\"left\" background=\"$::YEL_PIX\">"
          . "<img border=\"0\" "
          . "src=\"pict/file_h_meta_cur.jpg\" "
          . "width=\"62\" height=20 "
          . "alt=\"Meta\">"
          . "</td>\n";
    }
    else {
        $iurl = $url . "&sort=$SORT_META";
        print "  <td align=\"left\" background=\"$::YEL_PIX\">"
          . "<a href=\"$iurl\" target=\"_parent\">"
          . "<img border=\"0\" "
          . "src=\"pict/file_h_meta_link.jpg\" "
          . "width=\"41\" height=20 "
          . "alt=\"Meta\">"
          . "</a></td>\n";
    }
    print "</tr>\n";

    my $cnt = 0;
    my %seen;

    # sort fls into arrays
    while ($_ = Exec::read_pipe_line(*OUT)) {
        if (
/^($::REG_MTYPE)\/($::REG_MTYPE)\s*(\*?)\s*($::REG_META)(\(realloc\))?:\t(.+?)\t($::REG_DATE)\t($::REG_DATE)\t($::REG_DATE)\t($::REG_DATE)\t(\d+)\t(\d+)\t(\d+)$/o
          )
        {

            my $lcldir = $Args::args{'dir'};
            $dtype[$cnt]   = $1;
            $itype[$cnt]   = $2;
            $del[$cnt]     = $3;
            $meta[$cnt]    = $4;
            $realloc[$cnt] = "";
            $realloc[$cnt] = $5 if (defined $5);
            $name[$cnt]    = $6;
            $mod[$cnt]     = $7;
            $acc[$cnt]     = $8;
            $chg[$cnt]     = $9;
            $crt[$cnt]     = $10;
            $size[$cnt]    = $11;
            $gid[$cnt]     = $12;
            $uid[$cnt]     = $13;

            if ($meta[$cnt] =~ /^(\d+)(-\d+(-\d+)?)?$/) {
                $meta_int[$cnt] = $1;
            }
            else {
                $meta_int[$cnt] = $meta[$cnt];
            }

            # See if we have already seen this file yet
            if (exists $seen{"$name[$cnt]-$meta[$cnt]"}) {
                my $prev_cnt = $seen{"$name[$cnt]-$meta[$cnt]"};

                # If we saw it while it was deleted, & it
                # is now undel, then update it
                if (   ($del[$cnt] eq "")
                    && ($del[$prev_cnt] eq '*'))
                {
                    $del[$prev_cnt] = $del[$cnt];
                }
                next;

                # Add it to the seen list
            }
            else {
                $seen{"$name[$cnt]-$meta[$cnt]"} = $cnt;
            }

            # We must adjust the dir for directories
            if ($itype[$cnt] eq 'd') {

                # special cases for .. and .
                if ($name[$cnt] eq '..') {
                    my @dirs = split('/', $lcldir);
                    my $i;
                    $lcldir = "";
                    for ($i = 0; $i < $#dirs; $i++) {
                        $lcldir .= ($dirs[$i] . '/');
                    }
                }
                elsif ($name[$cnt] ne '.') {
                    $lcldir .= ($name[$cnt] . '/');
                }
                $name[$cnt] .= '/';
            }
            else {
                $lcldir .= $name[$cnt];
            }

            # format the date so that the time and time zone are on the
            # same line
            $mod[$cnt] = "$1&nbsp;$2"
              if ($mod[$cnt] =~ /($::REG_DAY\s+$::REG_TIME)\s+($::REG_ZONE2)/o);

            $acc[$cnt] = "$1&nbsp;$2"
              if ($acc[$cnt] =~ /($::REG_DAY\s+$::REG_TIME)\s+($::REG_ZONE2)/o);

            $chg[$cnt] = "$1&nbsp;$2"
              if ($chg[$cnt] =~ /($::REG_DAY\s+$::REG_TIME)\s+($::REG_ZONE2)/o);

            $crt[$cnt] = "$1&nbsp;$2"
              if ($crt[$cnt] =~ /($::REG_DAY\s+$::REG_TIME)\s+($::REG_ZONE2)/o);

            $dir[$cnt]   = Args::url_encode($lcldir);
            $entry[$cnt] = $cnt;
            $cnt++;

        }

        # We missed it for some reason
        else {
            print
"<tr><td colspan=10>Error Parsing File (Invalid Characters?):<br>$_</td></tr>\n";
        }
    }
    close(OUT);

    if ($cnt == 0) {
        print "</table>\n<center>No Contents</center>\n";
        return 0;
    }

    # Sort the above array based on the sort argument
    my @sorted;    # an array of indices

    if ($sort == $SORT_DTYPE) {
        @sorted =
          sort { $dtype[$a] cmp $dtype[$b] or lc($name[$a]) cmp lc($name[$b]) }
          @entry;
    }
    elsif ($sort == $SORT_ITYPE) {
        @sorted =
          sort { $itype[$a] cmp $itype[$b] or lc($name[$a]) cmp lc($name[$b]) }
          @entry;
    }
    elsif ($sort == $SORT_NAME) {
        @sorted = sort { lc($name[$a]) cmp lc($name[$b]) } @entry;
    }
    elsif ($sort == $SORT_MOD) {
        @sorted =
          sort { $mod[$a] cmp $mod[$b] or lc($name[$a]) cmp lc($name[$b]) }
          @entry;
    }
    elsif ($sort == $SORT_ACC) {
        @sorted =
          sort { $acc[$a] cmp $acc[$b] or lc($name[$a]) cmp lc($name[$b]) }
          @entry;
    }
    elsif ($sort == $SORT_CHG) {
        @sorted =
          sort { $chg[$a] cmp $chg[$b] or lc($name[$a]) cmp lc($name[$b]) }
          @entry;
    }
    elsif ($sort == $SORT_CRT) {
        @sorted =
          sort { $crt[$a] cmp $crt[$b] or lc($name[$a]) cmp lc($name[$b]) }
          @entry;
    }
    elsif ($sort == $SORT_SIZE) {
        @sorted =
          sort { $size[$a] <=> $size[$b] or lc($name[$a]) cmp lc($name[$b]) }
          @entry;
    }
    elsif ($sort == $SORT_UID) {
        @sorted =
          sort { $uid[$a] <=> $uid[$b] or lc($name[$a]) cmp lc($name[$b]) }
          @entry;
    }
    elsif ($sort == $SORT_GID) {
        @sorted =
          sort { $gid[$a] <=> $gid[$b] or lc($name[$a]) cmp lc($name[$b]) }
          @entry;
    }
    elsif ($sort == $SORT_META) {
        @sorted = sort {
            $meta_int[$a] <=> $meta_int[$b]
              or lc($name[$a]) cmp lc($name[$b])
        } @entry;
    }
    elsif ($sort == $SORT_DEL) {
        @sorted =
          sort { $del[$b] cmp $del[$a] or lc($name[$a]) cmp lc($name[$b]) }
          @entry;
    }

    # print them based on sorting
    my $row = 0;
    foreach my $i (@sorted) {
        my $url;
        my $target;
        my $color;
        my $lcolor;
        if ($del[$i] eq '*') {
            $color =
              "<font color=\"" . $::DEL_COLOR[$realloc[$i] ne ""] . "\">";
            $lcolor = $color;
        }
        else {
            $color  = "<font color=\"$::NORM_COLOR\">";
            $lcolor = "<font color=\"$::LINK_COLOR\">";
        }

        # directories have different targets and view values
        if ($itype[$i] eq 'd') {
            $target = "list";
            $url    =
                "$::PROGNAME?mod=$::MOD_FILE&view=$File::FILE_LIST&"
              . "$Args::baseargs&meta=$meta_int[$i]"
              . "&sort=$sort&dir=$dir[$i]&dirmode=$Args::enc_args{'dirmode'}";
        }
        else {
            $target = "content";
            $url    =
                "$::PROGNAME?mod=$::MOD_FILE&view=$File::CONT_FR&"
              . "$Args::baseargs&meta=$meta[$i]"
              . "&sort=$sort&dir=$dir[$i]&dirmode=$Args::enc_args{'dirmode'}";
            if ($del[$i] eq '*') {
                $url .= "&recmode=$File::REC_YES";
            }
            else {
                $url .= "&recmode=$File::REC_NO";
            }
        }

        if (($row % 2) == 0) {
            print
"<tr valign=\"TOP\" bgcolor=\"$::BACK_COLOR\">\n  <td align=\"center\">";
        }
        else {
            print
"<tr valign=\"TOP\" bgcolor=\"$::BACK_COLOR_TABLE\">\n  <td align=\"center\">";
        }

        print "<img src=\"pict/file_b_check.jpg\" border=\"0\">\n"
          if ($del[$i] eq '*');

        print "</td>\n"
          . "  <td>$sp</td>\n"
          . "  <td align=\"center\">${color}$dtype[$i]&nbsp;/&nbsp;$itype[$i]</td>\n"
          . "  <td>$sp</td>\n";

        # for valid files and directories make a link
        # Special rule for $OrphanFiles directory and HFS directories, which have a size of 0
        if (
               ($meta_int[$i] >= $Fs::first_meta{$ftype})
            && (($size[$i] > 0) || (($name[$i] =~ /^\$Orphan/) && ($itype[$i] eq 'd')) || (($ftype =~ /hfs/) && ($itype[$i] eq 'd')))
            && (   ($itype[$i] eq 'r')
                || ($itype[$i] eq 'd')
                || ($itype[$i] eq 'v'))
          )
        {
            print "  <td><a href=\"$url\" target=\"$target\">$lcolor";
        }
        else {
            print "  <td>$color";
        }
        print "<tt>"
          . Print::html_encode($name[$i])
          . "</tt></td>\n"
          . "  <td>$sp</td>\n";
        print "  <td>${color}$mod[$i]</td>\n" . "  <td>$sp</td>\n"
          if ($Fs::has_mtime{$ftype});
        print "  <td>${color}$acc[$i]</td>\n" . "  <td>$sp</td>\n";
        print "  <td>${color}$chg[$i]</td>\n" . "  <td>$sp</td>\n"
          if ($Fs::has_ctime{$ftype});
        print "  <td>${color}$crt[$i]</td>\n" . "  <td>$sp</td>\n"
          if ($Fs::has_crtime{$ftype});
        print "  <td>${color}$size[$i]</td>\n"
          . "  <td>$sp</td>\n"
          . "  <td>${color}$uid[$i]</td>\n"
          . "  <td>$sp</td>\n"
          . "  <td>${color}$gid[$i]</td>\n"
          . "  <td>$sp</td>\n";

        # for a valid meta, make a link to meta browsing mode
        if ($meta_int[$i] >= $Fs::first_meta{$ftype}) {
            my $iurl =
"$::PROGNAME?mod=$::MOD_FRAME&submod=$::MOD_META&$Args::baseargs&meta=$meta[$i]";
            print "<td><a href=\"$iurl\" target=\"_top\">$lcolor";
        }
        else {
            print "<td>$color";
        }
        print "$meta[$i]</a> $realloc[$i]</td>\n</tr>\n";

        $row++;
    }

    print "</table>\n";
    Print::print_html_footer();
    return 0;

};    #end of FIL_LIST

# This takes a directory name as an argument and converts it to
# the meta value and calls FIL_LIST
#
# The meta value can be anything when this is run, it will be
# overwritten
sub file_list_dir {

    my $vol     = Args::get_vol('vol');
    my $ftype   = $Caseman::vol2ftype{$vol};
    my $dir     = Args::get_dir();
    my $img     = $Caseman::vol2path{$vol};
    my $offset  = $Caseman::vol2start{$vol};
    my $imgtype = $Caseman::vol2itype{$vol};

    Print::log_host_inv(
        "$Args::args{'vol'}: Finding meta data address for $dir");

    # Use 'ifind -n' to get the meta data address for the given name
    local *OUT;
    Exec::exec_pipe(*OUT,
        "'$::TSKDIR/ifind' -f $ftype -n '$dir'  -o $offset -i $imgtype $img");
    my $meta;

    while ($_ = Exec::read_pipe_line(*OUT)) {
        $meta = $1
          if (/^($::REG_META)$/);
    }
    close(OUT);

    Print::print_check_err("Error finding meta data address for $dir")
      unless (defined $meta);

    Print::print_check_err("Error finding meta data address for $dir: $meta")
      unless ($meta =~ /^$::REG_META$/);

    # Verify it is a directory with istat
    Exec::exec_pipe(*OUT,
        "'$::TSKDIR/istat' -f $ftype  -o $offset -i $imgtype $img $meta");

    while ($_ = Exec::read_pipe_line(*OUT)) {

        # This is a directory
        if (   (/mode:\s+d/)
            || (/File Attributes: Directory/)
            || (/^Flags:.*?Directory/))
        {
            close(OUT);

            # Set the meta variables
            $Args::enc_args{'meta'} = $Args::args{'meta'} = $meta;

            $Args::args{'dir'} .= "/"
              unless ($Args::args{'dir'} =~ /.*?\/$/);
            $Args::enc_args{'dir'} .= "/"
              unless ($Args::enc_args{'dir'} =~ /.*?\/$/);

            # List the directory contents
            file_list();

            return 0;
        }
    }
    close(OUT);

    # This is not a directory, so just give a link
    Print::print_html_header("");

    my $meta_int = $meta;
    $meta_int = $1 if ($meta_int =~ /(\d+)-\d+(-\d+)?/);

    my $recmode = $File::REC_NO;
    local *OUT;
    Exec::exec_pipe(*OUT,
        "'$::TSKDIR/ils' -f $ftype -e  -o $offset -i $imgtype $img $meta_int");
    while ($_ = Exec::read_pipe_line(*OUT)) {
        chop;
        next unless ($_ =~ /^$meta/);
        if ($_ =~ /^$meta\|f/) {
            $recmode = $File::REC_YES;
        }
        elsif ($_ =~ /^$meta\|a/) {
            $recmode = $File::REC_NO;
        }
        else {
            Print::print_err("Error parsing ils output: $_");
        }
    }
    close(OUT);

    print <<EOF;

<tt>$dir</tt> (
<a href=\"$::PROGNAME?mod=$::MOD_FRAME&submod=$::MOD_META&$Args::baseargs&meta=$meta&recmode=$recmode\" target=\"_top\">
meta $meta</a>) is not a directory.

<p>
<a href=\"$::PROGNAME?mod=$::MOD_FILE&view=$File::CONT_FR&$Args::baseargs&meta=$meta&dir=$dir&recmode=$recmode\" target=\"content\">
  <img src=\"pict/but_viewcont.jpg\" height=20 width=123 alt=\"view contents\" border=\"0\">
</a>

EOF

    Print::print_html_footer();
    return 1;

}

# List the files that meet a certain pattern
sub file_list_file {
    Args::check_sort();
    Args::check_dirmode();
    Args::check_dir();

    my $vol     = Args::get_vol('vol');
    my $mnt     = $Caseman::vol2mnt{$vol};
    my $img     = $Caseman::vol2path{$vol};
    my $offset  = $Caseman::vol2start{$vol};
    my $imgtype = $Caseman::vol2itype{$vol};
    my $ftype   = $Caseman::vol2ftype{$vol};
    my $meta    = $Fs::root_meta{$ftype};
    my $sort    = Args::get_sort();
    my $dirmode = Args::get_dirmode();
    my $dir     = Args::get_dir();

    Print::print_html_header(
        "Filtered files on $Caseman::vol2sname{$vol} $mnt");

    my $tz = "";
    $tz = "-z '$Caseman::tz'" unless ("$Caseman::tz" eq "");

    my $sp = "&nbsp;&nbsp;";

    Print::log_host_inv(
        "$Caseman::vol2sname{$vol}: Listing all files with $dir");

    local *OUT;
    Exec::exec_pipe(*OUT,
"'$::TSKDIR/fls' -f $ftype -lpr $tz -s $Caseman::ts -o $offset -i $imgtype $img $meta"
    );

    print "<b>All files with \'<tt>$dir</tt>\' in the name</b><p>\n"
      . "<a href=\"$::PROGNAME?$Args::baseargs&dirmode=$Args::enc_args{'dirmode'}"
      . "&sort=$sort&mod=$::MOD_FILE&view=$File::FILE_LIST"
      . "&meta=$Fs::root_meta{$ftype}&dir=\">"
      . "<img border=\"0\" src=\"pict/file_b_allfiles.jpg\" width=\"112\" "
      . "alt=\"Show All Files\"></a>\n" . "<hr>"
      . "<table cellspacing=\"0\" cellpadding=\"2\"  border=0>\n"
      . "<tr valign=\"MIDDLE\" align=\"left\" "
      . "background=\"$::YEL_PIX\">\n";

    # deleted
    print "<td align=\"left\">"
      . "<img border=\"0\" src=\"pict/file_h_del_link.jpg\" "
      . "width=\"28\" height=20 alt=\"Deleted Files\">"
      . "</td>\n"
      . "<td>$sp</td>\n";

    # Type
    print "<th align=\"center\">&nbsp;&nbsp;Type&nbsp&nbsp;<br>"
      . "dir&nbsp;/&nbsp;in</th>"
      . "<td>$sp</td>\n";

    # Name
    print "  <td><img border=\"0\" "
      . "src=\"pict/file_h_nam_link.jpg\" "
      . "width=\"50\" height=20 "
      . "alt=\"File Name\">"
      . "</td>\n"
      . "<td>$sp</td>\n";

    # Mod / Written
    if ($Fs::has_mtime{$ftype}) {
        print "  <td><img border=\"0\" "
          . "src=\"pict/file_h_wr_link.jpg\" "
          . "width=\"60\" "
          . "alt=\"Written Time\">"
          . "</td>\n"
          . "<td>$sp</td>\n";
    }

    # Access
    print "  <td><img border=\"0\" "
      . "src=\"pict/file_h_acc_link.jpg\" "
      . "width=\"66\" height=20 "
      . "alt=\"Access Time\">"
      . "</td>\n"
      . "<td>$sp</td>\n";

    # Change
    if ($Fs::has_ctime{$ftype}) {
        print "  <td><img border=\"0\" "
          . "src=\"pict/file_h_chg_link.jpg\" "
          . "width=\"62\" "
          . "alt=\"Change Time\">"
          . "</td>\n"
          . "<td>$sp</td>\n";
    }

    # Create
    if ($Fs::has_crtime{$ftype}) {
        print "  <td><img border=\"0\" "
          . "src=\"pict/file_h_cre_link.jpg\" "
          . "width=\"59\" "
          . "alt=\"Create Time\">"
          . "</td>\n"
          . "<td>$sp</td>\n";
    }

    # Size
    print "  <td><img border=\"0\" "
      . "src=\"pict/file_h_siz_link.jpg\" "
      . "width=\"31\" height=20 "
      . "alt=\"Size\">"
      . "</td>\n"
      . "<td>$sp</td>\n";

    # UID
    print "  <td><img border=\"0\" "
      . "src=\"pict/file_h_uid_link.jpg\" "
      . "width=\"27\" height=20 "
      . "alt=\"UID\">"
      . "</td>\n"
      . "<td>$sp</td>\n";

    # GID
    print "  <td><img border=\"0\" "
      . "src=\"pict/file_h_gid_link.jpg\" "
      . "width=\"28\" height=20 "
      . "alt=\"GID\">"
      . "</td>\n"
      . "<td>$sp</td>\n";

    # Meta
    print "  <td><img border=\"0\" "
      . "src=\"pict/file_h_meta_link.jpg\" "
      . "width=\"41\" height=20 "
      . "alt=\"Meta\">"
      . "</td>\n"
      . "<td>$sp</td>\n";

    my $row = 0;
    while ($_ = Exec::read_pipe_line(*OUT)) {
        if (
/^($::REG_MTYPE)\/($::REG_MTYPE)\s*(\*?)\s*($::REG_META)(\(realloc\))?:\t(.+?)\t($::REG_DATE)\t($::REG_DATE)\t($::REG_DATE)\t($::REG_DATE)\t(\d+)\t(\d+)\t(\d+)$/o
          )
        {

            # We have to remove the / from the beginning of the file name so
            # save all values so they aren't lost
            my $dt = $1;
            my $it = $2;
            my $d  = $3;
            my $i  = $4;
            my $r  = 0;
            $r = 1 if (defined $5);
            my $n  = $6;
            my $m  = $7;
            my $a  = $8;
            my $c  = $9;
            my $cr = $10;
            my $s  = $11;
            my $g  = $12;
            my $u  = $13;

            if ($n =~ /^\/(.*)/) {
                $n = $1;
            }

            my $p = "";
            my $f = $n;

            if ($n =~ /^(.+?)\/([^\/]+)$/) {
                $p = $1;
                $f = $2;
            }

            next unless ($f =~ /$dir/i);

            my $enc_n = Args::url_encode($n);
            my $iurl  =
"$::PROGNAME?mod=$::MOD_FRAME&submod=$::MOD_META&$Args::baseargs&meta=$i";
            my $i_int = $i;
            $i_int = $1 if ($i =~ /(\d+)-\d+-\d+/);

            if (($row % 2) == 0) {
                print "<tr valign=\"TOP\" bgcolor=\"$::BACK_COLOR\">\n";
            }
            else {
                print "<tr valign=\"TOP\" bgcolor=\"$::BACK_COLOR_TABLE\">\n";
            }

            print "<td align=\"left\">\n";

            my $color;
            my $lcolor;
            if ($d eq '*') {
                $color  = "<font color=\"" . $::DEL_COLOR[$r] . "\">";
                $lcolor = $color;

                print "<img src=\"pict/file_b_check.jpg\" border=\"0\">\n";

            }
            else {
                $color  = "<font color=\"$::NORM_COLOR\">";
                $lcolor = "<font color=\"$::LINK_COLOR\">";
                print "&nbsp;";
            }

            print "</td><td>$sp</td>";

            print "<td align=\"center\">$color"
              . "$dt&nbsp;/&nbsp;$it</td>"
              . "<td>$sp</td>\n";

            if ($it eq 'd') {
                my $url =
                    "$::PROGNAME?mod=$::MOD_FILE&"
                  . "view=$File::FILE_LIST&$Args::baseargs&meta=$i"
                  . "&sort=$sort&dir=$enc_n&dirmode=$dirmode";

                print "<td>";
                if ($i_int >= $Fs::first_meta{$ftype}) {
                    print "<a href=\"$url\" target=\"_self\">$lcolor";
                }
                else {
                    print "$color";
                }
                print "<tt>"
                  . Print::html_encode($mnt . $n)
                  . "</tt></td>"
                  . "<td>$sp</td>\n";
            }
            else {
                my $url =
                    "$::PROGNAME?mod=$::MOD_FILE&view=$File::CONT_FR&"
                  . "$Args::baseargs&meta=$i&sort=$sort&dir=$enc_n";

                if ($d eq '*') {
                    $url .= "&recmode=$File::REC_YES";
                }
                else {
                    $url .= "&recmode=$File::REC_NO";
                }

                print "<td>";
                if (($i_int >= $Fs::first_meta{$ftype}) && ($it eq 'r')) {
                    print "<a href=\"$url\" target=\"content\">$lcolor";
                }
                else {
                    print "$color";
                }
                print "<tt>$mnt$n</tt></td>" . "<td>$sp</td>\n";
            }

            $m = "$1&nbsp;$2"
              if ($m =~ /($::REG_DAY\s+$::REG_TIME)\s+($::REG_ZONE2)/o);
            $a = "$1&nbsp;$2"
              if ($a =~ /($::REG_DAY\s+$::REG_TIME)\s+($::REG_ZONE2)/o);
            $c = "$1&nbsp;$2"
              if ($c =~ /($::REG_DAY\s+$::REG_TIME)\s+($::REG_ZONE2)/o);
            $cr = "$1&nbsp;$2"
              if ($cr =~ /($::REG_DAY\s+$::REG_TIME)\s+($::REG_ZONE2)/o);

            print "<td>$color$m</td>" . "<td>$sp</td>\n"
              if ($Fs::has_mtime{$ftype});

            print "<td>$color$a</td>" . "<td>$sp</td>\n";
            print "<td>$color$c</td>" . "<td>$sp</td>\n"
              if ($Fs::has_ctime{$ftype});
            print "<td>$color$cr</td>" . "<td>$sp</td>\n"
              if ($Fs::has_crtime{$ftype});

            print "<td>$color$s</td>"
              . "<td>$sp</td>\n"
              . "<td>$color$g</td>"
              . "<td>$sp</td>\n"
              . "<td>$color$u</td>"
              . "<td>$sp</td>\n";

            print "<td>";
            if ($i_int >= $Fs::first_meta{$ftype}) {
                print "<a href=\"$iurl\" target=\"_top\">";
                print "$lcolor$i</a>";
            }
            else {
                print "$color$i";
            }
            print " (realloc)" if $r;
            print "</td></tr>\n";
        }
        else {
            print "Error Parsing File (invalid characters?)<br>: $_\n<br>";
        }

        $row++;
    }
    close(OUT);
    print "</table>\n";

    print "<center>No files found with that pattern</center>\n"
      if ($row == 0);

    Print::print_html_footer();
    return 0;
}

# display deleted files only
#
# Sorting should be added to this
sub file_list_del {
    Args::check_sort();
    Args::check_dirmode();

    my $vol     = Args::get_vol('vol');
    my $ftype   = $Caseman::vol2ftype{$vol};
    my $mnt     = $Caseman::vol2mnt{$vol};
    my $img     = $Caseman::vol2path{$vol};
    my $offset  = $Caseman::vol2start{$vol};
    my $imgtype = $Caseman::vol2itype{$vol};

    my $meta    = $Fs::root_meta{$ftype};
    my $sort    = Args::get_sort();
    my $dirmode = Args::get_dirmode();

    Print::print_html_header("Deleted files on $Caseman::vol2sname{$vol} $mnt");

    my $tz = "";
    $tz = "-z '$Caseman::tz'" unless ("$Caseman::tz" eq "");

    my $sp = "&nbsp;&nbsp;";

    Print::log_host_inv("$Caseman::vol2sname{$vol}: Listing all deleted files");

    local *OUT;
    Exec::exec_pipe(*OUT,
"'$::TSKDIR/fls' -f $ftype -ldr $tz -s $Caseman::ts  -o $offset -i $imgtype $img $meta"
    );

    print "<b>All Deleted Files</b><p><hr>"
      . "<table cellspacing=\"0\" cellpadding=\"2\"  border=0>\n"
      . "<tr valign=\"MIDDLE\" align=\"left\" "
      . "background=\"$::YEL_PIX\">\n";

    # Type
    print "<th align=\"center\">&nbsp;&nbsp;Type&nbsp&nbsp;<br>"
      . "dir&nbsp;/&nbsp;in</th>"
      . "<td>$sp</td>\n";

    # Name
    print "  <td><img border=\"0\" "
      . "src=\"pict/file_h_nam_link.jpg\" "
      . "width=\"50\" height=20 "
      . "alt=\"File Name\">"
      . "</td>\n"
      . "<td>$sp</td>\n";

    # Mod / Written
    if ($Fs::has_mtime{$ftype}) {
        print "  <td><img border=\"0\" "
          . "src=\"pict/file_h_wr_link.jpg\" "
          . "width=\"60\" "
          . "alt=\"Written Time\">"
          . "</td>\n"
          . "<td>$sp</td>\n";
    }

    # Access
    print "  <td><img border=\"0\" "
      . "src=\"pict/file_h_acc_link.jpg\" "
      . "width=\"66\" height=20 "
      . "alt=\"Access Time\">"
      . "</td>\n"
      . "<td>$sp</td>\n";

    # Change
    if ($Fs::has_ctime{$ftype}) {
        print "  <td><img border=\"0\" "
          . "src=\"pict/file_h_chg_link.jpg\" "
          . "width=\"62\" "
          . "alt=\"Change Time\">"
          . "</td>\n"
          . "<td>$sp</td>\n";
    }

    # Create
    if ($Fs::has_crtime{$ftype}) {
        print "  <td><img border=\"0\" "
          . "src=\"pict/file_h_cre_link.jpg\" "
          . "width=\"59\" "
          . "alt=\"Create Time\">"
          . "</td>\n"
          . "<td>$sp</td>\n";
    }

    # Size
    print "  <td><img border=\"0\" "
      . "src=\"pict/file_h_siz_link.jpg\" "
      . "width=\"31\" height=20 "
      . "alt=\"Size\">"
      . "</td>\n"
      . "<td>$sp</td>\n";

    # UID
    print "  <td><img border=\"0\" "
      . "src=\"pict/file_h_uid_link.jpg\" "
      . "width=\"27\" height=20 "
      . "alt=\"UID\">"
      . "</td>\n"
      . "<td>$sp</td>\n";

    # GID
    print "  <td><img border=\"0\" "
      . "src=\"pict/file_h_gid_link.jpg\" "
      . "width=\"28\" height=20 "
      . "alt=\"GID\">"
      . "</td>\n"
      . "<td>$sp</td>\n";

    # Meta
    print "  <td><img border=\"0\" "
      . "src=\"pict/file_h_meta_link.jpg\" "
      . "width=\"41\" height=20 "
      . "alt=\"Meta\">"
      . "</td>\n"
      . "<td>$sp</td>\n";

    my $row = 0;
    while ($_ = Exec::read_pipe_line(*OUT)) {

        if (
/^($::REG_MTYPE)\/($::REG_MTYPE)\s*(\*?)\s*($::REG_META)(\(realloc\))?:\t(.+?)\t($::REG_DATE)\t($::REG_DATE)\t($::REG_DATE)\t($::REG_DATE)\t(\d+)\t(\d+)\t(\d+)$/o
          )
        {

            # We have to remove the / from the beginning of the file name so
            # save all values so they aren't lost
            my $dt = $1;
            my $it = $2;
            my $d  = $3;
            my $i  = $4;
            my $r  = 0;
            $r = 1 if (defined $5);
            my $n  = $6;
            my $m  = $7;
            my $a  = $8;
            my $c  = $9;
            my $cr = $10;
            my $s  = $11;
            my $g  = $12;
            my $u  = $13;

            if ($n =~ /^\/(.*)/) {
                $n = $1;
            }
            my $enc_n = Args::url_encode($n);
            my $iurl  =
"$::PROGNAME?mod=$::MOD_FRAME&submod=$::MOD_META&$Args::baseargs&meta=$i";
            my $i_int = $i;
            $i_int = $1 if ($i =~ /(\d+)-\d+-\d+/);

            if (($row % 2) == 0) {
                print "<tr valign=\"TOP\" bgcolor=\"$::BACK_COLOR\">\n";
            }
            else {
                print "<tr valign=\"TOP\" bgcolor=\"$::BACK_COLOR_TABLE\">\n";
            }

            print "<td align=\"center\"><font color=\"$::DEL_COLOR[$r]\">"
              . "$dt&nbsp;/&nbsp;$it</td>"
              . "<td>$sp</td>\n";

            if ($it eq 'd') {
                my $url =
                    "$::PROGNAME?mod=$::MOD_FILE&"
                  . "view=$File::FILE_LIST&$Args::baseargs&meta=$i"
                  . "&sort=$sort&dir=$enc_n&dirmode=$dirmode";

                print "<td>";
                if ($i_int >= $Fs::first_meta{$ftype}) {
                    print "<a href=\"$url\" target=\"_self\">";
                }
                print "<font color=\"$::DEL_COLOR[$r]\"><tt>"
                  . Print::html_encode($mnt . $n)
                  . "</tt></td>"
                  . "<td>$sp</td>\n";
            }
            else {
                my $url =
                    "$::PROGNAME?mod=$::MOD_FILE&view=$File::CONT_FR&"
                  . "$Args::baseargs&meta=$i&sort=$sort&dir=$enc_n"
                  . "&recmode=$File::REC_YES";

                print "<td>";
                if (($i_int >= $Fs::first_meta{$ftype}) && ($it eq 'r')) {
                    print "<a href=\"$url\" target=\"content\">";
                }
                print "<font color=\"$::DEL_COLOR[$r]\"><tt>"
                  . Print::html_encode($mnt . $n)
                  . "</tt></td>"
                  . "<td>$sp</td>\n";
            }

            $m = "$1&nbsp;$2"
              if ($m =~ /($::REG_DAY\s+$::REG_TIME)\s+($::REG_ZONE2)/o);
            $a = "$1&nbsp;$2"
              if ($a =~ /($::REG_DAY\s+$::REG_TIME)\s+($::REG_ZONE2)/o);
            $c = "$1&nbsp;$2"
              if ($c =~ /($::REG_DAY\s+$::REG_TIME)\s+($::REG_ZONE2)/o);
            $cr = "$1&nbsp;$2"
              if ($cr =~ /($::REG_DAY\s+$::REG_TIME)\s+($::REG_ZONE2)/o);

            print "<td><font color=\"$::DEL_COLOR[$r]\">$m</td>"
              . "<td>$sp</td>\n"
              if ($Fs::has_mtime{$ftype});

            print "<td><font color=\"$::DEL_COLOR[$r]\">$a</td>"
              . "<td>$sp</td>\n";
            print "<td><font color=\"$::DEL_COLOR[$r]\">$c</td>"
              . "<td>$sp</td>\n"
              if ($Fs::has_ctime{$ftype});
            print "<td><font color=\"$::DEL_COLOR[$r]\">$cr</td>"
              . "<td>$sp</td>\n"
              if ($Fs::has_crtime{$ftype});

            print "<td><font color=\"$::DEL_COLOR[$r]\">$s</td>"
              . "<td>$sp</td>\n"
              . "<td><font color=\"$::DEL_COLOR[$r]\">$g</td>"
              . "<td>$sp</td>\n"
              . "<td><font color=\"$::DEL_COLOR[$r]\">$u</td>"
              . "<td>$sp</td>\n";

            print "<td>";
            if ($i_int >= $Fs::first_meta{$ftype}) {
                print "<a href=\"$iurl\" target=\"_top\">";
            }
            print "<font color=\"$::DEL_COLOR[$r]\">$i</a>";
            print " (realloc)" if $r;
            print "</td></tr>\n";
        }
        else {
            print "Error Parsing File (invalid characters?)<br>: $_\n<br>";
        }

        $row++;
    }
    close(OUT);
    print "</table>\n";

    print "<center>None</center>\n"
      if ($row == 0);

    Print::print_html_footer();
    return 0;
}

# Content Frame
# This creates two frames for the lower rhs frame
#
sub content_fr {
    Print::print_html_header_frameset("");

    my $meta    = Args::get_meta('meta');
    my $vol     = Args::get_vol('vol');
    my $ftype   = $Caseman::vol2ftype{$vol};
    my $img     = $Caseman::vol2path{$vol};
    my $offset  = $Caseman::vol2start{$vol};
    my $imgtype = $Caseman::vol2itype{$vol};

    print "<frameset rows=\"65,*\">\n";

    my $recmode = $File::REC_NO;

    if (exists $Args::enc_args{'recmode'}) {
        $recmode = $Args::enc_args{'recmode'};
    }
    else {

        # We need to get the allocation status of this structure
        my $meta_int = $meta;
        $meta_int = $1 if ($meta_int =~ /(\d+)-\d+(-\d+)?/);

        local *OUT;
        Exec::exec_pipe(*OUT,
"'$::TSKDIR/ils' -f $ftype -e  -o $offset -i $imgtype $img $meta_int"
        );
        while ($_ = Exec::read_pipe_line(*OUT)) {
            chop;
            next unless ($_ =~ /^$meta/);
            if ($_ =~ /^$meta\|f/) {
                $recmode = $File::REC_YES;
            }
            elsif ($_ =~ /^$meta\|a/) {
                $recmode = $File::REC_NO;
            }
            else {
                Print::print_check_err("Error parsing ils output: $_");
            }
        }
    }
    close(OUT);

    # Get the file type so we can show the thumb nails automatically
    if ($recmode == $File::REC_YES) {
        Exec::exec_pipe(*OUT,
"'$::TSKDIR/icat' -f $ftype -r  -o $offset -i $imgtype $img $meta | '$::FILE_EXE' -z -b -"
        );
    }
    else {
        Exec::exec_pipe(*OUT,
"'$::TSKDIR/icat' -f $ftype  -o $offset -i $imgtype $img $meta | '$::FILE_EXE' -z -b -"
        );
    }

    my $apptype = Exec::read_pipe_line(*OUT);
    close(OUT);

    $apptype = "Error getting file type"
      if ((!defined $apptype) || ($apptype eq ""));

    # The menu for the different viewing options
    print "<frame src=\"$::PROGNAME?mod=$::MOD_FILE&view=$File::CONT_MENU&"
      . "$Args::baseargs&dir=$Args::enc_args{'dir'}"
      . "&meta=$Args::enc_args{'meta'}&sort=$FIL_SORT_ASC&recmode=$recmode\">\n";

    # Print the image thumbnail
    if (($apptype =~ /image data/) || ($apptype =~ /PC bitmap data/)) {
        print "<frame src=\"$::PROGNAME?mod=$::MOD_FILE&view=$File::CONT_IMG"
          . "&$Args::baseargs&dir=$Args::enc_args{'dir'}"
          . "&meta=$Args::enc_args{'meta'}"
          . "&sort=$FIL_SORT_ASC&recmode=$recmode\" name=\"cont2\">\n</frameset>";
    }
    else {

        # Where the actual content will be displayed
        print "<frame src=\"$::PROGNAME?mod=$::MOD_FILE&view=$File::CONT"
          . "&$Args::baseargs&dir=$Args::enc_args{'dir'}"
          . "&meta=$Args::enc_args{'meta'}"
          . "&sort=$FIL_SORT_ASC&recmode=$recmode\" name=\"cont2\">\n</frameset>";
    }

    Print::print_html_footer_frameset();
    return 0;
}

# This is the index for the lower rhs frame
# Choose the content display type here
sub content_menu {
    Args::check_sort();
    Args::check_recmode();

    Print::print_html_header("");

    my $meta    = Args::get_meta('meta');
    my $vol     = Args::get_vol('vol');
    my $ftype   = $Caseman::vol2ftype{$vol};
    my $img     = $Caseman::vol2path{$vol};
    my $offset  = $Caseman::vol2start{$vol};
    my $imgtype = $Caseman::vol2itype{$vol};
    my $recmode = Args::get_recmode();

    # Get the file type
    if ($recmode == $File::REC_YES) {
        Exec::exec_pipe(*OUT,
"'$::TSKDIR/icat' -f $ftype -r  -o $offset -i $imgtype $img $meta | '$::FILE_EXE' -z -b -"
        );
    }
    else {
        Exec::exec_pipe(*OUT,
"'$::TSKDIR/icat' -f $ftype  -o $offset -i $imgtype $img $meta | '$::FILE_EXE' -z -b -"
        );
    }

    my $apptype = Exec::read_pipe_line(*OUT);
    close(OUT);

    $apptype = "Error getting file type"
      if ((!defined $apptype) || ($apptype eq ""));

    # We already have the path in the content window below, so save space
    # print "<center><tt>$mnt$Args::args{'dir'}</tt>\n";
    print "<center>\n";

    my $url =
        "&$Args::baseargs&dir=$Args::enc_args{'dir'}"
      . "&meta=$Args::enc_args{'meta'}&recmode=$recmode";

    # Print the options for output display
    print "<table cellspacing=\"0\" cellpadding=\"2\">\n<tr>\n"
      . "<td>ASCII (<a href=\"$::PROGNAME?mod=$::MOD_FILE&view=$File::CONT&"
      . "sort=$FIL_SORT_ASC$url\" target=\"cont2\">display</a> - "
      . "<a href=\"$::PROGNAME?mod=$::MOD_FILE&view=$File::REPORT&"
      . "sort=$FIL_SORT_ASC$url\" target=\"_blank\">report</a>)</td>\n"
      . "<td>*</td>\n"
      . "<td>Hex ("
      . "<a href=\"$::PROGNAME?mod=$::MOD_FILE&view=$File::CONT&"
      . "sort=$FIL_SORT_HEX$url\" target=\"cont2\">display</a> - "
      . "<a href=\"$::PROGNAME?mod=$::MOD_FILE&view=$File::REPORT&"
      . "sort=$FIL_SORT_HEX$url\" target=\"_blank\">report</a>)</td>\n"
      . "<td>*</td>\n"
      . "<td>ASCII Strings ("
      . "<a href=\"$::PROGNAME?mod=$::MOD_FILE&view=$File::CONT&"
      . "sort=$FIL_SORT_STR$url\" target=\"cont2\">display</a> - "
      . "<a href=\"$::PROGNAME?mod=$::MOD_FILE&view=$File::REPORT&"
      . "sort=$FIL_SORT_STR$url\" target=\"_blank\">report</a>)</td>\n"
      . "<td>*</td>\n"
      . "<td><a href=\"$::PROGNAME?mod=$::MOD_FILE&view=$File::EXPORT&$url\">"
      . "Export</a></td>\n";

    # if the file is either image or HTML, then let them view it
    if (   ($apptype =~ /image data/)
        || ($apptype =~ /PC bitmap data/))
    {
        print "<td>*</td>\n<td><a href=\"$::PROGNAME?"
          . "mod=$::MOD_FILE&view=$File::CONT_IMG$url\""
          . "target=\"cont2\">View</a></td>\n";
    }
    elsif ($apptype =~ /HTML document text/) {
        print "<td>*</td>\n<td><a href=\"$::PROGNAME?"
          . "mod=$::MOD_APPVIEW&view=$Appview::CELL_FRAME$url\""
          . "target=\"_blank\">View</a></td>\n";
    }

    print "<td>*</td>\n"
      . "<td><a href=\"$::PROGNAME?mod=$::MOD_NOTES&view=$Notes::ENTER_FILE$url\" target=\"_blank\">"
      . "Add Note</a></td>\n"
      if ($::USE_NOTES == 1);

    print "</tr></table>\n";

    print "File Type: $apptype\n";
    print
      "<br><font color=\"$::DEL_COLOR[0]\">Deleted File Recovery Mode</font>\n"
      if ($recmode == $File::REC_YES);
    print "</center>\n";

    Print::print_html_footer();
    return 0;
}

#
# Display the actual content here
#
# NOTE: This has a media type of raw text
#
sub content {
    Args::check_sort();
    Args::check_recmode();

    Print::print_text_header();

    my $sort    = Args::get_sort();
    my $meta    = Args::get_meta('meta');
    my $vol     = Args::get_vol('vol');
    my $mnt     = $Caseman::vol2mnt{$vol};
    my $ftype   = $Caseman::vol2ftype{$vol};
    my $img     = $Caseman::vol2path{$vol};
    my $offset  = $Caseman::vol2start{$vol};
    my $imgtype = $Caseman::vol2itype{$vol};

    my $recflag = "";
    $recflag = " -r " if (Args::get_recmode() == $File::REC_YES);

    my $fname = "$mnt$Args::args{'dir'}";
    $fname =~ s/\/\//\//g;

    local *OUT;
    if ($sort == $FIL_SORT_ASC) {
        Print::log_host_inv(
            "$Caseman::vol2sname{$vol}: Viewing $fname ($meta) as ASCII");

        Exec::exec_pipe(*OUT,
"'$::TSKDIR/icat' -f $ftype $recflag -o $offset -i $imgtype $img $meta"
        );

        print "Contents Of File: $fname\n\n\n";
        Print::print_output($_) while ($_ = Exec::read_pipe_data(*OUT, 1024));
        close(OUT);
    }
    elsif ($sort == $FIL_SORT_HEX) {
        Print::log_host_inv(
            "$Caseman::vol2sname{$vol}: Viewing $fname ($meta) as Hex");

        Exec::exec_pipe(*OUT,
"'$::TSKDIR/icat' -f $ftype $recflag -o $offset -i $imgtype $img $meta"
        );

        print "Hex Contents Of File: $fname\n\n\n";
        my $offset = 0;
        while ($_ = Exec::read_pipe_data(*OUT, 1024)) {
            Print::print_hexdump($_, $offset * 1024);
            $offset++;
        }
        close(OUT);
    }
    elsif ($sort == $FIL_SORT_STR) {
        Print::log_host_inv(
            "$Caseman::vol2sname{$vol}: Viewing $fname ($meta) as strings");

        Exec::exec_pipe(*OUT,
"'$::TSKDIR/icat' -f $ftype $recflag -o $offset -i $imgtype $img $meta | '$::TSKDIR/srch_strings' -a"
        );

        print "ASCII String Contents Of File: $fname\n\n\n\n";
        Print::print_output($_) while ($_ = Exec::read_pipe_line(*OUT));
        close(OUT);
    }

    Print::print_text_footer();

    return 0;
}

sub content_img {

    Print::print_html_header("image content");

    my $vol   = Args::get_vol('vol');
    my $mnt   = $Caseman::vol2mnt{$vol};
    my $fname = "$mnt$Args::args{'dir'}";
    $fname =~ s/\/\//\//g;

    my $url =
        "&$Args::baseargs&meta=$Args::enc_args{'meta'}"
      . "&dir=$Args::enc_args{'dir'}&"
      . "cell_mode=2&recmode=$Args::enc_args{'recmode'}";

    print "<tt>$fname</tt><br><br>\n"
      . "<table><tr>\n"
      . "<td width=250 align=\"center\">"
      . "<b>Thumbnail:</b><br>"
      . "<img src=\"$::PROGNAME?mod=$::MOD_APPVIEW&view=$Appview::CELL_CONT${url}\" width=\"200\"></td>\n"
      . "<td valign=top>"
      . "<a href=\"$::PROGNAME?mod=$::MOD_APPVIEW&view=$Appview::CELL_CONT${url}\" "
      . "target=_blank>View Full Size Image</a><br>\n</td>\n"
      . "</tr></table>\n";

    Print::print_html_footer();

    return 0;
}

# Export the contents of a file
sub export {

    my $meta = Args::get_meta('meta');
    my $vol  = Args::get_vol('vol');
    my $mnt  = $Caseman::vol2mnt{$vol};

    my $ftype   = $Caseman::vol2ftype{$vol};
    my $img     = $Caseman::vol2path{$vol};
    my $offset  = $Caseman::vol2start{$vol};
    my $imgtype = $Caseman::vol2itype{$vol};

    my $fname = "$mnt$Args::args{'dir'}";
    $fname =~ s/\/\//\//g;

    my $recflag = "";

    $recflag = " -r "
      if ( (exists $Args::enc_args{'recmode'})
        && ($Args::enc_args{'recmode'} == $File::REC_YES));

    Print::log_host_inv(
        "$Caseman::vol2sname{$vol}: Saving contents of $fname ($meta)");

    local *OUT;
    Exec::exec_pipe(*OUT,
        "'$::TSKDIR/icat' -f $ftype $recflag -o $offset -i $imgtype $img $meta"
    );

    # We can't trust the mnt and dir values (since there
    # could be bad ASCII values, so only allow basic chars into name
    $fname =~ tr/a-zA-Z0-9\_\-\@\,/\./c;
    $fname = $1 if ($fname =~ /^\.(.*)$/);

    Print::print_oct_header("$vol-${fname}");

    print "$_" while ($_ = Exec::read_pipe_data(*OUT, 1024));

    Print::print_oct_footer();

    return 0;
}

# Display a report for a file
# This is intended to have its own window
#
sub report {
    Args::check_sort();

    my $sort = Args::get_sort();
    my $vol  = Args::get_vol('vol');
    my $meta = Args::get_meta('meta');
    my $mnt  = $Caseman::vol2mnt{$vol};

    my $ftype   = $Caseman::vol2ftype{$vol};
    my $img     = $Caseman::vol2path{$vol};
    my $offset  = $Caseman::vol2start{$vol};
    my $imgtype = $Caseman::vol2itype{$vol};
    my $type;
    my $fname = "$mnt$Args::args{'dir'}";
    $fname =~ s/\/\//\//g;
    my $tz = "";
    $tz = "-z '$Caseman::tz'" unless ("$Caseman::tz" eq "");

    my $recflag = "";

    $recflag = " -r "
      if ( (exists $Args::enc_args{'recmode'})
        && ($Args::enc_args{'recmode'} == $File::REC_YES));

    # We can't trust the mnt and dir values (since there
    # could be bad ASCII values, so only allow basic chars into name
    $fname =~ tr/a-zA-Z0-9\_\-\@\,/\./c;
    $fname = $1 if ($fname =~ /^\.+(.*)$/);
    $fname = $1 if ($fname =~ /^(.*?)\.+$/);

    Print::print_text_header("filename=$Args::args{'vol'}-${fname}.txt");

    $fname = "$mnt$Args::args{'dir'}";
    if ($sort == $FIL_SORT_ASC) {
        Print::log_host_inv(
"$Caseman::vol2sname{$vol}: Generating ASCII report for $fname ($meta)"
        );
        $type = "ASCII";
    }
    elsif ($sort == $FIL_SORT_HEX) {
        Print::log_host_inv(
            "$Args::args{'vol'}: Generating Hex report for $fname ($meta)");
        $type = "Hex";
    }
    elsif ($sort == $FIL_SORT_STR) {
        Print::log_host_inv(
"$Args::args{'vol'}: Generating ASCII strings report for $fname ($meta)"
        );
        $type = "string";
    }
    else {
        print "\n\ninvalid sort value";
        return 1;
    }

    # NOTE: There is a space in the beginning of the separator lines in
    # order to make clear@stamper.itconsult.co.uk time stamping happy
    # I think it confuses the lines that begin at the lhs with PGP
    # headers and will remove the second line.
    #
    print "                  Autopsy $type Report\n\n"
      . "-" x 70 . "\n"
      . "                   GENERAL INFORMATION\n\n"
      . "File: $fname\n";

    # Calculate the MD5 value
    local *OUT;
    Exec::exec_pipe(*OUT,
"'$::TSKDIR/icat' -f $ftype $recflag -o $offset -i $imgtype $img $meta | '$::MD5_EXE'"
    );
    my $md5 = Exec::read_pipe_line(*OUT);
    close(OUT);

    $md5 = "Error getting MD5 Value"
      if ((!defined $md5) || ($md5 eq ""));

    chomp $md5;
    if ($recflag eq "") {
        print "MD5 of file: $md5\n";
    }
    else {
        print "MD5 of recovered file: $md5\n";
    }

    if ($::SHA1_EXE ne "") {
        Exec::exec_pipe(*OUT,
"'$::TSKDIR/icat' -f $ftype $recflag -o $offset -i $imgtype $img $meta | '$::SHA1_EXE'"
        );
        my $sha1 = Exec::read_pipe_line(*OUT);
        close(OUT);

        $sha1 = "Error getting SHA-1 Value"
          if ((!defined $sha1) || ($sha1 eq ""));

        chomp $sha1;
        if ($recflag eq "") {
            print "SHA-1 of file: $sha1\n";
        }
        else {
            print "SHA-1 of recovered file: $sha1\n";
        }
    }

    if ($sort == $FIL_SORT_STR) {
        Exec::exec_pipe(*OUT,
"'$::TSKDIR/icat' -f $ftype $recflag -o $offset -i $imgtype $img $meta | '$::TSKDIR/srch_strings' -a | '$::MD5_EXE'"
        );
        $md5 = Exec::read_pipe_line(*OUT);
        close(OUT);

        $md5 = "Error getting MD5 Value"
          if ((!defined $md5) || ($md5 eq ""));

        chomp $md5;
        print "MD5 of ASCII strings: $md5\n";

        if ($::SHA1_EXE ne "") {
            Exec::exec_pipe(*OUT,
"'$::TSKDIR/icat' -f $ftype $recflag -o $offset -i $imgtype $img $meta | '$::TSKDIR/srch_strings' -a | '$::SHA1_EXE'"
            );
            $sha1 = Exec::read_pipe_line(*OUT);
            close(OUT);

            $sha1 = "Error getting SHA-1 Value"
              if ((!defined $sha1) || ($sha1 eq ""));

            chomp $sha1;
            print "SHA-1 of ASCII strings: $sha1\n";
        }
    }

    print "\nImage: $Caseman::vol2path{$vol}\n";
    if (($Caseman::vol2start{$vol} == 0) && ($Caseman::vol2end{$vol} == 0)) {
        print "Offset: Full image\n";
    }
    elsif ($Caseman::vol2end{$vol} == 0) {
        print "Offset: $Caseman::vol2start{$vol} to end\n";
    }
    else {
        print "Offset: $Caseman::vol2start{$vol} to $Caseman::vol2end{$vol}\n";
    }
    print "File System Type: $ftype\n";

    my $date = localtime();
    print "\nDate Generated: $date\n"
      . "Investigator: $Args::args{'inv'}\n\n"
      . "-" x 70 . "\n"
      . "                   META DATA INFORMATION\n\n";

    # Get the meta details
    Exec::exec_pipe(*OUT,
"'$::TSKDIR/istat' -f $ftype $tz -s $Caseman::ts -o $offset -i $imgtype $img $meta"
    );
    print $_ while ($_ = Exec::read_pipe_line(*OUT));
    close(OUT);

    # File Type
    Exec::exec_pipe(*OUT,
"'$::TSKDIR/icat' -f $ftype $recflag -o $offset -i $imgtype $img $meta | '$::FILE_EXE' -z -b -"
    );
    my $apptype = Exec::read_pipe_line(*OUT);
    close(OUT);

    $apptype = "Error getting file type"
      if ((!defined $apptype) || ($apptype eq ""));

    print "\nFile Type: $apptype";

    print "\n" . "-" x 70 . "\n";
    if ($sort == $FIL_SORT_ASC) {
        print "           CONTENT (Non-ASCII data may not be shown)\n\n";
    }
    else {
        print "                        CONTENT\n\n";
    }

    if ($sort == $FIL_SORT_ASC) {
        Exec::exec_pipe(*OUT,
"'$::TSKDIR/icat' -f $ftype $recflag -o $offset -i $imgtype $img $meta"
        );
        Print::print_output($_) while ($_ = Exec::read_pipe_data(*OUT, 1024));
        close(OUT);
    }
    elsif ($sort == $FIL_SORT_HEX) {
        Exec::exec_pipe(*OUT,
"'$::TSKDIR/icat' -f $ftype $recflag -o $offset -i $imgtype $img $meta"
        );
        my $offset = 0;
        while ($_ = Exec::read_pipe_data(*OUT, 1024)) {
            Print::print_hexdump($_, $offset * 1024);
            $offset++;
        }
        close(OUT);
    }
    elsif ($sort == $FIL_SORT_STR) {
        Exec::exec_pipe(*OUT,
"'$::TSKDIR/icat' -f $ftype $recflag -o $offset -i $imgtype $img $meta | '$::TSKDIR/srch_strings' -a"
        );
        Print::print_output($_) while ($_ = Exec::read_pipe_line(*OUT));
        close(OUT);
    }

    print "\n"
      . "-" x 70 . "\n"
      . "                   VERSION INFORMATION\n\n"
      . "Autopsy Version: $::VER\n";
    print "The Sleuth Kit Version: " . ::get_tskver() . "\n";

    Print::print_text_footer();
    return 0;
}

# Generate the MD5 value for every file in a given directory and save
# them to a text file
sub md5list {
    my $vol  = Args::get_vol('vol');
    my $meta = Args::get_meta('meta');
    my $mnt  = $Caseman::vol2mnt{$vol};

    my $ftype   = $Caseman::vol2ftype{$vol};
    my $img     = $Caseman::vol2path{$vol};
    my $offset  = $Caseman::vol2start{$vol};
    my $imgtype = $Caseman::vol2itype{$vol};

    my $fname = "$mnt$Args::args{'dir'}";
    $fname = 'root' if ($fname eq '/');
    $fname =~ s/\/\//\//g;

    # We can't trust the mnt and dir values (since there
    # could be bad ASCII values, so only allow basic chars into name
    $fname =~ tr/a-zA-Z0-9\_\-\@\,/\./c;

    # remove .'s at beginning and end
    $fname = $1 if ($fname =~ /^\.+(.*)$/);
    $fname = $1 if ($fname =~ /^(.*?)\.+$/);

    Print::print_text_header("filename=$fname.md5");

    $fname = "$mnt$Args::args{'dir'}";
    $fname =~ s/\/\//\//g;

    local *OUT;
    Exec::exec_pipe(*OUT,
        "'$::TSKDIR/fls' -f $ftype -Fu -o $offset -i $imgtype $img $meta");

    print "MD5 Values for files in $fname ($Caseman::vol2sname{$vol})\n\n";

    while ($_ = Exec::read_pipe_line(*OUT)) {

        # area for allocated files
        if (   (/r\/[\w\-]\s+([\d\-]+):\s+(.*)$/)
            || (/-\/r\s+([\d\-]+):\s+(.*)$/))
        {
            my $in   = $1;
            my $name = $2;

            local *OUT_MD5;
            Exec::exec_pipe(*OUT_MD5,
"'$::TSKDIR/icat' -f $ftype -r -o $offset -i $imgtype $img $in | '$::MD5_EXE'"
            );
            my $md5out = Exec::read_pipe_line(*OUT_MD5);

            $md5out = "Error calculating MD5"
              if ((!defined $md5out) || ($md5out eq ""));

            chomp $md5out;
            print "$md5out\t" . Print::html_encode($name) . "\n";
            close(OUT_MD5);
        }
        elsif (/[\w\-]\/[\w\-]\s+([\d\-]+):\s+(.*)$/) {

           # ignore, non-file types such as sockets or symlinks that do not have
           # MD5 values that make sense
        }

        # Hmmmm
        else {
            print "Error parsing file (invalid characters?): $_\n";
        }
    }
    close(OUT);

    Print::print_text_footer();

    return 0;
}

# Blank Page
sub blank {
    Print::print_html_header("");
    print "<br><center><h3>File Browsing Mode</h3><br>\n"
      . "<p>In this mode, you can view file and directory contents.</p>\n"
      . "<p>File contents will be shown in this window.<br>\n"
      . "More file details can be found using the Metadata link at the end of the list (on the right).<br>\n"
      . "You can also sort the files using the column headers</p>\n";
    Print::print_html_footer();
    return 0;
}