aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/zed/zed_file.c
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/zed/zed_file.c')
-rw-r--r--cmd/zed/zed_file.c89
1 files changed, 0 insertions, 89 deletions
diff --git a/cmd/zed/zed_file.c b/cmd/zed/zed_file.c
index d73e64976..7b77345d1 100644
--- a/cmd/zed/zed_file.c
+++ b/cmd/zed/zed_file.c
@@ -225,92 +225,3 @@ zed_file_close_on_exec(int fd)
return (0);
}
-
-/*
- * Create the directory [dir_name] and any missing parent directories.
- * Directories will be created with permissions 0755 modified by the umask.
- * Return 0 on success, or -1 on error.
- * FIXME: Deprecate in favor of mkdirp(). (lib/libspl/mkdirp.c)
- */
-int
-zed_file_create_dirs(const char *dir_name)
-{
- struct stat st;
- char dir_buf[PATH_MAX];
- mode_t dir_mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
- char *p;
-
- if ((dir_name == NULL) || (dir_name[0] == '\0')) {
- zed_log_msg(LOG_WARNING,
- "Failed to create directory: no directory specified");
- errno = EINVAL;
- return (-1);
- }
- if (dir_name[0] != '/') {
- zed_log_msg(LOG_WARNING,
- "Failed to create directory \"%s\": not absolute path",
- dir_name);
- errno = EINVAL;
- return (-1);
- }
- /* Check if directory already exists. */
- if (stat(dir_name, &st) == 0) {
- if (S_ISDIR(st.st_mode))
- return (0);
-
- errno = EEXIST;
- zed_log_msg(LOG_WARNING,
- "Failed to create directory \"%s\": %s",
- dir_name, strerror(errno));
- return (-1);
- }
- /* Create copy for modification. */
- if (strlen(dir_name) >= sizeof (dir_buf)) {
- errno = ENAMETOOLONG;
- zed_log_msg(LOG_WARNING,
- "Failed to create directory \"%s\": %s",
- dir_name, strerror(errno));
- return (-1);
- }
- strncpy(dir_buf, dir_name, sizeof (dir_buf));
-
- /* Remove trailing slashes. */
- p = dir_buf + strlen(dir_buf) - 1;
- while ((p > dir_buf) && (*p == '/'))
- *p-- = '\0';
-
- /* Process directory components starting from the root dir. */
- p = dir_buf;
-
- while (1) {
-
- /* Skip over adjacent slashes. */
- while (*p == '/')
- p++;
-
- /* Advance to the next path component. */
- p = strchr(p, '/');
- if (p != NULL)
- *p = '\0';
-
- /* Create directory. */
- if (mkdir(dir_buf, dir_mode) < 0) {
-
- int mkdir_errno = errno;
-
- if ((mkdir_errno == EEXIST) ||
- (stat(dir_buf, &st) < 0) ||
- (!S_ISDIR(st.st_mode))) {
- zed_log_msg(LOG_WARNING,
- "Failed to create directory \"%s\": %s",
- dir_buf, strerror(mkdir_errno));
- return (-1);
- }
- }
- if (p == NULL)
- break;
-
- *p++ = '/';
- }
- return (0);
-}