Flask.thy
changeset 65 6f9a588bcfc4
parent 61 0d219ddd6354
child 67 811e3028d169
equal deleted inserted replaced
64:0753309adfc7 65:6f9a588bcfc4
   309 
   309 
   310 definition current_files :: "t_state \<Rightarrow> t_file set"
   310 definition current_files :: "t_state \<Rightarrow> t_file set"
   311 where
   311 where
   312   "current_files \<tau> = {f. \<exists> i. inum_of_file \<tau> f = Some i}" 
   312   "current_files \<tau> = {f. \<exists> i. inum_of_file \<tau> f = Some i}" 
   313 
   313 
       
   314 (* experimentary: for the delete obj's (file or socket) inode num, it is unnecessary for itag_of_inum to be NONE, cause this is the situation blocked by inum_of_file / inum_of_socket !!! *)  
       
   315 (* delete a file, just recycle its inode num, but not destroy its inode \<dots>, so it is irrelative to these events, like closeFd, Rmdir, UnLink \<dots>*)
       
   316 fun itag_of_inum :: "t_state \<Rightarrow> (t_inode_num \<rightharpoonup> t_inode_tag)"
       
   317 where
       
   318   "itag_of_inum [] = init_itag_of_inum"
       
   319 | "itag_of_inum (Open p f flags fd (Some ino) # \<tau>) = (itag_of_inum \<tau>) (ino := Some Tag_FILE)"
       
   320 | "itag_of_inum (Mkdir p f ino # \<tau>) = (itag_of_inum \<tau>) (ino := Some Tag_DIR)" 
       
   321 | "itag_of_inum (CreateSock p af st fd ino # \<tau>) = 
       
   322      (case st of 
       
   323         STREAM \<Rightarrow> (itag_of_inum \<tau>) (ino := Some Tag_TCP_SOCK)
       
   324       | DGRAM  \<Rightarrow> (itag_of_inum \<tau>) (ino := Some Tag_UDP_SOCK) )"
       
   325 | "itag_of_inum (Accept p fd addr lport' fd' ino # \<tau>) = 
       
   326      (itag_of_inum \<tau>) (ino := Some Tag_TCP_SOCK)"
       
   327 | "itag_of_inum (_ # \<tau>) = itag_of_inum \<tau>"  
       
   328 
       
   329 definition is_file:: "t_state \<Rightarrow> t_file \<Rightarrow> bool"
       
   330 where
       
   331   "is_file \<tau> f \<equiv> (case (inum_of_file \<tau> f) of
       
   332                     Some i \<Rightarrow> (case (itag_of_inum \<tau> i) of
       
   333                                  Some Tag_FILE \<Rightarrow> True
       
   334                                | _             \<Rightarrow> False)
       
   335                   | _      \<Rightarrow> False)"
       
   336 
       
   337 definition is_dir:: "t_state \<Rightarrow> t_file \<Rightarrow> bool"
       
   338 where
       
   339   "is_dir \<tau> f \<equiv> (case (inum_of_file \<tau> f) of
       
   340                     Some i \<Rightarrow> (case (itag_of_inum \<tau> i) of
       
   341                                  Some Tag_DIR \<Rightarrow> True
       
   342                                | _            \<Rightarrow> False)
       
   343                   | _      \<Rightarrow> False)"
       
   344 
       
   345 definition dir_is_empty :: "t_state \<Rightarrow> t_file \<Rightarrow> bool"
       
   346 where
       
   347   "dir_is_empty \<tau> f \<equiv> is_dir \<tau> f \<and> \<not> (\<exists> f'. f' \<in> current_files \<tau> \<and> f \<prec> f')"
       
   348 
       
   349 definition same_inode_files :: "t_state \<Rightarrow> t_file \<Rightarrow> t_file set"
       
   350 where
       
   351   "same_inode_files s f \<equiv> if is_file s f then {f'. inum_of_file s f = inum_of_file s f'} else {}"
       
   352 
   314 definition has_same_inode :: "t_state \<Rightarrow> t_file \<Rightarrow> t_file \<Rightarrow> bool"
   353 definition has_same_inode :: "t_state \<Rightarrow> t_file \<Rightarrow> t_file \<Rightarrow> bool"
   315 where 
   354 where 
   316   "has_same_inode \<tau> fa fb = 
   355   "has_same_inode s fa fb \<equiv> fb \<in> same_inode_files s fa"
   317      (\<exists>i. inum_of_file \<tau> fa = Some i \<and> inum_of_file \<tau> fb = Some i)"
       
   318 
   356 
   319 fun inum_of_socket :: "t_state \<Rightarrow> (t_socket \<rightharpoonup> t_inode_num)"
   357 fun inum_of_socket :: "t_state \<Rightarrow> (t_socket \<rightharpoonup> t_inode_num)"
   320 where
   358 where
   321   "inum_of_socket [] = init_inum_of_socket"
   359   "inum_of_socket [] = init_inum_of_socket"
   322 | "inum_of_socket (CloseFd p fd # \<tau>) = 
   360 | "inum_of_socket (CloseFd p fd # \<tau>) = 
   341 
   379 
   342 definition current_sockets :: "t_state \<Rightarrow> t_socket set"
   380 definition current_sockets :: "t_state \<Rightarrow> t_socket set"
   343 where
   381 where
   344   "current_sockets \<tau> = {s. \<exists> i. inum_of_socket \<tau> s = Some i}"
   382   "current_sockets \<tau> = {s. \<exists> i. inum_of_socket \<tau> s = Some i}"
   345 
   383 
   346 (* experimentary: for the delete obj's (file or socket) inode num, it is unnecessary for itag_of_inum to be NONE, cause this is the situation blocked by inum_of_file / inum_of_socket !!! *)  
       
   347 (* delete a file, just recycle its inode num, but not destroy its inode \<dots>, so it is irrelative to these events, like closeFd, Rmdir, UnLink \<dots>*)
       
   348 fun itag_of_inum :: "t_state \<Rightarrow> (t_inode_num \<rightharpoonup> t_inode_tag)"
       
   349 where
       
   350   "itag_of_inum [] = init_itag_of_inum"
       
   351 | "itag_of_inum (Open p f flags fd (Some ino) # \<tau>) = (itag_of_inum \<tau>) (ino := Some Tag_FILE)"
       
   352 | "itag_of_inum (Mkdir p f ino # \<tau>) = (itag_of_inum \<tau>) (ino := Some Tag_DIR)" 
       
   353 | "itag_of_inum (CreateSock p af st fd ino # \<tau>) = 
       
   354      (case st of 
       
   355         STREAM \<Rightarrow> (itag_of_inum \<tau>) (ino := Some Tag_TCP_SOCK)
       
   356       | DGRAM  \<Rightarrow> (itag_of_inum \<tau>) (ino := Some Tag_UDP_SOCK) )"
       
   357 | "itag_of_inum (Accept p fd addr lport' fd' ino # \<tau>) = 
       
   358      (itag_of_inum \<tau>) (ino := Some Tag_TCP_SOCK)"
       
   359 | "itag_of_inum (_ # \<tau>) = itag_of_inum \<tau>"  
       
   360 
       
   361 definition is_file:: "t_state \<Rightarrow> t_file \<Rightarrow> bool"
       
   362 where
       
   363   "is_file \<tau> f \<equiv> (case (inum_of_file \<tau> f) of
       
   364                     Some i \<Rightarrow> (case (itag_of_inum \<tau> i) of
       
   365                                  Some Tag_FILE \<Rightarrow> True
       
   366                                | _             \<Rightarrow> False)
       
   367                   | _      \<Rightarrow> False)"
       
   368 
       
   369 definition is_dir:: "t_state \<Rightarrow> t_file \<Rightarrow> bool"
       
   370 where
       
   371   "is_dir \<tau> f \<equiv> (case (inum_of_file \<tau> f) of
       
   372                     Some i \<Rightarrow> (case (itag_of_inum \<tau> i) of
       
   373                                  Some Tag_DIR \<Rightarrow> True
       
   374                                | _            \<Rightarrow> False)
       
   375                   | _      \<Rightarrow> False)"
       
   376 
       
   377 definition dir_is_empty :: "t_state \<Rightarrow> t_file \<Rightarrow> bool"
       
   378 where
       
   379   "dir_is_empty \<tau> f \<equiv> is_dir \<tau> f \<and> \<not> (\<exists> f'. f' \<in> current_files \<tau> \<and> f \<prec> f')"
       
   380 
       
   381 definition is_tcp_sock :: "t_state \<Rightarrow> t_socket \<Rightarrow> bool"
   384 definition is_tcp_sock :: "t_state \<Rightarrow> t_socket \<Rightarrow> bool"
   382 where
   385 where
   383   "is_tcp_sock \<tau> s \<equiv> (case (inum_of_socket \<tau> s) of
   386   "is_tcp_sock \<tau> s \<equiv> (case (inum_of_socket \<tau> s) of
   384                         Some i \<Rightarrow> (case (itag_of_inum \<tau> i) of
   387                         Some i \<Rightarrow> (case (itag_of_inum \<tau> i) of
   385                                      Some Tag_TCP_SOCK \<Rightarrow> True
   388                                      Some Tag_TCP_SOCK \<Rightarrow> True
   519   "current_sock_inums \<tau> = {im. \<exists> s. inum_of_socket \<tau> s = Some im}"
   522   "current_sock_inums \<tau> = {im. \<exists> s. inum_of_socket \<tau> s = Some im}"
   520 
   523 
   521 definition current_inode_nums :: "t_state \<Rightarrow> nat set"
   524 definition current_inode_nums :: "t_state \<Rightarrow> nat set"
   522 where
   525 where
   523   "current_inode_nums \<tau> = current_file_inums \<tau> \<union> current_sock_inums \<tau>"
   526   "current_inode_nums \<tau> = current_file_inums \<tau> \<union> current_sock_inums \<tau>"
   524 
       
   525 definition same_inode_files :: "t_state \<Rightarrow> t_file \<Rightarrow> t_file set"
       
   526 where
       
   527   "same_inode_files s f \<equiv> if is_file s f then {f'. inum_of_file s f = inum_of_file s f'} else {}"
       
   528 
   527 
   529 fun flags_of_proc_fd :: "t_state \<Rightarrow> t_process \<Rightarrow> t_fd \<Rightarrow> t_open_flags option"
   528 fun flags_of_proc_fd :: "t_state \<Rightarrow> t_process \<Rightarrow> t_fd \<Rightarrow> t_open_flags option"
   530 where
   529 where
   531   "flags_of_proc_fd [] p fd = init_oflags_of_proc_fd p fd" 
   530   "flags_of_proc_fd [] p fd = init_oflags_of_proc_fd p fd" 
   532 | "flags_of_proc_fd (Open p f flags fd iopt # \<tau>) p' fd' = 
   531 | "flags_of_proc_fd (Open p f flags fd iopt # \<tau>) p' fd' =