Commits

Anonymous committed 112dcb7

Fix bug where create was not using the whole path name and thus not creating files inside directories.
Cleanup open and create.

  • Participants
  • Parent commits 5811bf1

Comments (0)

Files changed (1)

 /*
  * todo:
+ * deal with .. in walk
  * measure performance penalty
  * notify failed operations?
  * threads?
 
 	a = fid->aux;
 	snprint(npath, sizeof npath, "%s/%s", a->name, name);
-	
+
 	/* aux contains the parent fid info, free them */
 	free(a->name);
 	free(a);
-	fid->aux = nil;
 
 	d = dirstat(npath);
 	if(!d){
+		fid->aux = nil;
 		free(d);
 		return "file not found";
 	}
 	return nil;
 }
 
-static int
-opencreate(Req *r, int creat)
-{
+static void
+fsopen(Req *r)
+{	
 	Aux *a;
 	int fd;
 
-	if(creat){
-		fd = create(r->ifcall.name, r->ifcall.mode, r->ifcall.perm);
-		a = newaux(r->ifcall.name);
-		r->fid->aux = a;
-	}else{
-		a = r->fid->aux;
-		fd = open(a->name, r->ifcall.mode);
-	}
-
-	if(fd < 0)
-		return -1;
-	a->fd = fd;
-	return 0;
-}
-
-static void
-fsopen(Req *r)
-{
-	if(opencreate(r, 0) < 0){
+	a = r->fid->aux;
+	fd = open(a->name, r->ifcall.mode);
+	if(fd < 0){
 		respond(r, "could not open");
 		return;
 	}
 
+	a->fd = fd;
 	respond(r, nil);
 	fprint(ctlfd, "open %s %d\n", ((Aux*)r->fid->aux)->name, r->ifcall.mode);
 }
 fscreate(Req *r)
 {
 	Aux *a;
+	int fd;
+	char name[1024];
 
-	if(opencreate(r, 1) < 0){
-		respond(r, "could not create");
+	a = r->fid->aux;
+
+	snprint(name, sizeof name, "%s/%s", a->name, r->ifcall.name);
+	fd = create(name, r->ifcall.mode, r->ifcall.perm);
+	if(fd < 0){
+		respond(r, "create failed");
 		return;
 	}
 
-	a = r->fid->aux;
-	path2qid(a->name, &r->fid->qid);
+	a->fd = fd;
+	path2qid(estrdup9p(name), &r->fid->qid);
 	r->ofcall.qid = r->fid->qid;
 
 	respond(r, nil);
-	fprint(ctlfd, "create %s %d %d\n", a->name, r->ifcall.mode, r->ifcall.perm);
+	fprint(ctlfd, "create %s %d %uo\n", name, r->ifcall.mode, r->ifcall.perm);
 }
 
 static void