#include "fs.h"
char buf[512];
-struct stat stat;
+struct stat st;
struct dirent dirent;
int
printf(2, "ls: cannot open .\n");
exit();
}
- if (fstat(fd, &stat) < 0) {
+ if (fstat(fd, &st) < 0) {
printf(2, "ls: cannot open .\n");
exit();
}
- if (stat.st_type != T_DIR) {
+ if (st.st_type != T_DIR) {
printf(2, "ls: . is not a dir\n");
}
- for(off = 0; off < stat.st_size; off += sizeof(struct dirent)) {
+ cprintf("size %d\n", st.st_size);
+ for(off = 0; off < st.st_size; off += sizeof(struct dirent)) {
if (read(fd, &dirent, sizeof(struct dirent)) != sizeof(struct dirent)) {
printf(2, "ls: read error\n");
exit();
}
- if (dirent.inum != 0)
- printf(1, "%s\n", dirent.name);
+ if (dirent.inum != 0) {
+
+ if (stat (dirent.name, &st) < 0)
+ printf(2, "stat: failed\n");
+
+ printf(1, "%s t %d\n", dirent.name, st.st_type);
+ }
}
close(fd);
return (nip == 0) ? -1 : 0;
}
+int
+sys_mkdir(void)
+{
+ struct proc *cp = curproc[cpu()];
+ struct inode *nip;
+ uint arg0;
+ int l;
+
+ if(fetcharg(0, &arg0) < 0)
+ return -1;
+
+ if((l = checkstring(arg0)) < 0)
+ return -1;
+
+ if(l >= DIRSIZ)
+ return -1;
+
+ nip = mknod (cp->mem + arg0, T_DIR, 0, 0);
+
+ // XXX put . and .. in
+
+ iput(nip);
+ return (nip == 0) ? -1 : 0;
+}
+
int
sys_unlink(void)
{
case SYS_link:
ret = sys_link();
break;
+ case SYS_mkdir:
+ ret = sys_mkdir();
+ break;
default:
cprintf("unknown sys call %d\n", num);
// XXX fault
#define SYS_unlink 16
#define SYS_fstat 17
#define SYS_link 18
+#define SYS_mkdir 19
+#include "types.h"
+#include "stat.h"
+#include "fcntl.h"
#include "user.h"
int
buf[i] = '\0';
return buf;
}
+
+int
+stat(char *n, struct stat *st)
+{
+ int fd = open(n, O_RDONLY);
+ int r;
+
+ if (fd < 0) return -1;
+
+ r = fstat(fd, st);
+ close(fd);
+ return r;
+}
int open(char *, int);
int mknod (char*,short,short,short);
int unlink (char*);
-struct stat;
int fstat (int fd, struct stat *stat);
int link(char *, char *);
+int mkdir(char *);
+int stat(char *, struct stat *stat);
int puts(char*);
char* strcpy(char*, char*);
printf(stdout, "read failed\n");
}
close(fd);
+
+ printf(stdout, "unlink doesnotexist\n");
+
unlink("doesnotexist");
+
+ printf(stdout, "many creates, followed by unlink\n");
+
name[0] = 'a';
name[2] = '\0';
for (i = 0; i < 52; i++) {
unlink(name);
}
+ printf(stdout, "mkdir\n");
+
+ if (mkdir("dir0") < 0)
+ printf(stdout, "mkdir failed\n");
+
+ // unlink("dir0");
+
//exec("echo", echo_args);
printf(stdout, "about to do exec\n");
exec("cat", cat_args);
STUB(unlink)
STUB(fstat)
STUB(link)
+STUB(mkdir)