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