This commit was manufactured by cvs2svn to create branch
[linux-2.6.git] / arch / um / include / os.h
1 /* 
2  * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3  * Licensed under the GPL
4  */
5
6 #ifndef __OS_H__
7 #define __OS_H__
8
9 #include "asm/types.h"
10 #include "../os/include/file.h"
11
12 #define OS_TYPE_FILE 1 
13 #define OS_TYPE_DIR 2 
14 #define OS_TYPE_SYMLINK 3 
15 #define OS_TYPE_CHARDEV 4
16 #define OS_TYPE_BLOCKDEV 5
17 #define OS_TYPE_FIFO 6
18 #define OS_TYPE_SOCK 7
19
20 /* os_access() flags */
21 #define OS_ACC_F_OK    0       /* Test for existence.  */
22 #define OS_ACC_X_OK    1       /* Test for execute permission.  */
23 #define OS_ACC_W_OK    2       /* Test for write permission.  */
24 #define OS_ACC_R_OK    4       /* Test for read permission.  */
25 #define OS_ACC_RW_OK   (OS_ACC_W_OK | OS_ACC_R_OK) /* Test for RW permission */
26
27 /*
28  * types taken from stat_file() in hostfs_user.c
29  * (if they are wrong here, they are wrong there...).
30  */
31 struct uml_stat {
32         int                ust_major;      /* device */
33         int                ust_minor;
34         unsigned long long ust_ino;        /* inode */
35         int                ust_mode;       /* protection */
36         int                ust_nlink;      /* number of hard links */
37         int                ust_uid;        /* user ID of owner */
38         int                ust_gid;        /* group ID of owner */
39         unsigned long long ust_size;       /* total size, in bytes */
40         int                ust_blksize;    /* blocksize for filesystem I/O */
41         unsigned long long ust_blocks;     /* number of blocks allocated */
42         unsigned long      ust_atime;      /* time of last access */
43         unsigned long      ust_mtime;      /* time of last modification */
44         unsigned long      ust_ctime;      /* time of last change */
45         int                ust_rmajor;
46         int                ust_rminor;
47 };
48
49 struct openflags {
50         unsigned int r : 1;
51         unsigned int w : 1;
52         unsigned int s : 1;     /* O_SYNC */
53         unsigned int c : 1;     /* O_CREAT */
54         unsigned int t : 1;     /* O_TRUNC */
55         unsigned int a : 1;     /* O_APPEND */
56         unsigned int e : 1;     /* O_EXCL */
57         unsigned int cl : 1;    /* FD_CLOEXEC */
58         unsigned int d : 1;     /* O_DIRECT */
59 };
60
61 #define OPENFLAGS() ((struct openflags) { .r = 0, .w = 0, .s = 0, .c = 0, \
62                                           .t = 0, .a = 0, .e = 0, .cl = 0, \
63                                           .d = 0 })
64
65 static inline struct openflags of_read(struct openflags flags)
66 {
67         flags.r = 1; 
68         return(flags);
69 }
70
71 static inline struct openflags of_write(struct openflags flags)
72 {
73         flags.w = 1; 
74         return(flags); 
75 }
76
77 static inline struct openflags of_rdwr(struct openflags flags)
78 {
79         return(of_read(of_write(flags)));
80 }
81
82 static inline struct openflags of_set_rw(struct openflags flags, int r, int w)
83 {
84         flags.r = r;
85         flags.w = w;
86         return(flags);
87 }
88
89 static inline struct openflags of_sync(struct openflags flags)
90
91         flags.s = 1; 
92         return(flags); 
93 }
94
95 static inline struct openflags of_create(struct openflags flags)
96
97         flags.c = 1; 
98         return(flags); 
99 }
100  
101 static inline struct openflags of_trunc(struct openflags flags)
102
103         flags.t = 1; 
104         return(flags); 
105 }
106  
107 static inline struct openflags of_append(struct openflags flags)
108
109         flags.a = 1; 
110         return(flags); 
111 }
112  
113 static inline struct openflags of_excl(struct openflags flags)
114
115         flags.e = 1; 
116         return(flags); 
117 }
118
119 static inline struct openflags of_cloexec(struct openflags flags)
120
121         flags.cl = 1; 
122         return(flags); 
123 }
124   
125 static inline struct openflags of_direct(struct openflags flags)
126
127         flags.d = 1; 
128         return(flags); 
129 }
130
131 extern int os_stat_file(const char *file_name, struct uml_stat *buf);
132 extern int os_lstat_file(const char *file_name, struct uml_stat *ubuf);
133 extern int os_stat_fd(const int fd, struct uml_stat *buf);
134 extern int os_access(const char *file, int mode);
135 extern int os_set_file_time(const char *file, unsigned long access, 
136                             unsigned long mod);
137 extern int os_set_file_perms(const char *file, int mode);
138 extern int os_set_file_owner(const char *file, int owner, int group);
139 extern void os_print_error(int error, const char* str);
140 extern int os_get_exec_close(int fd, int *close_on_exec);
141 extern int os_set_exec_close(int fd, int close_on_exec);
142 extern int os_ioctl_generic(int fd, unsigned int cmd, unsigned long arg);
143 extern int os_window_size(int fd, int *rows, int *cols);
144 extern int os_new_tty_pgrp(int fd, int pid);
145 extern int os_get_ifname(int fd, char *namebuf);
146 extern int os_set_slip(int fd);
147 extern int os_set_owner(int fd, int pid);
148 extern int os_sigio_async(int master, int slave);
149 extern int os_mode_fd(int fd, int mode);
150
151 extern int os_seek_file(int fd, __u64 offset);
152 extern int os_open_file(char *file, struct openflags flags, int mode);
153 extern void *os_open_dir(char *dir, int *err_out);
154 extern int os_seek_dir(void *stream, unsigned long long pos);
155 extern int os_read_dir(void *stream, unsigned long long *ino_out, 
156                        char **name_out);
157 extern int os_tell_dir(void *stream);
158 extern int os_close_dir(void *stream);
159 extern int os_remove_file(const char *file);
160 extern int os_move_file(const char *from, const char *to);
161 extern int os_truncate_file(const char *file, unsigned long long len);
162 extern int os_truncate_fd(int fd, unsigned long long len);
163 extern int os_read_file(int fd, void *buf, int len);
164 extern int os_write_file(int fd, const void *buf, int count);
165 extern int os_file_size(char *file, long long *size_out);
166 extern int os_fd_size(int fd, long long *size_out);
167 extern int os_file_modtime(char *file, unsigned long *modtime);
168 extern int os_pipe(int *fd, int stream, int close_on_exec);
169 extern int os_set_fd_async(int fd, int owner);
170 extern int os_clear_fd_async(int fd);
171 extern int os_set_fd_block(int fd, int blocking);
172 extern int os_accept_connection(int fd);
173 extern int os_create_unix_socket(char *file, int len, int close_on_exec);
174 extern int os_make_symlink(const char *to, const char *from);
175 extern int os_read_symlink(const char *file, char *buf, int size);
176 extern int os_link_file(const char *to, const char *from);
177 extern int os_make_dir(const char *dir, int mode);
178 extern int os_remove_dir(const char *dir);
179 extern int os_make_dev(const char *name, int mode, int major, int minor);
180 extern int os_shutdown_socket(int fd, int r, int w);
181 extern void os_close_file(int fd);
182 extern int os_rcv_fd(int fd, int *helper_pid_out);
183 extern int create_unix_socket(char *file, int len, int close_on_exec);
184 extern int os_connect_socket(char *name);
185 extern int os_file_type(char *file);
186 extern int os_file_mode(char *file, struct openflags *mode_out);
187 extern int os_lock_file(int fd, int excl);
188
189 extern unsigned long os_process_pc(int pid);
190 extern int os_process_parent(int pid);
191 extern void os_stop_process(int pid);
192 extern void os_kill_process(int pid, int reap_child);
193 extern void os_usr1_process(int pid);
194 extern int os_getpid(void);
195
196 extern int os_map_memory(void *virt, int fd, unsigned long long off, 
197                          unsigned long len, int r, int w, int x);
198 extern int os_protect_memory(void *addr, unsigned long len, 
199                              int r, int w, int x);
200 extern int os_unmap_memory(void *addr, int len);
201 extern void os_flush_stdout(void);
202 extern int os_stat_filesystem(char *path, long *bsize_out, 
203                               long long *blocks_out, long long *bfree_out,
204                               long long *bavail_out, long long *files_out,
205                               long long *ffree_out, void *fsid_out, 
206                               int fsid_size, long *namelen_out, 
207                               long *spare_out);
208 extern unsigned long long os_usecs(void);
209
210 #endif
211
212 /*
213  * Overrides for Emacs so that we follow Linus's tabbing style.
214  * Emacs will notice this stuff at the end of the file and automatically
215  * adjust the settings for this buffer only.  This must remain at the end
216  * of the file.
217  * ---------------------------------------------------------------------------
218  * Local variables:
219  * c-file-style: "linux"
220  * End:
221  */