Add time support to vfs
This commit is contained in:
parent
3cdb7b8748
commit
e83f88bacb
2
Makefile
2
Makefile
@ -68,6 +68,8 @@ term-kvm: system
|
||||
${EMU} ${EMUARGS} ${EMUKVM} -append "vid=qemu single hdd"
|
||||
debug: system
|
||||
${EMU} ${EMUARGS} -append "logtoserial=0 vid=qemu hdd"
|
||||
debug-term: system
|
||||
${EMU} ${EMUARGS} -append "logtoserial=0 vid=qemu single hdd"
|
||||
run-config: system
|
||||
util/config-parser | xargs ${EMU}
|
||||
|
||||
|
@ -927,6 +927,12 @@ uint32_t ext2_disk_node_from_file(ext2_inodetable_t *inode, ext2_dir_t *direntry
|
||||
if ((inode->mode & EXT2_S_IFLNK) == EXT2_S_IFLNK) {
|
||||
fnode->flags |= FS_SYMLINK;
|
||||
}
|
||||
|
||||
fnode->atime = inode->atime;
|
||||
fnode->mtime = inode->mtime;
|
||||
fnode->ctime = inode->ctime;
|
||||
debug_print(INFO, "file a/m/c times are %d/%d/%d", fnode->atime, fnode->mtime, fnode->ctime);
|
||||
|
||||
fnode->read = read_ext2_disk;
|
||||
fnode->write = write_ext2_disk;
|
||||
fnode->open = open_ext2_disk;
|
||||
@ -980,6 +986,11 @@ uint32_t ext2_disk_node_root(ext2_inodetable_t *inode, fs_node_t *fnode) {
|
||||
if ((inode->mode & EXT2_S_IFLNK) == EXT2_S_IFLNK) {
|
||||
fnode->flags |= FS_SYMLINK;
|
||||
}
|
||||
|
||||
fnode->atime = inode->atime;
|
||||
fnode->mtime = inode->mtime;
|
||||
fnode->ctime = inode->ctime;
|
||||
|
||||
fnode->read = read_ext2_disk;
|
||||
fnode->write = write_ext2_disk;
|
||||
fnode->open = open_ext2_disk;
|
||||
|
@ -206,6 +206,10 @@ fs_node_t * make_pipe(size_t size) {
|
||||
fnode->readdir = NULL;
|
||||
fnode->finddir = NULL;
|
||||
|
||||
fnode->atime = now();
|
||||
fnode->mtime = fnode->atime;
|
||||
fnode->ctime = fnode->atime;
|
||||
|
||||
fnode->inode = (uintptr_t)pipe;
|
||||
|
||||
pipe->buffer = malloc(size);
|
||||
|
@ -1,4 +1,9 @@
|
||||
/* Serial device */
|
||||
/* vim: tabstop=4 shiftwidth=4 noexpandtab
|
||||
*
|
||||
* Serial communication device
|
||||
*
|
||||
*/
|
||||
|
||||
#include <system.h>
|
||||
#include <fs.h>
|
||||
|
||||
@ -52,5 +57,10 @@ fs_node_t * serial_device_create(int device) {
|
||||
fnode->close = close_serial;
|
||||
fnode->readdir = NULL;
|
||||
fnode->finddir = NULL;
|
||||
|
||||
fnode->atime = now();
|
||||
fnode->mtime = fnode->atime;
|
||||
fnode->ctime = fnode->atime;
|
||||
|
||||
return fnode;
|
||||
}
|
||||
|
@ -56,6 +56,9 @@ typedef struct fs_node {
|
||||
struct fs_node *ptr; // Used by mountpoints and symlinks.
|
||||
uint32_t offset;
|
||||
int32_t shared_with;
|
||||
uint32_t atime;
|
||||
uint32_t mtime;
|
||||
uint32_t ctime;
|
||||
} fs_node_t;
|
||||
|
||||
struct dirent {
|
||||
@ -68,10 +71,16 @@ struct stat {
|
||||
uint16_t st_ino;
|
||||
uint32_t st_mode;
|
||||
uint16_t st_nlink;
|
||||
uint16_t st_uid;
|
||||
uint16_t st_gid;
|
||||
uint16_t st_uid;
|
||||
uint16_t st_gid;
|
||||
uint16_t st_rdev;
|
||||
uint32_t st_size;
|
||||
uint32_t st_atime;
|
||||
uint32_t __unused1;
|
||||
uint32_t st_mtime;
|
||||
uint32_t __unused2;
|
||||
uint32_t st_ctime;
|
||||
uint32_t __unused3;
|
||||
};
|
||||
|
||||
extern fs_node_t *fs_root;
|
||||
|
@ -261,6 +261,10 @@ static int stat(int fd, uint32_t st) {
|
||||
f->st_rdev = 0;
|
||||
f->st_size = fn->length;
|
||||
|
||||
f->st_atime = fn->atime;
|
||||
f->st_mtime = fn->mtime;
|
||||
f->st_ctime = fn->ctime;
|
||||
|
||||
if (fn->flags & FS_PIPE) {
|
||||
/* Pipes have dynamic sizes */
|
||||
f->st_size = pipe_size(fn);
|
||||
|
@ -32,6 +32,8 @@
|
||||
|
||||
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||
|
||||
#define LINE_LEN 4096
|
||||
|
||||
/* The program */
|
||||
|
||||
int entcmp(const void * c1, const void * c2) {
|
||||
@ -72,6 +74,32 @@ void print_entry(const char * filename, const char * srcpath, int colwidth) {
|
||||
}
|
||||
}
|
||||
|
||||
void print_username(int uid) {
|
||||
FILE * passwd = fopen("/etc/passwd", "r");
|
||||
char line[LINE_LEN];
|
||||
|
||||
while (fgets(line, LINE_LEN, passwd) != NULL) {
|
||||
|
||||
line[strlen(line)-1] = '\0';
|
||||
|
||||
char *p, *tokens[10], *last;
|
||||
int i = 0;
|
||||
for ((p = strtok_r(line, ":", &last)); p;
|
||||
(p = strtok_r(NULL, ":", &last)), i++) {
|
||||
if (i < 511) tokens[i] = p;
|
||||
}
|
||||
tokens[i] = NULL;
|
||||
|
||||
if (atoi(tokens[2]) == uid) {
|
||||
printf("%s", tokens[0]);
|
||||
fclose(passwd);
|
||||
return;
|
||||
}
|
||||
}
|
||||
printf("%d", uid);
|
||||
fclose(passwd);
|
||||
}
|
||||
|
||||
void print_entry_long(const char * filename, const char * srcpath) {
|
||||
/* Figure out full relpath */
|
||||
char * relpath = malloc(strlen(srcpath) + strlen(filename) + 2);
|
||||
@ -94,7 +122,12 @@ void print_entry_long(const char * filename, const char * srcpath) {
|
||||
ansi_color_str = REG_COLOR;
|
||||
}
|
||||
|
||||
printf( (S_ISDIR(statbuf.st_mode)) ? "d" : "-");
|
||||
/* file permissions */
|
||||
if (S_ISLNK(statbuf.st_mode)) {
|
||||
printf("l");
|
||||
} else {
|
||||
printf( (S_ISDIR(statbuf.st_mode)) ? "d" : "-");
|
||||
}
|
||||
printf( (statbuf.st_mode & S_IRUSR) ? "r" : "-");
|
||||
printf( (statbuf.st_mode & S_IWUSR) ? "w" : "-");
|
||||
printf( (statbuf.st_mode & S_IXUSR) ? "x" : "-");
|
||||
@ -105,7 +138,20 @@ void print_entry_long(const char * filename, const char * srcpath) {
|
||||
printf( (statbuf.st_mode & S_IWOTH) ? "w" : "-");
|
||||
printf( (statbuf.st_mode & S_IXOTH) ? "x" : "-");
|
||||
|
||||
printf(" %10d ", statbuf.st_size);
|
||||
printf( " - "); /* number of links, not supported */
|
||||
|
||||
print_username(statbuf.st_uid);
|
||||
printf("\t");
|
||||
print_username(statbuf.st_gid);
|
||||
printf("\t");
|
||||
|
||||
printf(" %8d ", statbuf.st_size);
|
||||
|
||||
char time_buf[80];
|
||||
struct tm * timeinfo;
|
||||
timeinfo = localtime(&statbuf.st_mtime);
|
||||
strftime(time_buf, 80, "%b %d %Y", timeinfo);
|
||||
printf("%s ", time_buf);
|
||||
|
||||
/* Print the file name */
|
||||
printf("\033[%sm%s\033[0m\n", ansi_color_str, filename);
|
||||
|
Loading…
x
Reference in New Issue
Block a user