aboutsummaryrefslogtreecommitdiffstats
path: root/test/readdir0.awk
blob: 296c03c76d544b86a411a42d8f28677311131ff7 (plain)
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
BEGIN {
	while ((getline x < extout) > 0) {
		numrec++
		if ((split(x, f, "/") == 3) && (f[3] == "u"))
			num_unknown++
	}
	close(extout)
	if ((numrec > 0) && (num_unknown == numrec)) {
		print "Notice: this filesystem does not appear to support file type information" > "/dev/stderr"
		ftype_unknown = 1
	}
}

BEGIN {
	dir = ARGV[1]
	delete ARGV[1]
	ls_afi = "ls -afi " dir
	ls_al = ("ls -lna " dir " | sed 1d")

	for (i = 1; (ls_afi | getline) > 0; i++) {
		# inode number is $1, filename is read of record
		inode = $1
		$1 = ""
		$0 = $0
		sub(/^ */, "")
		names[i] = $0
		ino[names[i]] = inode
	}
	close(ls_afi)

	for (j = 1; (ls_al | getline) > 0; j++) {
		type_let = substr($0, 1, 1)
		if (type_let == "-")
			type_let = "f"
		$1 = $2 = $3 = $4 = $5 = $6 = $7 = $8 = ""
		$0 = $0
		sub(/^ */, "")
		type[$0] = type_let
	}
	close(ls_al)

	if (i != j)
		printf("mismatch: %d from `ls -afi' and %d from `ls -l'\n", i, j) > "/dev/stderr"
	
	for (i = 1; i in names; i++)
		printf("%s/%s/%s\n", ino[names[i]], names[i], (ftype_unknown ? "u" : type[names[i]]))
}