VirtualBox

source: kBuild/trunk/src/kash/shfile.h@ 2309

Last change on this file since 2309 was 2307, checked in by bird, 16 years ago

kash: More file inheritance stuff.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
File size: 5.1 KB
Line 
1/* $Id: shfile.h 2307 2009-03-01 09:48:04Z bird $ */
2/** @file
3 *
4 * File management.
5 *
6 * Copyright (c) 2007-2009 knut st. osmundsen <[email protected]>
7 *
8 *
9 * This file is part of kBuild.
10 *
11 * kBuild is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * kBuild is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with kBuild; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 *
25 */
26
27#ifndef ___shfile_h
28#define ___shfile_h
29
30#include "shtypes.h"
31#include "shthread.h"
32#include <fcntl.h>
33#include <sys/stat.h>
34#ifdef _MSC_VER
35# define _PATH_DEVNULL "nul"
36# define _PATH_DEFPATH "."
37#else
38# if !defined(__sun__)
39# include <paths.h>
40# endif
41# ifdef _PATH_DEVNULL
42# define _PATH_DEVNULL "/dev/null"
43# endif
44# ifndef _PATH_DEFPATH
45# define _PATH_DEFPATH "/bin:/usr/bin:/sbin:/usr/sbin"
46# endif
47#endif
48#ifndef _MSC_VER
49# include <sys/fcntl.h>
50# include <unistd.h>
51# ifndef O_BINARY
52# define O_BINARY 0
53# endif
54# ifndef O_TEXT
55# define O_TEXT 0
56# endif
57
58#else
59# include <io.h>
60# include <direct.h>
61
62# define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
63# define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
64# define S_ISLNK(m) 0
65# define S_IRWXU (_S_IREAD | _S_IWRITE | _S_IEXEC)
66# define S_IXUSR _S_IEXEC
67# define S_IWUSR _S_IWRITE
68# define S_IRUSR _S_IREAD
69# define S_IRWXG 0000070
70# define S_IRGRP 0000040
71# define S_IWGRP 0000020
72# define S_IXGRP 0000010
73# define S_IRWXO 0000007
74# define S_IROTH 0000004
75# define S_IWOTH 0000002
76# define S_IXOTH 0000001
77# define S_ISUID 0004000
78# define S_ISGID 0002000
79# define ALLPERMS 0000777
80
81# define F_DUPFD 0
82# define F_GETFD 1
83# define F_SETFD 2
84# define F_GETFL 3
85# define F_SETFL 4
86# define FD_CLOEXEC 1
87
88# define F_OK 0
89# define X_OK 1
90# define W_OK 2
91# define R_OK 4
92
93# define O_NONBLOCK 0 /** @todo */
94
95#endif
96
97
98/**
99 * One file.
100 */
101typedef struct shfile
102{
103 int fd; /**< The shell file descriptor number. */
104 unsigned oflags; /**< Open flags. */
105 unsigned shflags; /**< The shell file descriptor flags. */
106 intptr_t native; /**< The native file descriptor number. */
107} shfile;
108
109/** @name shfile::shflags values.
110 * @{
111 */
112#define SHFILE_FLAGS_CLOSE_ON_EXEC 0x0001
113#define SHFILE_FLAGS_TYPE_MASK 0x00f0
114#define SHFILE_FLAGS_FILE 0x0000
115#define SHFILE_FLAGS_PIPE 0x0010
116#define SHFILE_FLAGS_DIR 0x0020
117#define SHFILE_FLAGS_TTY 0x0030
118/** @} */
119
120/**
121 * The file descriptor table for a shell.
122 */
123typedef struct shfdtab
124{
125 shmtx mtx; /**< Mutex protecting any operations on the table and it's handles. */
126 char *cwd; /**< The current directory for this shell instance. */
127 unsigned size; /**< The size of the table (number of entries). */
128 shfile *tab; /**< Pointer to the table. */
129} shfdtab;
130
131int shfile_init(shfdtab *, shfdtab *);
132void shfile_fork_win(shfdtab *pfdtab, int set, intptr_t *hndls);
133void *shfile_exec_win(shfdtab *pfdtab, int prepare, unsigned short *sizep, intptr_t *hndls);
134
135int shfile_open(shfdtab *, const char *, unsigned, mode_t);
136int shfile_pipe(shfdtab *, int [2]);
137int shfile_close(shfdtab *, unsigned);
138long shfile_read(shfdtab *, int, void *, size_t);
139long shfile_write(shfdtab *, int, const void *, size_t);
140long shfile_lseek(shfdtab *, int, long, int);
141int shfile_fcntl(shfdtab *, int fd, int cmd, int arg);
142int shfile_dup(shfdtab *, int fd);
143
144int shfile_stat(shfdtab *, const char *, struct stat *);
145int shfile_lstat(shfdtab *, const char *, struct stat *);
146int shfile_chdir(shfdtab *, const char *);
147char *shfile_getcwd(shfdtab *, char *, int);
148int shfile_access(shfdtab *, const char *, int);
149int shfile_isatty(shfdtab *, int);
150int shfile_cloexec(shfdtab *, int, int);
151int shfile_ioctl(shfdtab *, int, unsigned long, void *);
152#ifdef _MSC_VER
153# define TIOCGWINSZ 0x4201
154typedef struct sh_winsize
155{
156 unsigned ws_row; /**< Rows, in characters. */
157 unsigned ws_col; /**< Columns, in characters. */
158 unsigned ws_xpixel; /**< Horizontal size, pixels. */
159 unsigned ws_ypixel; /**< Vertical size, pixels. */
160} sh_winsize;
161#else
162typedef struct winsize sh_winsize;
163#endif
164mode_t shfile_get_umask(shfdtab *);
165void shfile_set_umask(shfdtab *, mode_t);
166
167
168typedef struct sh_dirent
169{
170 char name[260];
171} shdirent;
172
173typedef struct shdir
174{
175 shfdtab *shfdtab;
176 void *native;
177 shdirent ent;
178} shdir;
179
180shdir *shfile_opendir(shfdtab *, const char *);
181shdirent *shfile_readdir(struct shdir *);
182void shfile_closedir(struct shdir *);
183
184#endif
185
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette