summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjdike <jdike>2004-04-07 20:44:49 +0000
committerjdike <jdike>2004-04-07 20:44:49 +0000
commit4c71bbd87ef2ba262e8be1832765100eaa93828d (patch)
tree0202337eeb4bde900d0d539689b1e9ffb65d034a
parent8a6ea56bd5cb82f5cf2b7d80265841d2325f8610 (diff)
downloaduml-history-4c71bbd87ef2ba262e8be1832765100eaa93828d.tar.gz
Added some more file operations, plus os_usecs.
-rw-r--r--arch/um/include/os.h8
-rw-r--r--arch/um/os-Linux/file.c68
-rw-r--r--arch/um/os-Linux/time.c21
3 files changed, 96 insertions, 1 deletions
diff --git a/arch/um/include/os.h b/arch/um/include/os.h
index 7d6b4a8..bc610a5 100644
--- a/arch/um/include/os.h
+++ b/arch/um/include/os.h
@@ -134,12 +134,17 @@ extern int os_mode_fd(int fd, int mode);
extern int os_seek_file(int fd, __u64 offset);
extern int os_open_file(char *file, struct openflags flags, int mode);
+extern int os_remove_file(const char *file);
+extern int os_remove_dir(const char *file);
+extern int os_truncate_fd(int fd, unsigned long long len);
extern int os_read_file(int fd, void *buf, int len);
extern int os_write_file(int fd, const void *buf, int count);
extern int os_file_size(char *file, long long *size_out);
+extern int os_fd_size(int fd, long long *size_out);
extern int os_file_modtime(char *file, unsigned long *modtime);
extern int os_pipe(int *fd, int stream, int close_on_exec);
extern int os_set_fd_async(int fd, int owner);
+extern int os_clear_fd_async(int fd);
extern int os_set_fd_block(int fd, int blocking);
extern int os_accept_connection(int fd);
extern int os_create_unix_socket(char *file, int len, int close_on_exec);
@@ -165,6 +170,9 @@ extern int os_protect_memory(void *addr, unsigned long len,
int r, int w, int x);
extern int os_unmap_memory(void *addr, int len);
extern void os_flush_stdout(void);
+extern int os_ftruncate(int fd, __u64 size);
+
+extern unsigned long long os_usecs(void);
#endif
diff --git a/arch/um/os-Linux/file.c b/arch/um/os-Linux/file.c
index 4083bf9..03f8938 100644
--- a/arch/um/os-Linux/file.c
+++ b/arch/um/os-Linux/file.c
@@ -278,6 +278,38 @@ int os_open_file(char *file, struct openflags flags, int mode)
return(fd);
}
+int os_remove_file(const char *file)
+{
+ int err;
+
+ err = unlink(file);
+ if(err)
+ return(-errno);
+
+ return(0);
+}
+
+int os_truncate_fd(int fd, unsigned long long len)
+{
+ int err;
+
+ err = ftruncate(fd, len);
+ if(err)
+ return(-errno);
+ return(0);
+}
+
+int os_remove_dir(const char *file)
+{
+ int err;
+
+ err = rmdir(file);
+ if(err)
+ return(-errno);
+
+ return(0);
+}
+
int os_connect_socket(char *name)
{
struct sockaddr_un sock;
@@ -307,7 +339,8 @@ int os_seek_file(int fd, __u64 offset)
__u64 actual;
actual = lseek64(fd, offset, SEEK_SET);
- if(actual != offset) return(-errno);
+ if(actual != offset)
+ return(-errno);
return(0);
}
@@ -395,6 +428,19 @@ int os_file_size(char *file, long long *size_out)
return(0);
}
+int os_fd_size(int fd, long long *size_out)
+{
+ struct stat buf;
+ int err;
+
+ err = fstat(fd, &buf);
+ if(err)
+ return(-errno);
+
+ *size_out = buf.st_size;
+ return(0);
+}
+
int os_file_modtime(char *file, unsigned long *modtime)
{
struct uml_stat buf;
@@ -495,6 +541,16 @@ int os_set_fd_async(int fd, int owner)
return(0);
}
+int os_clear_fd_async(int fd)
+{
+ int flags = fcntl(fd, F_GETFL);
+
+ flags &= ~(O_ASYNC | O_NONBLOCK);
+ if(fcntl(fd, F_SETFL, flags) < 0)
+ return(-errno);
+ return(0);
+}
+
int os_set_fd_block(int fd, int blocking)
{
int flags;
@@ -656,6 +712,16 @@ int os_lock_file(int fd, int excl)
return(err);
}
+int os_ftruncate(int fd, __u64 size)
+{
+ int err;
+
+ err = ftruncate(fd, size);
+ if(err < 0)
+ return(-errno);
+ return(0);
+}
+
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
diff --git a/arch/um/os-Linux/time.c b/arch/um/os-Linux/time.c
new file mode 100644
index 0000000..cf30a39
--- /dev/null
+++ b/arch/um/os-Linux/time.c
@@ -0,0 +1,21 @@
+#include <stdlib.h>
+#include <sys/time.h>
+
+unsigned long long os_usecs(void)
+{
+ struct timeval tv;
+
+ gettimeofday(&tv, NULL);
+ return((unsigned long long) tv.tv_sec * 1000000 + tv.tv_usec);
+}
+
+/*
+ * Overrides for Emacs so that we follow Linus's tabbing style.
+ * Emacs will notice this stuff at the end of the file and automatically
+ * adjust the settings for this buffer only. This must remain at the end
+ * of the file.
+ * ---------------------------------------------------------------------------
+ * Local variables:
+ * c-file-style: "linux"
+ * End:
+ */