11import sys
2- import uos
32import uerrno
3+ try :
4+ import uos_vfs as uos
5+ open = uos .vfs_open
6+ except ImportError :
7+ import uos
48try :
59 uos .VfsFat
610except AttributeError :
@@ -40,10 +44,12 @@ def ioctl(self, op, arg):
4044 sys .exit ()
4145
4246uos .VfsFat .mkfs (bdev )
43- vfs = uos .VfsFat (bdev , "/ramdisk" )
47+ vfs = uos .VfsFat (bdev )
48+ uos .mount (vfs , '/ramdisk' )
49+ uos .chdir ('/ramdisk' )
4450
4551# file IO
46- f = vfs . open ("foo_file.txt" , "w" )
52+ f = open ("foo_file.txt" , "w" )
4753print (str (f )[:17 ], str (f )[- 1 :])
4854f .write ("hello!" )
4955f .flush ()
@@ -65,14 +71,14 @@ def ioctl(self, op, arg):
6571 print (e .args [0 ] == uerrno .EINVAL )
6672
6773try :
68- vfs . open ("foo_file.txt" , "x" )
74+ open ("foo_file.txt" , "x" )
6975except OSError as e :
7076 print (e .args [0 ] == uerrno .EEXIST )
7177
72- with vfs . open ("foo_file.txt" , "a" ) as f :
78+ with open ("foo_file.txt" , "a" ) as f :
7379 f .write ("world!" )
7480
75- with vfs . open ("foo_file.txt" ) as f2 :
81+ with open ("foo_file.txt" ) as f2 :
7682 print (f2 .read ())
7783 print (f2 .tell ())
7884
@@ -90,9 +96,10 @@ def ioctl(self, op, arg):
9096 print (f2 .read (1 ))
9197
9298# using constructor of FileIO type to open a file
93- FileIO = type (f )
94- with FileIO ("/ramdisk/foo_file.txt" ) as f :
95- print (f .read ())
99+ # no longer working with new VFS sub-system
100+ #FileIO = type(f)
101+ #with FileIO("/ramdisk/foo_file.txt") as f:
102+ # print(f.read())
96103
97104# dirs
98105vfs .mkdir ("foo_dir" )
@@ -123,13 +130,13 @@ def ioctl(self, op, arg):
123130 print (e .args [0 ] == uerrno .ENOENT )
124131
125132# file in dir
126- with vfs . open ("foo_dir/file-in-dir.txt" , "w+t" ) as f :
133+ with open ("foo_dir/file-in-dir.txt" , "w+t" ) as f :
127134 f .write ("data in file" )
128135
129- with vfs . open ("foo_dir/file-in-dir.txt" , "r+b" ) as f :
136+ with open ("foo_dir/file-in-dir.txt" , "r+b" ) as f :
130137 print (f .read ())
131138
132- with vfs . open ("foo_dir/sub_file.txt" , "w" ) as f :
139+ with open ("foo_dir/sub_file.txt" , "w" ) as f :
133140 f .write ("subdir file" )
134141
135142# directory not empty
@@ -146,11 +153,11 @@ def ioctl(self, op, arg):
146153print (vfs .listdir ())
147154
148155# check that renaming to existing file will overwrite it
149- with vfs . open ("temp" , "w" ) as f :
156+ with open ("temp" , "w" ) as f :
150157 f .write ("new text" )
151158vfs .rename ("temp" , "moved-to-root.txt" )
152159print (vfs .listdir ())
153- with vfs . open ("moved-to-root.txt" ) as f :
160+ with open ("moved-to-root.txt" ) as f :
154161 print (f .read ())
155162
156163# valid removes
@@ -163,7 +170,7 @@ def ioctl(self, op, arg):
163170try :
164171 bsize = vfs .statvfs ("/ramdisk" )[0 ]
165172 free = vfs .statvfs ("/ramdisk" )[2 ] + 1
166- f = vfs . open ("large_file.txt" , "wb" )
173+ f = open ("large_file.txt" , "wb" )
167174 f .write (bytearray (bsize * free ))
168175except OSError as e :
169176 print ("ENOSPC:" , e .args [0 ] == 28 ) # uerrno.ENOSPC
0 commit comments