src/HOL/Unix/Unix.thy
author wenzelm
Sat, 05 Jan 2019 17:24:33 +0100
changeset 69597 ff784d5a5bfb
parent 68451 c34aa23a1fb6
child 69964 699ffc7cbab8
permissions -rw-r--r--
isabelle update -u control_cartouches;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
     1
(*  Title:      HOL/Unix/Unix.thy
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
     2
    Author:     Markus Wenzel, TU Muenchen
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
     3
*)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
     4
58889
5b7a9633cfa8 modernized header uniformly as section;
wenzelm
parents: 58613
diff changeset
     5
section \<open>Unix file-systems \label{sec:unix-file-system}\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
     6
17455
151e76f0e3c7 tuned document;
wenzelm
parents: 17146
diff changeset
     7
theory Unix
64517
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
     8
  imports
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
     9
    Nested_Environment
66453
cc19f7ca2ed6 session-qualified theory imports: isabelle imports -U -i -d '~~/src/Benchmarks' -a;
wenzelm
parents: 64517
diff changeset
    10
    "HOL-Library.Sublist"
17455
151e76f0e3c7 tuned document;
wenzelm
parents: 17146
diff changeset
    11
begin
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
    12
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
    13
text \<open>
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    14
  We give a simple mathematical model of the basic structures underlying the
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    15
  Unix file-system, together with a few fundamental operations that could be
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    16
  imagined to be performed internally by the Unix kernel. This forms the basis
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    17
  for the set of Unix system-calls to be introduced later (see
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    18
  \secref{sec:unix-trans}), which are the actual interface offered to
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    19
  processes running in user-space.
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
    20
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    21
  \<^medskip>
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    22
  Basically, any Unix file is either a \<^emph>\<open>plain file\<close> or a \<^emph>\<open>directory\<close>,
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    23
  consisting of some \<^emph>\<open>content\<close> plus \<^emph>\<open>attributes\<close>. The content of a plain
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    24
  file is plain text. The content of a directory is a mapping from names to
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    25
  further files.\<^footnote>\<open>In fact, this is the only way that names get associated with
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    26
  files. In Unix files do \<^emph>\<open>not\<close> have a name in itself. Even more, any number
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    27
  of names may be associated with the very same file due to \<^emph>\<open>hard links\<close>
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    28
  (although this is excluded from our model).\<close> Attributes include information
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    29
  to control various ways to access the file (read, write etc.).
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
    30
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    31
  Our model will be quite liberal in omitting excessive detail that is easily
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    32
  seen to be ``irrelevant'' for the aspects of Unix file-systems to be
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    33
  discussed here. First of all, we ignore character and block special files,
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    34
  pipes, sockets, hard links, symbolic links, and mount points.
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
    35
\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
    36
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
    37
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
    38
subsection \<open>Names\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
    39
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
    40
text \<open>
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    41
  User ids and file name components shall be represented by natural numbers
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    42
  (without loss of generality). We do not bother about encoding of actual
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    43
  names (e.g.\ strings), nor a mapping between user names and user ids as
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    44
  would be present in a reality.
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
    45
\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
    46
41579
4031fb078acc type_synonym;
wenzelm
parents: 41413
diff changeset
    47
type_synonym uid = nat
4031fb078acc type_synonym;
wenzelm
parents: 41413
diff changeset
    48
type_synonym name = nat
4031fb078acc type_synonym;
wenzelm
parents: 41413
diff changeset
    49
type_synonym path = "name list"
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
    50
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
    51
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
    52
subsection \<open>Attributes\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
    53
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
    54
text \<open>
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    55
  Unix file attributes mainly consist of \<^emph>\<open>owner\<close> information and a number of
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    56
  \<^emph>\<open>permission\<close> bits which control access for ``user'', ``group'', and
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    57
  ``others'' (see the Unix man pages \<open>chmod(2)\<close> and \<open>stat(2)\<close> for more
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    58
  details).
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
    59
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    60
  \<^medskip>
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    61
  Our model of file permissions only considers the ``others'' part. The
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    62
  ``user'' field may be omitted without loss of overall generality, since the
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    63
  owner is usually able to change it anyway by performing \<open>chmod\<close>.\<^footnote>\<open>The
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    64
  inclined Unix expert may try to figure out some exotic arrangements of a
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    65
  real-world Unix file-system such that the owner of a file is unable to apply
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    66
  the \<open>chmod\<close> system call.\<close> We omit ``group'' permissions as a genuine
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    67
  simplification as we just do not intend to discuss a model of multiple
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    68
  groups and group membership, but pretend that everyone is member of a single
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    69
  global group.\<^footnote>\<open>A general HOL model of user group structures and related
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    70
  issues is given in @{cite "Naraschewski:2001"}.\<close>
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
    71
\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
    72
58310
91ea607a34d8 updated news
blanchet
parents: 58249
diff changeset
    73
datatype perm =
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
    74
    Readable
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
    75
  | Writable
67443
3abf6a722518 standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents: 66453
diff changeset
    76
  | Executable    \<comment> \<open>(ignored)\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
    77
41579
4031fb078acc type_synonym;
wenzelm
parents: 41413
diff changeset
    78
type_synonym perms = "perm set"
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
    79
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
    80
record att =
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
    81
  owner :: uid
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
    82
  others :: perms
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
    83
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
    84
text \<open>
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
    85
  For plain files \<^term>\<open>Readable\<close> and \<^term>\<open>Writable\<close> specify read and write
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    86
  access to the actual content, i.e.\ the string of text stored here. For
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
    87
  directories \<^term>\<open>Readable\<close> determines if the set of entry names may be
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
    88
  accessed, and \<^term>\<open>Writable\<close> controls the ability to create or delete any
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    89
  entries (both plain files or sub-directories).
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
    90
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
    91
  As another simplification, we ignore the \<^term>\<open>Executable\<close> permission
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    92
  altogether. In reality it would indicate executable plain files (also known
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    93
  as ``binaries''), or control actual lookup of directory entries (recall that
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
    94
  mere directory browsing is controlled via \<^term>\<open>Readable\<close>). Note that the
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
    95
  latter means that in order to perform any file-system operation whatsoever,
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
    96
  all directories encountered on the path would have to grant \<^term>\<open>Executable\<close>. We ignore this detail and pretend that all directories give
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
    97
  \<^term>\<open>Executable\<close> permission to anybody.
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
    98
