[comp.sys.mips] RISC/os 4.512

bruce@cs.su.oz (Bruce Janson) (04/30/91)

Summary:
	"cpio -pdm" sometimes fails to create empty directories.

Repeat by:
	$ uname -a
	joyce joyce 4_52 UMIPS mips
	$ id
	uid=0(root) gid=0(root)
	$ cd /tmp; mkdir t f f/a f/a/b; cd f
	$ find . -depth -print | cpio -pdm ../t
	cpio: WARNING: Cannot change the mode of file "../t/a/b" to 16877.
	cpio: WARNING: Cannot change owner to 0 and group to 0 for file "../t/a/b".
	0 blocks
	$ 

Fix by:
	?

Further detail:
	Here's a trace of the file system calls executed by the
	offending cpio from the above example:

 ..
 18754:sysv_umask(0x0) = 0x12
 18754:sysv_umask(0x0) = 0x0
 ..
 18754:sysv_access("../t", 0x2) = 0
 18754:sysv_stat("../t", {st_dev=0x101c, st_ino=2048, st_mode=0x41ed, st_nlink=2, st_uid=0, st_gid=0, st_rdev=0x1868, st_size=512, st_atime=673029105, st_mtime=673029106, st_ctime=673029106,}) = 0
 ..
 18754:sysv_ioctl(0, TCGETA, {c_iflag=, c_oflag=NL0|CR0|TAB0|BS0|VT0|FF0, c_cflag=B0|CS5, c_lflag=, c_line=0, c_cc=[VINTR=0x00,VQUIT=0x00,VERASE=0x00,VKILL=0x00,VEOF=0x00,VEOL=0x00,VEOL2=0x00,VSWTCH=0x00,V_START=0x00,V_STOP=0x00,V_SUSP=0x00,V_DSUSP=0x00,V_RPRNT=0x00,V_FLUSH=0x00,V_WERAS=0x00,V_LNEXT=0x00,V_STATUS=0x40,V_SAVED_EOF=0x8a,V_SAVED_EOL=0xac,19=0x00,20=0x00,21=0x00,22=0x00,], c_saved_flags=0x0, c_filler=0x20}) = -1 ENOTTY (Not a character device)
 18754:sysv_read(0, "./a/b\012./a\012.\012", 4096) = 12
 18754:sysv_lstat("a/b", {st_dev=0x101c, st_ino=8192, st_mode=0x41ed, st_nlink=2, st_uid=0, st_gid=0, st_rdev=0x6188, st_size=512, st_atime=673029107, st_mtime=673029106, st_ctime=673029106,}) = 0
 18754:sysv_stat("../t/a/b", {st_dev=0x0, st_ino=3, st_mode=0x41ed, st_nlink=2, st_uid=0, st_gid=0, st_rdev=0x1868, st_size=512, st_atime=673029105, st_mtime=673029106, st_ctime=673029106,}) = -1 ENOENT (No such file or directory)
 18754:sysv_umask(0x12) = 0x0
 18754:sysv_mkdir("../t/a/b", 0x1ff) = -1 ENOENT (No such file or directory)
 18754:sysv_umask(0x0) = 0x12
 18754:sysv_chmod("../t/a/b", 0x41ed) = -1 ENOENT (No such file or directory)
 18754:sysv_write(2, "c", 1) = 1
 18754:sysv_write(2, "p", 1) = 1
 18754:sysv_write(2, "i", 1) = 1
 18754:sysv_write(2, "o", 1) = 1
 18754:sysv_write(2, ":", 1) = 1
 18754:sysv_write(2, " ", 1) = 1
 18754:sysv_write(2, "WARNING: ", 9) = 9
 ..
 18754:sysv_chown("../t/a/b", 0, 0) = -1 ENOENT (No such file or directory)
 18754:sysv_write(2, "c", 1) = 1
 18754:sysv_write(2, "p", 1) = 1
 18754:sysv_write(2, "i", 1) = 1
 18754:sysv_write(2, "o", 1) = 1
 18754:sysv_write(2, ":", 1) = 1
 18754:sysv_write(2, " ", 1) = 1
 18754:sysv_write(2, "WARNING: ", 9) = 9
 ..
 18754:sysv_utime("../t/a/b", 0x10005550) = -1 ENOENT (No such file or directory)
 18754:sysv_lstat("a", {st_dev=0x101c, st_ino=6144, st_mode=0x41ed, st_nlink=3, st_uid=0, st_gid=0, st_rdev=0x4928, st_size=512, st_atime=673029107, st_mtime=673029106, st_ctime=673029106,}) = 0
 18754:sysv_stat("../t/a", {st_dev=0x0, st_ino=3, st_mode=0x41ed, st_nlink=2, st_uid=0, st_gid=0, st_rdev=0x1868, st_size=512, st_atime=673029105, st_mtime=673029106, st_ctime=673029106,}) = -1 ENOENT (No such file or directory)
 18754:sysv_umask(0x12) = 0x0
 18754:sysv_mkdir("../t/a", 0x1ff) = 0
 18754:sysv_stat("..", {st_dev=0x101c, st_ino=2, st_mode=0x41ff, st_nlink=5, st_uid=2, st_gid=3, st_rdev=0x130, st_size=1536, st_atime=673029107, st_mtime=673029107, st_ctime=673029107,}) = 0
 18754:sysv_stat("../t", {st_dev=0x101c, st_ino=2048, st_mode=0x41ed, st_nlink=3, st_uid=0, st_gid=0, st_rdev=0x1868, st_size=512, st_atime=673029105, st_mtime=673029112, st_ctime=673029112,}) = 0
 18754:sysv_mkdir("../t/a", 0x1ff) = -1 EEXIST (File exists)
 18754:sysv_umask(0x0) = 0x12
 18754:sysv_chmod("../t/a", 0x41ed) = 0
 18754:sysv_chown("../t/a", 0, 0) = 0
 18754:sysv_utime("../t/a", 0x10005550) = 0
 18754:sysv_lstat(".", {st_dev=0x101c, st_ino=4096, st_mode=0x41ed, st_nlink=3, st_uid=0, st_gid=0, st_rdev=0x30c8, st_size=512, st_atime=673029107, st_mtime=673029106, st_ctime=673029106,}) = 0
 18754:sysv_stat("../t/.", {st_dev=0x101c, st_ino=2048, st_mode=0x41ed, st_nlink=3, st_uid=0, st_gid=0, st_rdev=0x1868, st_size=512, st_atime=673029105, st_mtime=673029112, st_ctime=673029112,}) = 0
 18754:sysv_chmod("../t/.", 0x41ed) = 0
 18754:sysv_chown("../t/.", 0, 0) = 0
 18754:sysv_utime("../t/.", 0x10005550) = 0
 18754:sysv_read(0, "", 4096) = 0
 18754:sysv_write(2, "0", 1) = 1
 18754:sysv_write(2, " ", 1) = 1
 18754:sysv_write(2, "b", 1) = 1
 18754:sysv_write(2, "l", 1) = 1
 18754:sysv_write(2, "o", 1) = 1
 18754:sysv_write(2, "c", 1) = 1
 18754:sysv_write(2, "k", 1) = 1
 18754:sysv_write(2, "s", 1) = 1
 18754:sysv_write(2, "\012", 1) = 1
 18754:sysv_close(0) = 0
 18754:sysv_close(1) = 0
 18754:sysv_close(2) = 0

