From fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Wed, 8 Jul 2015 20:46:52 -0400 Subject: Initial commit --- sys/fio/protect.x | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 sys/fio/protect.x (limited to 'sys/fio/protect.x') diff --git a/sys/fio/protect.x b/sys/fio/protect.x new file mode 100644 index 00000000..64434638 --- /dev/null +++ b/sys/fio/protect.x @@ -0,0 +1,61 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include +include +include +include +include + +# PROTECT -- Protect a file from deletion. The recognized action codes are +# defined in 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 + +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 -- cgit