\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
    99
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   100
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   101
subsection \<open>Files\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   102
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   103
text \<open>
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   104
  In order to model the general tree structure of a Unix file-system we use
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   105
  the arbitrarily branching datatype \<^typ>\<open>('a, 'b, 'c) env\<close> from the
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   106
  standard library of Isabelle/HOL @{cite "Bauer-et-al:2002:HOL-Library"}.
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   107
  This type provides constructors \<^term>\<open>Val\<close> and \<^term>\<open>Env\<close> as follows:
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   108
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   109
  \<^medskip>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   110
  {\def\isastyleminor{\isastyle}
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   111
  \begin{tabular}{l}
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   112
  @{term [source] "Val :: 'a \<Rightarrow> ('a, 'b, 'c) env"} \\
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   113
  @{term [source] "Env :: 'b \<Rightarrow> ('c \<Rightarrow> ('a, 'b, 'c) env option) \<Rightarrow> ('a, 'b, 'c) env"} \\
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   114
  \end{tabular}}
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   115
  \<^medskip>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   116
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   117
  Here the parameter \<^typ>\<open>'a\<close> refers to plain values occurring at leaf
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   118
  positions, parameter \<^typ>\<open>'b\<close> to information kept with inner branch nodes,
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   119
  and parameter \<^typ>\<open>'c\<close> to the branching type of the tree structure. For our
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   120
  purpose we use the type instance with \<^typ>\<open>att \<times> string\<close> (representing
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   121
  plain files), \<^typ>\<open>att\<close> (for attributes of directory nodes), and \<^typ>\<open>name\<close> (for the index type of directory nodes).
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   122
\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   123
41579
4031fb078acc type_synonym;
wenzelm
parents: 41413
diff changeset
   124
type_synonym "file" = "(att \<times> string, att, name) env"
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   125
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   126
text \<open>
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   127
  \<^medskip>
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   128
  The HOL library also provides \<^term>\<open>lookup\<close> and \<^term>\<open>update\<close> operations
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   129
  for general tree structures with the subsequent primitive recursive
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   130
  characterizations.
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   131
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   132
  \<^medskip>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   133
  {\def\isastyleminor{\isastyle}
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   134
  \begin{tabular}{l}
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   135
  @{term [source] "lookup :: ('a, 'b, 'c) env \<Rightarrow> 'c list \<Rightarrow> ('a, 'b, 'c) env option"} \\
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   136
  @{term [source]
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   137
  "update :: 'c list \<Rightarrow> ('a, 'b, 'c) env option \<Rightarrow> ('a, 'b, 'c) env \<Rightarrow> ('a, 'b, 'c) env"} \\
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   138
  \end{tabular}}
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   139
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   140
  @{thm [display, indent = 2, eta_contract = false] lookup_eq [no_vars]}
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   141
  @{thm [display, indent = 2, eta_contract = false] update_eq [no_vars]}
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   142
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   143
  Several further properties of these operations are proven in @{cite
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   144
  "Bauer-et-al:2002:HOL-Library"}. These will be routinely used later on
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   145
  without further notice.
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   146
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   147
  \<^bigskip>
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   148
  Apparently, the elements of type \<^typ>\<open>file\<close> contain an \<^typ>\<open>att\<close>
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   149
  component in either case. We now define a few auxiliary operations to
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   150
  manipulate this field uniformly, following the conventions for record types
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   151
  in Isabelle/HOL @{cite "Nipkow-et-al:2000:HOL"}.
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   152
\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   153
19086
1b3780be6cc2 new-style definitions/abbreviations;
wenzelm
parents: 18730
diff changeset
   154
definition
1b3780be6cc2 new-style definitions/abbreviations;
wenzelm
parents: 18730
diff changeset
   155
  "attributes file =
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   156
    (case file of
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   157
      Val (att, text) \<Rightarrow> att
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   158
    | Env att dir \<Rightarrow> att)"
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   159
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21372
diff changeset
   160
definition
21001
408f3a1cef2e replaced attributes_update by map_attributes;
wenzelm
parents: 20503
diff changeset
   161
  "map_attributes f file =
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   162
    (case file of
21001
408f3a1cef2e replaced attributes_update by map_attributes;
wenzelm
parents: 20503
diff changeset
   163
      Val (att, text) \<Rightarrow> Val (f att, text)
408f3a1cef2e replaced attributes_update by map_attributes;
wenzelm
parents: 20503
diff changeset
   164
    | Env att dir \<Rightarrow> Env (f att) dir)"
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   165
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   166
lemma [simp]: "attributes (Val (att, text)) = att"
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   167
  by (simp add: attributes_def)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   168
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   169
lemma [simp]: "attributes (Env att dir) = att"
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   170
  by (simp add: attributes_def)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   171
21001
408f3a1cef2e replaced attributes_update by map_attributes;
wenzelm
parents: 20503
diff changeset
   172
lemma [simp]: "attributes (map_attributes f file) = f (attributes file)"
408f3a1cef2e replaced attributes_update by map_attributes;
wenzelm
parents: 20503
diff changeset
   173
  by (cases "file") (simp_all add: attributes_def map_attributes_def
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   174
    split_tupled_all)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   175
21001
408f3a1cef2e replaced attributes_update by map_attributes;
wenzelm
parents: 20503
diff changeset
   176
lemma [simp]: "map_attributes f (Val (att, text)) = Val (f att, text)"
408f3a1cef2e replaced attributes_update by map_attributes;
wenzelm
parents: 20503
diff changeset
   177
  by (simp add: map_attributes_def)
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   178
21001
408f3a1cef2e replaced attributes_update by map_attributes;
wenzelm
parents: 20503
diff changeset
   179
lemma [simp]: "map_attributes f (Env att dir) = Env (f att) dir"
408f3a1cef2e replaced attributes_update by map_attributes;
wenzelm
parents: 20503
diff changeset
   180
  by (simp add: map_attributes_def)
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   181
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   182
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   183
subsection \<open>Initial file-systems\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   184
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   185
text \<open>
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   186
  Given a set of \<^emph>\<open>known users\<close> a file-system shall be initialized by
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   187
  providing an empty home directory for each user, with read-only access for
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   188
  everyone else. (Note that we may directly use the user id as home directory
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   189
  name, since both types have been identified.) Certainly, the very root
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   190
  directory is owned by the super user (who has user id 0).
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   191
\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   192
19086
1b3780be6cc2 new-style definitions/abbreviations;
wenzelm
parents: 18730
diff changeset
   193
definition
1b3780be6cc2 new-style definitions/abbreviations;
wenzelm
parents: 18730
diff changeset
   194
  "init users =
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   195
    Env \<lparr>owner = 0, others = {Readable}\<rparr>
68451
c34aa23a1fb6 empty -> Map.empty
nipkow
parents: 67443
diff changeset
   196
      (\<lambda>u. if u \<in> users then Some (Env \<lparr>owner = u, others = {Readable}\<rparr> Map.empty)
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   197
        else None)"
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   198
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   199
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   200
subsection \<open>Accessing file-systems\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   201
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   202
text \<open>
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   203
  The main internal file-system operation is access of a file by a user,
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   204
  requesting a certain set of permissions. The resulting \<^typ>\<open>file option\<close>
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   205
  indicates if a file had been present at the corresponding \<^typ>\<open>path\<close> and if
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   206
  access was granted according to the permissions recorded within the
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   207
  file-system.
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   208
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   209
  Note that by the rules of Unix file-system security (e.g.\ @{cite
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   210
  "Tanenbaum:1992"}) both the super-user and owner may always access a file
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   211
  unconditionally (in our simplified model).
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   212
\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   213
19086
1b3780be6cc2 new-style definitions/abbreviations;
wenzelm
parents: 18730
diff changeset
   214
definition
20321
wenzelm
parents: 19363
diff changeset
   215
  "access root path uid perms =
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   216
    (case lookup root path of
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   217
      None \<Rightarrow> None
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   218
    | Some file \<Rightarrow>
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   219
        if uid = 0
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   220
          \<or> uid = owner (attributes file)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   221
          \<or> perms \<subseteq> others (attributes file)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   222
        then Some file
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   223
        else None)"
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   224
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   225
text \<open>
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   226
  \<^medskip>
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   227
  Successful access to a certain file is the main prerequisite for
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   228
  system-calls to be applicable (cf.\ \secref{sec:unix-trans}). Any
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   229
  modification of the file-system is then performed using the basic \<^term>\<open>update\<close> operation.
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   230
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   231
  \<^medskip>
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   232
  We see that \<^term>\<open>access\<close> is just a wrapper for the basic \<^term>\<open>lookup\<close>
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   233
  function, with additional checking of attributes. Subsequently we establish
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   234
  a few auxiliary facts that stem from the primitive \<^term>\<open>lookup\<close> used
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   235
  within \<^term>\<open>access\<close>.
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   236
\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   237
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   238
lemma access_empty_lookup: "access root path uid {} = lookup root path"
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   239
  by (simp add: access_def split: option.splits)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   240
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   241
lemma access_some_lookup:
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   242
  "access root path uid perms = Some file \<Longrightarrow>
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   243
    lookup root path = Some file"
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   244
  by (simp add: access_def split: option.splits if_splits)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   245
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   246
lemma access_update_other:
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   247
  assumes parallel: "path' \<parallel> path"
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   248
  shows "access (update path' opt root) path uid perms = access root path uid perms"
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   249
proof -
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   250
  from parallel obtain y z xs ys zs where
11072
wenzelm
parents: 11004
diff changeset
   251
      "y \<noteq> z" and "path' = xs @ y # ys" and "path = xs @ z # zs"
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   252
    by (blast dest: parallel_decomp)
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   253
  then have "lookup (update path' opt root) path = lookup root path"
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   254
    by (blast intro: lookup_update_other)
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   255
  then show ?thesis by (simp only: access_def)
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   256
qed
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   257
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   258
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   259
section \<open>File-system transitions \label{sec:unix-trans}\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   260
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   261
subsection \<open>Unix system calls \label{sec:unix-syscall}\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   262
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   263
text \<open>
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   264
  According to established operating system design (cf.\ @{cite
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   265
  "Tanenbaum:1992"}) user space processes may only initiate system operations
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   266
  by a fixed set of \<^emph>\<open>system-calls\<close>. This enables the kernel to enforce
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   267
  certain security policies in the first place.\<^footnote>\<open>Incidently, this is the very
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   268
  same principle employed by any ``LCF-style'' theorem proving system
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   269
  according to Milner's principle of ``correctness by construction'', such as
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   270
  Isabelle/HOL itself.\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   271
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   272
  \<^medskip>
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   273
  In our model of Unix we give a fixed datatype \<open>operation\<close> for the syntax of
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   274
  system-calls, together with an inductive definition of file-system state
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   275
  transitions of the form \<open>root \<midarrow>x\<rightarrow> root'\<close> for the operational semantics.
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   276
\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   277
58310
91ea607a34d8 updated news
blanchet
parents: 58249
diff changeset
   278
datatype operation =
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   279
    Read uid string path
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   280
  | Write uid string path
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   281
  | Chmod uid perms path
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   282
  | Creat uid perms path
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   283
  | Unlink uid path
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   284
  | Mkdir uid perms path
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   285
  | Rmdir uid path
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   286
  | Readdir uid "name set" path
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   287
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   288
text \<open>
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   289
  The \<^typ>\<open>uid\<close> field of an operation corresponds to the \<^emph>\<open>effective user id\<close>
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   290
  of the underlying process, although our model never mentions processes
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   291
  explicitly. The other parameters are provided as arguments by the caller;
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   292
  the \<^term>\<open>path\<close> one is common to all kinds of system-calls.
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   293
\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   294
44601
04f64e602fa6 tuned document;
wenzelm
parents: 44236
diff changeset
   295
primrec uid_of :: "operation \<Rightarrow> uid"
64517
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   296
  where
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   297
    "uid_of (Read uid text path) = uid"
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   298
  | "uid_of (Write uid text path) = uid"
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   299
  | "uid_of (Chmod uid perms path) = uid"
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   300
  | "uid_of (Creat uid perms path) = uid"
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   301
  | "uid_of (Unlink uid path) = uid"
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   302
  | "uid_of (Mkdir uid path perms) = uid"
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   303
  | "uid_of (Rmdir uid path) = uid"
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   304
  | "uid_of (Readdir uid names path) = uid"
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   305
44601
04f64e602fa6 tuned document;
wenzelm
parents: 44236
diff changeset
   306
primrec path_of :: "operation \<Rightarrow> path"
64517
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   307
  where
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   308
    "path_of (Read uid text path) = path"
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   309
  | "path_of (Write uid text path) = path"
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   310
  | "path_of (Chmod uid perms path) = path"
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   311
  | "path_of (Creat uid perms path) = path"
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   312
  | "path_of (Unlink uid path) = path"
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   313
  | "path_of (Mkdir uid perms path) = path"
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   314
  | "path_of (Rmdir uid path) = path"
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   315
  | "path_of (Readdir uid names path) = path"
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   316
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   317
text \<open>
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   318
  \<^medskip>
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   319
  Note that we have omitted explicit \<open>Open\<close> and \<open>Close\<close> operations, pretending
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   320
  that \<^term>\<open>Read\<close> and \<^term>\<open>Write\<close> would already take care of this behind
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   321
  the scenes. Thus we have basically treated actual sequences of real
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   322
  system-calls \<open>open\<close>--\<open>read\<close>/\<open>write\<close>--\<open>close\<close> as atomic.
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   323
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   324
  In principle, this could make big a difference in a model with explicit
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   325
  concurrent processes. On the other hand, even on a real Unix system the
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   326
  exact scheduling of concurrent \<open>open\<close> and \<open>close\<close> operations does \<^emph>\<open>not\<close>
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   327
  directly affect the success of corresponding \<open>read\<close> or \<open>write\<close>. Unix allows
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   328
  several processes to have files opened at the same time, even for writing!
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   329
  Certainly, the result from reading the contents later may be hard to
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   330
  predict, but the system-calls involved here will succeed in any case.
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   331
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   332
  \<^bigskip>
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   333
  The operational semantics of system calls is now specified via transitions
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   334
  of the file-system configuration. This is expressed as an inductive relation
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   335
  (although there is no actual recursion involved here).
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   336
\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   337
44601
04f64e602fa6 tuned document;
wenzelm
parents: 44236
diff changeset
   338
inductive transition :: "file \<Rightarrow> operation \<Rightarrow> file \<Rightarrow> bool"
04f64e602fa6 tuned document;
wenzelm
parents: 44236
diff changeset
   339
  ("_ \<midarrow>_\<rightarrow> _" [90, 1000, 90] 100)
64517
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   340
  where
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   341
    read:
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   342
      "root \<midarrow>(Read uid text path)\<rightarrow> root"
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   343
      if "access root path uid {Readable} = Some (Val (att, text))"
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   344
  | "write":
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   345
      "root \<midarrow>(Write uid text path)\<rightarrow> update path (Some (Val (att, text))) root"
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   346
      if "access root path uid {Writable} = Some (Val (att, text'))"
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   347
  | chmod:
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   348
      "root \<midarrow>(Chmod uid perms path)\<rightarrow>
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   349
        update path (Some (map_attributes (others_update (\<lambda>_. perms)) file)) root"
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   350
      if "access root path uid {} = Some file" and "uid = 0 \<or> uid = owner (attributes file)"
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   351
  | creat:
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   352
      "root \<midarrow>(Creat uid perms path)\<rightarrow>
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   353
        update path (Some (Val (\<lparr>owner = uid, others = perms\<rparr>, []))) root"
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   354
      if "path = parent_path @ [name]"
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   355
      and "access root parent_path uid {Writable} = Some (Env att parent)"
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   356
      and "access root path uid {} = None"
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   357
  | unlink:
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   358
      "root \<midarrow>(Unlink uid path)\<rightarrow> update path None root"
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   359
      if "path = parent_path @ [name]"
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   360
      and "access root parent_path uid {Writable} = Some (Env att parent)"
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   361
      and "access root path uid {} = Some (Val plain)"
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   362
  | mkdir:
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   363
      "root \<midarrow>(Mkdir uid perms path)\<rightarrow>
68451
c34aa23a1fb6 empty -> Map.empty
nipkow
parents: 67443
diff changeset
   364
        update path (Some (Env \<lparr>owner = uid, others = perms\<rparr> Map.empty)) root"
64517
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   365
      if "path = parent_path @ [name]"
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   366
      and "access root parent_path uid {Writable} = Some (Env att parent)"
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   367
      and "access root path uid {} = None"
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   368
  | rmdir:
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   369
      "root \<midarrow>(Rmdir uid path)\<rightarrow> update path None root"
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   370
      if "path = parent_path @ [name]"
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   371
      and "access root parent_path uid {Writable} = Some (Env att parent)"
68451
c34aa23a1fb6 empty -> Map.empty
nipkow
parents: 67443
diff changeset
   372
      and "access root path uid {} = Some (Env att' Map.empty)"
64517
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   373
  | readdir:
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   374
      "root \<midarrow>(Readdir uid names path)\<rightarrow> root"
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   375
      if "access root path uid {Readable} = Some (Env att dir)"
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   376
      and "names = dom dir"
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   377
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   378
text \<open>
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   379
  \<^medskip>
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   380
  Certainly, the above specification is central to the whole formal
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   381
  development. Any of the results to be established later on are only
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   382
  meaningful to the outside world if this transition system provides an
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   383
  adequate model of real Unix systems. This kind of ``reality-check'' of a
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   384
  formal model is the well-known problem of \<^emph>\<open>validation\<close>.
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   385
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   386
  If in doubt, one may consider to compare our definition with the informal
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   387
  specifications given the corresponding Unix man pages, or even peek at an
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   388
  actual implementation such as @{cite "Torvalds-et-al:Linux"}. Another common
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   389
  way to gain confidence into the formal model is to run simple simulations
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   390
  (see \secref{sec:unix-examples}), and check the results with that of
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   391
  experiments performed on a real Unix system.
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   392
\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   393
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   394
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   395
subsection \<open>Basic properties of single transitions \label{sec:unix-single-trans}\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   396
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   397
text \<open>
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   398
  The transition system \<open>root \<midarrow>x\<rightarrow> root'\<close> defined above determines a unique
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   399
  result \<^term>\<open>root'\<close> from given \<^term>\<open>root\<close> and \<^term>\<open>x\<close> (this is holds
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   400
  rather trivially, since there is even only one clause for each operation).
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   401
  This uniqueness statement will simplify our subsequent development to some
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   402
  extent, since we only have to reason about a partial function rather than a
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   403
  general relation.
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   404
\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   405
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   406
theorem transition_uniq:
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   407
  assumes root': "root \<midarrow>x\<rightarrow> root'"
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   408
    and root'': "root \<midarrow>x\<rightarrow> root''"
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   409
  shows "root' = root''"
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   410
  using root''
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   411
proof cases
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   412
  case read
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   413
  with root' show ?thesis by cases auto
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   414
next
36504
7cc639e20cb2 avoid clash with keyword 'write';
wenzelm
parents: 25974
diff changeset
   415
  case "write"
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   416
  with root' show ?thesis by cases auto
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   417
next
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   418
  case chmod
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   419
  with root' show ?thesis by cases auto
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   420
next
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   421
  case creat
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   422
  with root' show ?thesis by cases auto
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   423
next
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   424
  case unlink
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   425
  with root' show ?thesis by cases auto
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   426
next
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   427
  case mkdir
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   428
  with root' show ?thesis by cases auto
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   429
next
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   430
  case rmdir
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   431
  with root' show ?thesis by cases auto
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   432
next
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   433
  case readdir
