aboutsummaryrefslogtreecommitdiff
path: root/sys/imio/imaccess.x
blob: cc6d450eba0eedcffaad2ab6b16819a4e49b20e2 (plain) (blame)
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
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

include	<syserr.h>


# IMACCESS -- Test if an image exists and is accessible with the given access
# mode.  If the access mode given is NEW_IMAGE, test if the image name given
# is legal (has a legal extension, i.e., type).  YES is returned if the named
# image exists, NO if no image exists with the given name, and ERR if the
# image name is ambiguous (multiple images, e.g. of different types, exist
# with the same name).

int procedure imaccess (image, acmode)

char	image[ARB]		# image name
int	acmode			# access mode

int	exists, cl_index, cl_size, mode, status
pointer	sp, cluster, ksection, section, root, extn, im
int	iki_access()
errchk	syserrs
pointer	immap()

begin
	call smark (sp)
	call salloc (cluster, SZ_PATHNAME, TY_CHAR)
	call salloc (ksection, SZ_FNAME, TY_CHAR)
	call salloc (section, SZ_FNAME, TY_CHAR)
	call salloc (root, SZ_PATHNAME, TY_CHAR)
	call salloc (extn, SZ_FNAME, TY_CHAR)

	call iki_init()

	call imparse (image,
	    Memc[cluster], SZ_PATHNAME,
	    Memc[ksection], SZ_FNAME,
	    Memc[section], SZ_FNAME, cl_index, cl_size)

	# If an image section, kernel section, or cluster index was specified
	# we must actually attempt to open the image to determine if the
	# object specified by the full notation exists, otherwise we can just
	# call the IKI access function to determine if the cluster exists.

	if (Memc[section] != EOS || Memc[ksection] != EOS || cl_index >= 0) {
	    mode = acmode
	    if (acmode == 0)
		mode = READ_ONLY
	    iferr (im = immap (image, mode, 0))
		exists = NO
	    else {
		exists = YES
		call imunmap (im)
	    }
	} else {
	    status = iki_access (image, Memc[root], Memc[extn], acmode)
	    if (status > 0)
		exists = YES
	    else if (status == 0)
		exists = NO
	    else
		call syserrs (SYS_IKIAMBIG, image)
	}

	call sfree (sp)
	return (exists)
end