8 #include <linux/magic.h>
31 for (i = 0; i < str_len; i++) {
32 const unsigned char c = p[
i];
36 else if (c >
' ' && c < 127)
48 for (i = 0; i < str_len; i++) {
49 const unsigned char c = p[
i];
54 }
else if (c >
' ' && c < 127) {
58 *cp++ = (c >> 6) +
'0';
59 *cp++ = ((c >> 3) & 7) +
'0';
60 *cp++ = (c & 7) +
'0';
92 static char *tomoyo_get_absolute_path(
struct path *
path,
char *
const buffer,
99 if (!IS_ERR(pos) && *pos ==
'/' && pos[1]) {
102 buffer[buflen - 2] =
'/';
103 buffer[buflen - 1] =
'\0';
121 static char *tomoyo_get_dentry_path(
struct dentry *
dentry,
char *
const buffer,
124 char *pos = ERR_PTR(-
ENOMEM);
127 if (!IS_ERR(pos) && *pos ==
'/' && pos[1]) {
130 buffer[buflen - 2] =
'/';
131 buffer[buflen - 1] =
'\0';
147 static char *tomoyo_get_local_path(
struct dentry *dentry,
char *
const buffer,
151 char *pos = tomoyo_get_dentry_path(dentry, buffer, buflen);
158 if (*ep ==
'/' && pid && pid ==
165 goto prepend_filesystem_name;
169 goto prepend_filesystem_name;
176 if (inode->
i_op && !inode->
i_op->rename)
177 goto prepend_filesystem_name;
184 name[
sizeof(
name) - 1] =
'\0';
195 prepend_filesystem_name:
197 const char *name = sb->
s_type->name;
198 const int name_len =
strlen(name);
219 static char *tomoyo_get_socket_name(
struct path *path,
char *
const buffer,
222 struct inode *inode = path->
dentry->d_inode;
224 struct sock *
sk = sock ? sock->
sk :
NULL;
226 snprintf(buffer, buflen,
"socket:[family=%u:type=%u:"
227 "protocol=%u]", sk->sk_family, sk->
sk_type,
230 snprintf(buffer, buflen,
"socket:[unknown]");
255 struct dentry *dentry = path->
dentry;
269 buf[buf_len - 1] =
'\0';
272 pos = tomoyo_get_socket_name(path, buf, buf_len - 1);
276 if (dentry->
d_op && dentry->
d_op->d_dname) {
277 pos = dentry->
d_op->d_dname(dentry, buf, buf_len - 1);
280 inode = sb->
s_root->d_inode;
285 if (!path->
mnt || (inode->
i_op && !inode->
i_op->rename))
286 pos = tomoyo_get_local_path(path->
dentry, buf,
290 pos = tomoyo_get_absolute_path(path, buf, buf_len - 1);
295 if (pos == ERR_PTR(-
EINVAL))
296 pos = tomoyo_get_local_path(path->
dentry, buf,
322 if (pathname &&
kern_path(pathname, 0, &path) == 0) {