JFFS2 no udef, all char/block devices hardlinked to /dev/console
Hi
I'm doing a Yocto Zeus build for a very old Linux Kernel (The Kernel is built outside of Yocto). Since my target CPU, based on mips32 little endian, was removed from Linux mainline I've opted to use musl to keep at least the user space up to date.
I'm building a JFFS2 root fs using --devtable= since my kernel does not have devfs/udev. The file looks like:
/dev/console c 640 0 0 5 1 - - - /dev/full c 640 0 0 1 7 - - - /dev/mtd c 640 0 0 90 0 0 2 8 /dev/mtdblock b 640 0 0 31 0 0 1 8 /dev/null c 666 0 0 1 3 - - -
...
Running mkfs.jffs2 outside Yocto works. Running mkfs.jffs2 as part of the default image build step breaks my char/block devices. All device files are hard linked to the first one. Moreover the permissions are also reset.
Example Output of ls /dev/*:
crw-r----- 16 root root 5, 1, Jan 1 1970 /dev/console crw-r----- 16 root root 5, 1, Jan 1 1970 /dev/full crw-r----- 16 root root 5, 1, Jan 1 1970 /dev/mtd0 crw-r----- 16 root root 5, 1, Jan 1 1970 /dev/mtd1
...
crw-r----- 16 root root 5, 1, Jan 1 1970 /dev/mtdblock0 crw-r----- 16 root root 5, 1, Jan 1 1970 /dev/mtdblock1 ..
crw-r----- 16 root root 5, 1, Jan 1 1970 /dev/mtdchar crw-r----- 16 root root 5, 1, Jan 1 1970 /dev/null
It looks like add_host_filesystem_entry calls lstat for all files added to the JFFS2 including files that do not exist. For some reason I do not yet understand lstat returns garbage instead of just failing on my system (Ubuntu 18.04). This in turn leads to the hard linking and permisson issues described above. I suggest to disable lstat for device files to counter this issue:
--- jffsX-utils/mkfs.jffs2.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
jffsX-utils/mkfs.jffs2.c +6 -2
@@ -219,14 +219,18 @@ static struct filesystem_entry *add_host_filesystem_entry(const char *name, const char *path, unsigned long uid, unsigned long gid, unsigned long mode, dev_t rdev, struct filesystem_entry *parent) { - int status; + int status = -1;char *tmp;struct stat sb;time_t timestamp =time (NULL );struct filesystem_entry *entry;memset (&sb,0 ,sizeof (struct stat )); - status =lstat (path, &sb); + +//Do not call lstat for char- and block-devices +if (major (rdev) ==0 ) { + status =lstat (path, &sb); + }if (status >=0 ) {/* It is ok for some types of files to not exit on disk (such as
Signature · 3 lines
2.17.1 Andreas