45671
1c769a2a2421 tuned proofs;
wenzelm
parents: 44890
diff changeset
   434
  with root' show ?thesis by cases blast+
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   435
qed
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   436
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   437
text \<open>
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   438
  \<^medskip>
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   439
  Apparently, file-system transitions are \<^emph>\<open>type-safe\<close> in the sense that the
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   440
  result of transforming an actual directory yields again a directory.
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   441
\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   442
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   443
theorem transition_type_safe:
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   444
  assumes tr: "root \<midarrow>x\<rightarrow> root'"
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   445
    and inv: "\<exists>att dir. root = Env att dir"
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   446
  shows "\<exists>att dir. root' = Env att dir"
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   447
proof (cases "path_of x")
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   448
  case Nil
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   449
  with tr inv show ?thesis
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   450
    by cases (auto simp add: access_def split: if_splits)
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   451
next
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   452
  case Cons
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   453
  from tr obtain opt where
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   454
      "root' = root \<or> root' = update (path_of x) opt root"
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   455
    by cases auto
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   456
  with inv Cons show ?thesis
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   457
    by (auto simp add: update_eq split: list.splits)
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   458
qed
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   459
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   460
text \<open>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   461
  The previous result may be seen as the most basic invariant on the
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   462
  file-system state that is enforced by any proper kernel implementation. So
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   463
  user processes --- being bound to the system-call interface --- may never
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   464
  mess up a file-system such that the root becomes a plain file instead of a
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   465
  directory, which would be a strange situation indeed.
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   466
\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   467
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   468
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   469
subsection \<open>Iterated transitions\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   470
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   471
text \<open>
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   472
  Iterated system transitions via finite sequences of system operations are
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   473
  modeled inductively as follows. In a sense, this relation describes the
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   474
  cumulative effect of the sequence of system-calls issued by a number of
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   475
  running processes over a finite amount of time.
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   476
\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   477
64517
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   478
inductive transitions :: "file \<Rightarrow> operation list \<Rightarrow> file \<Rightarrow> bool"  ("_ \<Midarrow>_\<Rightarrow> _" [90, 1000, 90] 100)
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   479
  where
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   480
    nil: "root \<Midarrow>[]\<Rightarrow> root"
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   481
  | cons: "root \<Midarrow>(x # xs)\<Rightarrow> root''" if "root \<midarrow>x\<rightarrow> root'" and "root' \<Midarrow>xs\<Rightarrow> root''"
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   482
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   483
text \<open>
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   484
  \<^medskip>
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   485
  We establish a few basic facts relating iterated transitions with single
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   486
  ones, according to the recursive structure of lists.
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   487
\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   488
62176
1221f2a46945 tuned syntax;
wenzelm
parents: 61893
diff changeset
   489
