1 /* libguestfs - the guestfsd daemon
2 * Copyright (C) 2010 Red Hat Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include <sys/types.h>
28 #include "guestfs_protocol.h"
33 do_exists (const char *path)
38 r = access (path, F_OK);
44 static int get_mode (const char *path, mode_t *mode);
47 do_is_file (const char *path)
50 int r = get_mode (path, &mode);
52 return S_ISREG (mode);
56 do_is_dir (const char *path)
59 int r = get_mode (path, &mode);
61 return S_ISDIR (mode);
65 do_is_chardev (const char *path)
68 int r = get_mode (path, &mode);
70 return S_ISCHR (mode);
74 do_is_blockdev (const char *path)
77 int r = get_mode (path, &mode);
79 return S_ISBLK (mode);
83 do_is_fifo (const char *path)
86 int r = get_mode (path, &mode);
88 return S_ISFIFO (mode);
92 do_is_symlink (const char *path)
95 int r = get_mode (path, &mode);
97 return S_ISLNK (mode);
101 do_is_socket (const char *path)
104 int r = get_mode (path, &mode);
105 if (r <= 0) return r;
106 return S_ISSOCK (mode);
110 get_mode (const char *path, mode_t *mode)
116 r = lstat (path, &buf);
120 if (errno != ENOENT && errno != ENOTDIR) {
121 reply_with_perror ("stat: %s", path);
125 return 0; /* Doesn't exist, means return false. */