8 static struct file
* tfs_file_open(struct tfs_sb_info
*sbi
, char *filename
, uint32_t flags
)
12 file
= tfs_open(sbi
, filename
, flags
);
14 printk("tfs_open: open file %s error!\n", filename
);
21 void cd(struct tfs_sb_info
*sbi
, char *dst_dir
)
26 this_dir
= tfs_opendir(sbi
, dst_dir
);
28 printk("cd: %s: no such directory\n", dst_dir
);
33 if (this_dir
->dd_dir
->inode
->i_mode
!= TFS_DIR
) {
34 printk("cd: %s: is not a directory\n", dst_dir
);
35 tfs_closedir(this_dir
);
42 TFS_DEBUG("CDed in '%s' with inode '%d'\n", dst_dir
, this_dir
->dd_dir
->inode
->i_ino
);
46 void cat(struct tfs_sb_info
*sbi
, char *filename
)
48 struct file
*file
= tfs_file_open(sbi
, filename
, 0);
54 while ((bytes_read
= tfs_read(file
, buf
, sizeof(buf
))) > 0)
59 void ls(struct tfs_sb_info
*sbi
, char *filename
)
61 DIR *dir
= tfs_opendir(sbi
, filename
);
65 printk("open dir %s failed!\n", filename
);
69 if (dir
->dd_dir
->inode
->i_mode
== TFS_FILE
) {
70 printk("%d\t %s\n", dir
->dd_dir
->inode
->i_ino
, filename
);
75 while ((de
= tfs_readdir(dir
))) {
76 printk("%6d\t %s\n", de
->d_ino
, de
->d_name
);
83 void mkdir(struct tfs_sb_info
*sbi
, char *filename
)
85 tfs_mkdir(sbi
, filename
);
88 void rmdir(struct tfs_sb_info
*sbi
, char *filename
)
90 tfs_rmdir(sbi
, filename
);
93 void rm(struct tfs_sb_info
*sbi
, char *filename
)
95 tfs_unlink(sbi
, filename
);
98 void touch (struct tfs_sb_info
*sbi
, char *filename
)
100 struct file
*file
= tfs_file_open(sbi
, filename
, LOOKUP_CREATE
);
104 void cp(struct tfs_sb_info
*sbi
, char *from
, char *to
)
108 struct file
*from_file
;
109 struct file
*to_file
;
112 from_file
= tfs_file_open(sbi
, from
, 0);
115 to_file
= tfs_file_open(sbi
, to
, LOOKUP_CREATE
);
117 tfs_close(from_file
);
121 while ((count
= tfs_read(from_file
, buf
, sizeof(buf
))) > 0) {
122 count
= tfs_write(to_file
, buf
, count
);
124 printk("write error!\n");
126 printk(" == %d bytes written!\n", count
);
129 tfs_close(from_file
);