Browse Source

Plan 9 from Bell Labs 2013-02-07

David du Colombier 11 years ago
parent
commit
9f540e52b1
3 changed files with 34 additions and 15 deletions
  1. 9 3
      sys/man/2/stat
  2. 2 0
      sys/man/5/stat
  3. 23 12
      sys/src/ape/lib/ap/plan9/chmod.c

+ 9 - 3
sys/man/2/stat

@@ -170,7 +170,10 @@ are defined by
 \fL	0x80000000\fP	directory
 \fL	0x40000000\fP	append only
 \fL	0x20000000\fP	exclusive use (locked)
-
+.\" \fL	0x10000000\fP	mounted channel
+.\" \fL	0x08000000\fP	authentication file
+\fL	0x04000000\fP	non-backed-up files
+.sp 0.3v
 \fL	      0400\fP	read permission by owner
 \fL	      0200\fP	write permission by owner
 \fL	      0100\fP	execute permission (search on directory) by owner
@@ -183,9 +186,12 @@ There are constants defined in
 for these bits:
 .BR DMDIR ,
 .BR DMAPPEND ,
+.BR DMEXCL ,
+.\" .BR DMMOUNT ,
+.\" .BR DMAUTH ,
 and
-.B DMEXCL
-for the first three; and
+.BR DMTMP
+for the first four; and
 .BR DMREAD ,
 .BR DMWRITE ,
 and

+ 2 - 0
sys/man/5/stat

@@ -34,6 +34,8 @@ machine-independent
 .IR entry ,
 .IR stat ,
 laid out as follows:
+.TF \fIqid.path[8]
+.PD
 .TP
 .I size\f1[2]\fP
 total byte count of the following data

+ 23 - 12
sys/src/ape/lib/ap/plan9/chmod.c

@@ -4,30 +4,41 @@
 #include "sys9.h"
 #include "dir.h"
 
+static int
+seterrno(void)
+{
+	_syserrno();
+	return -1;
+}
+
 int
 chmod(const char *path, mode_t mode)
 {
-	Dir d;
+	Dir d, *dir;
 
+	dir = _dirstat(path);
+	if(dir == nil)
+		return seterrno();
 	_nulldir(&d);
-	d.mode = mode & 0777;
-	if(_dirwstat(path, &d) < 0){
-		_syserrno();	
-		return -1;
-	}
+	d.mode = (dir->mode & ~0777) | (mode & 0777);
+	free(dir);
+	if(_dirwstat(path, &d) < 0)
+		return seterrno();
 	return 0;
 }
 
 int
 fchmod(int fd, mode_t mode)
 {
-	Dir d;
+	Dir d, *dir;
 
+	dir = _dirfstat(fd);
+	if(dir == nil)
+		return seterrno();
 	_nulldir(&d);
-	d.mode = mode & 0777;
-	if(_dirfwstat(fd, &d) < 0){
-		_syserrno();	
-		return -1;
-	}
+	d.mode = (dir->mode & ~0777) | (mode & 0777);
+	free(dir);
+	if(_dirfwstat(fd, &d) < 0)
+		return seterrno();
 	return 0;
 }