Cheers,
bruce.

Bruce Janson					Email:	bruce@cs.su.oz.au
Basser Department of Computer Science		Phone:	+61-2-692-3272
University of Sydney, N.S.W., 2006, AUSTRALIA	Fax:	+61-2-692-3838

trevc@tecate.mips.com (Trevor Cotton) (05/01/91)

In article <2368@cluster.cs.su.oz.au>, bruce@cs.su.oz (Bruce Janson) writes:
|> Summary:
|> 	"cpio -pdm" sometimes fails to create empty directories.
|> 
|> Repeat by:
|> 	$ uname -a
|> 	joyce joyce 4_52 UMIPS mips
|> 	$ id
|> 	uid=0(root) gid=0(root)
|> 	$ cd /tmp; mkdir t f f/a f/a/b; cd f
|> 	$ find . -depth -print | cpio -pdm ../t
|> 	cpio: WARNING: Cannot change the mode of file "../t/a/b" to 16877.
|> 	cpio: WARNING: Cannot change owner to 0 and group to 0 for file "../t/a/b".
|> 	0 blocks
|> 	$ 

Because the -depth option to find is used, cpio will be fed 
./a/b and then ./a
Because the -d option to cpio is used, it will try and create the needed
directory 'a' first.

The problem is that cpio is doing a

if (!mkdir(namep, df_mode)) {

When trying to create the directory ../t/a

mkdir returns 0 on success, -1 on failure which means that cpio thinks it
managed to create the directory when it did not.
The reason it gives the "Cannot change the mode of file "../t/a/b" to 16877."
error message is actually because ../t/a/b does not exist.

Changing the offending line of code to

if (mkdir(namep, df_mode) == -1) {

cures the problem.

I will make sure that a bug report is submitted so that we can get this
fixed in the next release.

-- 
--trevc--

  Trevor Cotton, Sustaining Engineering, MIPS Computer Systems Inc.
  MS 6-05, 930 DeGuigne Drive, Sunnyvale, CA 94088-3650
  Tel: +1 408 524 7286  Fax: +1 408 524 7521
  Email: {wyse,ames,decwrl,pyramid}!mips!trevc    trevc@mips.com