Co2sobj_prop.thy
author chunhan
Thu, 16 May 2013 15:18:44 +0800
changeset 8 289a30c4cfb7
parent 7 f27882976251
child 10 ac66d8ba86d9
permissions -rw-r--r--
find bugs in deleted & inum_of_file

(*<*)
theory Co2sobj_prop
imports Main Flask Flask_type Static Static_type Sectxt_prop Init_prop Current_files_prop Current_sockets_prop Delete_prop
begin
(*<*)

context tainting_s begin

(****************** cf2sfile path simpset ***************)

lemma sroot_only:
  "cf2sfile s [] = Some sroot"
by (simp add:cf2sfile_def)

lemma not_file_is_dir:
  "\<lbrakk>\<not> is_file s f; f \<in> current_files s; valid s\<rbrakk> \<Longrightarrow> is_dir s f"
by (auto simp:is_file_def current_files_def is_dir_def 
         dest:finum_has_itag finum_has_ftag' split:t_inode_tag.splits option.splits)

lemma not_dir_is_file:
  "\<lbrakk>\<not> is_dir s f; f \<in> current_files s; valid s\<rbrakk> \<Longrightarrow> is_file s f"
by (auto simp:is_file_def current_files_def is_dir_def 
         dest:finum_has_itag finum_has_ftag' split:t_inode_tag.splits option.splits)

lemma is_file_or_dir:
  "\<lbrakk>f \<in> current_files s; valid s\<rbrakk> \<Longrightarrow> is_file s f \<or> is_dir s f"
by (auto dest:not_dir_is_file)

lemma current_file_has_sfile:
  "\<lbrakk>f \<in> current_files s; valid s\<rbrakk> \<Longrightarrow> \<exists> sf. cf2sfile s f = Some sf"
apply (induct f)
apply (rule_tac x = "sroot" in exI, simp add:sroot_only)
apply (frule parentf_in_current', simp, clarsimp)
apply (frule parentf_is_dir'', simp)
apply (frule is_file_or_dir, simp)
apply (auto dest!:current_has_sec'
            simp:cf2sfile_def split:option.splits if_splits dest!:get_pfs_secs_prop')
done

definition sectxt_of_pf :: "t_state \<Rightarrow> t_file \<Rightarrow> security_context_t option"
where
  "sectxt_of_pf s f = (case f of [] \<Rightarrow> None | (a # pf) \<Rightarrow> sectxt_of_obj s (O_dir pf))"

definition get_parentfs_ctxts' :: "t_state \<Rightarrow> t_file \<Rightarrow> (security_context_t list) option"
where
  "get_parentfs_ctxts' s f = (case f of [] \<Rightarrow> None | (a # pf) \<Rightarrow> get_parentfs_ctxts s pf)"

lemma is_file_has_sfile:
  "\<lbrakk>is_file s f; valid s\<rbrakk> \<Longrightarrow> \<exists> sec psec asecs. cf2sfile s f = Some 
      (if (\<not> deleted (O_file f) s \<and> is_init_file f) then Init f else Created,
       sec, Some psec, set asecs) \<and> (sectxt_of_obj s (O_file f) = Some sec) \<and>
       (sectxt_of_pf s f = Some psec) \<and> (get_parentfs_ctxts' s f = Some asecs)"
apply (case_tac f, simp, drule root_is_dir', simp, simp)
apply (frule is_file_in_current)
apply (drule current_file_has_sfile, simp)
apply (auto simp:cf2sfile_def sectxt_of_pf_def get_parentfs_ctxts'_def split:if_splits option.splits)
done

lemma is_dir_has_sfile:
  "\<lbrakk>is_dir s f; valid s\<rbrakk> \<Longrightarrow> (case f of
      [] \<Rightarrow> cf2sfile s f = Some sroot
    | a # pf \<Rightarrow> (\<exists> sec psec asecs. cf2sfile s f = Some 
      (if (\<not> deleted (O_dir f) s \<and> is_init_dir f) then Init f else Created,
       sec, Some psec, set asecs) \<and> (sectxt_of_obj s (O_dir f) = Some sec) \<and>
       (sectxt_of_obj s (O_dir pf) = Some psec) \<and> (get_parentfs_ctxts s pf = Some asecs)))"
apply (case_tac f, simp add:sroot_only)
apply (frule is_dir_in_current, frule is_dir_not_file)
apply (drule current_file_has_sfile, simp)
apply (auto simp:cf2sfile_def split:if_splits option.splits)
done

lemma sroot_set:
  "valid s \<Longrightarrow> \<exists> sec. sroot = (Init [], sec, None, {}) \<and> sectxt_of_obj s (O_dir []) = Some sec"
apply (frule root_is_dir)
apply (drule is_dir_has_sec, simp)
apply (auto simp:sroot_def sec_of_root_def sectxt_of_obj_def type_of_obj.simps 
                 root_type_remains root_user_remains
           dest!:root_has_type' root_has_user' root_has_init_type' root_has_init_user'
           split:option.splits)
done

lemma cf2sfile_path_file:
  "\<lbrakk>is_file s (f # pf); valid s\<rbrakk>
   \<Longrightarrow> cf2sfile s (f # pf) = (
     case (cf2sfile s pf) of
       Some (pfi, pfsec, psec, asecs) \<Rightarrow> 
          (case (sectxt_of_obj s (O_file (f # pf))) of
              Some fsec \<Rightarrow> Some (if (\<not> deleted (O_file (f # pf)) s \<and> is_init_file (f # pf)) then Init (f # pf)
                                else Created, fsec, Some pfsec, asecs \<union> {pfsec})
           | None \<Rightarrow> None)
     | _ \<Rightarrow> None)"
apply (frule is_file_in_current, drule parentf_is_dir'', simp)
apply (frule is_dir_has_sfile, simp, frule is_file_has_sfile, simp)
apply (frule sroot_set)
apply (case_tac pf, (clarsimp simp:get_parentfs_ctxts'_def sectxt_of_pf_def)+) 
done

lemma cf2sfile_path_dir:
  "\<lbrakk>is_dir s (f # pf); valid s\<rbrakk>
   \<Longrightarrow> cf2sfile s (f # pf) = (
     case (cf2sfile s pf) of
       Some (pfi, pfsec, psec, asecs) \<Rightarrow> 
          (case (sectxt_of_obj s (O_dir (f # pf))) of
              Some fsec \<Rightarrow> Some (if (\<not> deleted (O_dir (f # pf)) s \<and> is_init_dir (f # pf)) then Init (f # pf)
                                else Created, fsec, Some pfsec, asecs \<union> {pfsec})
           | None \<Rightarrow> None)
     | _ \<Rightarrow> None)"
apply (frule is_dir_in_current, drule parentf_is_dir'', simp)
apply (frule_tac f = "f # pf" in is_dir_has_sfile, simp)
apply (frule_tac f = "pf" in is_dir_has_sfile, simp)
apply (frule sroot_set)
apply (case_tac pf, (clarsimp simp:get_parentfs_ctxts'_def sectxt_of_pf_def)+) 
done  

lemma cf2sfile_path:
  "\<lbrakk>f # pf \<in> current_files s; valid s\<rbrakk> \<Longrightarrow> cf2sfile s (f # pf) = (
     case (cf2sfile s pf) of
       Some (pfi, pfsec, psec, asecs) \<Rightarrow> (if (is_file s (f # pf))
         then (case (sectxt_of_obj s (O_file (f # pf))) of
                 Some fsec \<Rightarrow> Some (if (\<not> deleted (O_file (f # pf)) s \<and> is_init_file (f # pf)) then Init (f # pf)
                                   else Created, fsec, Some pfsec, asecs \<union> {pfsec})
               | None \<Rightarrow> None)
         else (case (sectxt_of_obj s (O_dir (f # pf))) of
                 Some fsec \<Rightarrow> Some (if (\<not> deleted (O_dir (f # pf)) s \<and> is_init_dir (f # pf)) then Init (f # pf)
                                   else Created, fsec, Some pfsec, asecs \<union> {pfsec})
               | None \<Rightarrow> None)           )
     | None \<Rightarrow> None)"
apply (drule is_file_or_dir, simp)
apply (erule disjE)
apply (frule cf2sfile_path_file, simp) defer
apply (frule cf2sfile_path_dir, simp, drule is_dir_not_file)
apply (auto split:option.splits)
done

lemma cf2sfile_path_file_prop1:
  "\<lbrakk>is_file s (f # pf); cf2sfile s pf = Some (pfi, pfsec, psec, asecs); valid s\<rbrakk>
   \<Longrightarrow> \<exists> fsec. cf2sfile s (f # pf) = 
                 Some (if (\<not> deleted (O_file (f # pf)) s \<and> is_init_file (f # pf)) then Init (f # pf)
                       else Created, fsec, Some pfsec, asecs \<union> {pfsec}) \<and> 
               sectxt_of_obj s (O_file (f # pf)) = Some fsec"
apply (frule is_file_has_sfile, simp)
by (auto simp:cf2sfile_path_file)

lemma cf2sfile_path_file_prop2:
  "\<lbrakk>is_file s (f # pf); cf2sfile s pf = Some (pfi, pfsec, psec, asecs); 
    sectxt_of_obj s (O_file (f # pf)) = Some fsec; valid s\<rbrakk> \<Longrightarrow> cf2sfile s (f # pf) = 
      Some (if (\<not> deleted (O_file (f # pf)) s \<and> is_init_file (f # pf)) then Init (f # pf)
            else Created, fsec, Some pfsec, asecs \<union> {pfsec})"
by (drule cf2sfile_path_file_prop1, auto)

lemma cf2sfile_path_dir_prop1:
  "\<lbrakk>is_dir s (f # pf); cf2sfile s pf = Some (pfi, pfsec, psec, asecs); valid s\<rbrakk>
   \<Longrightarrow> \<exists> fsec. cf2sfile s (f # pf) = 
                 Some (if (\<not> deleted (O_dir (f # pf)) s \<and> is_init_dir (f # pf)) then Init (f # pf)
                       else Created, fsec, Some pfsec, asecs \<union> {pfsec}) \<and> 
               sectxt_of_obj s (O_dir (f # pf)) = Some fsec"
apply (frule is_dir_has_sfile, simp)
by (auto simp:cf2sfile_path_dir)

lemma cf2sfile_path_dir_prop2:
  "\<lbrakk>is_dir s (f # pf); cf2sfile s pf = Some (pfi, pfsec, psec, asecs); 
    sectxt_of_obj s (O_dir (f # pf)) = Some fsec; valid s\<rbrakk> \<Longrightarrow> cf2sfile s (f # pf) = 
      Some (if (\<not> deleted (O_dir (f # pf)) s \<and> is_init_dir (f # pf)) then Init (f # pf)
            else Created, fsec, Some pfsec, asecs \<union> {pfsec})"
by (drule cf2sfile_path_dir_prop1, auto)

(**************** cf2sfile event list simpset ****************)

lemma cf2sfile_open_none':
  "valid (Open p f flag fd None # s) \<Longrightarrow> cf2sfile (Open p f flag fd None # s) f'= cf2sfile s f'"
apply (frule vd_cons, frule vt_grant_os)
apply (induct f', simp add:cf2sfile_def)
apply (simp add:cf2sfile_def is_file_simps is_dir_simps current_files_simps sectxt_of_obj_simps 
               get_parentfs_ctxts_simps)
done

lemma cf2sfile_open_none:
  "valid (Open p f flag fd None # s) \<Longrightarrow> cf2sfile (Open p f flag fd None # s) = cf2sfile s"
apply (rule ext)
by (simp add:cf2sfile_open_none')

lemma cf2sfile_open_some1:
  "\<lbrakk>valid (Open p f flag fd (Some inum) # s); f' \<in> current_files s\<rbrakk>
   \<Longrightarrow> cf2sfile (Open p f flag fd (Some inum) # s) f' = cf2sfile s f'"
apply (frule vd_cons, frule vt_grant_os, frule noroot_events)
apply (case_tac "f = f'", simp)
apply (induct f', simp add:sroot_only, simp)
apply (frule parentf_in_current', simp+)
apply (simp add:cf2sfile_def is_file_simps is_dir_simps current_files_simps sectxt_of_obj_simps 
               get_parentfs_ctxts_simps)
done

lemma cf2sfile_open_some2:
  "\<lbrakk>valid (Open p f flag fd (Some inum) # s); is_file s f'\<rbrakk>
   \<Longrightarrow> cf2sfile (Open p f flag fd (Some inum) # s) f' = cf2sfile s f'"
apply (frule vd_cons, drule is_file_in_current)
by (simp add:cf2sfile_open_some1)

lemma cf2sfile_open_some3:
  "\<lbrakk>valid (Open p f flag fd (Some inum) # s); is_dir s f'\<rbrakk>
   \<Longrightarrow> cf2sfile (Open p f flag fd (Some inum) # s) f' = cf2sfile s f'"
apply (frule vd_cons, drule is_dir_in_current)
by (simp add:cf2sfile_open_some1)

lemma cf2sfile_open_some4:
  "valid (Open p f flag fd (Some inum) # s) \<Longrightarrow> cf2sfile (Open p f flag fd (Some inum) # s) f = (
     case (parent f) of
       Some pf \<Rightarrow> (case (sectxt_of_obj (Open p f flag fd (Some inum) # s) (O_file f), sectxt_of_obj s (O_dir pf), 
                         get_parentfs_ctxts s pf) of
                    (Some sec, Some psec, Some asecs) \<Rightarrow> Some (Created, sec, Some psec, set asecs)
                  | _ \<Rightarrow> None)
     | None \<Rightarrow> None)"
apply (frule vd_cons, frule vt_grant_os, frule noroot_events)
apply (case_tac f, simp)
apply (simp add:cf2sfile_def is_file_simps is_dir_simps current_files_simps sectxt_of_obj_simps 
               get_parentfs_ctxts_simps)
apply (rule impI, (erule conjE)+)
apply (drule not_deleted_init_file, simp+)
apply (simp add:is_file_in_current)
done

lemma cf2sfile_open:
  "\<lbrakk>valid (Open p f flag fd opt # s); f' \<in> current_files (Open p f flag fd opt # s)\<rbrakk>
   \<Longrightarrow> cf2sfile (Open p f flag fd opt # s) f' = (
     if (opt = None) then cf2sfile s f'
     else if (f' = f) 
     then (case (parent f) of
             Some pf \<Rightarrow> (case (sectxt_of_obj (Open p f flag fd opt # s) (O_file f), sectxt_of_obj s (O_dir pf), 
                 get_parentfs_ctxts s pf) of
                          (Some sec, Some psec, Some asecs) \<Rightarrow> Some (Created, sec, Some psec, set asecs)
                        | _ \<Rightarrow> None)
           | None \<Rightarrow> None)
     else cf2sfile s f')"
apply (case_tac opt)
apply (simp add:cf2sfile_open_none)
apply (case_tac "f = f'")
apply (simp add:cf2sfile_open_some4 split:option.splits)
apply (simp add:cf2sfile_open_some1 current_files_simps)
done

lemma cf2sfile_mkdir1:
  "\<lbrakk>valid (Mkdir p f i # s); f' \<in> current_files s\<rbrakk>
   \<Longrightarrow> cf2sfile (Mkdir p f i # s) f' = cf2sfile s f'"
apply (frule vd_cons, frule vt_grant_os, frule noroot_events)
apply (case_tac "f = f'", simp)
apply (induct f', simp add:sroot_only, simp)
apply (frule parentf_in_current', simp+)
apply (case_tac "f = f'", simp)
apply (simp add:cf2sfile_path is_file_simps is_dir_simps current_files_simps sectxt_of_obj_simps 
               get_parentfs_ctxts_simps split:if_splits option.splits)
done

lemma cf2sfile_mkdir2:
  "\<lbrakk>valid (Mkdir p f i # s); is_file s f'\<rbrakk>
   \<Longrightarrow> cf2sfile (Mkdir p f i # s) f' = cf2sfile s f'"
apply (frule vd_cons, drule is_file_in_current)
by (simp add:cf2sfile_mkdir1)

lemma cf2sfile_mkdir3:
  "\<lbrakk>valid (Mkdir p f i # s); is_dir s f'\<rbrakk>
   \<Longrightarrow> cf2sfile (Mkdir p f i # s) f' = cf2sfile s f'"
apply (frule vd_cons, drule is_dir_in_current)
by (simp add:cf2sfile_mkdir1)

lemma cf2sfile_mkdir4:
  "valid (Mkdir p f i # s)
  \<Longrightarrow> cf2sfile (Mkdir p f i # s) f = (case (parent f) of
         Some pf \<Rightarrow> (case (sectxt_of_obj (Mkdir p f i # s) (O_dir f), sectxt_of_obj s (O_dir pf), 
                           get_parentfs_ctxts s pf) of
                      (Some sec, Some psec, Some asecs) \<Rightarrow> Some (Created, sec, Some psec, set asecs)
                    | _ \<Rightarrow> None)
       | None \<Rightarrow> None)"
apply (frule vd_cons, frule vt_grant_os, frule noroot_events)
apply (case_tac f, simp)
apply (clarsimp simp:os_grant.simps)
apply (simp add:sectxt_of_obj_simps)
apply (frule current_proc_has_sec, simp)
apply (frule is_dir_has_sec, simp)
apply (frule get_pfs_secs_prop, simp)
apply (frule is_dir_not_file)
apply (auto simp add:cf2sfile_def is_file_simps is_dir_simps current_files_simps sectxt_of_obj_simps 
               get_parentfs_ctxts_simps split:option.splits if_splits 
            dest:not_deleted_init_dir is_dir_in_current not_deleted_init_file is_file_in_current)
done

lemma cf2sfile_mkdir:
  "\<lbrakk>valid (Mkdir p f i # s); f' \<in> current_files (Mkdir p f i # s)\<rbrakk>
  \<Longrightarrow> cf2sfile (Mkdir p f i # s) f' = (
    if (f' = f) 
    then (case (parent f) of
             Some pf \<Rightarrow> (case (sectxt_of_obj (Mkdir p f i # s) (O_dir f), sectxt_of_obj s (O_dir pf), 
                 get_parentfs_ctxts s pf) of
                          (Some sec, Some psec, Some asecs) \<Rightarrow> Some (Created, sec, Some psec, set asecs)
                        | _ \<Rightarrow> None)
           | None \<Rightarrow> None)
     else cf2sfile s f')"
apply (case_tac "f = f'")
apply (simp add:cf2sfile_mkdir4 split:option.splits)
apply (simp add:cf2sfile_mkdir1 current_files_simps)
done

lemma cf2sfile_linkhard1:
  "\<lbrakk>valid (LinkHard p oldf f # s); f' \<in> current_files s\<rbrakk>
   \<Longrightarrow> cf2sfile (LinkHard p oldf f# s) f' = cf2sfile s f'"
apply (frule vd_cons, frule vt_grant_os, frule noroot_events)
apply (case_tac "f = f'", simp)
apply (induct f', simp add:sroot_only, simp)
apply (frule parentf_in_current', simp+)
apply (simp add:cf2sfile_def is_file_simps is_dir_simps current_files_simps sectxt_of_obj_simps 
               get_parentfs_ctxts_simps split:if_splits option.splits)
done

lemma cf2sfile_linkhard2:
  "\<lbrakk>valid (LinkHard p oldf f # s); is_file s f'\<rbrakk>
   \<Longrightarrow> cf2sfile (LinkHard p oldf f # s) f' = cf2sfile s f'"
apply (frule vd_cons, drule is_file_in_current)
by (simp add:cf2sfile_linkhard1)

lemma cf2sfile_linkhard3:
  "\<lbrakk>valid (LinkHard p oldf f # s); is_dir s f'\<rbrakk>
   \<Longrightarrow> cf2sfile (LinkHard p oldf f # s) f' = cf2sfile s f'"
apply (frule vd_cons, drule is_dir_in_current)
by (simp add:cf2sfile_linkhard1)

lemma cf2sfile_linkhard4:
  "valid (LinkHard p oldf f # s)
  \<Longrightarrow> cf2sfile (LinkHard p oldf f # s) f = (case (parent f) of
         Some pf \<Rightarrow> (case (sectxt_of_obj (LinkHard p oldf f # s) (O_file f), sectxt_of_obj s (O_dir pf), 
                           get_parentfs_ctxts s pf) of
                      (Some sec, Some psec, Some asecs) \<Rightarrow> Some (Created, sec, Some psec, set asecs)
                    | _ \<Rightarrow> None)
       | None \<Rightarrow> None)"
apply (frule vd_cons, frule vt_grant_os, frule noroot_events)
apply (case_tac f, simp)
apply (simp add:cf2sfile_def is_file_simps is_dir_simps current_files_simps sectxt_of_obj_simps 
               get_parentfs_ctxts_simps)
apply (rule impI, (erule conjE)+)
apply (drule not_deleted_init_file, simp+)
apply (simp add:is_file_in_current)
done

lemma cf2sfile_linkhard:
  "\<lbrakk>valid (LinkHard p oldf f # s); f' \<in> current_files (LinkHard p oldf f # s)\<rbrakk>
  \<Longrightarrow> cf2sfile (LinkHard p oldf f # s) f' = (
    if (f' = f) 
    then (case (parent f) of
             Some pf \<Rightarrow> (case (sectxt_of_obj (LinkHard p oldf f # s) (O_file f), sectxt_of_obj s (O_dir pf), 
                 get_parentfs_ctxts s pf) of
                          (Some sec, Some psec, Some asecs) \<Rightarrow> Some (Created, sec, Some psec, set asecs)
                        | _ \<Rightarrow> None)
           | None \<Rightarrow> None)
     else cf2sfile s f')"
apply (case_tac "f = f'")
apply (simp add:cf2sfile_linkhard4 split:option.splits)
apply (simp add:cf2sfile_linkhard1 current_files_simps)
done

lemma cf2sfile_other:
  "\<lbrakk>ff \<in> current_files s;
    \<forall> p f flag fd opt. e \<noteq> Open p f flag fd opt;
    \<forall> p fd. e \<noteq> CloseFd p fd;
    \<forall> p f. e \<noteq> UnLink p f;
    \<forall> p f. e \<noteq> Rmdir p f;
    \<forall> p f i. e \<noteq> Mkdir p f i;
    \<forall> p f f'. e \<noteq> LinkHard p f f'; 
    valid (e # s)\<rbrakk> \<Longrightarrow> cf2sfile (e # s) ff = cf2sfile s ff"
apply (frule vd_cons, frule vt_grant_os)
apply (induct ff, simp add:sroot_only)
apply (frule parentf_in_current', simp+, case_tac e)
apply (auto simp:current_files_simps is_file_simps is_dir_simps sectxt_of_obj_simps cf2sfile_path 
           split:if_splits option.splits)                     
done     

lemma cf2sfile_unlink:
  "\<lbrakk>valid (UnLink p f # s); f' \<in> current_files (UnLink p f # s)\<rbrakk>
   \<Longrightarrow> cf2sfile (UnLink p f # s) f' = cf2sfile s f'"
apply (frule vd_cons, frule vt_grant_os)
apply (simp add:current_files_simps split:if_splits)
apply (auto simp:cf2sfile_def sectxt_of_obj_simps get_parentfs_ctxts_simps is_file_simps is_dir_simps
 split:if_splits option.splits)


lemmas cf2sfile_simps = cf2sfile_open cf2sfile_mkdir cf2sfile_linkhard cf2sfile_other
  














lemma cf2sfile_keep_path: "\<lbrakk>f \<preceq> f'; \<tau> \<in> vt rc_cs\<rbrakk> \<Longrightarrow> cf2sfile \<tau> f \<preceq> cf2sfile \<tau> f'"
apply (induct f', simp add:no_junior_def)
apply (case_tac "f = a # f'", simp add:cf2sfile.simps)
apply (drule no_junior_noteq, simp, simp add:cf2sfile.simps)
done

lemma ckp'_aux: "\<not> f \<preceq> a # f' \<Longrightarrow> \<not> f \<preceq> f'"
by (auto simp:no_junior_def)

lemma cf2sfile_keep_path': "\<lbrakk>\<not> f \<preceq> f'; \<tau> \<in> vt rc_cs; f \<in> current_files \<tau>; f' \<in> current_files \<tau>\<rbrakk> \<Longrightarrow> \<not> cf2sfile \<tau> f \<preceq> cf2sfile \<tau> f'"
apply (induct f', simp add:no_junior_def cf2sfile.simps, rule notI, drule cf2sfile_root_file, simp)
apply (case_tac "f = a # f'", simp add:cf2sfile.simps)
apply (rule notI)
apply (frule ckp'_aux, simp, frule parentf_in_current', simp+)
apply (case_tac "cf2sfile \<tau> f = cf2sfile \<tau> (a # f')", drule cf2sfile_inj, simp+)
apply (simp add:cf2sfile.simps)
by (drule no_junior_noteq, simp+)

lemma cf2sfile_keep_path'': "\<lbrakk>cf2sfile \<tau> f \<preceq> cf2sfile \<tau> f'; \<tau> \<in> vt rc_cs; f \<in> current_files \<tau>; f' \<in> current_files \<tau>\<rbrakk> \<Longrightarrow> f \<preceq> f'"
using cf2sfile_keep_path'
by (auto)

lemma cf2sfile_open_some': "\<lbrakk>f \<in> current_files \<tau>; Open p f' flags fd (Some inum) # \<tau> \<in> vt rc_cs\<rbrakk> \<Longrightarrow> cf2sfile (Open p f' flags fd (Some inum) # \<tau>) f = cf2sfile \<tau> f"
apply (frule vt_cons')
apply (drule vt_grant_os)
apply (induct f)
apply (simp add:cf2sfile.simps)+
apply (frule parentf_in_current', simp)
apply (auto simp:os_grant.simps index_of_file.simps split:option.splits)
done

lemma cf2sfile_open_some: "\<lbrakk>Open p f flags fd (Some inum) # \<tau> \<in> vt rc_cs; parent f = Some pf\<rbrakk> 
                           \<Longrightarrow> cf2sfile (Open p f flags fd (Some inum) # \<tau>) f = (SCrea (Suc (length \<tau>)) # (cf2sfile \<tau> pf))"
apply (case_tac f, simp)
apply (frule vt_grant_os)
apply (simp add:cf2sfile.simps os_grant.simps current_files_simps index_of_file.simps cf2sfile_open_some')
done

lemma cf2sfile_open_none: "cf2sfile (Open p f flags fd None # \<tau>) f' = cf2sfile \<tau> f'"
apply (induct f')
by (simp add:cf2sfile.simps index_of_file.simps split:option.splits nat.splits)+

lemma cf2sfile_open: "\<lbrakk>Open p f flags fd opt # \<tau> \<in> vt rc_cs; f' \<in> current_files (Open p f flags fd opt # \<tau>)\<rbrakk> \<Longrightarrow> 
                       cf2sfile (Open p f flags fd opt # \<tau>) f' = (
                         if (opt = None) then cf2sfile \<tau> f'
                         else if (f' = f) then (case (parent f) of
                                                  Some pf \<Rightarrow> (SCrea (Suc (length \<tau>)) # (cf2sfile \<tau> pf))
                                                | _       \<Rightarrow> [])
                              else cf2sfile \<tau> f'                                                          )"
apply (frule vt_grant_os)
by (auto simp:os_grant.simps current_files_simps intro:cf2sfile_open_none cf2sfile_open_some cf2sfile_open_some' split:if_splits option.splits)

lemma cf2sfile_mkdir_some': "\<lbrakk>Mkdir p f' inum # \<tau> \<in> vt rc_cs; f \<in> current_files \<tau>\<rbrakk> \<Longrightarrow> cf2sfile (Mkdir p f' inum # \<tau>) f = cf2sfile \<tau> f"
apply (frule vt_cons', drule vt_grant_os)
apply (induct f, (simp add:cf2sfile.simps)+)
apply (frule parentf_in_current', simp)
apply (auto simp:os_grant.simps index_of_file.simps split:option.splits)
done

lemma cf2sfile_mkdir_some: "\<lbrakk>Mkdir p f inum # \<tau> \<in> vt rc_cs; parent f = Some pf\<rbrakk>
                             \<Longrightarrow> cf2sfile (Mkdir p f inum # \<tau>) f = (SCrea (Suc (length \<tau>)) # (cf2sfile \<tau> pf))"
apply (case_tac f, simp)
apply (frule vt_grant_os)
apply (simp add:cf2sfile.simps os_grant.simps current_files_simps index_of_file.simps cf2sfile_mkdir_some')
done

lemma cf2sfile_mkdir: "\<lbrakk>Mkdir p f inum # \<tau> \<in> vt rc_cs; f' \<in> current_files (Mkdir p f inum # \<tau>)\<rbrakk> \<Longrightarrow>
                        cf2sfile (Mkdir p f inum # \<tau>) f' = (
                          if (f' = f) then (case (parent f) of
                                              Some pf \<Rightarrow> (SCrea (Suc (length \<tau>)) # (cf2sfile \<tau> pf))
                                            | _       \<Rightarrow> [])
                          else cf2sfile \<tau> f'               ) "
apply (frule vt_grant_os)
by (auto simp:os_grant.simps current_files_simps intro:cf2sfile_mkdir_some cf2sfile_mkdir_some' split:if_splits option.splits)

lemma cf2sfile_linkhard_none: "\<lbrakk>LinkHard p f\<^isub>1 f\<^isub>2 # \<tau> \<in> vt rc_cs; f \<in> current_files \<tau>\<rbrakk> \<Longrightarrow> cf2sfile (LinkHard p f\<^isub>1 f\<^isub>2 # \<tau>) f = cf2sfile \<tau> f"
apply (frule vt_cons')
apply (drule vt_grant_os)
apply (induct f)
apply (simp add:cf2sfile.simps)+
apply (frule parentf_in_current', simp)
apply (auto simp:os_grant.simps index_of_file.simps split:option.splits)
done

lemma cf2sfile_linkhard_some: 
  "\<lbrakk>LinkHard p f\<^isub>1 f\<^isub>2 # \<tau> \<in> vt rc_cs; parent f\<^isub>2 = Some pf\<^isub>2\<rbrakk> \<Longrightarrow> cf2sfile (LinkHard p f\<^isub>1 f\<^isub>2 # \<tau>) f\<^isub>2 = (SCrea (Suc (length \<tau>)) # (cf2sfile \<tau> pf\<^isub>2))"
apply (case_tac f\<^isub>2, simp)
apply (frule vt_grant_os)
apply (simp add:cf2sfile.simps os_grant.simps current_files_simps index_of_file.simps cf2sfile_linkhard_none)
done

lemma cf2sfile_linkhard: "\<lbrakk>LinkHard p f\<^isub>1 f\<^isub>2 # \<tau> \<in> vt rc_cs; f \<in> current_files (LinkHard p f\<^isub>1 f\<^isub>2 # \<tau>)\<rbrakk> \<Longrightarrow>
                           cf2sfile (LinkHard p f\<^isub>1 f\<^isub>2 # \<tau>) f = (
                             if (f = f\<^isub>2) then (case (parent f\<^isub>2) of
                                                 Some pf\<^isub>2 \<Rightarrow> SCrea (Suc (length \<tau>)) # (cf2sfile \<tau> pf\<^isub>2)
                                               | _        \<Rightarrow> [])
                             else cf2sfile \<tau> f                 )"
apply (frule vt_grant_os)
by (auto simp:os_grant.simps current_files_simps intro:cf2sfile_linkhard_none cf2sfile_linkhard_some split:if_splits option.splits)


lemma no_junior_aux: "\<not> f\<^isub>2 \<preceq> a # f \<Longrightarrow> \<not> f\<^isub>2 \<preceq> f"
by (auto simp:no_junior_def)

lemma cf2sfile_rename_aux: "\<lbrakk>Rename p f\<^isub>2 f\<^isub>3 # \<tau> \<in> vt rc_cs; f \<in> current_files \<tau>\<rbrakk> \<Longrightarrow> f \<noteq> f\<^isub>3 \<and> \<not> f\<^isub>3 \<preceq> f"
apply (frule vt_grant_os, simp add:os_grant.simps, (erule exE|erule conjE)+)
apply (rule conjI, rule notI, simp)
apply (rule notI, drule vt_cons', simp add:ancenf_in_current)
done

lemma cf2sfile_rename'1: 
  "\<lbrakk>Rename p f\<^isub>2 f\<^isub>3 # \<tau> \<in> vt rc_cs; f \<in> current_files \<tau>; \<not> (f\<^isub>2 \<preceq> f)\<rbrakk> \<Longrightarrow> cf2sfile (Rename p f\<^isub>2 f\<^isub>3 # \<tau>) f = cf2sfile \<tau> f"
apply (frule vt_cons',frule vt_grant_os,  induct f)
apply (simp add:cf2sfile.simps)
apply (frule parentf_in_current', simp, simp)
apply (frule no_junior_aux, simp)
apply (simp add:os_grant.simps, (erule exE|erule conjE)+)
apply (drule cf2sfile_rename_aux, simp, erule conjE)
apply (auto simp add:cf2sfile.simps index_of_file.simps split:option.splits nat.splits)
done

lemma cf2sfile_rename'2: 
  "\<lbrakk>Rename p f\<^isub>2 f\<^isub>3 # \<tau> \<in> vt rc_cs; \<not> (f\<^isub>3 \<preceq> f)\<rbrakk> \<Longrightarrow> cf2sfile (Rename p f\<^isub>2 f\<^isub>3 # \<tau>) f = cf2sfile \<tau> f"
apply (frule vt_cons', induct f)
by (auto simp add:index_of_file.simps cf2sfile.simps no_junior_def split:option.splits nat.splits)

lemma cf2sfile_rename1:
  "\<lbrakk>Rename p f\<^isub>2 f\<^isub>3 # \<tau> \<in> vt rc_cs; parent f\<^isub>3 = Some pf\<^isub>3\<rbrakk> \<Longrightarrow> cf2sfile (Rename p f\<^isub>2 f\<^isub>3 # \<tau>) f\<^isub>3 = SCrea (Suc (length \<tau>)) # (cf2sfile \<tau> pf\<^isub>3)"
apply (case_tac f\<^isub>3, simp add:cf2sfile.simps)
apply (auto dest!:cf2sfile_rename'2 simp add:no_junior_def cf2sfile.simps index_of_file.simps split:option.splits)
done

lemma index_of_file_rename1: "\<lbrakk>f\<^isub>2 \<preceq> f; f \<noteq> f\<^isub>2\<rbrakk> \<Longrightarrow> index_of_file (Rename p f\<^isub>2 f\<^isub>3 # \<tau>) (file_after_rename f\<^isub>2 f\<^isub>3 f) = index_of_file \<tau> f"
apply (clarsimp simp add:index_of_file.simps split:option.splits)
by (frule_tac f\<^isub>3 = f\<^isub>3 in file_renaming_prop3, simp, erule conjE, simp add:file_renaming_prop5)

lemma cf2sfile_rename2: "\<lbrakk>Rename p f\<^isub>2 f\<^isub>3 # \<tau> \<in> vt rc_cs; (file_before_rename f\<^isub>2 f\<^isub>3 f) \<in> current_files \<tau>; parent f\<^isub>3 = Some pf\<^isub>3; f\<^isub>3 \<preceq> f\<rbrakk> 
   \<Longrightarrow> cf2sfile (Rename p f\<^isub>2 f\<^isub>3 # \<tau>) f = file_after_rename (cf2sfile \<tau> f\<^isub>2) (SCrea (Suc (length \<tau>)) # (cf2sfile \<tau> pf\<^isub>3)) (cf2sfile \<tau> (file_before_rename f\<^isub>2 f\<^isub>3 f))"
apply (induct f, simp add:no_junior_def)
apply (case_tac "a # f = f\<^isub>3", simp)
apply (drule cf2sfile_rename1, simp, simp add:file_renaming_prop0' file_renaming_prop0)

apply (frule no_junior_noteq, simp, simp)
apply (frule_tac file_renaming_prop1')
apply (frule_tac f = f\<^isub>2 and \<tau> = \<tau> in cf2sfile_keep_path, simp add:vt_cons')
apply (frule_tac f\<^isub>2 = f\<^isub>2 and a = a in file_renaming_prop8')
apply (frule_tac f\<^isub>2 = f\<^isub>2 and a = a in file_renaming_prop6')
apply (frule_tac f = "file_before_rename f\<^isub>2 f\<^isub>3 (a # f)" and \<tau> = \<tau> and f\<^isub>2 = f\<^isub>2 and f\<^isub>3 = f\<^isub>3 and p = p in index_of_file_rename1, simp add:file_before_rename_def)
apply (drule_tac f\<^isub>3 = f\<^isub>3 and f\<^isub>1 = f and a = a and f\<^isub>2 = f\<^isub>2 in file_renaming_prop9', simp)
apply (drule parentf_in_current', simp add:vt_cons')
apply (simp add:cf2sfile.simps)
apply (erule file_renaming_prop6[THEN sym])
done

lemma cf2sfile_rename2': "\<lbrakk>Rename p f\<^isub>2 f\<^isub>3 # \<tau> \<in> vt rc_cs; f \<in> current_files \<tau>; parent f\<^isub>3 = Some pf\<^isub>3; f\<^isub>2 \<preceq> f\<rbrakk> 
   \<Longrightarrow> cf2sfile (Rename p f\<^isub>2 f\<^isub>3 # \<tau>) (file_after_rename f\<^isub>2 f\<^isub>3 f) = file_after_rename (cf2sfile \<tau> f\<^isub>2) (SCrea (Suc (length \<tau>)) # (cf2sfile \<tau> pf\<^isub>3)) (cf2sfile \<tau> f)"
apply (frule_tac f\<^isub>3 = f\<^isub>3 in file_renaming_prop5)
apply (frule_tac f\<^isub>3 = f\<^isub>3 in file_renaming_prop1)
apply (drule_tac f = "file_after_rename f\<^isub>2 f\<^isub>3 f" in cf2sfile_rename2, simp+)
done

lemma cf2sfile_rename3: "\<lbrakk>Rename p f\<^isub>2 f\<^isub>3 # \<tau> \<in> vt rc_cs; f \<in> current_files \<tau>; parent f\<^isub>3 = Some pf\<^isub>3\<rbrakk> 
   \<Longrightarrow> cf2sfile (Rename p f\<^isub>2 f\<^isub>3 # \<tau>) (file_after_rename f\<^isub>2 f\<^isub>3 f) = file_after_rename (cf2sfile \<tau> f\<^isub>2) (SCrea (Suc (length \<tau>)) # (cf2sfile \<tau> pf\<^isub>3)) (cf2sfile \<tau> f)"
apply (case_tac "f\<^isub>2 \<preceq> f")
apply (rule cf2sfile_rename2', simp+)
apply (frule vt_grant_os)
apply (frule_tac \<tau> = \<tau> in cf2sfile_keep_path', simp add:vt_cons', simp add:os_grant.simps, simp)
apply (simp add:file_after_rename_def)
by (rule cf2sfile_rename'1, simp+)

lemma cf2sfile_rename: "\<lbrakk>Rename p f\<^isub>2 f\<^isub>3 # \<tau> \<in> vt rc_cs; f \<in> current_files (Rename p f\<^isub>2 f\<^isub>3 # \<tau>)\<rbrakk> \<Longrightarrow>
                         cf2sfile (Rename p f\<^isub>2 f\<^isub>3 # \<tau>) f = (
                           if (f\<^isub>3 \<preceq> f) then (case (parent f\<^isub>3) of 
                                               Some pf\<^isub>3 \<Rightarrow> file_after_rename (cf2sfile \<tau> f\<^isub>2) (SCrea (Suc (length \<tau>)) # (cf2sfile \<tau> pf\<^isub>3)) (cf2sfile \<tau> (file_before_rename f\<^isub>2 f\<^isub>3 f))
                                             | _        \<Rightarrow> [])
                           else cf2sfile \<tau> f               )"
apply (frule vt_grant_os)
apply (case_tac "f = f\<^isub>3", clarsimp simp:os_grant.simps, drule cf2sfile_rename1, simp+, simp add:file_renaming_prop0' file_renaming_prop0)

apply (auto simp:os_grant.simps current_files_simps intro:cf2sfile_rename'2 cf2sfile_rename1 split:if_splits option.splits) 
apply (rule cf2sfile_rename2, simp, drule rename_renaming_decom, simp+)
apply (drule_tac f\<^isub>2 = f\<^isub>2 and f\<^isub>1 = f\<^isub>1 and f\<^isub>3 = f\<^isub>3 in file_renaming_prop5, simp+)
done

lemma cf2sfile_other: "\<lbrakk>
                        \<forall> p f flags fd opt. e \<noteq> Open p f flags fd opt;
                        \<forall> p f im. e \<noteq> Mkdir p f im;
                        \<forall> p f\<^isub>1 f\<^isub>2. e \<noteq> LinkHard p f\<^isub>1 f\<^isub>2;
                        \<forall> p f\<^isub>2 f\<^isub>3. e \<noteq> Rename p f\<^isub>2 f\<^isub>3\<rbrakk> \<Longrightarrow> cf2sfile (e # \<tau>) f' = cf2sfile \<tau> f'"
apply (induct f', simp add:cf2sfile.simps index_of_file.simps split:option.splits nat.splits)
apply (case_tac e, auto simp add:cf2sfile.simps index_of_file.simps split:option.splits nat.splits)
done

lemmas cf2sfile_nil = init_cf2sfile

lemma cf2sfile_nil': "f \<in> current_files [] \<Longrightarrow> cf2sfile [] f = map SInit f"
by (simp add:cf2sfile_nil current_files_simps)

lemmas cf2sfile_simps = cf2sfile_nil cf2sfile_nil' cf2sfile_open cf2sfile_mkdir cf2sfile_linkhard cf2sfile_rename cf2sfile_other

lemmas cf2sfile_simpss = cf2sfile_nil cf2sfile_nil' cf2sfile_open_some' cf2sfile_open_some cf2sfile_open_none cf2sfile_open cf2sfile_mkdir_some' cf2sfile_mkdir_some
                         cf2sfile_mkdir cf2sfile_linkhard_none cf2sfile_linkhard_some cf2sfile_linkhard cf2sfile_rename'1 cf2sfile_rename'2 cf2sfile_rename1
                         cf2sfile_rename2 cf2sfile_rename2' cf2sfile_rename3 cf2sfile_rename cf2sfile_other

lemma cf2sfile_open_some'_inum: "\<lbrakk>Open p f' flags fd (Some inum) # \<tau> \<in> vt rc_cs; inum_of_file \<tau> f = Some im\<rbrakk> \<Longrightarrow> cf2sfile (Open p f' flags fd (Some inum) # \<tau>) f = cf2sfile \<tau> f"
by (simp add:cf2sfile_open_some' current_files_def)

lemma cf2sfile_mkdir_some'_inum: "\<lbrakk>Mkdir p f' inum # \<tau> \<in> vt rc_cs; inum_of_file \<tau> f = Some im\<rbrakk> \<Longrightarrow> cf2sfile (Mkdir p f' inum # \<tau>) f = cf2sfile \<tau> f"
by (simp add:cf2sfile_mkdir_some' current_files_def)

lemma cf2sfile_linkhard_none_inum: "\<lbrakk>LinkHard p f\<^isub>1 f\<^isub>2 # \<tau> \<in> vt rc_cs; inum_of_file \<tau> f = Some im\<rbrakk> \<Longrightarrow> cf2sfile (LinkHard p f\<^isub>1 f\<^isub>2 # \<tau>) f = cf2sfile \<tau> f"
by (simp add:cf2sfile_linkhard_none current_files_def)

lemma cf2sfile_rename'1_inum: 
  "\<lbrakk>Rename p f\<^isub>2 f\<^isub>3 # \<tau> \<in> vt rc_cs; inum_of_file \<tau> f = Some im ; \<not> (f\<^isub>2 \<preceq> f)\<rbrakk> \<Longrightarrow> cf2sfile (Rename p f\<^isub>2 f\<^isub>3 # \<tau>) f = cf2sfile \<tau> f"
by (simp add:cf2sfile_rename'1 current_files_def)

lemma cf2sfile_rename2_inum: "\<lbrakk>Rename p f\<^isub>2 f\<^isub>3 # \<tau> \<in> vt rc_cs; inum_of_file \<tau> (file_before_rename f\<^isub>2 f\<^isub>3 f) = Some im; parent f\<^isub>3 = Some pf\<^isub>3; f\<^isub>3 \<preceq> f\<rbrakk> 
   \<Longrightarrow> cf2sfile (Rename p f\<^isub>2 f\<^isub>3 # \<tau>) f = file_after_rename (cf2sfile \<tau> f\<^isub>2) (SCrea (Suc (length \<tau>)) # (cf2sfile \<tau> pf\<^isub>3)) (cf2sfile \<tau> (file_before_rename f\<^isub>2 f\<^isub>3 f))"
by (simp add:cf2sfile_rename2 current_files_def)

lemma cf2sfile_rename2'_inum: "\<lbrakk>Rename p f\<^isub>2 f\<^isub>3 # \<tau> \<in> vt rc_cs; inum_of_file \<tau> f = Some im; parent f\<^isub>3 = Some pf\<^isub>3; f\<^isub>2 \<preceq> f\<rbrakk> 
   \<Longrightarrow> cf2sfile (Rename p f\<^isub>2 f\<^isub>3 # \<tau>) (file_after_rename f\<^isub>2 f\<^isub>3 f) = file_after_rename (cf2sfile \<tau> f\<^isub>2) (SCrea (Suc (length \<tau>)) # (cf2sfile \<tau> pf\<^isub>3)) (cf2sfile \<tau> f)"
by (simp add:cf2sfile_rename2' current_files_def)

lemma cf2sfile_rename3_inum: "\<lbrakk>Rename p f\<^isub>2 f\<^isub>3 # \<tau> \<in> vt rc_cs; inum_of_file \<tau> f = Some im; parent f\<^isub>3 = Some pf\<^isub>3\<rbrakk> 
   \<Longrightarrow> cf2sfile (Rename p f\<^isub>2 f\<^isub>3 # \<tau>) (file_after_rename f\<^isub>2 f\<^isub>3 f) = file_after_rename (cf2sfile \<tau> f\<^isub>2) (SCrea (Suc (length \<tau>)) # (cf2sfile \<tau> pf\<^isub>3)) (cf2sfile \<tau> f)"
by (simp add:cf2sfile_rename3 current_files_def)

lemma cf2sfile_nil'_inum: "inum_of_file [] f = Some im \<Longrightarrow> cf2sfile [] f = map SInit f"
by (simp add:cf2sfile_nil' current_files_def)

lemmas cf2sfile_simps_inum = cf2sfile_nil cf2sfile_nil'_inum cf2sfile_open_some'_inum cf2sfile_open_some cf2sfile_open_none cf2sfile_open cf2sfile_mkdir_some'_inum cf2sfile_mkdir_some
                         cf2sfile_mkdir cf2sfile_linkhard_none_inum cf2sfile_linkhard_some cf2sfile_linkhard cf2sfile_rename'1_inum cf2sfile_rename'2 cf2sfile_rename1
                         cf2sfile_rename2_inum cf2sfile_rename2'_inum cf2sfile_rename3_inum cf2sfile_rename cf2sfile_other

(*************** cp2sproc simpset *********************)

lemma cp2sproc_nil: "p \<in> init_processes \<Longrightarrow> cp2sproc [] p = SInit p"
by (simp add:cp2sproc_def index_of_proc.simps)

lemma cp2sproc_nil': "p \<in> current_procs [] \<Longrightarrow> cp2sproc [] p = SInit p"
by (simp add:cp2sproc_nil current_procs.simps)

lemma cp2sproc_clone: "cp2sproc (Clone p p' # \<tau>) p'' = (
                         if (p'' = p') then SCrea (Suc (length \<tau>))
                         else cp2sproc \<tau> p''           )"
by (auto simp:cp2sproc_def index_of_proc.simps d2s_aux.simps)

lemma cp2sproc_other: "\<forall> p p'. e \<noteq> Clone p p' \<Longrightarrow> cp2sproc (e # \<tau>) p'' = cp2sproc \<tau> p''"
apply (case_tac e)
by (auto simp:cp2sproc_def index_of_proc.simps d2s_aux.simps)

lemmas cp2sproc_simps = cp2sproc_nil cp2sproc_nil' cp2sproc_clone cp2sproc_other

(******************** ch2sshm simpset **************************)

lemma ch2sshm_nil: "h \<in> init_shms \<Longrightarrow> ch2sshm [] h = SInit h"
by (simp add:ch2sshm_def index_of_shm.simps)

lemma ch2sshm_nil': "h \<in> current_shms [] \<Longrightarrow> ch2sshm [] h = SInit h"
by (simp add:ch2sshm_nil current_shms.simps)

lemma ch2sshm_createshm: "ch2sshm (CreateShM p h # \<tau>) h' = (if (h' = h) then SCrea (Suc (length \<tau>)) else ch2sshm \<tau> h')"
by (simp add:ch2sshm_def index_of_shm.simps d2s_aux.simps) 

lemma ch2sshm_other: "\<forall> p h. e \<noteq> CreateShM p h \<Longrightarrow> ch2sshm (e # \<tau>) h' = ch2sshm \<tau> h'"
apply (case_tac e)
by (auto simp add:ch2sshm_def index_of_shm.simps d2s_aux.simps) 

lemmas ch2sshm_simps = ch2sshm_nil ch2sshm_nil' ch2sshm_createshm ch2sshm_other

(********************* cm2smsg simpset ***********************)

lemma cm2smsg_nil: "m \<in> init_msgs \<Longrightarrow> cm2smsg [] m = SInit m"
by (simp add:cm2smsg_def index_of_msg.simps)

lemma cm2smsg_nil': "m \<in> current_msgs [] \<Longrightarrow> cm2smsg [] m = SInit m"
by (simp add:cm2smsg_nil current_msgs.simps)

lemma cm2smsg_createmsg: "cm2smsg (CreateMsg p m # \<tau>) m' = (if (m' = m) then SCrea (Suc (length \<tau>)) else cm2smsg \<tau> m')"
by (simp add:cm2smsg_def index_of_msg.simps d2s_aux.simps)

lemma cm2smsg_other: "\<forall> p m. e \<noteq> CreateMsg p m \<Longrightarrow> cm2smsg (e # \<tau>) m' = cm2smsg \<tau> m'"
apply (case_tac e)
by (auto simp:cm2smsg_def index_of_msg.simps d2s_aux.simps)

lemmas cm2smsg_simps = cm2smsg_nil cm2smsg_nil' cm2smsg_createmsg cm2smsg_other

(********************** cfd2fd_s simpset ******************************)

lemma cfd2fd_s_nil: "fd \<in> init_fds_of_proc p \<Longrightarrow> cfd2fd_s [] p fd = SInit fd"
by (simp add:cfd2fd_s_def index_of_fd.simps)

lemma cfd2fd_s_nil': "fd \<in> current_proc_fds [] p \<Longrightarrow> cfd2fd_s [] p fd = SInit fd"
by (simp add:cfd2fd_s_nil current_proc_fds.simps)

lemma cfd2fd_s_open: "cfd2fd_s (Open p f flags fd opt # \<tau>) p' fd' = (
                        if (p = p') then (if (fd = fd') then SCrea (Suc (length \<tau>)) 
                                          else cfd2fd_s \<tau> p' fd')
                        else cfd2fd_s \<tau> p' fd'                      )"
by (simp add:cfd2fd_s_def index_of_fd.simps d2s_aux.simps)

lemma cfd2fd_s_createsock: "cfd2fd_s (CreateSock p af st fd im # \<tau>) p' fd' = (
                              if (p = p') then (if (fd = fd') then SCrea (Suc (length \<tau>)) 
                                          else cfd2fd_s \<tau> p' fd')
                              else cfd2fd_s \<tau> p' fd'                         )"
by (simp add:cfd2fd_s_def index_of_fd.simps d2s_aux.simps)

lemma cfd2fd_s_accept: "cfd2fd_s (Accept p fd addr port fd' im # \<tau>) p' fd'' = (
                          if (p' = p) then (if (fd'' = fd') then SCrea (Suc (length \<tau>))
                                            else cfd2fd_s \<tau> p' fd'')
                          else cfd2fd_s \<tau> p' fd''                             )"
by (simp add:cfd2fd_s_def index_of_fd.simps d2s_aux.simps)

lemma cfd2fd_s_clone: "cfd2fd_s (Clone p p' # \<tau>) p'' fd = (if (p'' = p') then cfd2fd_s \<tau> p fd else cfd2fd_s \<tau> p'' fd)"
by (simp add:cfd2fd_s_def index_of_fd.simps d2s_aux.simps)

lemma cfd2fd_s_other: "\<lbrakk>\<forall> p f flags fd opt. e \<noteq> Open p f flags fd opt;
                        \<forall> p af st fd im. e \<noteq> CreateSock p af st fd im;
                        \<forall> p fd addr port fd' im. e \<noteq> Accept p fd addr port fd' im;
                        \<forall> p p'. e \<noteq> Clone p p'\<rbrakk> \<Longrightarrow> cfd2fd_s (e # \<tau>) p'' fd'' = cfd2fd_s \<tau> p'' fd''"
by (case_tac e, auto simp:cfd2fd_s_def index_of_fd.simps d2s_aux.simps)

lemmas cfd2fd_s_simps = cfd2fd_s_nil cfd2fd_s_nil' cfd2fd_s_open cfd2fd_s_createsock cfd2fd_s_accept cfd2fd_s_clone cfd2fd_s_other

(************* cim2im_s simpset **************************)

(* no such lemma
lemma cim2im_s_nil: "init_itag_of_inum im = Some tag \<Longrightarrow> cim2im_s [] im = SInit im"
by (simp add:cim2im_s_def)
*)

lemma cim2im_s_open: "cim2im_s (Open p f flags fd (Some im) # \<tau>) im' = (if (im' = im) then SCrea (Suc (length \<tau>)) else cim2im_s \<tau> im')"
by (simp add:cim2im_s_def)

lemma cim2im_s_open': "cim2im_s (Open p f flags fd None # \<tau>) im = cim2im_s \<tau> im"
by (simp add:cim2im_s_def)

lemma cim2im_s_mkdir: "cim2im_s (Mkdir p f im # \<tau>) im' = (if (im' = im) then SCrea (Suc (length \<tau>)) else cim2im_s \<tau> im')"
by (simp add:cim2im_s_def)

lemma cim2im_s_createsock: "cim2im_s (CreateSock p sf st fd im # \<tau>) im' = (if (im' = im) then SCrea (Suc (length \<tau>)) else cim2im_s \<tau> im')"
by (simp add:cim2im_s_def)

lemma cim2im_s_accept: "cim2im_s (Accept p fd addr port fd' im # \<tau>) im' = (if (im' = im) then SCrea (Suc (length \<tau>)) else cim2im_s \<tau> im')"
by (simp add:cim2im_s_def)

lemma cim2im_s_other: "\<lbrakk>\<forall> p f flags fd opt. e \<noteq> Open p f flags fd opt;
                        \<forall> p f im. e \<noteq> Mkdir p f im;
                        \<forall> p sf st fd im. e \<noteq> CreateSock p sf st fd im;
                        \<forall> p fd addr port fd' im. e \<noteq> Accept p fd addr port fd' im\<rbrakk> \<Longrightarrow> cim2im_s (e # \<tau>) im = cim2im_s \<tau> im"
by (case_tac e, auto simp:cim2im_s_def)

lemmas cim2im_s_simps = cim2im_s_open cim2im_s_open' cim2im_s_mkdir cim2im_s_createsock cim2im_s_accept cim2im_s_other


lemma cig2ig_s_simp: "cig2ig_s (e # \<tau>) tag = cig2ig_s \<tau> tag"
apply (case_tac tag)
by auto

(******************* cobj2sobj no Suc (length \<tau>) ***********************)

lemma cf2sfile_le_len: "\<lbrakk>cf2sfile \<tau> f = SCrea (Suc (length \<tau>)) # spf; f \<in> current_files \<tau>; \<tau> \<in> vt rc_cs\<rbrakk> \<Longrightarrow> False"
apply (case_tac f, (simp add:cf2sfile.simps d2s_aux.simps)+)
apply (case_tac "index_of_file \<tau> (a # list)", (simp add:d2s_aux.simps)+)
by (drule index_of_file_le_length', simp+)

lemma cf2sfile_le_len': "\<lbrakk>SCrea (Suc (length \<tau>)) # spf \<preceq> cf2sfile \<tau> f; f \<in> current_files \<tau>; \<tau> \<in> vt rc_cs\<rbrakk> \<Longrightarrow> False"
apply (induct f)
apply (simp add:no_junior_def cf2sfile.simps d2s_aux.simps)
apply (case_tac "cf2sfile \<tau> (a # f) = SCrea (Suc (length \<tau>)) # spf") 
apply (drule_tac f = "a # f" in cf2sfile_le_len, simp+)
apply (simp only:cf2sfile.simps d2s_aux.simps)
apply (drule_tac no_junior_noteq, simp+)
apply (rule impI, erule impE, simp+)
apply (drule parentf_in_current', simp+)
done

lemma cp2sproc_le_len: "cp2sproc \<tau> p = SCrea (Suc (length \<tau>)) \<Longrightarrow> False"
apply (simp add:cp2sproc_def, case_tac "index_of_proc \<tau> p")
apply (simp add:d2s_aux.simps)+
by (drule index_of_proc_le_length', simp)

lemma ch2sshm_le_len: "ch2sshm \<tau> h = SCrea (Suc (length \<tau>)) \<Longrightarrow> False"
apply (simp add:ch2sshm_def, case_tac "index_of_shm \<tau> h")
apply (simp add:d2s_aux.simps)+
by (drule index_of_shm_le_length', simp)

lemma cm2smsg_le_len: "cm2smsg \<tau> m = SCrea (Suc (length \<tau>)) \<Longrightarrow> False"
apply (simp add:cm2smsg_def, case_tac "index_of_msg \<tau> m")
apply (simp add:d2s_aux.simps)+
by (drule index_of_msg_le_length', simp)

lemma cim2im_s_le_len: "cim2im_s \<tau> im = SCrea (Suc (length \<tau>)) \<Longrightarrow> False"
apply (simp add:cim2im_s_def, case_tac "inum2ind \<tau> im")
apply (simp add:d2s_aux.simps)+
by (drule inum2ind_le_length', simp)

lemma cfd2fd_s_le_len: "cfd2fd_s \<tau> p fd = SCrea (Suc (length \<tau>)) \<Longrightarrow> False"
apply (simp add:cfd2fd_s_def, case_tac "index_of_fd \<tau> p fd")
apply (simp add:d2s_aux.simps)+
by (drule index_of_fd_le_length', simp)

end

(*<*)
end
(*>*)