OpenMPI  0.1.1
os_dirpath.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
3  * University Research and Technology
4  * Corporation. All rights reserved.
5  * Copyright (c) 2004-2005 The University of Tennessee and The University
6  * of Tennessee Research Foundation. All rights
7  * reserved.
8  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
9  * University of Stuttgart. All rights reserved.
10  * Copyright (c) 2004-2005 The Regents of the University of California.
11  * All rights reserved.
12  * $COPYRIGHT$
13  *
14  * Additional copyrights may follow
15  *
16  * $HEADER$
17  */
18 
19 /** @file:
20  * Creates a directory tree set to the specified permissions.
21  *
22  * The opal_os_dirpath_create() function creates a directory
23  * tree, with each directory that is created in the tree having the specified
24  * access permissions. Existing directories within the tree are left
25  * untouched - however, if they do not permit the user to create a directory
26  * within them, the function will return an error condition.
27  *
28  * If the specified full path name already exists, the
29  * opal_os_dirpath_create() function will check to ensure that
30  * the final directory in the tree has at least the specified access permission. In other
31  * words, if the directory has read-write-execute for all, and the user
32  * has requested read-write access for just the user, then the function
33  * will consider the directory acceptable. If the minimal permissions are
34  * not currently provided, the function will attempt to change the
35  * access permissions of the directory to add the specified
36  * permissions. The function will return OPAL_ERROR if this cannot
37  * be done.
38  **/
39 
40 #ifndef OPAL_OS_DIRPATH_CREATE_H
41 #define OPAL_OS_DIRPATH_CREATE_H
42 
43 #include "opal_config.h"
44 #ifdef HAVE_SYS_STAT_H
45 #include <sys/stat.h>
46 #endif
47 
48 BEGIN_C_DECLS
49 
50 /**
51  * @param path A pointer to a string that contains the path name to be built.
52  * @param mode A mode_t bit mask that specifies the access permissions for the
53  * directories being constructed.
54  * @retval OPAL_SUCCESS If the directory tree has been successfully created with
55  * the specified access permissions.
56  * @retval OPAL_ERROR If the directory tree could not be created with the
57  * specified access permissions.
58  */
59 
60 OPAL_DECLSPEC int opal_os_dirpath_create(const char *path, const mode_t mode);
61 
62 /**
63  * Check to see if a directory is empty
64  *
65  * @param path A pointer to a string that contains the path name to be checked.
66  *
67  * @retval true If the directory is empty
68  * @retval false If the directory is not empty
69  */
70 OPAL_DECLSPEC bool opal_os_dirpath_is_empty(const char *path);
71 
72 /**
73  * Check access to the directory
74  *
75  * @param path A pointer to a string that contains the path name to be checked.
76  * @param mode A mode_t bit mask that specifies the access permissions for the
77  * directory to be accessed.
78  *
79  * @retval OPAL_SUCCESS If directory exists, and permissions match
80  * @retval OPAL_ERR_NOT_FOUND If directory does not exist
81  * @retval OPAL_ERROR If directory exists, and permissions do not match
82  */
83 OPAL_DECLSPEC int opal_os_dirpath_access(const char *path, const mode_t mode );
84 
85 /**
86  * Callback for opal_os_dirpath_destroy(). Call for every file/directory before
87  * taking action to remove/unlink it.
88  *
89  * @param root A pointer to a string that contains the base path name (e.g., /tmp/foo from /tmp/foo/bar)
90  * @param path A pointer to a string that contains the file or directory (e.g., bar from /tmp/foo/bar)
91  *
92  * @retval true Allow the program to remove the file/directory
93  * @retval false Do not allow the program to remove the file/directory
94  */
95 typedef bool (*opal_os_dirpath_destroy_callback_fn_t)(const char *root, const char *path);
96 
97 /**
98  * Destroy a directory
99  *
100  * @param path A pointer to a string that contains the path name to be destroyed
101  * @param recursive Recursively desend the directory removing all files and directories.
102  * if set to 'false' then the directory must be empty to succeed.
103  * @param cbfunc A function that will be called before removing a file or directory.
104  * If NULL, then assume all remove.
105  *
106  * @retval OPAL_SUCCESS If the directory was successfully removed or removed to the
107  * specification of the user (i.e., obeyed the callback function).
108  * @retval OPAL_ERR_NOT_FOUND If directory does not exist.
109  * @retval OPAL_ERROR If the directory cannnot be removed, accessed properly, or contains
110  * directories that could not be removed..
111  */
112 OPAL_DECLSPEC int opal_os_dirpath_destroy(const char *path,
113  bool recursive,
115 
116 END_C_DECLS
117 
118 #endif
OPAL_DECLSPEC int opal_os_dirpath_destroy(const char *path, bool recursive, opal_os_dirpath_destroy_callback_fn_t cbfunc)
Destroy a directory.
Definition: os_dirpath.c:175
OPAL_DECLSPEC int opal_os_dirpath_access(const char *path, const mode_t mode)
Check access to the directory.
Definition: os_dirpath.c:415
bool(* opal_os_dirpath_destroy_callback_fn_t)(const char *root, const char *path)
Callback for opal_os_dirpath_destroy().
Definition: os_dirpath.h:95
OPAL_DECLSPEC bool opal_os_dirpath_is_empty(const char *path)
Check to see if a directory is empty.
Definition: os_dirpath.c:365
BEGIN_C_DECLS OPAL_DECLSPEC int opal_os_dirpath_create(const char *path, const mode_t mode)
Definition: os_dirpath.c:42