lemma transitions_nil_eq: "root \<Midarrow>[]\<Rightarrow> root' \<longleftrightarrow> root = root'"
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   490
proof
62176
1221f2a46945 tuned syntax;
wenzelm
parents: 61893
diff changeset
   491
  assume "root \<Midarrow>[]\<Rightarrow> root'"
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   492
  then show "root = root'" by cases simp_all
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   493
next
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   494
  assume "root = root'"
62176
1221f2a46945 tuned syntax;
wenzelm
parents: 61893
diff changeset
   495
  then show "root \<Midarrow>[]\<Rightarrow> root'" by (simp only: transitions.nil)
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   496
qed
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   497
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   498
lemma transitions_cons_eq:
62176
1221f2a46945 tuned syntax;
wenzelm
parents: 61893
diff changeset
   499
  "root \<Midarrow>(x # xs)\<Rightarrow> root'' \<longleftrightarrow> (\<exists>root'. root \<midarrow>x\<rightarrow> root' \<and> root' \<Midarrow>xs\<Rightarrow> root'')"
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   500
proof
62176
1221f2a46945 tuned syntax;
wenzelm
parents: 61893
diff changeset
   501
  assume "root \<Midarrow>(x # xs)\<Rightarrow> root''"
1221f2a46945 tuned syntax;
wenzelm
parents: 61893
diff changeset
   502
  then show "\<exists>root'. root \<midarrow>x\<rightarrow> root' \<and> root' \<Midarrow>xs\<Rightarrow> root''"
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   503
    by cases auto
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   504
next
62176
1221f2a46945 tuned syntax;
wenzelm
parents: 61893
diff changeset
   505
  assume "\<exists>root'. root \<midarrow>x\<rightarrow> root' \<and> root' \<Midarrow>xs\<Rightarrow> root''"
1221f2a46945 tuned syntax;
wenzelm
parents: 61893
diff changeset
   506
  then show "root \<Midarrow>(x # xs)\<Rightarrow> root''"
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   507
    by (blast intro: transitions.cons)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   508
qed
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   509
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   510
text \<open>
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   511
  The next two rules show how to ``destruct'' known transition sequences. Note
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   512
  that the second one actually relies on the uniqueness property of the basic
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   513
  transition system (see \secref{sec:unix-single-trans}).
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   514
\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   515
62176
1221f2a46945 tuned syntax;
wenzelm
parents: 61893
diff changeset
   516
lemma transitions_nilD: "root \<Midarrow>[]\<Rightarrow> root' \<Longrightarrow> root' = root"
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   517
  by (simp add: transitions_nil_eq)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   518
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   519
lemma transitions_consD:
62176
1221f2a46945 tuned syntax;
wenzelm
parents: 61893
diff changeset
   520
  assumes list: "root \<Midarrow>(x # xs)\<Rightarrow> root''"
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   521
    and hd: "root \<midarrow>x\<rightarrow> root'"
62176
1221f2a46945 tuned syntax;
wenzelm
parents: 61893
diff changeset
   522
  shows "root' \<Midarrow>xs\<Rightarrow> root''"
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   523
proof -
62176
1221f2a46945 tuned syntax;
wenzelm
parents: 61893
diff changeset
   524
  from list obtain r' where r': "root \<midarrow>x\<rightarrow> r'" and root'': "r' \<Midarrow>xs\<Rightarrow> root''"
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   525
    by cases simp_all
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   526
  from r' hd have "r' = root'" by (rule transition_uniq)
62176
1221f2a46945 tuned syntax;
wenzelm
parents: 61893
diff changeset
   527
  with root'' show "root' \<Midarrow>xs\<Rightarrow> root''" by simp
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   528
qed
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   529
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   530
text \<open>
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   531
  \<^medskip>
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   532
  The following fact shows how an invariant \<^term>\<open>Q\<close> of single transitions
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   533
  with property \<^term>\<open>P\<close> may be transferred to iterated transitions. The
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   534
  proof is rather obvious by rule induction over the definition of \<^term>\<open>root \<Midarrow>xs\<Rightarrow> root'\<close>.
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   535
\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   536
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   537
lemma transitions_invariant:
47175
6b906beec36f tuned whitespace;
wenzelm
parents: 47099
diff changeset
   538
  assumes r: "\<And>r x r'. r \<midarrow>x\<rightarrow> r' \<Longrightarrow> Q r \<Longrightarrow> P x \<Longrightarrow> Q r'"
