Added monitor command to do an "ls -R"
authorBarret Rhoden <brho@cs.berkeley.edu>
Tue, 10 Aug 2010 20:31:44 +0000 (13:31 -0700)
committerKevin Klues <klueska@cs.berkeley.edu>
Thu, 3 Nov 2011 00:35:51 +0000 (17:35 -0700)
kern/include/vfs.h
kern/src/kfs.c
kern/src/monitor.c
kern/src/vfs.c

index abd3688..0cd85e1 100644 (file)
@@ -505,4 +505,7 @@ int insert_file(struct files_struct *open_files, struct file *file);
 void close_all_files(struct files_struct *open_files, bool cloexec);
 void clone_files(struct files_struct *src, struct files_struct *dst);
 
+/* Debugging */
+int ls_dash_r(char *path);
+
 #endif /* ROS_KERN_VFS_H */
index 79d9135..03959d3 100644 (file)
@@ -496,7 +496,7 @@ off_t kfs_llseek(struct file *file, off_t offset, int whence)
  * read and write, there will be issues with userspace and the *dirent buf.
  * TODO: we don't really do anything with userspace concerns here, in part
  * because memcpy_to doesn't work well.  When we fix how we want to handle the
- * userbuffers, we can write this accordingly.  */
+ * userbuffers, we can write this accordingly. (UMEM)  */
 int kfs_readdir(struct file *dir, struct dirent *dirent)
 {
        int count = 0;
@@ -825,28 +825,3 @@ void parse_cpio_entries(struct super_block *sb, void *cpio_b)
        }
        kfree(c_bhdr);
 }
-
-/* Debugging */
-void print_dir_tree(struct dentry *dentry, int depth)
-{
-       struct inode *inode = dentry->d_inode;
-       struct kfs_i_info *k_i_info = (struct kfs_i_info*)inode->i_fs_info;
-       struct dentry *d_i;
-       assert(dentry && inode && inode->i_type & FS_I_DIR);
-       char buf[32] = {0};
-
-       for (int i = 0; i < depth; i++)
-               buf[i] = '\t';
-
-       TAILQ_FOREACH(d_i, &dentry->d_subdirs, d_subdirs_link) {
-               printk("%sDir %s has child dir: %s\n", buf, dentry->d_name.name,
-                      d_i->d_name.name);
-               print_dir_tree(d_i, depth + 1);
-       }
-       TAILQ_FOREACH(d_i, &k_i_info->children, d_subdirs_link) {
-               printk("%sDir %s has child file: %s ", buf, dentry->d_name.name,
-                      d_i->d_name.name);
-               printk("file starts at: %p\n",
-                      ((struct kfs_i_info*)d_i->d_inode->i_fs_info)->filestart);
-       }
-}
index 812c0f2..f116501 100644 (file)
@@ -768,6 +768,7 @@ int mon_fs(int argc, char *NTS *NT COUNT(argc) argv, trapframe_t *tf)
        if (argc < 2) {
                printk("Usage: fs OPTION\n");
                printk("\topen: show all open files\n");
+               printk("\tls DIR: print the dir tree starting with DIR\n");
                printk("\tpid: proc PID's fs crap placeholder\n");
                return 1;
        }
@@ -778,6 +779,17 @@ int mon_fs(int argc, char *NTS *NT COUNT(argc) argv, trapframe_t *tf)
                               file_name(i), kref_refcnt(&i->f_kref),
                                   kref_refcnt(&i->f_dentry->d_kref),
                                   kref_refcnt(&i->f_dentry->d_inode->i_kref));
+       } else if (!strcmp(argv[1], "ls")) {
+               if (argc != 3) {
+                       printk("Give me a dir.\n");
+                       return 1;
+               }
+               if (argv[2][0] != '/') {
+                       printk("Dear fellow giraffe lover, Use absolute paths.\n");
+                       return 1;
+               }
+               ls_dash_r(argv[2]);
+               /* whatever.  placeholder. */
        } else if (!strcmp(argv[1], "pid")) {
                if (argc != 3) {
                        printk("Give me a pid number.\n");
index 9339f2a..ebd35c5 100644 (file)
@@ -1148,3 +1148,66 @@ void clone_files(struct files_struct *src, struct files_struct *dst)
        spin_unlock(&dst->lock);
        spin_unlock(&src->lock);
 }
+
+static void print_dir(struct dentry *dentry, char *buf, int depth)
+{
+       struct dentry *child_d;
+       struct dirent next;
+       struct file *dir;
+       int retval;
+       int child_num = 0;
+
+       if (!dentry->d_inode->i_type & FS_I_DIR) {
+               warn("Thought this was only directories!!");
+               return;
+       }
+       /* Print this dentry */
+       printk("%s%s/\n", buf, dentry->d_name.name);
+       if (depth >= 32)
+               return;
+       /* Set buffer for our kids */
+       buf[depth] = '\t';
+       dir = dentry_open(dentry, 0);
+       if (!dir)
+               panic("Filesystem seems inconsistent - unable to open a dir!");
+       /* Process every child, recursing on directories */
+       while (1) {
+               next.d_off = child_num++;
+               retval = dir->f_op->readdir(dir, &next);
+               if (retval >= 0) {
+                       /* there is an entry, now get its dentry */
+                       child_d = do_lookup(dentry, next.d_name);
+                       if (!child_d)
+                               panic("Inconsistent FS, dirent doesn't have a dentry!");
+                       /* Recurse for directories, or just print the name for others */
+                       if (child_d->d_inode->i_type & FS_I_DIR)
+                               print_dir(child_d, buf, depth + 1);
+                       else
+                               printk("%s%s  size(B): %d\n", buf, next.d_name,
+                                      child_d->d_inode->i_size);
+                       kref_put(&child_d->d_kref);     
+               }
+               if (retval <= 0)
+                       break;
+       }
+       /* Reset buffer to the way it was */
+       buf[depth] = '\0';
+       kref_put(&dir->f_kref);
+}
+
+/* Debugging */
+int ls_dash_r(char *path)
+{
+       struct nameidata nd_r = {0}, *nd = &nd_r;
+       int error;
+       char buf[32] = {0};
+
+       error = path_lookup(path, LOOKUP_ACCESS | LOOKUP_DIRECTORY, nd);
+       if (error) {
+               path_release(nd);
+               return error;
+       }
+       print_dir(nd->dentry, buf, 0);
+       path_release(nd);
+       return 0;
+}