Diff

Differences From Artifact [662da588b0]:

To Artifact [20e6e11465]:


     1      1   #! /usr/bin/env tcl
     2      2   
     3      3   package require vfs
     4      4   
     5         -namespace eval ::vfs::kitdll {}
            5  +namespace eval ::vfs::cvfs {}
     6      6   
     7      7   # Convience functions
     8         -proc ::vfs::kitdll::Mount {hashkey local} {
     9         -	vfs::filesystem mount $local [list ::vfs::kitdll::vfshandler $hashkey]
            8  +proc ::vfs::cvfs::Mount {hashkey local} {
            9  +	vfs::filesystem mount $local [list ::vfs::cvfs::vfshandler $hashkey]
    10     10   	catch {
    11         -		vfs::RegisterMount $local [list ::vfs::kitdll::Unmount]
           11  +		vfs::RegisterMount $local [list ::vfs::cvfs::Unmount]
    12     12   	}
    13     13   }
    14     14   
    15         -proc ::vfs::kitdll::Unmount {local} {
           15  +proc ::vfs::cvfs::Unmount {local} {
    16     16   	vfs::filesystem unmount $local
    17     17   }
    18     18   
    19     19   # Implementation
    20     20   ## I/O Handlers (pass to appropriate hashkey)
    21         -namespace eval ::vfs::kitdll::data {}
    22         -proc ::vfs::kitdll::data::getChildren args {
           21  +namespace eval ::vfs::cvfs::data {}
           22  +proc ::vfs::cvfs::data::getChildren args {
    23     23   	set hashkey [lindex $args 0]
    24     24   
    25         -	set cmd "::vfs::kitdll::data::${hashkey}::getChildren"
           25  +	set cmd "::vfs::cvfs::data::${hashkey}::getChildren"
    26     26   	set cmd [linsert $args 0 $cmd]
    27     27   
    28     28   	eval $cmd
    29     29   }
    30     30   
    31         -proc ::vfs::kitdll::data::getMetadata args {
           31  +proc ::vfs::cvfs::data::getMetadata args {
    32     32   	set hashkey [lindex $args 0]
    33     33   
    34         -	set cmd "::vfs::kitdll::data::${hashkey}::getMetadata"
           34  +	set cmd "::vfs::cvfs::data::${hashkey}::getMetadata"
    35     35   	set cmd [linsert $args 0 $cmd]
    36     36   
    37     37   	eval $cmd
    38     38   }
    39     39   
    40         -proc ::vfs::kitdll::data::getData args {
           40  +proc ::vfs::cvfs::data::getData args {
    41     41   	set hashkey [lindex $args 0]
    42     42   
    43         -	set cmd "::vfs::kitdll::data::${hashkey}::getData"
           43  +	set cmd "::vfs::cvfs::data::${hashkey}::getData"
    44     44   	set cmd [linsert $args 0 $cmd]
    45     45   
    46     46   	eval $cmd
    47     47   }
    48     48   
    49     49   ## VFS and Chan I/O
    50     50   ### Dispatchers
    51         -proc ::vfs::kitdll::vfshandler {hashkey subcmd args} {
           51  +proc ::vfs::cvfs::vfshandler {hashkey subcmd args} {
    52     52   	set cmd $args
    53         -	set cmd [linsert $cmd 0 "::vfs::kitdll::vfsop_${subcmd}" $hashkey]
           53  +	set cmd [linsert $cmd 0 "::vfs::cvfs::vfsop_${subcmd}" $hashkey]
    54     54   
    55     55   	return [eval $cmd]
    56     56   }
    57     57   
    58         -proc ::vfs::kitdll::chanhandler {hashkey subcmd args} {
           58  +proc ::vfs::cvfs::chanhandler {hashkey subcmd args} {
    59     59   	set cmd $args
    60         -	set cmd [linsert $cmd 0 "::vfs::kitdll::chanop_${subcmd}" $hashkey]
           60  +	set cmd [linsert $cmd 0 "::vfs::cvfs::chanop_${subcmd}" $hashkey]
    61     61   
    62     62   	return [eval $cmd]
    63     63   }
    64     64   
    65     65   ### Actual handlers
    66     66   #### Channel operation handlers
    67         -proc ::vfs::kitdll::chanop_initialize {hashkey chanId mode} {
           67  +proc ::vfs::cvfs::chanop_initialize {hashkey chanId mode} {
    68     68   	return [list initialize finalize watch read seek]
    69     69   }
    70     70   
    71         -proc ::vfs::kitdll::chanop_finalize {hashkey chanId} {
    72         -	unset -nocomplain ::vfs::kitdll::chandata([list $hashkey $chanId])
           71  +proc ::vfs::cvfs::chanop_finalize {hashkey chanId} {
           72  +	unset -nocomplain ::vfs::cvfs::chandata([list $hashkey $chanId])
    73     73   
    74     74   	return
    75     75   }
    76     76   
    77         -proc ::vfs::kitdll::chanop_watch {hashkey chanId eventSpec} {
    78         -	array set chaninfo $::vfs::kitdll::chandata([list $hashkey $chanId])
           77  +proc ::vfs::cvfs::chanop_watch {hashkey chanId eventSpec} {
           78  +	array set chaninfo $::vfs::cvfs::chandata([list $hashkey $chanId])
    79     79   
    80     80   	set chaninfo(watching) $eventSpec
    81     81   
    82         -	set ::vfs::kitdll::chandata([list $hashkey $chanId]) [array get chaninfo]
           82  +	set ::vfs::cvfs::chandata([list $hashkey $chanId]) [array get chaninfo]
    83     83   
    84     84   	if {[lsearch -exact $chaninfo(watching) "read"] != -1} {
    85     85   		after 0 [list catch "chan postevent $chanId [list {read}]"]
    86     86   	}
    87     87   
    88     88   	return
    89     89   }
    90     90   
    91         -proc ::vfs::kitdll::chanop_read {hashkey chanId bytes} {
    92         -	array set chaninfo $::vfs::kitdll::chandata([list $hashkey $chanId])
           91  +proc ::vfs::cvfs::chanop_read {hashkey chanId bytes} {
           92  +	array set chaninfo $::vfs::cvfs::chandata([list $hashkey $chanId])
    93     93   
    94     94   	set pos $chaninfo(pos)
    95     95   	set len $chaninfo(len)
    96     96   
    97     97   	if {[lsearch -exact $chaninfo(watching) "read"] != -1} {
    98     98   		after 0 [list catch "chan postevent $chanId [list {read}]"]
    99     99   	}
................................................................................
   103    103   	}
   104    104   
   105    105   	set end [expr {$pos + $bytes}]
   106    106   	if {$end > $len} {
   107    107   		set end $len
   108    108   	}
   109    109   
   110         -	set data [::vfs::kitdll::data::getData $hashkey $chaninfo(file) $pos $end]
          110  +	set data [::vfs::cvfs::data::getData $hashkey $chaninfo(file) $pos $end]
   111    111   
   112    112   	set dataLen [string length $data]
   113    113   	incr pos $dataLen
   114    114   
   115    115   	set chaninfo(pos) $pos
   116    116   
   117         -	set ::vfs::kitdll::chandata([list $hashkey $chanId]) [array get chaninfo]
          117  +	set ::vfs::cvfs::chandata([list $hashkey $chanId]) [array get chaninfo]
   118    118   
   119    119   	return $data
   120    120   }
   121    121   
   122         -proc ::vfs::kitdll::chanop_seek {hashkey chanId offset origin} {
   123         -	array set chaninfo $::vfs::kitdll::chandata([list $hashkey $chanId])
          122  +proc ::vfs::cvfs::chanop_seek {hashkey chanId offset origin} {
          123  +	array set chaninfo $::vfs::cvfs::chandata([list $hashkey $chanId])
   124    124   
   125    125   	set pos $chaninfo(pos)
   126    126   	set len $chaninfo(len)
   127    127   
   128    128   	switch -- $origin {
   129    129   		"start" - "0" {
   130    130   			set pos $offset
................................................................................
   142    142   	}
   143    143   
   144    144   	if {$pos > $len} {
   145    145   		set pos $len
   146    146   	}
   147    147   
   148    148   	set chaninfo(pos) $pos
   149         -	set ::vfs::kitdll::chandata([list $hashkey $chanId]) [array get chaninfo]
          149  +	set ::vfs::cvfs::chandata([list $hashkey $chanId]) [array get chaninfo]
   150    150   
   151    151   	return $pos
   152    152   }
   153    153   
   154    154   #### VFS operation handlers
   155         -proc ::vfs::kitdll::vfsop_stat {hashkey root relative actualpath} {
          155  +proc ::vfs::cvfs::vfsop_stat {hashkey root relative actualpath} {
   156    156   	catch {
   157         -		set ret [::vfs::kitdll::data::getMetadata $hashkey $relative]
          157  +		set ret [::vfs::cvfs::data::getMetadata $hashkey $relative]
   158    158   	}
   159    159   
   160    160   	if {![info exists ret]} {
   161    161   		vfs::filesystem posixerror $::vfs::posix(ENOENT)
   162    162   	}
   163    163   
   164    164   	return $ret
   165    165   }
   166    166   
   167         -proc ::vfs::kitdll::vfsop_access {hashkey root relative actualpath mode} {
   168         -	set ret [::vfs::kitdll::data::getMetadata $hashkey $relative]
          167  +proc ::vfs::cvfs::vfsop_access {hashkey root relative actualpath mode} {
          168  +	set ret [::vfs::cvfs::data::getMetadata $hashkey $relative]
   169    169   
   170    170   	if {$mode & 0x2} {
   171    171   		vfs::filesystem posixerror $::vfs::posix(EROFS)
   172    172   	}
   173    173   
   174    174   	return 1
   175    175   }
   176    176   
   177         -proc ::vfs::kitdll::vfsop_matchindirectory {hashkey root relative actualpath pattern types} {
          177  +proc ::vfs::cvfs::vfsop_matchindirectory {hashkey root relative actualpath pattern types} {
   178    178   	set ret [list]
   179    179   
   180    180   	catch {
   181         -		array set metadata [::vfs::kitdll::data::getMetadata $hashkey $relative]
          181  +		array set metadata [::vfs::cvfs::data::getMetadata $hashkey $relative]
   182    182   	}
   183    183   
   184    184   	if {![info exists metadata]} {
   185    185   		return [list]
   186    186   	}
   187    187   
   188    188   	if {$pattern == ""} {
   189    189   		set children [list $relative]
   190    190   	} else {
   191         -		set children [::vfs::kitdll::data::getChildren $hashkey $relative]
          191  +		set children [::vfs::cvfs::data::getChildren $hashkey $relative]
   192    192   	}
   193    193   
   194    194   	foreach child $children {
   195    195   		if {$pattern != ""} {
   196    196   			if {![string match $pattern $child]} {
   197    197   				continue
   198    198   			}
   199    199   		}
   200    200   
   201    201   		unset -nocomplain metadata
   202    202   		catch {
   203         -			array set metadata [::vfs::kitdll::data::getMetadata $hashkey $child]
          203  +			array set metadata [::vfs::cvfs::data::getMetadata $hashkey $child]
   204    204   		}
   205    205   
   206    206   		if {[string index $root end] == "/"} {
   207    207   			set child "${root}${child}"
   208    208   		} else {
   209    209   			set child "${root}/${child}"
   210    210   		}
................................................................................
   238    238   
   239    239   		lappend ret $child
   240    240   	}
   241    241   
   242    242   	return $ret
   243    243   }
   244    244   
   245         -proc ::vfs::kitdll::vfsop_fileattributes {hashkey root relative actualpath {index -1} {value ""}} {
          245  +proc ::vfs::cvfs::vfsop_fileattributes {hashkey root relative actualpath {index -1} {value ""}} {
   246    246   	set attrs [list -owner -group -permissions]
   247    247   
   248    248   	if {$value != ""} {
   249    249   		vfs::filesystem posixerror $::vfs::posix(EROFS)
   250    250   	}
   251    251   
   252    252   	if {$index == -1} {
   253    253   		return $attrs
   254    254   	}
   255    255   
   256         -	array set metadata [::vfs::kitdll::data::getMetadata $hashkey $relative]
          256  +	array set metadata [::vfs::cvfs::data::getMetadata $hashkey $relative]
   257    257   
   258    258   	set attr [lindex $attrs $index]
   259    259   
   260    260   	switch -- $attr {
   261    261   		"-owner" {
   262    262   			return $metadata(uid)
   263    263   		}
................................................................................
   272    272   			return [format {0%o} $metadata(mode)]
   273    273   		}
   274    274   	}
   275    275   
   276    276   	return -code error "Invalid index"
   277    277   }
   278    278   
   279         -proc ::vfs::kitdll::vfsop_open {hashkey root relative actualpath mode permissions} {
          279  +proc ::vfs::cvfs::vfsop_open {hashkey root relative actualpath mode permissions} {
   280    280   	if {$mode != "" && $mode != "r"} {
   281    281   		vfs::filesystem posixerror $::vfs::posix(EROFS)
   282    282   	}
   283    283   
   284    284   	catch {
   285         -		array set metadata [::vfs::kitdll::data::getMetadata $hashkey $relative]
          285  +		array set metadata [::vfs::cvfs::data::getMetadata $hashkey $relative]
   286    286   	}
   287    287   
   288    288   	if {![info exists metadata]} {
   289    289   		vfs::filesystem posixerror $::vfs::posix(ENOENT)
   290    290   	}
   291    291   
   292    292   	if {$metadata(type) == "directory"} {
   293    293   		vfs::filesystem posixerror $::vfs::posix(EISDIR)
   294    294   	}
   295    295   
   296    296   	if {[info command chan] != ""} {
   297         -		set chan [chan create [list "read"] [list ::vfs::kitdll::chanhandler $hashkey]]
          297  +		set chan [chan create [list "read"] [list ::vfs::cvfs::chanhandler $hashkey]]
   298    298   
   299         -		set ::vfs::kitdll::chandata([list $hashkey $chan]) [list file $relative pos 0 len $metadata(size) watching ""]
          299  +		set ::vfs::cvfs::chandata([list $hashkey $chan]) [list file $relative pos 0 len $metadata(size) watching ""]
   300    300   
   301    301   		return [list $chan]
   302    302   	}
   303    303   
   304    304   	if {[info command rechan] == ""} {
   305    305   		catch {
   306    306   			package require rechan
   307    307   		}
   308    308   	}
   309    309   
   310    310   	if {[info command rechan] != ""} {
   311         -		set chan [rechan [list ::vfs::kitdll::chanhandler $hashkey] 2]
          311  +		set chan [rechan [list ::vfs::cvfs::chanhandler $hashkey] 2]
   312    312   
   313         -		set ::vfs::kitdll::chandata([list $hashkey $chan]) [list file $relative pos 0 len $metadata(size) watching ""]
          313  +		set ::vfs::cvfs::chandata([list $hashkey $chan]) [list file $relative pos 0 len $metadata(size) watching ""]
   314    314   
   315    315   		return [list $chan]
   316    316   	}
   317    317   
   318    318   	return -code error "No way to generate a channel, need either Tcl 8.5+, \"rechan\""
   319    319   }
   320    320   
   321    321   ##### No-Ops since we are a readonly filesystem
   322         -proc ::vfs::kitdll::vfsop_createdirectory {args} {
          322  +proc ::vfs::cvfs::vfsop_createdirectory {args} {
          323  +	vfs::filesystem posixerror $::vfs::posix(EROFS)
          324  +}
          325  +proc ::vfs::cvfs::vfsop_deletefile {args} {
   323    326   	vfs::filesystem posixerror $::vfs::posix(EROFS)
   324    327   }
   325         -proc ::vfs::kitdll::vfsop_deletefile {args} {
          328  +proc ::vfs::cvfs::vfsop_removedirectory {args} {
   326    329   	vfs::filesystem posixerror $::vfs::posix(EROFS)
   327    330   }
   328         -proc ::vfs::kitdll::vfsop_removedirectory {args} {
   329         -	vfs::filesystem posixerror $::vfs::posix(EROFS)
   330         -}
   331         -proc ::vfs::kitdll::vfsop_utime {} {
          331  +proc ::vfs::cvfs::vfsop_utime {} {
   332    332   	vfs::filesystem posixerror $::vfs::posix(EROFS)
   333    333   }
   334    334   
   335         -package provide vfs::kitdll 1.0
          335  +package provide vfs::cvfs 1.0