@@ -187,6 +187,54 @@ fn test_create_file(directory: &mut Directory) {
187187 file. write ( b"test output data" ) . unwrap ( ) ;
188188}
189189
190+ /// Test directory creation by
191+ /// - creating a new directory
192+ /// - creating a file in that directory
193+ /// - accessing the new directory via a flat path and a deep path
194+ fn test_create_directory ( root_dir : & mut Directory ) {
195+ info ! ( "Testing directory creation" ) ;
196+
197+ // Create a new directory.
198+ let new_dir = root_dir
199+ . open (
200+ cstr16 ! ( "created_dir" ) ,
201+ FileMode :: CreateReadWrite ,
202+ FileAttribute :: DIRECTORY ,
203+ )
204+ . expect ( "failed to create directory" ) ;
205+
206+ let mut new_dir = new_dir. into_directory ( ) . expect ( "Should be a directory" ) ;
207+
208+ // create new file in new director
209+ let msg = "hello_world" ;
210+ let file = new_dir
211+ . open (
212+ cstr16 ! ( "foobar" ) ,
213+ FileMode :: CreateReadWrite ,
214+ FileAttribute :: empty ( ) ,
215+ )
216+ . unwrap ( ) ;
217+
218+ let mut file = file. into_regular_file ( ) . expect ( "Should be a file!" ) ;
219+ file. write ( msg. as_bytes ( ) ) . unwrap ( ) ;
220+
221+ // now access the new file with a deep path and read its content
222+ let file = root_dir
223+ . open (
224+ cstr16 ! ( "created_dir\\ foobar" ) ,
225+ FileMode :: Read ,
226+ FileAttribute :: empty ( ) ,
227+ )
228+ . expect ( "Must open created file with deep path." ) ;
229+ let mut file = file. into_regular_file ( ) . expect ( "Should be a file!" ) ;
230+
231+ let mut buf = vec ! [ 0 ; msg. len( ) ] ;
232+ let read_bytes = file. read ( & mut buf) . unwrap ( ) ;
233+ let read = & buf[ 0 ..read_bytes] ;
234+
235+ assert_eq ! ( msg. as_bytes( ) , read) ;
236+ }
237+
190238/// Get the media ID via the BlockIO protocol.
191239fn get_block_media_id ( handle : Handle , bt : & BootServices ) -> u32 {
192240 // This cannot be opened in `EXCLUSIVE` mode, as doing so
@@ -339,6 +387,7 @@ pub fn test_known_disk(bt: &BootServices) {
339387 test_delete_warning ( & mut root_directory) ;
340388 test_existing_file ( & mut root_directory) ;
341389 test_create_file ( & mut root_directory) ;
390+ test_create_directory ( & mut root_directory) ;
342391 }
343392
344393 test_raw_disk_io ( handle, bt) ;
0 commit comments