2 * Copyright 2007, Ingo Weinhold, bonefish@cs.tu-berlin.de.
3 * Distributed under the terms of the MIT License.
6 #include "compatibility.h"
10 #include <SupportDefs.h>
14 #include "fssh_errno.h"
15 #include "partition_support.h"
16 #include "stat_priv.h"
17 #include "stat_util.h"
20 using FSShell::from_platform_stat
;
21 using FSShell::to_platform_mode
;
24 #if (!defined(__BEOS__) && !defined(__HAIKU__))
25 // The _kern_read_stat() defined in libroot_build.so.
26 # define _kern_read_stat _kernbuild_read_stat
27 extern "C" status_t
_kern_read_stat(int fd
, const char *path
,
28 bool traverseLink
, struct stat
*st
, size_t statSize
);
33 FSShell::unrestricted_stat(const char *path
, struct fssh_stat
*fsshStat
)
37 // Use the _kern_read_stat() defined in libroot on BeOS incompatible
38 // systems. Required for support for opening symlinks.
39 #if (defined(__BEOS__) || defined(__HAIKU__))
40 if (::stat(path
, &st
) < 0)
43 status_t error
= _kern_read_stat(-1, path
, true, &st
, sizeof(st
));
45 fssh_set_errno(error
);
50 from_platform_stat(&st
, fsshStat
);
57 FSShell::unrestricted_fstat(int fd
, struct fssh_stat
*fsshStat
)
61 // Use the _kern_read_stat() defined in libroot on BeOS incompatible
62 // systems. Required for support for opening symlinks.
63 #if (defined(__BEOS__) || defined(__HAIKU__))
64 if (fstat(fd
, &st
) < 0)
67 status_t error
= _kern_read_stat(fd
, NULL
, false, &st
, sizeof(st
));
69 fssh_set_errno(error
);
74 from_platform_stat(&st
, fsshStat
);
81 FSShell::unrestricted_lstat(const char *path
, struct fssh_stat
*fsshStat
)
85 // Use the _kern_read_stat() defined in libroot on BeOS incompatible
86 // systems. Required for support for opening symlinks.
87 #if (defined(__BEOS__) || defined(__HAIKU__))
88 if (lstat(path
, &st
) < 0)
91 status_t error
= _kern_read_stat(-1, path
, false, &st
, sizeof(st
));
93 fssh_set_errno(error
);
98 from_platform_stat(&st
, fsshStat
);
106 fssh_mkdir(const char *path
, fssh_mode_t mode
)
108 return mkdir(path
, to_platform_mode(mode
));
113 fssh_stat(const char *path
, struct fssh_stat
*fsshStat
)
115 if (FSShell::unrestricted_stat(path
, fsshStat
) < 0)
118 FSShell::restricted_file_restrict_stat(fsshStat
);
125 fssh_fstat(int fd
, struct fssh_stat
*fsshStat
)
127 if (FSShell::unrestricted_fstat(fd
, fsshStat
) < 0)
130 FSShell::restricted_file_restrict_stat(fsshStat
);
137 fssh_lstat(const char *path
, struct fssh_stat
*fsshStat
)
139 if (FSShell::unrestricted_lstat(path
, fsshStat
) < 0)
142 FSShell::restricted_file_restrict_stat(fsshStat
);