@@ -45,6 +45,27 @@ static int filter_dot(const struct dirent *d)
4545 return (strcmp (d -> d_name , ".." ) && strcmp (d -> d_name , "." ));
4646}
4747
48+ static u32 build_default_directory_structure (time_t fixed_time )
49+ {
50+ u32 inode ;
51+ u32 root_inode ;
52+ struct dentry dentries = {
53+ .filename = "lost+found" ,
54+ .file_type = EXT4_FT_DIR ,
55+ .mode = S_IRWXU ,
56+ .uid = 0 ,
57+ .gid = 0 ,
58+ .mtime = (fixed_time != -1 ) ? fixed_time : 0 ,
59+ };
60+ root_inode = make_directory (0 , 1 , & dentries , 1 );
61+ inode = make_directory (root_inode , 0 , NULL , 0 );
62+ * dentries .inode = inode ;
63+ inode_set_permissions (inode , dentries .mode ,
64+ dentries .uid , dentries .gid , dentries .mtime );
65+
66+ return root_inode ;
67+ }
68+
4869/* Read a local directory and create the same tree in the generated filesystem.
4970 Calls itself recursively with each directory in the given directory.
5071 full_path is an absolute or relative path, with a trailing slash, to the
@@ -367,12 +388,8 @@ int make_ext4fs_internal(int fd, const char *_directory,
367388 if (setjmp (setjmp_env ))
368389 return EXIT_FAILURE ; /* Handle a call to longjmp() */
369390
370- if (_directory == NULL ) {
371- fprintf (stderr , "Need a source directory\n" );
372- return EXIT_FAILURE ;
373- }
374-
375- directory = canonicalize_rel_slashes (_directory );
391+ if (_directory )
392+ directory = canonicalize_rel_slashes (_directory );
376393
377394 if (info .len <= 0 )
378395 info .len = get_file_size (fd );
@@ -457,11 +474,15 @@ int make_ext4fs_internal(int fd, const char *_directory,
457474 if (info .feat_compat & EXT4_FEATURE_COMPAT_RESIZE_INODE )
458475 ext4_create_resize_inode ();
459476
460- root_inode_num = build_directory_structure (directory , "" , 0 ,
461- fs_config_func , verbose , fixed_time );
477+ if (directory )
478+ root_inode_num = build_directory_structure (directory , "" , 0 ,
479+ fs_config_func , verbose , fixed_time );
480+ else
481+ root_inode_num = build_default_directory_structure (fixed_time );
462482
463483 root_mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH ;
464- inode_set_permissions (root_inode_num , root_mode , 0 , 0 , 0 );
484+ inode_set_permissions (root_inode_num , root_mode , 0 , 0 ,
485+ (fixed_time != 1 ) ? fixed_time : 0 );
465486
466487 ext4_update_free ();
467488
0 commit comments