aboutsummaryrefslogtreecommitdiff
path: root/sys/fio/protect.x
blob: 644346385bd70564514de23692d5fcbc9bf88ea5 (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
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

include	<protect.h>
include	<config.h>
include	<syserr.h>
include	<knet.h>
include	<fio.h>

# PROTECT -- Protect a file from deletion.  The recognized action codes are
# defined in <protect.h> and are used to set, remove, or query file
# protection.

int procedure protect (fname, action)

char	fname[ARB]		# file name
int	action			# protect action (prot, unprot, query)

bool	fnullfile()
int	status, access()
errchk	filerr, fmapfn
include	<fio.com>

begin
	# The null file "dev$null" is a special case; ignore attempts to
	# alter the protection of this file.

	if (fnullfile (fname))
	    if (action == QUERY_PROTECTION)
		return (YES)
	    else
		return (OK)

	call fmapfn (fname, pathname, SZ_PATHNAME)
	call zfprot (pathname, action, status)

	if (status == ERR) {
	    if (access (fname,0,0) == YES) {
		switch (action) {
		case SET_PROTECTION:
		    call filerr (fname, SYS_FPROTECT)
		case REMOVE_PROTECTION:
		    call filerr (fname, SYS_FUNPROTECT)
		default:
		    # If the file exists but we cannot query its protection,
		    # better to indicate that it is protected than to abort.
		    return (YES)
		}
	    } else if (access (fname, 0, DIRECTORY_FILE) == YES) {
		switch (action) {
		case SET_PROTECTION:
		    return (OK)			# directory files are protected
		case REMOVE_PROTECTION:
		    call filerr (fname, SYS_FUNPROTECT)
		default:
		    return (YES)
		}
	    } else
		call filerr (fname, SYS_FPROTNEXFIL)
	} else
	    return (status)
end