2 * Copyright 2005-2007, Ingo Weinhold, bonefish@users.sf.net.
3 * Distributed under the terms of the MIT License.
6 #include "compatibility.h"
13 #include "fssh_fcntl.h"
14 #include "fssh_stat.h"
19 // Haiku only mode_t flags
20 #ifndef HAIKU_HOST_PLATFORM_HAIKU
21 # define S_LINK_SELF_HEALING 0
22 # define S_LINK_AUTO_DELETE 0
27 from_platform_mode(mode_t mode
)
29 #define SET_ST_MODE_BIT(flag, fsshFlag) \
33 fssh_mode_t fsshMode
= 0;
36 #if (defined(__BEOS__) || defined(__HAIKU__))
37 SET_ST_MODE_BIT(FSSH_S_ATTR_DIR
, S_ATTR_DIR
);
38 SET_ST_MODE_BIT(FSSH_S_ATTR
, S_ATTR
);
39 SET_ST_MODE_BIT(FSSH_S_INDEX_DIR
, S_INDEX_DIR
);
40 SET_ST_MODE_BIT(FSSH_S_INT_INDEX
, S_INT_INDEX
);
41 SET_ST_MODE_BIT(FSSH_S_UINT_INDEX
, S_UINT_INDEX
);
42 SET_ST_MODE_BIT(FSSH_S_LONG_LONG_INDEX
, S_LONG_LONG_INDEX
);
43 SET_ST_MODE_BIT(FSSH_S_ULONG_LONG_INDEX
, S_ULONG_LONG_INDEX
);
44 SET_ST_MODE_BIT(FSSH_S_FLOAT_INDEX
, S_FLOAT_INDEX
);
45 SET_ST_MODE_BIT(FSSH_S_DOUBLE_INDEX
, S_DOUBLE_INDEX
);
46 SET_ST_MODE_BIT(FSSH_S_ALLOW_DUPS
, S_ALLOW_DUPS
);
47 SET_ST_MODE_BIT(FSSH_S_LINK_SELF_HEALING
, S_LINK_SELF_HEALING
);
48 SET_ST_MODE_BIT(FSSH_S_LINK_AUTO_DELETE
, S_LINK_AUTO_DELETE
);
51 switch (mode
& S_IFMT
) {
53 fsshMode
|= FSSH_S_IFLNK
;
56 fsshMode
|= FSSH_S_IFREG
;
59 fsshMode
|= FSSH_S_IFBLK
;
62 fsshMode
|= FSSH_S_IFDIR
;
65 fsshMode
|= FSSH_S_IFIFO
;
69 SET_ST_MODE_BIT(FSSH_S_ISUID
, S_ISUID
);
70 SET_ST_MODE_BIT(FSSH_S_ISGID
, S_ISGID
);
71 SET_ST_MODE_BIT(FSSH_S_ISVTX
, S_ISVTX
);
72 SET_ST_MODE_BIT(FSSH_S_IRUSR
, S_IRUSR
);
73 SET_ST_MODE_BIT(FSSH_S_IWUSR
, S_IWUSR
);
74 SET_ST_MODE_BIT(FSSH_S_IXUSR
, S_IXUSR
);
75 SET_ST_MODE_BIT(FSSH_S_IRGRP
, S_IRGRP
);
76 SET_ST_MODE_BIT(FSSH_S_IWGRP
, S_IWGRP
);
77 SET_ST_MODE_BIT(FSSH_S_IXGRP
, S_IXGRP
);
78 SET_ST_MODE_BIT(FSSH_S_IROTH
, S_IROTH
);
79 SET_ST_MODE_BIT(FSSH_S_IWOTH
, S_IWOTH
);
80 SET_ST_MODE_BIT(FSSH_S_IXOTH
, S_IXOTH
);
82 #undef SET_ST_MODE_BIT
89 to_platform_mode(fssh_mode_t fsshMode
)
91 #define SET_ST_MODE_BIT(flag, fsshFlag) \
92 if (fsshMode & fsshFlag) \
98 #if (defined(__BEOS__) || defined(__HAIKU__))
99 SET_ST_MODE_BIT(FSSH_S_ATTR_DIR
, S_ATTR_DIR
);
100 SET_ST_MODE_BIT(FSSH_S_ATTR
, S_ATTR
);
101 SET_ST_MODE_BIT(FSSH_S_INDEX_DIR
, S_INDEX_DIR
);
102 SET_ST_MODE_BIT(FSSH_S_INT_INDEX
, S_INT_INDEX
);
103 SET_ST_MODE_BIT(FSSH_S_UINT_INDEX
, S_UINT_INDEX
);
104 SET_ST_MODE_BIT(FSSH_S_LONG_LONG_INDEX
, S_LONG_LONG_INDEX
);
105 SET_ST_MODE_BIT(FSSH_S_ULONG_LONG_INDEX
, S_ULONG_LONG_INDEX
);
106 SET_ST_MODE_BIT(FSSH_S_FLOAT_INDEX
, S_FLOAT_INDEX
);
107 SET_ST_MODE_BIT(FSSH_S_DOUBLE_INDEX
, S_DOUBLE_INDEX
);
108 SET_ST_MODE_BIT(FSSH_S_ALLOW_DUPS
, S_ALLOW_DUPS
);
109 SET_ST_MODE_BIT(FSSH_S_LINK_SELF_HEALING
, S_LINK_SELF_HEALING
);
110 SET_ST_MODE_BIT(FSSH_S_LINK_AUTO_DELETE
, S_LINK_AUTO_DELETE
);
113 switch (fsshMode
& FSSH_S_IFMT
) {
131 SET_ST_MODE_BIT(FSSH_S_ISUID
, S_ISUID
);
132 SET_ST_MODE_BIT(FSSH_S_ISGID
, S_ISGID
);
133 SET_ST_MODE_BIT(FSSH_S_ISVTX
, S_ISVTX
);
134 SET_ST_MODE_BIT(FSSH_S_IRUSR
, S_IRUSR
);
135 SET_ST_MODE_BIT(FSSH_S_IWUSR
, S_IWUSR
);
136 SET_ST_MODE_BIT(FSSH_S_IXUSR
, S_IXUSR
);
137 SET_ST_MODE_BIT(FSSH_S_IRGRP
, S_IRGRP
);
138 SET_ST_MODE_BIT(FSSH_S_IWGRP
, S_IWGRP
);
139 SET_ST_MODE_BIT(FSSH_S_IXGRP
, S_IXGRP
);
140 SET_ST_MODE_BIT(FSSH_S_IROTH
, S_IROTH
);
141 SET_ST_MODE_BIT(FSSH_S_IWOTH
, S_IWOTH
);
142 SET_ST_MODE_BIT(FSSH_S_IXOTH
, S_IXOTH
);
144 #undef SET_ST_MODE_BIT
151 from_platform_stat(const struct stat
*st
, struct fssh_stat
*fsshStat
)
153 fsshStat
->fssh_st_dev
= st
->st_dev
;
154 fsshStat
->fssh_st_ino
= st
->st_ino
;
155 fsshStat
->fssh_st_mode
= from_platform_mode(st
->st_mode
);
156 fsshStat
->fssh_st_nlink
= st
->st_nlink
;
157 fsshStat
->fssh_st_uid
= st
->st_uid
;
158 fsshStat
->fssh_st_gid
= st
->st_gid
;
159 fsshStat
->fssh_st_size
= st
->st_size
;
160 fsshStat
->fssh_st_blksize
= st
->st_blksize
;
161 fsshStat
->fssh_st_atime
= st
->st_atime
;
162 fsshStat
->fssh_st_mtime
= st
->st_mtime
;
163 fsshStat
->fssh_st_ctime
= st
->st_ctime
;
164 fsshStat
->fssh_st_crtime
= st
->st_ctime
;
165 fsshStat
->fssh_st_type
= 0;
170 to_platform_stat(const struct fssh_stat
*fsshStat
, struct stat
*st
)
172 st
->st_dev
= fsshStat
->fssh_st_dev
;
173 st
->st_ino
= fsshStat
->fssh_st_ino
;
174 st
->st_mode
= to_platform_mode(fsshStat
->fssh_st_mode
);
175 st
->st_nlink
= fsshStat
->fssh_st_nlink
;
176 st
->st_uid
= fsshStat
->fssh_st_uid
;
177 st
->st_gid
= fsshStat
->fssh_st_gid
;
178 st
->st_size
= fsshStat
->fssh_st_size
;
179 st
->st_blksize
= fsshStat
->fssh_st_blksize
;
180 st
->st_atime
= fsshStat
->fssh_st_atime
;
181 st
->st_mtime
= fsshStat
->fssh_st_mtime
;
182 st
->st_ctime
= fsshStat
->fssh_st_ctime
;
183 // st->st_crtime = fsshStat->fssh_st_crtime;
184 // st->st_type = fsshStat->fssh_st_type;
189 to_platform_open_mode(int fsshMode
)
191 #define SET_OPEN_MODE_FLAG(flag, fsshFlag) \
192 if (fsshMode & fsshFlag) \
198 switch (fsshMode
& FSSH_O_RWMASK
) {
211 //SET_OPEN_MODE_FLAG(O_CLOEXEC, FSSH_O_CLOEXEC)
212 SET_OPEN_MODE_FLAG(O_NONBLOCK
, FSSH_O_NONBLOCK
)
213 SET_OPEN_MODE_FLAG(O_EXCL
, FSSH_O_EXCL
)
214 SET_OPEN_MODE_FLAG(O_CREAT
, FSSH_O_CREAT
)
215 SET_OPEN_MODE_FLAG(O_TRUNC
, FSSH_O_TRUNC
)
216 SET_OPEN_MODE_FLAG(O_APPEND
, FSSH_O_APPEND
)
217 SET_OPEN_MODE_FLAG(O_NOCTTY
, FSSH_O_NOCTTY
)
218 SET_OPEN_MODE_FLAG(O_NOTRAVERSE
, FSSH_O_NOTRAVERSE
)
219 //SET_OPEN_MODE_FLAG(O_TEXT, FSSH_O_TEXT)
220 //SET_OPEN_MODE_FLAG(O_BINARY, FSSH_O_BINARY)
222 #undef SET_OPEN_MODE_FLAG
227 } // namespace FSShell