62176
1221f2a46945 tuned syntax;
wenzelm
parents: 61893
diff changeset
   539
    and trans: "root \<Midarrow>xs\<Rightarrow> root'"
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   540
  shows "Q root \<Longrightarrow> \<forall>x \<in> set xs. P x \<Longrightarrow> Q root'"
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   541
  using trans
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   542
proof induct
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   543
  case nil
23463
9953ff53cc64 tuned proofs -- avoid implicit prems;
wenzelm
parents: 23394
diff changeset
   544
  show ?case by (rule nil.prems)
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   545
next
21372
4a0a83378669 converted to 'inductive2';
wenzelm
parents: 21226
diff changeset
   546
  case (cons root x root' xs root'')
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   547
  note P = \<open>\<forall>x \<in> set (x # xs). P x\<close>
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   548
  then have "P x" by simp
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   549
  with \<open>root \<midarrow>x\<rightarrow> root'\<close> and \<open>Q root\<close> have Q': "Q root'" by (rule r)
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   550
  from P have "\<forall>x \<in> set xs. P x" by simp
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   551
  with Q' show "Q root''" by (rule cons.hyps)
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   552
qed
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   553
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   554
text \<open>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   555
  As an example of applying the previous result, we transfer the basic
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   556
  type-safety property (see \secref{sec:unix-single-trans}) from single
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   557
  transitions to iterated ones, which is a rather obvious result indeed.
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   558
\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   559
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   560
theorem transitions_type_safe:
62176
1221f2a46945 tuned syntax;
wenzelm
parents: 61893
diff changeset
   561
  assumes "root \<Midarrow>xs\<Rightarrow> root'"
16670
wenzelm
parents: 16417
diff changeset
   562
    and "\<exists>att dir. root = Env att dir"
wenzelm
parents: 16417
diff changeset
   563
  shows "\<exists>att dir. root' = Env att dir"
23394
474ff28210c0 tuned proofs;
wenzelm
parents: 21404
diff changeset
   564
  using transition_type_safe and assms
16670
wenzelm
parents: 16417
diff changeset
   565
proof (rule transitions_invariant)
wenzelm
parents: 16417
diff changeset
   566
  show "\<forall>x \<in> set xs. True" by blast
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   567
qed
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   568
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   569
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   570
section \<open>Executable sequences\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   571
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   572
text \<open>
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   573
  An inductively defined relation such as the one of \<open>root \<midarrow>x\<rightarrow> root'\<close> (see
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   574
  \secref{sec:unix-syscall}) has two main aspects. First of all, the resulting
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   575
  system admits a certain set of transition rules (introductions) as given in
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   576
  the specification. Furthermore, there is an explicit least-fixed-point
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   577
  construction involved, which results in induction (and case-analysis) rules
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   578
  to eliminate known transitions in an exhaustive manner.
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   579
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   580
  \<^medskip>
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   581
  Subsequently, we explore our transition system in an experimental style,
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   582
  mainly using the introduction rules with basic algebraic properties of the
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   583
  underlying structures. The technique closely resembles that of Prolog
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   584
  combined with functional evaluation in a very simple manner.
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   585
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   586
  Just as the ``closed-world assumption'' is left implicit in Prolog, we do
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   587
  not refer to induction over the whole transition system here. So this is
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   588
  still purely positive reasoning about possible executions; exhaustive
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   589
  reasoning will be employed only later on (see \secref{sec:unix-bogosity}),
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   590
  when we shall demonstrate that certain behavior is \<^emph>\<open>not\<close> possible.
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   591
\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   592
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   593
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   594
subsection \<open>Possible transitions\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   595
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   596
text \<open>
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   597
  Rather obviously, a list of system operations can be executed within a
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   598
  certain state if there is a result state reached by an iterated transition.
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   599
\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   600
62176
1221f2a46945 tuned syntax;
wenzelm
parents: 61893
diff changeset
   601
definition "can_exec root xs \<longleftrightarrow> (\<exists>root'. root \<Midarrow>xs\<Rightarrow> root')"
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   602
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   603
lemma can_exec_nil: "can_exec root []"
18730
843da46f89ac tuned proofs;
wenzelm
parents: 18576
diff changeset
   604
  unfolding can_exec_def by (blast intro: transitions.intros)
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   605
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   606
lemma can_exec_cons:
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   607
    "root \<midarrow>x\<rightarrow> root' \<Longrightarrow> can_exec root' xs \<Longrightarrow> can_exec root (x # xs)"
18730
843da46f89ac tuned proofs;
wenzelm
parents: 18576
diff changeset
   608
  unfolding can_exec_def by (blast intro: transitions.intros)
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   609
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   610
text \<open>
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   611
  \<^medskip>
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   612
  In case that we already know that a certain sequence can be executed we may
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   613
  destruct it backwardly into individual transitions.
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   614
\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   615
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   616
lemma can_exec_snocD: "can_exec root (xs @ [y])
62176
1221f2a46945 tuned syntax;
wenzelm
parents: 61893
diff changeset
   617
    \<Longrightarrow> \<exists>root' root''. root \<Midarrow>xs\<Rightarrow> root' \<and> root' \<midarrow>y\<rightarrow> root''"
20503
503ac4c5ef91 induct method: renamed 'fixing' to 'arbitrary';
wenzelm
parents: 20321
diff changeset
   618
proof (induct xs arbitrary: root)
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   619
  case Nil
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   620
  then show ?case
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   621
    by (simp add: can_exec_def transitions_nil_eq transitions_cons_eq)
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   622
next
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   623
  case (Cons x xs)
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   624
  from \<open>can_exec root ((x # xs) @ [y])\<close> obtain r root'' where
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   625
      x: "root \<midarrow>x\<rightarrow> r" and
62176
1221f2a46945 tuned syntax;
wenzelm
parents: 61893
diff changeset
   626
      xs_y: "r \<Midarrow>(xs @ [y])\<Rightarrow> root''"
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   627
    by (auto simp add: can_exec_def transitions_nil_eq transitions_cons_eq)
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   628
  from xs_y Cons.hyps obtain root' r'
62176
1221f2a46945 tuned syntax;
wenzelm
parents: 61893
diff changeset
   629
    where xs: "r \<Midarrow>xs\<Rightarrow> root'" and y: "root' \<midarrow>y\<rightarrow> r'"
18730
843da46f89ac tuned proofs;
wenzelm
parents: 18576
diff changeset
   630
    unfolding can_exec_def by blast
62176
1221f2a46945 tuned syntax;
wenzelm
parents: 61893
diff changeset
   631
  from x xs have "root \<Midarrow>(x # xs)\<Rightarrow> root'"
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   632
    by (rule transitions.cons)
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   633
  with y show ?case by blast
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   634
qed
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   635
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   636
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   637
subsection \<open>Example executions \label{sec:unix-examples}\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   638
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   639
text \<open>
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   640
  We are now ready to perform a few experiments within our formal model of
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   641
  Unix system-calls. The common technique is to alternate introduction rules
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   642
  of the transition system (see \secref{sec:unix-trans}), and steps to solve
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   643
  any emerging side conditions using algebraic properties of the underlying
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   644
  file-system structures (see \secref{sec:unix-file-system}).
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   645
\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   646
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   647
lemmas eval = access_def init_def
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   648
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   649
theorem "u \<in> users \<Longrightarrow> can_exec (init users)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   650
    [Mkdir u perms [u, name]]"
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   651
  apply (rule can_exec_cons)
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   652
    \<comment> \<open>back-chain \<^term>\<open>can_exec\<close> (of @{term [source] Cons})\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   653
  apply (rule mkdir)
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   654
    \<comment> \<open>back-chain \<^term>\<open>Mkdir\<close>\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   655
  apply (force simp add: eval)+
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   656
    \<comment> \<open>solve preconditions of \<^term>\<open>Mkdir\<close>\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   657
  apply (simp add: eval)
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   658
    \<comment> \<open>peek at resulting dir (optional)\<close>
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   659
  txt \<open>@{subgoals [display]}\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   660
  apply (rule can_exec_nil)
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   661
    \<comment> \<open>back-chain \<^term>\<open>can_exec\<close> (of @{term [source] Nil})\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   662
  done
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   663
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   664
text \<open>
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   665
  By inspecting the result shown just before the final step above, we may gain
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   666
  confidence that our specification of Unix system-calls actually makes sense.
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   667
  Further common errors are usually exhibited when preconditions of transition
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   668
  rules fail unexpectedly.
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   669
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   670
  \<^medskip>
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   671
  Here are a few further experiments, using the same techniques as before.
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   672
\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   673
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   674
theorem "u \<in> users \<Longrightarrow> can_exec (init users)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   675
   [Creat u perms [u, name],
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   676
    Unlink u [u, name]]"
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   677
  apply (rule can_exec_cons)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   678
  apply (rule creat)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   679
  apply (force simp add: eval)+
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   680
  apply (simp add: eval)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   681
  apply (rule can_exec_cons)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   682
  apply (rule unlink)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   683
  apply (force simp add: eval)+
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   684
  apply (simp add: eval)
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   685
  txt \<open>peek at result: @{subgoals [display]}\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   686
  apply (rule can_exec_nil)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   687
  done
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   688
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   689
theorem "u \<in> users \<Longrightarrow> Writable \<in> perms\<^sub>1 \<Longrightarrow>
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   690
  Readable \<in> perms\<^sub>2 \<Longrightarrow> name\<^sub>3 \<noteq> name\<^sub>4 \<Longrightarrow>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   691
  can_exec (init users)
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   692
   [Mkdir u perms\<^sub>1 [u, name\<^sub>1],
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   693
    Mkdir u' perms\<^sub>2 [u, name\<^sub>1, name\<^sub>2],
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   694
    Creat u' perms\<^sub>3 [u, name\<^sub>1, name\<^sub>2, name\<^sub>3],
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   695
    Creat u' perms\<^sub>3 [u, name\<^sub>1, name\<^sub>2, name\<^sub>4],
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   696
    Readdir u {name\<^sub>3, name\<^sub>4} [u, name\<^sub>1, name\<^sub>2]]"
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   697
  apply (rule can_exec_cons, rule transition.intros,
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   698
    (force simp add: eval)+, (simp add: eval)?)+
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   699
  txt \<open>peek at result: @{subgoals [display]}\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   700
  apply (rule can_exec_nil)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   701
  done
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   702
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   703
theorem "u \<in> users \<Longrightarrow> Writable \<in> perms\<^sub>1 \<Longrightarrow> Readable \<in> perms\<^sub>3 \<Longrightarrow>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   704
  can_exec (init users)
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   705
   [Mkdir u perms\<^sub>1 [u, name\<^sub>1],
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   706
    Mkdir u' perms\<^sub>2 [u, name\<^sub>1, name\<^sub>2],
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   707
    Creat u' perms\<^sub>3 [u, name\<^sub>1, name\<^sub>2, name\<^sub>3],
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   708
    Write u' ''foo'' [u, name\<^sub>1, name\<^sub>2, name\<^sub>3],
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   709
    Read u ''foo'' [u, name\<^sub>1, name\<^sub>2, name\<^sub>3]]"
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   710
  apply (rule can_exec_cons, rule transition.intros,
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   711
    (force simp add: eval)+, (simp add: eval)?)+
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   712
  txt \<open>peek at result: @{subgoals [display]}\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   713
  apply (rule can_exec_nil)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   714
  done
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   715
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   716
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   717
section \<open>Odd effects --- treated formally \label{sec:unix-bogosity}\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   718
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   719
text \<open>
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   720
  We are now ready to give a completely formal treatment of the slightly odd
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   721
  situation discussed in the introduction (see \secref{sec:unix-intro}): the
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   722
  file-system can easily reach a state where a user is unable to remove his
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   723
  very own directory, because it is still populated by items placed there by
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   724
  another user in an uncouth manner.
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   725
\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   726
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   727
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   728
subsection \<open>The general procedure \label{sec:unix-inv-procedure}\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   729
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   730
text \<open>
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   731
  The following theorem expresses the general procedure we are following to
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   732
  achieve the main result.
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   733
\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   734
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   735
theorem general_procedure:
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   736
  assumes cannot_y: "\<And>r r'. Q r \<Longrightarrow> r \<midarrow>y\<rightarrow> r' \<Longrightarrow> False"
62176
1221f2a46945 tuned syntax;
wenzelm
parents: 61893
diff changeset
   737
    and init_inv: "\<And>root. init users \<Midarrow>bs\<Rightarrow> root \<Longrightarrow> Q root"
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   738
    and preserve_inv: "\<And>r x r'. r \<midarrow>x\<rightarrow> r' \<Longrightarrow> Q r \<Longrightarrow> P x \<Longrightarrow> Q r'"
62176
1221f2a46945 tuned syntax;
wenzelm
parents: 61893
diff changeset
   739
    and init_result: "init users \<Midarrow>bs\<Rightarrow> root"
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   740
  shows "\<not> (\<exists>xs. (\<forall>x \<in> set xs. P x) \<and> can_exec root (xs @ [y]))"
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   741
proof -
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   742
  {
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   743
    fix xs
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   744
    assume Ps: "\<forall>x \<in> set xs. P x"
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   745
    assume can_exec: "can_exec root (xs @ [y])"
64517
62832c7df18f tuned whitespace;
wenzelm
parents: 63117
diff changeset
   746
    then obtain root' root'' where xs: "root \<Midarrow>xs\<Rightarrow> root'" and y: "root' \<midarrow>y\<rightarrow> root''"
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   747
      by (blast dest: can_exec_snocD)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   748
    from init_result have "Q root" by (rule init_inv)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   749
    from preserve_inv xs this Ps have "Q root'"
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   750
      by (rule transitions_invariant)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   751
    from this y have False by (rule cannot_y)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   752
  }
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   753
  then show ?thesis by blast
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   754
qed
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   755
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   756
text \<open>
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   757
  Here \<^prop>\<open>P x\<close> refers to the restriction on file-system operations that
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   758
  are admitted after having reached the critical configuration; according to
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   759
  the problem specification this will become \<^prop>\<open>uid_of x = user\<^sub>1\<close> later
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   760
  on. Furthermore, \<^term>\<open>y\<close> refers to the operations we claim to be
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   761
  impossible to perform afterwards, we will take \<^term>\<open>Rmdir\<close> later. Moreover
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   762
  \<^term>\<open>Q\<close> is a suitable (auxiliary) invariant over the file-system; choosing
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   763
  \<^term>\<open>Q\<close> adequately is very important to make the proof work (see
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   764
  \secref{sec:unix-inv-lemmas}).
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   765
\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   766
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   767
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   768
subsection \<open>The particular situation\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   769
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   770
text \<open>
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   771
  We introduce a few global declarations and axioms to describe our particular
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   772
  situation considered here. Thus we avoid excessive use of local parameters
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   773
  in the subsequent development.
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   774
\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   775
60374
wenzelm
parents: 58889
diff changeset
   776
context
12079
054153c48bde use locales instead of consts/axioms;
wenzelm
parents: 11881
diff changeset
   777
  fixes users :: "uid set"
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   778
    and user\<^sub>1 :: uid
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   779
    and user\<^sub>2 :: uid
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   780
    and name\<^sub>1 :: name
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   781
    and name\<^sub>2 :: name
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   782
    and name\<^sub>3 :: name
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   783
    and perms\<^sub>1 :: perms
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   784
    and perms\<^sub>2 :: perms
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   785
  assumes user\<^sub>1_known: "user\<^sub>1 \<in> users"
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   786
    and user\<^sub>1_not_root: "user\<^sub>1 \<noteq> 0"
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   787
    and users_neq: "user\<^sub>1 \<noteq> user\<^sub>2"
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   788
    and perms\<^sub>1_writable: "Writable \<in> perms\<^sub>1"
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   789
    and perms\<^sub>2_not_writable: "Writable \<notin> perms\<^sub>2"
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   790
  notes facts = user\<^sub>1_known user\<^sub>1_not_root users_neq
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   791
    perms\<^sub>1_writable perms\<^sub>2_not_writable
21029
b98fb9cf903b locale begin/end;
wenzelm
parents: 21001
diff changeset
   792
begin
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   793
21029
b98fb9cf903b locale begin/end;
wenzelm
parents: 21001
diff changeset
   794
definition
19086
1b3780be6cc2 new-style definitions/abbreviations;
wenzelm
parents: 18730
diff changeset
   795
  "bogus =
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   796
     [Mkdir user\<^sub>1 perms\<^sub>1 [user\<^sub>1, name\<^sub>1],
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   797
      Mkdir user\<^sub>2 perms\<^sub>2 [user\<^sub>1, name\<^sub>1, name\<^sub>2],
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   798
      Creat user\<^sub>2 perms\<^sub>2 [user\<^sub>1, name\<^sub>1, name\<^sub>2, name\<^sub>3]]"
60374
wenzelm
parents: 58889
diff changeset
   799
wenzelm
parents: 58889
diff changeset
   800
definition "bogus_path = [user\<^sub>1, name\<^sub>1, name\<^sub>2]"
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   801
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   802
text \<open>
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   803
  The \<^term>\<open>bogus\<close> operations are the ones that lead into the uncouth
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   804
  situation; \<^term>\<open>bogus_path\<close> is the key position within the file-system
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   805
  where things go awry.
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   806
\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   807
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   808
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   809
subsection \<open>Invariance lemmas \label{sec:unix-inv-lemmas}\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   810
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   811
text \<open>
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   812
  The following invariant over the root file-system describes the bogus
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   813
  situation in an abstract manner: located at a certain \<^term>\<open>path\<close> within
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   814
  the file-system is a non-empty directory that is neither owned nor writable
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   815
  by \<^term>\<open>user\<^sub>1\<close>.
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   816
\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   817
47215
ca516aa5b6ce "invariant" is free in main HOL (cf. 56adbf5bcc82, e64ffc96a49f);
wenzelm
parents: 47175
diff changeset
   818
definition
62176
1221f2a46945 tuned syntax;
wenzelm
parents: 61893
diff changeset
   819
  "invariant root path \<longleftrightarrow>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   820
    (\<exists>att dir.
68451
c34aa23a1fb6 empty -> Map.empty
nipkow
parents: 67443
diff changeset
   821
      access root path user\<^sub>1 {} = Some (Env att dir) \<and> dir \<noteq> Map.empty \<and>
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   822
      user\<^sub>1 \<noteq> owner att \<and>
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   823
      access root path user\<^sub>1 {Writable} = None)"
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   824
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   825
text \<open>
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   826
  Following the general procedure (see \secref{sec:unix-inv-procedure}) we
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   827
  will now establish the three key lemmas required to yield the final result.
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   828
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   829
    \<^enum> The invariant is sufficiently strong to entail the pathological case
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   830
    that \<^term>\<open>user\<^sub>1\<close> is unable to remove the (owned) directory at \<^term>\<open>[user\<^sub>1, name\<^sub>1]\<close>.
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   831
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   832
    \<^enum> The invariant does hold after having executed the \<^term>\<open>bogus\<close> list of
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   833
    operations (starting with an initial file-system configuration).
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   834
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   835
    \<^enum> The invariant is preserved by any file-system operation performed by
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   836
    \<^term>\<open>user\<^sub>1\<close> alone, without any help by other users.
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   837
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   838
  As the invariant appears both as assumptions and conclusions in the course
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   839
  of proof, its formulation is rather critical for the whole development to
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   840
  work out properly. In particular, the third step is very sensitive to the
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   841
  invariant being either too strong or too weak. Moreover the invariant has to
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   842
  be sufficiently abstract, lest the proof become cluttered by confusing
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   843
  detail.
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   844
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   845
  \<^medskip>
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   846
  The first two lemmas are technically straight forward --- we just have to
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   847
  inspect rather special cases.
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   848
\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   849
21029
b98fb9cf903b locale begin/end;
wenzelm
parents: 21001
diff changeset
   850
lemma cannot_rmdir:
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   851
  assumes inv: "invariant root bogus_path"
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   852
    and rmdir: "root \<midarrow>(Rmdir user\<^sub>1 [user\<^sub>1, name\<^sub>1])\<rightarrow> root'"
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   853
  shows False
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   854
proof -
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   855
  from inv obtain "file" where "access root bogus_path user\<^sub>1 {} = Some file"
18730
843da46f89ac tuned proofs;
wenzelm
parents: 18576
diff changeset
   856
    unfolding invariant_def by blast
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   857
  moreover
68451
c34aa23a1fb6 empty -> Map.empty
nipkow
parents: 67443
diff changeset
   858
  from rmdir obtain att where "access root [user\<^sub>1, name\<^sub>1] user\<^sub>1 {} = Some (Env att Map.empty)"
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   859
    by cases auto
68451
c34aa23a1fb6 empty -> Map.empty
nipkow
parents: 67443
diff changeset
   860
  then have "access root ([user\<^sub>1, name\<^sub>1] @ [name\<^sub>2]) user\<^sub>1 {} = Map.empty name\<^sub>2"
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   861
    by (simp only: access_empty_lookup lookup_append_some) simp
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   862
  ultimately show False by (simp add: bogus_path_def)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   863
qed
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   864
21029
b98fb9cf903b locale begin/end;
wenzelm
parents: 21001
diff changeset
   865
lemma
62176
1221f2a46945 tuned syntax;
wenzelm
parents: 61893
diff changeset
   866
  assumes init: "init users \<Midarrow>bogus\<Rightarrow> root"
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   867
  shows init_invariant: "invariant root bogus_path"
60374
wenzelm
parents: 58889
diff changeset
   868
  supply eval = facts access_def init_def
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   869
  using init
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   870
  apply (unfold bogus_def bogus_path_def)
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   871
  apply (drule transitions_consD, rule transition.intros,
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   872
      (force simp add: eval)+, (simp add: eval)?)+
67443
3abf6a722518 standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents: 66453
diff changeset
   873
    \<comment> \<open>evaluate all operations\<close>
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   874
  apply (drule transitions_nilD)
67443
3abf6a722518 standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents: 66453
diff changeset
   875
    \<comment> \<open>reach final result\<close>
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   876
  apply (simp add: invariant_def eval)
67443
3abf6a722518 standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents: 66453
diff changeset
   877
    \<comment> \<open>check the invariant\<close>
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   878
  done
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   879
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   880
text \<open>
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   881
  \<^medskip>
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
   882
  At last we are left with the main effort to show that the ``bogosity''
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   883
  invariant is preserved by any file-system operation performed by \<^term>\<open>user\<^sub>1\<close> alone. Note that this holds for any \<^term>\<open>path\<close> given, the
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68451
diff changeset
   884
  particular \<^term>\<open>bogus_path\<close> is not required here.
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
   885
\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   886
21029
b98fb9cf903b locale begin/end;
wenzelm
parents: 21001
diff changeset
   887
lemma preserve_invariant:
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   888
  assumes tr: "root \<midarrow>x\<rightarrow> root'"
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   889
    and inv: "invariant root path"
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   890
    and uid: "uid_of x = user\<^sub>1"
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   891
  shows "invariant root' path"
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   892
proof -
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   893
  from inv obtain att dir where
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   894
      inv1: "access root path user\<^sub>1 {} = Some (Env att dir)" and
68451
c34aa23a1fb6 empty -> Map.empty
nipkow
parents: 67443
diff changeset
   895
      inv2: "dir \<noteq> Map.empty" and
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   896
      inv3: "user\<^sub>1 \<noteq> owner att" and
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   897
      inv4: "access root path user\<^sub>1 {Writable} = None"
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   898
    by (auto simp add: invariant_def)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   899
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   900
  from inv1 have lookup: "lookup root path = Some (Env att dir)"
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   901
    by (simp only: access_empty_lookup)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   902
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   903
  from inv1 inv3 inv4 and user\<^sub>1_not_root
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   904
  have not_writable: "Writable \<notin> others att"
39224
39e0d3b86112 tuned proofs (based on fancy gutter icons in Isabelle/jEdit);
wenzelm
parents: 36862
diff changeset
   905
    by (auto simp add: access_def split: option.splits)
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   906
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   907
  show ?thesis
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   908
  proof cases
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   909
    assume "root' = root"
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   910
    with inv show "invariant root' path" by (simp only:)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   911
  next
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   912
    assume changed: "root' \<noteq> root"
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   913
    with tr obtain opt where root': "root' = update (path_of x) opt root"
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   914
      by cases auto
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   915
    show ?thesis
63117
acb6d72fc42e renamed prefix* in Library/Sublist
nipkow
parents: 63067
diff changeset
   916
    proof (rule prefix_cases)
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   917
      assume "path_of x \<parallel> path"
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   918
      with inv root'
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   919
      have "\<And>perms. access root' path user\<^sub>1 perms = access root path user\<^sub>1 perms"
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   920
        by (simp only: access_update_other)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   921
      with inv show "invariant root' path"
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   922
        by (simp only: invariant_def)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   923
    next
63117
acb6d72fc42e renamed prefix* in Library/Sublist
nipkow
parents: 63067
diff changeset
   924
      assume "prefix (path_of x) path"
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   925
      then obtain ys where path: "path = path_of x @ ys" ..
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   926
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   927
      show ?thesis
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   928
      proof (cases ys)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   929
        assume "ys = []"
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
   930
        with tr uid inv2 inv3 lookup changed path and user\<^sub>1_not_root
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   931
        have False
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   932
          by cases (auto simp add: access_empty_lookup dest: access_some_lookup)
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 17455
diff changeset
   933
        then show ?thesis ..
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   934
      next
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   935
        fix z zs assume ys: "ys = z # zs"
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   936
        have "lookup root' path = lookup root path"
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   937
        proof -
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   938
          from inv2 lookup path ys
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   939
          have look: "lookup root (path_of x @ z # zs) = Some (Env att dir)"
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   940
            by (simp only:)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   941
          then obtain att' dir' file' where
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   942
              look': "lookup root (path_of x) = Some (Env att' dir')" and
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   943
              dir': "dir' z = Some file'" and
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   944
              file': "lookup file' zs = Some (Env att dir)"
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   945
            by (blast dest: lookup_some_upper)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   946
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   947
          from tr uid changed look' dir' obtain att'' where
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   948
              look'': "lookup root' (path_of x) = Some (Env att'' dir')"
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   949
            by cases (auto simp add: access_empty_lookup lookup_update_some
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   950
              dest: access_some_lookup)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   951
          with dir' file' have "lookup root' (path_of x @ z # zs) =
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   952
              Some (Env att dir)"
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   953
            by (simp add: lookup_append_some)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   954
          with look path ys show ?thesis
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   955
            by simp
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   956
        qed
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   957
        with inv show "invariant root' path"
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   958
          by (simp only: invariant_def access_def)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   959
      qed
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   960
    next
63117
acb6d72fc42e renamed prefix* in Library/Sublist
nipkow
parents: 63067
diff changeset
   961
      assume "strict_prefix path (path_of x)"
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   962
      then obtain y ys where path: "path_of x = path @ y # ys" ..
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   963
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   964
      obtain dir' where
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   965
        lookup': "lookup root' path = Some (Env att dir')" and
68451
c34aa23a1fb6 empty -> Map.empty
nipkow
parents: 67443
diff changeset
   966
        inv2': "dir' \<noteq> Map.empty"
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   967
      proof (cases ys)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   968
        assume "ys = []"
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   969
        with path have parent: "path_of x = path @ [y]" by simp
17146
67e9b86ed211 Put quotation marks around some occurrences of "file", since it is now
berghofe
parents: 16670
diff changeset
   970
        with tr uid inv4 changed obtain "file" where
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   971
            "root' = update (path_of x) (Some file) root"
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   972
          by cases auto
10979
wenzelm
parents: 10966
diff changeset
   973
        with lookup parent have "lookup root' path = Some (Env att (dir(y\<mapsto>file)))"
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   974
          by (simp only: update_append_some update_cons_nil_env)
68451
c34aa23a1fb6 empty -> Map.empty
nipkow
parents: 67443
diff changeset
   975
        moreover have "dir(y\<mapsto>file) \<noteq> Map.empty" by simp
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   976
        ultimately show ?thesis ..
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   977
      next
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   978
        fix z zs assume ys: "ys = z # zs"
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   979
        with lookup root' path
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   980
        have "lookup root' path = Some (update (y # ys) opt (Env att dir))"
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   981
          by (simp only: update_append_some)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   982
        also obtain file' where
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   983
          "update (y # ys) opt (Env att dir) = Env att (dir(y\<mapsto>file'))"
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   984
        proof -
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   985
          have "dir y \<noteq> None"
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   986
          proof -
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   987
            have "dir y = lookup (Env att dir) [y]"
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   988
              by (simp split: option.splits)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   989
            also from lookup have "\<dots> = lookup root (path @ [y])"
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   990
              by (simp only: lookup_append_some)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   991
            also have "\<dots> \<noteq> None"
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   992
            proof -
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   993
              from ys obtain us u where rev_ys: "ys = us @ [u]"
45671
1c769a2a2421 tuned proofs;
wenzelm
parents: 44890
diff changeset
   994
                by (cases ys rule: rev_cases) simp
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   995
              with tr path
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   996
              have "lookup root ((path @ [y]) @ (us @ [u])) \<noteq> None \<or>
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   997
                  lookup root ((path @ [y]) @ us) \<noteq> None"
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
   998
                by cases (auto dest: access_some_lookup)
49676
882aa078eeae tuned whitespace;
wenzelm
parents: 49086
diff changeset
   999
              then show ?thesis
46206
d3d62b528487 tuned proofs;
wenzelm
parents: 45671
diff changeset
  1000
                by (fastforce dest!: lookup_some_append)
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
  1001
            qed
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
  1002
            finally show ?thesis .
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
  1003
          qed
39224
39e0d3b86112 tuned proofs (based on fancy gutter icons in Isabelle/jEdit);
wenzelm
parents: 36862
diff changeset
  1004
          with ys show ?thesis using that by auto
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
  1005
        qed
68451
c34aa23a1fb6 empty -> Map.empty
nipkow
parents: 67443
diff changeset
  1006
        also have "dir(y\<mapsto>file') \<noteq> Map.empty" by simp
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
  1007
        ultimately show ?thesis ..
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
  1008
      qed
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
  1009
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
  1010
      from lookup' have inv1': "access root' path user\<^sub>1 {} = Some (Env att dir')"
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
  1011
        by (simp only: access_empty_lookup)
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
  1012
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
  1013
      from inv3 lookup' and not_writable user\<^sub>1_not_root
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
  1014
      have "access root' path user\<^sub>1 {Writable} = None"
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
  1015
        by (simp add: access_def)
18730
843da46f89ac tuned proofs;
wenzelm
parents: 18576
diff changeset
  1016
      with inv1' inv2' inv3 show ?thesis unfolding invariant_def by blast
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
  1017
    qed
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
  1018
  qed
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
  1019
qed
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
  1020
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
  1021
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
  1022
subsection \<open>Putting it all together \label{sec:unix-main-result}\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
  1023
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
  1024
text \<open>
61893
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
  1025
  The main result is now imminent, just by composing the three invariance
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
  1026
  lemmas (see \secref{sec:unix-inv-lemmas}) according the the overall
4121cc8479f8 misc tuning and modernization;
wenzelm
parents: 60374
diff changeset
  1027
  procedure (see \secref{sec:unix-inv-procedure}).
58613
4a16f8e41879 more cartouches;
wenzelm
parents: 58310
diff changeset
  1028
\<close>
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
  1029
21029
b98fb9cf903b locale begin/end;
wenzelm
parents: 21001
diff changeset
  1030
corollary
62176
1221f2a46945 tuned syntax;
wenzelm
parents: 61893
diff changeset
  1031
  assumes bogus: "init users \<Midarrow>bogus\<Rightarrow> root"
53015
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
  1032
  shows "\<not> (\<exists>xs. (\<forall>x \<in> set xs. uid_of x = user\<^sub>1) \<and>
a1119cf551e8 standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents: 52979
diff changeset
  1033
    can_exec root (xs @ [Rmdir user\<^sub>1 [user\<^sub>1, name\<^sub>1]]))"
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
  1034
proof -
13380
ec17b9cac1fb adapted locales;
wenzelm
parents: 12079
diff changeset
  1035
  from cannot_rmdir init_invariant preserve_invariant
ec17b9cac1fb adapted locales;
wenzelm
parents: 12079
diff changeset
  1036
    and bogus show ?thesis by (rule general_procedure)
10966
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
  1037
qed
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
  1038
8f2c27041a8e added HOL-Unix example;
wenzelm
parents:
diff changeset
  1039
end
21029
b98fb9cf903b locale begin/end;
wenzelm
parents: 21001
diff changeset
  1040
b98fb9cf903b locale begin/end;
wenzelm
parents: 21001
diff changeset
  1041
end