xref: /illumos-gate/usr/src/lib/libfsmgt/common/libfsmgt.h (revision 1da57d551424de5a9d469760be7c4b4d4f10a755)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _LIBFSMGT_H
28 #define	_LIBFSMGT_H
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #include <stdio.h>
35 #include <sys/param.h>
36 #include <nfs/nfs_sec.h>
37 #include <sys/utsname.h>
38 
39 #define	DFSTYPES	"/etc/dfs/fstypes"		/* dfs list */
40 #define	DFSTAB		"/etc/dfs/dfstab"		/* dfs list */
41 #define	BUFSIZE		65536
42 #define	LINESZ		2048
43 
44 typedef void *fs_dfstab_entry_t;
45 
46 /*
47  * Public data type declarations
48  */
49 
50 /*
51  * Represents a list of the /etc/vfstab entries
52  */
53 typedef struct mount_default_list {
54 	struct mount_default_list *next;
55 	char *resource;
56 	char *fsckdevice;
57 	char *mountp;
58 	char *fstype;
59 	char *fsckpass;
60 	char *mountatboot;
61 	char *mntopts;
62 } fs_mntdefaults_t;
63 
64 /*
65  * Represents a list of /etc/mnttab entries
66  */
67 typedef struct mount_list {
68 	struct mount_list *next;
69 	char *resource;
70 	char *mountp;
71 	char *fstype;
72 	char *mntopts;
73 	char *time;
74 	uint_t major;
75 	uint_t minor;
76 	boolean_t overlayed;
77 } fs_mntlist_t;
78 
79 /*
80  * Represents a /etc/dfs/sharetab entry
81  */
82 typedef struct share_list {
83 	struct share_list *next;
84 	char *path;
85 	char *resource;
86 	char *fstype;
87 	char *options;
88 	char *description;
89 } fs_sharelist_t;
90 
91 /*
92  * Represents a list of /etc/mnttab entries with associated
93  * information from kstat.
94  */
95 typedef struct nfs_mntlist {
96 	struct nfs_mntlist *next;
97 	char		nml_curpath[MAXPATHLEN];	/* current path on */
98 							/* server */
99 	char		nml_curserver[SYS_NMLN];	/* current server */
100 	char		**nml_failoverlist;	/* The list of servers */
101 						/* and corresponding */
102 						/* paths for failover. */
103 	char		*nml_fstype;		/* filesystem type */
104 	char		*nml_mntopts;		/* mount options */
105 	char		*nml_mountp;		/* mount point */
106 	char		*nml_resource;		/* mnttab.mnt_special */
107 	char		nml_proto[KNC_STRSIZE];	/* transfer protocol */
108 	char		*nml_securitymode;	/* security mode name */
109 	char		*nml_time;		/* time mounted */
110 	int		nml_failovercount;	/* number of failover servers */
111 	int		nml_retrans;		/* times to retry request */
112 	int		nml_timeo;		/* inital timeout in 10th sec */
113 	ulong_t		nml_fsid;		/* filesystem ID */
114 	uint_t		nml_acdirmax;	/* max time to hold cached dir attr */
115 	uint_t		nml_acdirmin;	/* min time to hold cached dir attr */
116 	uint_t		nml_acregmax;	/* max time to hold cached file attr */
117 	uint_t		nml_acregmin;	/* min time to hold cached file attr */
118 	uint32_t	nml_curread;		/* current read size */
119 	uint32_t	nml_curwrite;		/* current write size */
120 	uint32_t	nml_vers;		/* nfs version */
121 	boolean_t	nml_directio;	/* force direct IO */
122 	boolean_t	nml_grpid;	/* group id inherited from parent */
123 	boolean_t	nml_hard;	/* hard or soft mount */
124 	boolean_t	nml_intr;	/* Key board intrupts */
125 	boolean_t	nml_noac;	/* no ata and attribute caching */
126 	boolean_t	nml_nocto;	/* no close-to-open  consistency */
127 	boolean_t	nml_overlayed;	/* Is filesystem overlayed */
128 	boolean_t	nml_xattr;	/* allow extended attributes */
129 } nfs_mntlist_t;
130 
131 /*
132  * Command execution interface method declarations
133  */
134 
135 /*
136  * Method: cmd_execute_command
137  *
138  * Description: Executes the command passed into the function as if it was
139  * the input to a shell and returns the separated stdout and stderr messages
140  * which can be accessed by the client via the returned file descriptors using
141  * the cmd_retrieve_string method or one of their own methods.
142  *
143  * Parameters:
144  * char * - The command to execute.  Expected in the format of a shell command.
145  * int * - Upon return from the function, this is the file descriptor that can
146  * 	be used to access the output from the command to stdout.
147  * int * - Upon return from the function, this is the file descriptor that can
148  *	be used to access the output from the command to stderr.
149  *
150  * Return:
151  * Returns 0 (zero).
152  * Supposed to be the integer representing the exit value of the command
153  * executed, but due to the way blocking on file descriptors works, it will
154  * only return a 0 (zero) value.  The reason: The producer, in this case the
155  * command being executed, will block when a certain amount of data is written
156  * to the file descriptor and will not be able to write any more data until the
157  * consumer reads from the file descriptor so since we are not reading in the
158  * data from the file descriptors in this method and we are allowing the client
159  * do what they want with the data we can't wait until the command is finished
160  * executing to get the return value.
161  */
162 int	cmd_execute_command(char *cmd, int *output_filedes, int *error_filedes);
163 
164 /*
165  * Method: cmd_execute_command_and_retrieve_string
166  *
167  * Description: Executes the command passed into the function as if it was the
168  * input to a shell and returns the output to stderr and stdout as a string as
169  * it would appear in the shell (stdout and stderr are mixed).
170  *
171  * Parameters:
172  * char * - The command to execute.  Expected in the format of a shell command.
173  * int * - Upon return from the function, this should be used to determine if an
174  * 	error occurred in the execution of the command and the retrieval of
175  *	output data from the command.
176  * data from the command.
177  *
178  * Return:
179  * The output to stdout and stderr created by the execution of the passed in
180  * command.
181  */
182 char	*cmd_execute_command_and_retrieve_string(char *cmd, int *errp);
183 
184 /*
185  * Method: cmd_retrieve_string
186  *
187  * Description: Retrieves the data from the passed in file descriptor and
188  * returns it to the caller in the form of a string.
189  *
190  * Parameters:
191  * int - The file descriptor to be read from.
192  * int * - Upon return from the function, this should be the used to determine
193  * 	if an error occurred in the retrieval of the data from the file
194  *	descriptor.
195  *	A non-zero value represents the occurrence of an error.
196  *
197  * Return:
198  * The data from the file descriptor in the form of a string.
199  * NOTE: The caller must free the space allocated (with calloc) for the return
200  * value using free().
201  */
202 char	*cmd_retrieve_string(int filedes, int *errp);
203 
204 /*
205  * File interface method declarations
206  */
207 
208 /*
209  * NOTE: the caller of this function is responsible for freeing any
210  * memory allocated by calling fileutil_free_string_array()
211  *
212  * Method: fileutil_add_string_to_array
213  *
214  * Description: Adds one line to the file image string array
215  *
216  * Parameters:
217  * char ***string_array - pointer array of strings holding the lines
218  *         for the new file
219  * char *line - the line to be added to the new file
220  * int *count - the number of elements in the string array
221  * int *err - error pointer for returning any errors encountered
222  *
223  * Return:
224  * B_TRUE on success, B_FALSE on failure.
225  *
226  * Note:
227  * On success string_array is set to the new array of strings. On failure
228  * string_array is unchanged.
229  */
230 boolean_t fileutil_add_string_to_array(char ***, char *, int *, int *);
231 
232 /*
233  * Method: fileutil_free_string_array
234  *
235  * Description: Frees the space allocated to a string array.
236  *
237  * Parameters:
238  * char ** - is the array to be freed
239  * int - the number of elements in the array
240  */
241 void	fileutil_free_string_array(char **, int);
242 
243 /*
244  * Method: fileutil_get_cmd_from_string
245  *
246  * Description: Returns a string containing a line with all comments and
247  * trailing white space removed.
248  *
249  * Parameters:
250  * char *input_stringp - the line to remove all coments and trailing white
251  *	space.
252  *
253  * Note: The memory allocated for the returned string must be freed by the
254  * caller of fileutil_get_cmd_from_string().
255  */
256 char	*fileutil_get_cmd_from_string(char *input_stringp);
257 
258 /*
259  * Method: fileutil_get_first_column_data
260  *
261  * Description: Returns a string array which is filled with the data in the
262  * first column of the lines in a table formatted file.
263  * Examples of table formatted files include: /etc/netcofig, /etc/nfssec.conf
264  *
265  * Parameters:
266  * FILE* - The file pointer of the table formatted file to get data from.
267  * int* - will be filled with the number of elements in the array that is passed
268  *	back.
269  * int* - error pointer.  If an error occurs this will be non-zero upon return
270  * 	the function.
271  *
272  * Returns:
273  * Two-dimensional array of characters (string array).  Each element in the
274  * array is the first column data of each row in the table.
275  */
276 char	**fileutil_get_first_column_data(FILE *, int *, int *);
277 
278 /*
279  * Method: fileutil_getfs
280  *
281  * Description: Convenience function for retrieving the default remote file
282  * system type from /etc/dfs/fstypes.
283  *
284  * Parameters:
285  * FILE * - The /etc/dfs/fstypes file pointer.
286  *
287  * Return:
288  * The default remote filesystem type.
289  */
290 char	*fileutil_getfs(FILE *);
291 
292 /*
293  * Method: fileutil_getline
294  *
295  * Description: Convenience function for retrieving the next line from a file.
296  *              Commented lines are not returned and comments at the end of
297  *              a line are removed.
298  *
299  * Parameters:
300  * FILE * - The file pointer to a file that has been opened for reading.
301  * char * - The line retrived from the file will be placed in this string.
302  * int * - error pointer - If an error occurs this will be non-zero upon
303  *                         return from the function.
304  *
305  * Return:
306  * If successfull the line retrieved from the file will be returned.
307  * Otherwise NULL be be returned.
308  */
309 char	*fileutil_getline(FILE *, char *, int);
310 
311 /*
312  * Mount defaults (/etc/vfstab) interface method declarations
313  */
314 /*
315  * Method: fs_add_mount_default
316  *
317  * Description: Adds an entry to vfstab based on the fs_mntdefaults_t
318  *              structure that is passed in.
319  *
320  * Parameters:
321  * fs_mntdefaults_t *newp - The structure containing the mount information
322  *                          to be placed in vfstab.
323  * int *errp - error pointer - If an error occurs this will be non-zero upon
324  *                             return from the function.
325  *
326  * Return:
327  * If successful a pointer to a list containing all the present vfstab
328  * entries is returned. On failure NULL is returned.
329  */
330 fs_mntdefaults_t	*fs_add_mount_default(fs_mntdefaults_t *, int *);
331 
332 /*
333  * Method: fs_check_for_duplicate_DFStab_paths
334  *
335  * Description: Checks dfstab for duplicate paths and returns the number of
336  * times the path passed in was encountered. The functon is used to help make
337  * sure a path is only listed in dfstab once.
338  *
339  * Parameters:
340  * char *path - the path to check for
341  * int *err - error pointer - If an error occurs this will be non-zero upon
342  *	return from the function.
343  *
344  * Return:
345  * The number of times the specified path is encountered in dfstab.
346  */
347 int fs_check_for_duplicate_DFStab_paths(char *path, int *err);
348 
349 /*
350  * Method: fs_del_mount_default_ent
351  *
352  * Description: Deletes the specified vfstab entry from the vfstab file.
353  *
354  * Parameters:
355  * fs_mntdefaults_t *old_vfstab_ent - The mount information that corresponds
356  *                                    to the vfstab entry to be deleted.
357  * int *errp - error pointer - If an error occurs this will be non-zero upon
358  *                             return from the function.
359  *
360  * Return:
361  * If successful a pointer to a list containing all the changed vfstab
362  * entries is returned. On failure NULL is returned.
363  */
364 fs_mntdefaults_t	*fs_del_mount_default_ent(fs_mntdefaults_t *, int *);
365 
366 /*
367  * Method: fs_edit_mount_defaults
368  *
369  * Description: Edits the specified vfstab entry with the new mount
370  * information passed in.
371  *
372  * Parameters:
373  * fs_mntdefaults_t *old_vfstab_ent - The old vfstab entry that is to be edited.
374  * fs_mntdefaults_t *new_vfstab_ent - The new vfstab entry information.
375  * int *errp - error pointer - If an error occurs this will be non-zero upon
376  *                             return from the function
377  *
378  * Return:
379  */
380 fs_mntdefaults_t	*fs_edit_mount_defaults(fs_mntdefaults_t *,
381 				fs_mntdefaults_t *, int *);
382 
383 /*
384  * Method: fs_free_mntdefaults_list
385  *
386  * Description: Frees the memory used when a fs_mntdefaults_t structure
387  *              is populated.
388  *
389  * Parameters:
390  * fs_mntdefaults_t *headp - The pointer to the first element in the list
391  *                           of mntdefault structures.
392  */
393 void	fs_free_mntdefaults_list(fs_mntdefaults_t *headp);
394 
395 
396 /*
397  * Method: fs_get_filtered_mount_defaults
398  *
399  * Description: Retrieves vfstab entries based in the fields in the
400  * fs_mntdefaults_t structure passed in. The fields that are not to
401  * be used in the filter will be set to NULL.
402  *
403  * Parameters:
404  * fs_mntdefaults_t *filter - The structure containing the fields to be
405  *                            used for the filter.
406  * int *errp - error pointer - If an error occurs this will be non-zero upon
407  *                             return from the function
408  *
409  * Return:
410  * The list of all vfstab entries meeting the filter criteria are returned.
411  * On failure NULL is returned.
412  */
413 fs_mntdefaults_t	*fs_get_filtered_mount_defaults(
414 				fs_mntdefaults_t *filter, int *errp);
415 
416 /*
417  * Method: fs_get_mount_defaults
418  *
419  * Description: Retrieves vfstab entries and returns a list of
420  *              fs_mntdefaults_t structures.
421  *
422  * Parameters:
423  * int *errp - error pointer - If an error occurs this will be non-zero upon
424  *                             return from the function
425  *
426  * Return:
427  * fs_mntdefaults_t * - Returns a list of all vfstab entries.
428  */
429 fs_mntdefaults_t	*fs_get_mount_defaults(int *errp);
430 
431 /*
432  * Mount (/etc/mnttab) interface method declarations
433  */
434 /*
435  * Method: fs_free_mount_list
436  *
437  * Description: Frees the mount list created when retrieving mnttab entries.
438  *
439  * Parameters:
440  * fs_mntlist_t *headp - The mount list to be freed.
441  */
442 void	fs_free_mount_list(fs_mntlist_t *mnt_list);
443 
444 /*
445  * Method: fs_get_availablesize
446  *
447  * Description: Calculates the total size available on the filesystem.
448  *
449  * Parameters:
450  * char *mntpnt - The mount point to use for gathering the stat information
451  * int *errp - error pointer - If an error occurs this will be non-zero upon
452  *                             return from the function
453  *
454  * Return:
455  * The total size available on the filesystem.
456  */
457 unsigned long long	fs_get_availablesize(char *mntpnt, int *errp);
458 
459 /*
460  * Method: fs_get_avail_for_nonsuperuser_size
461  *
462  * Description: Calculates the available space on the filesystem for
463  *              nonsuperusers.
464  *
465  * Parameters:
466  * char *mntpnt - The mount point for the filesystem.
467  * int *errp - error pointer - If an error occurs this will be non-zero upon
468  *                             return from the function
469  *
470  * Return:
471  * The available space for nonsuperusers.
472  * On failure NULL is returned.
473  */
474 unsigned long long	fs_get_avail_for_nonsuperuser_size(char *mntpnt,
475 				int *errp);
476 
477 /*
478  * Method: fs_get_blocksize
479  *
480  * Description: Retrieves the preferred filesystem block size.
481  *
482  * Parameters:
483  * char *mntpnt - The mount point for the filesystem.
484  * int *errp - error pointer - If an error occurs this will be non-zero upon
485  *                             return from the function
486  *
487  * Return:
488  * Returns the preferred filesystem block size.
489  * On failure NULL is returned.
490  */
491 
492 unsigned long long	fs_get_blocksize(char *mntpnt, int *errp);
493 
494 /*
495  * Method: fs_get_filtered_mount_list
496  *
497  * Description: Can be used to filter mounts only by the following mount
498  * attributes or a mixture of them:
499  * 1.) resource
500  * 2.) mount point
501  * 3.) mount option string
502  * 4.) time mounted
503  *
504  * Parameters:
505  * char *resource - The name of the resource to be mounted
506  * char *mountp - The pathname of the directory on which the filesystem
507  *                is mounted
508  * char *mntopts - The mount options
509  * char *time - The time at which the filesystem was mounted
510  * boolean_t find_overlays - Flag used to turn on overlay checking
511  * int *errp - error pointer - If an error occurs this will be non-zero upon
512  *                             return from the function
513  *
514  * Return:
515  * The list of all mnttab entries meeting the filter criteria are returned.
516  * On failure NULL is returned.
517  */
518 fs_mntlist_t		*fs_get_filtered_mount_list(char *resource,
519 				char *mountp, char *fstype, char *mntopts,
520 				char *time, boolean_t find_overlays,
521 				int *errp);
522 
523 /*
524  * Method: fs_get_fragsize
525  *
526  * Description: Determines the fundamental filesystem block size.
527  *
528  * Parameters:
529  * char *mntpnt - The mount point for the filesystem.
530  * int *errp - error pointer - If an error occurs this will be non-zero upon
531  *                             return from the function
532  *
533  * Return:
534  * Returns the fundamental filesystem block size.
535  * On failure NULL is returned.
536  */
537 unsigned long		fs_get_fragsize(char *mntpnt, int *errp);
538 
539 /*
540  * Method: fs_get_maxfilenamelen
541  *
542  * Description: Determines the maximum file name length for the filesystem.
543  *
544  * Parameters:
545  * char *mntpnt - The mount point for the filesystem.
546  * int *errp - error pointer - If an error occurs this will be non-zero upon
547  *                             return from the function
548  *
549  * Return:
550  * Returns the  maximum file name length for the specified filesystem.
551  * On failure NULL is returned.
552  */
553 unsigned long		fs_get_maxfilenamelen(char *mntpnt, int *errp);
554 
555 /*
556  * Method: fs_get_mounts_by_mntopt
557  *
558  * Description: Returns only mounts with the specified mount option set.
559  *
560  * Parameters:
561  * char *mntopt - The mount option used for filtering mounts
562  * boolean_t find_overlays - Flag used to turn on overlay checking
563  * int *errp - error pointer - If an error occurs this will be non-zero upon
564  *                             return from the function
565  *
566  * Return:
567  * Returns the list of all mnttab entries with the matching mount option.
568  * On failure NULL is returned.
569  */
570 fs_mntlist_t		*fs_get_mounts_by_mntopt(char *mntopt,
571 				boolean_t find_overlays, int *errp);
572 
573 /*
574  * Method: fs_get_mount_list
575  *
576  * Description: Returns a list of all mounts in mnttab
577  *
578  * Parameters:
579  * char *mntpnt - The mount point for the filesystem
580  * boolean_t find_overlays - Flag used to turn on overlay checking
581  * int *errp - error pointer - If an error occurs this will be non-zero upon
582  *                             return from the function
583  *
584  * Return:
585  * Returns the list of all mounts and associated mount information for mounts
586  * listed in mnttab. On failure NULL is returned.
587  */
588 fs_mntlist_t		*fs_get_mount_list(boolean_t find_overlays, int *errp);
589 
590 /*
591  * Method: fs_get_totalsize
592  *
593  * Description: Determines the total size of the filesystem using the
594  * total number of blocks and the block size.
595  *
596  * Parameters:
597  * char *mntpnt - The mount point for the filesystem
598  * int *errp - error pointer - If an error occurs this will be non-zero upon
599  *                             return from the function
600  *
601  * Return:
602  * Returns the total size of the filesystem.
603  * On failure NULL is returned.
604  */
605 unsigned long long	fs_get_totalsize(char *mntpnt, int *errp);
606 
607 /*
608  * Method: fs_get_usedsize
609  *
610  * Description: Calculates the size of the used portion of the filesystem.
611  *
612  * Parameters:
613  * char *mntpnt - The mount point for the filesystem
614  * int *errp - error pointer - If an error occurs this will be non-zero upon
615  *                             return from the function
616  *
617  * Return:
618  * Returns the size of the the used portion of the filesystem.
619  * On failure NULL is returned.
620  */
621 unsigned long long	fs_get_usedsize(char *mntpnt, int *errp);
622 
623 /*
624  * Method: fs_is_readonly
625  *
626  * Description: Checks the filesystem flags to see if the filesystem is
627  * readonly.
628  *
629  * Parameters:
630  * char *mntpnt - The mount point for the filesystem
631  * int *errp - error pointer - If an error occurs this will be non-zero upon
632  *                             return from the function
633  *
634  * Return:
635  * Returns B_TRUE if the readonly flag is set and B_FALSE if not.
636  * On error the error pointer is set to errno.
637  */
638 boolean_t		fs_is_readonly(char *mntpnt, int *errp);
639 
640 /*
641  * Method: fs_parse_optlist_for_option
642  *
643  * Description:
644  * This method will parse the given comma delimited option list (optlist) for
645  * the option passed into the function.  If the option (opt) to search for
646  * is one that sets a value such as onerror=, the value to the right of the "="
647  * character will be returned from the function.  This function expects the
648  * opt parameter to have the "=" character appended when searching for options
649  * which set a value.
650  *
651  * Parameters:
652  * char *optlist - The option string to be parsed
653  * char *opt - The option to search for
654  * int *errp - error pointer - If an error occurs this will be non-zero upon
655  *                             return from the function
656  *
657  * Return:
658  * Returns the option as found in the option list.
659  * If the option is not found NULL is returned.
660  * On error NULL is returned and the error pointer is set to errno.
661  */
662 char			*fs_parse_optlist_for_option(char *optlist, char *opt,
663 				int *errp);
664 
665 /*
666  * Share (/etc/dfs/sharetab) interface method declarations
667  */
668 /*
669  * Method: fs_free_share_list
670  *
671  * Description: Used to free populated fs_sharelist_t structures
672  *
673  * Parameters:
674  * fs_sharelist_t *headp - the pointer to the first element in the list.
675  */
676 void		fs_free_share_list(fs_sharelist_t *share_list);
677 
678 /*
679  * Method: fs_get_share_list
680  *
681  * Description: Gets a list of the shares on the system from /etc/dfs/sharetab
682  *
683  * Parameters:
684  * int *errp - error pointer - If an error occurs this will be non-zero upon
685  *                             return from the function
686  *
687  * Return:
688  * Returns a list of fs_sharelist_t structures containing all of the shares
689  * from sharetab.
690  * On error NULL is returned and errp is set to errno.
691  */
692 fs_sharelist_t	*fs_get_share_list(int *errp);
693 
694 /*
695  * Method: fs_parse_opts_for_sec_modes
696  *
697  * Description: Parses the option string for security modes and returns
698  * an array of strings containing all modes.
699  *
700  * Parameters:
701  * 	char * - options string to be parsed.
702  * 	int * - count of the number of modes found.
703  *	int * - error code.
704  *
705  * Return:
706  * Returns an array of string containing all security opts listed in the
707  * passed in option string. On error NULL is returned.
708  */
709 char **fs_parse_opts_for_sec_modes(char *, int *, int *);
710 
711 /*
712  * Method: fs_create_array_from_accesslist
713  *
714  * Description: Takes the colon seperated access list parses the list
715  *              into an array containing all the elements of the list.
716  *              The array created is returned and count is set to the
717  *              number of elements in the array.
718  *
719  * Parameters:
720  * char *access_list - The string containing the colon sperated access list.
721  * int *count - Will contain the number of elements in the array.
722  * int *err - any errors encountered.
723  */
724 char **fs_create_array_from_accesslist(char *access_list, int *count, int *err);
725 
726 /*
727  * FS dfstab (/etc/dfs/dfstab) interface method declarations
728  */
729 
730 /*
731  * Method: fs_add_DFStab_ent
732  *
733  * Description: Adds an entry to dfstab and to the list of dfstab
734  * entries. Returns a pointer to the head of the dfstab entry list.
735  *
736  * Parameters:
737  * char *cmd - the share command to be added to dfstab
738  * int *errp - error pointer - If an error occurs this will be non-zero upon
739  *                             return from the function
740  *
741  * Return:
742  * Returns the pointer to the updated dfstab entry list.
743  */
744 fs_dfstab_entry_t fs_add_DFStab_ent(char *, int *);
745 
746 /*
747  * Method: fs_del_DFStab_ent
748  *
749  * Description: Deletes an entry from dfstab and from the list of
750  *              dfstab entries.
751  *
752  * Parameters:
753  * char *del_cmd - The share command to be removed
754  * int *errp - error pointer - If an error occurs this will be non-zero upon
755  *                             return from the function
756  *
757  * Return:
758  * Returns the pointer to the updated dfstab entry list.
759  */
760 fs_dfstab_entry_t fs_del_DFStab_ent(char *, int *);
761 
762 /*
763  * NOTE: the caller of this function is responsible for freeing any
764  * memory allocated by calling fs_free_DFStab_ents()
765  *
766  * Method: fs_edit_DFStab_ent
767  *
768  * Description: Changes the specified line in dfstab to match the second
769  *              string passed in.
770  *
771  * Parameters:
772  * char *old_cmd - The share command that will be changed.
773  * char *new_cmd - The share command that will replace old_cmd.
774  * int *errp - error pointer - If an error occurs this will be non-zero upon
775  *                             return from the function
776  *
777  * Return:
778  * Returns the pointer to the updated dfstab entry list.
779  */
780 fs_dfstab_entry_t fs_edit_DFStab_ent(char *, char *, int *);
781 
782 /*
783  * Method: fs_free_DFStab_ents
784  *
785  * Description: Frees the dfstab entry list.
786  *
787  * Parameters:
788  * fs_dfstab_entry_t list - The pointer to the dfstab entry list.
789  */
790 void fs_free_DFStab_ents(fs_dfstab_entry_t);
791 
792 /*
793  * NOTE: the caller of this function is responsible for freeing any
794  * memory allocated by calling fs_free_DFStab_ents()
795  *
796  * Method: fs_get_DFStab_ents
797  *
798  * Description: Retrieves the dfstab entry list.
799  *
800  * Parameters:
801  * int *errp - error pointer - If an error occurs this will be non-zero upon
802  *                             return from the function
803  *
804  * Return:
805  * Returns the pointer to the dfstab entry list.
806  * If NULL is returned and errp is 0 then dfstab has no entries. If errp is
807  * not 0 there was an error and the value of errp is set to the errno
808  * value for that error.
809  */
810 fs_dfstab_entry_t fs_get_DFStab_ents(int *err);
811 
812 /*
813  * NOTE: the caller of this function is responsible for freeing any
814  * memory allocated by calling fs_free_DFStab_ents()
815  *
816  * Method: fs_get_DFStab_ent_Desc
817  *
818  * Description: Retrieves the description information for the present
819  *              dfstab entry.
820  *
821  * Parameters:
822  * fs_dfstab_entry_t entry - the dfstab entry to retrieve the description from.
823  *
824  * Return:
825  * The string containing the description for the dfstab entry.
826  * If the description is not set NULL is returned.
827  *
828  * Note: the description is an optional share option and a return value of
829  *       NULL is not an error but indicates that the description was not set.
830  */
831 char *fs_get_DFStab_ent_Desc(fs_dfstab_entry_t);
832 
833 /*
834  * Method: fs_get_DFStab_ent_Fstype
835  *
836  * Description: Retrieves the filesystem type information from the dfstab
837  *              entry passed in.
838  *
839  * Parameters:
840  * fs_dfstab_entry_t entry - the dfstab entry to retrieve the fstype from.
841  *
842  * Return:
843  * The string containing the filesystem type.
844  *
845  * Note: if fstype is not set in the dfstab entry the default fstype is
846  *       returned.
847  */
848 char *fs_get_DFStab_ent_Fstype(fs_dfstab_entry_t);
849 
850 /*
851  * Method: fs_get_DFStab_ent_Next
852  *
853  * Description: Retrieves the next entry in the dfstab entry list.
854  *
855  * Parameters:
856  * fs_dfstab_entry_t entry - The dfstab entry pointer to get the next
857  *                           pointer from.
858  *
859  * Return:
860  * Returns the next dfstab entry.
861  * A return value of NULL indicates the end of the dfstab entry list.
862  */
863 fs_dfstab_entry_t fs_get_DFStab_ent_Next(fs_dfstab_entry_t);
864 
865 /*
866  * Method: fs_get_DFStab_ent_Options
867  *
868  * Description: Retrieves the share options from the dfstab
869  *              entry passed in.
870  *
871  * Parameters:
872  * fs_dfstab_entry_t entry - The dfstab entry to retrieve the share
873  *                           options from.
874  *
875  * Return:
876  * Returns the string containing the share options.
877  * A NULL value indicates that no options were specified in the dfstab entry.
878  */
879 char *fs_get_DFStab_ent_Options(fs_dfstab_entry_t);
880 
881 /*
882  * Method: fs_get_DFStab_ent_Path
883  *
884  * Description: Retrieves the path information from the dfstab
885  *              entry passed in.
886  *
887  * Parameters:
888  * fs_dfstab_entry_t entry - the dfstab entry to retrieve the path from.
889  *
890  * Return:
891  * Returns the string containing the path.
892  * A NULL value indecates that no path information is available for the
893  * dfstab entry. A NULL value here is an error and indicates an invalid
894  * dfstab entry.
895  */
896 char *fs_get_DFStab_ent_Path(fs_dfstab_entry_t);
897 
898 /*
899  * Method: fs_get_DFStab_ent_Res
900  *
901  * Description: Retrieves the resource information from the dfstab entry
902  *              passed in.
903  *
904  * Parameters:
905  * fs_dfstab_entry_t entry - the dfstab entry to retrieve the resource
906  *                           information from.
907  *
908  * Return:
909  * Returns the string containing the path.
910  * A NULL value indecates that no resource information is available for the
911  * dfstab entry.
912  */
913 char *fs_get_DFStab_ent_Res(fs_dfstab_entry_t);
914 
915 /*
916  * Method: fs_get_Dfstab_share_cmd
917  *
918  * Description: Retrieves the share command that corresponds to the
919  *              dfstab entry passed in.
920  *
921  * Parameters:
922  * fs_dfstab_entry_t entry - The dfstab entry that will be used to create
923  *                           a share command.
924  * int *errp - error pointer - If an error occurs this will be non-zero upon
925  *                             return from the function
926  *
927  * Return:
928  * Returns the string containing the share command.
929  * A NULL value indicates an error occured and errp will be non zero.
930  */
931 char *fs_get_Dfstab_share_cmd(fs_dfstab_entry_t, int *);
932 
933 /*
934  * NOTE: the caller of this function is responsible for freeing any
935  * memory allocated by calling fs_free_DFStab_ents()
936  *
937  * Method: fs_set_DFStab_ent
938  *
939  * Description: Used to add entries into dfstab
940  *
941  * Parameters:
942  * char *path - The path for the dfstab entry
943  * char *fstype - The filesystem type for the share
944  * char *options - The share options to be used for the dfstab entry
945  * char *description - The description for the share
946  * int *errp - error pointer - If an error occurs this will be non-zero upon
947  *                             return from the function
948  *
949  * Return:
950  * Returns a pointer to the begining of the dfstab entry list
951  * Failure returns NULL
952  */
953 fs_dfstab_entry_t fs_set_DFStab_ent(char *, char *, char *, char *, int *);
954 
955 /*
956  * NOTE: the caller of this function is responsible for freeing any
957  * memory allocated by calling fs_free_DFStab_ents()
958  *
959  * Method: fs_del_All_DFStab_ents_with_Path
960  *
961  * Description: Removes all dfstab entries with the specified path.
962  *
963  * Parameters:
964  *            char *path - The path to checked for removal from dfstab.
965  *            int *err - error pointer.
966  *
967  * Return: returns a pointer to the nfs list of dfstab entries.
968  */
969 fs_dfstab_entry_t fs_del_All_DFStab_ents_with_Path(char *, int *);
970 
971 /*
972  * Debuging functions
973  */
974 void fs_print_dfstab_entries(fs_dfstab_entry_t);
975 
976 /*
977  * NFS mount interface method declarations
978  */
979 /*
980  * Method: nfs_free_mntinfo_list
981  *
982  * Description: Used to free the network id list, which is an array of strings.
983  *
984  * Parameters:
985  * nfs_mntlist_t *mountinfo_list - The list of mounts and associated mount
986  *                                 information
987  *
988  */
989 void nfs_free_mntinfo_list(nfs_mntlist_t *);
990 
991 /*
992  * NOTE: the caller of this function is responsible for freeing any
993  * memory allocated by calling nfs_free_mntinfo_list()
994  *
995  * Method: nfs_get_filtered_mount_list
996  *
997  * Description: Can be used to filter nfs mounts only by the following mount
998  * attributes or a mixture of them:
999  * 1.) resource
1000  * 2.) mount point
1001  * 3.) mount option string
1002  * 4.) time mounted
1003  *
1004  * NULL must be passed into the options that are not being used in the filter.
1005  *
1006  * Parameters:
1007  * char *resource - The name of the resource to be mounted
1008  * char *mountp - The pathname of the directory on which the filesystem
1009  *                is mounted
1010  * char *mntopts - The mount options
1011  * char *time - The time at which the filesystem was mounted
1012  * boolean_t find_overlays - Flag used to turn on overlay checking
1013  * int *errp - error pointer - If an error occurs this will be non-zero upon
1014  *                             return from the function
1015  *
1016  * Return:
1017  * nfs_mntlist_t * - Returns a list of nfs mounts based on the
1018  *                   parameters passed in.
1019  */
1020 nfs_mntlist_t *nfs_get_filtered_mount_list(char *resource, char *mountp,
1021 	char *mntopts, char *time, boolean_t find_overlays,
1022 	int *errp);
1023 
1024 /*
1025  * NOTE: the caller of this function is responsible for freeing any
1026  * memory allocated by calling nfs_free_mntinfo_list()
1027  *
1028  * Method: nfs_get_mounts_by_mntopt
1029  *
1030  * Description: Can be used to filter mounts by the mount options attribute.
1031  *
1032  * Parameters:
1033  * char *mntopts - The mount options
1034  * boolean_t find_overlays - Flag used to turn on overlay checking
1035  * int *errp - error pointer - If an error occurs this will be non-zero upon
1036  *                             return from the function
1037  *
1038  * Return:
1039  * nfs_mntlist_t * - Returns a list of nfs mounts based on the
1040  *                   parameters passed in.
1041  */
1042 nfs_mntlist_t *nfs_get_mounts_by_mntopt(char *mntopt, boolean_t find_overlays,
1043 	int *errp);
1044 
1045 /*
1046  * NOTE: the caller of this function is responsible for freeing any
1047  * memory allocated by calling nfs_free_mntinfo_list()
1048  *
1049  * Method: nfs_get_mount_list
1050  *
1051  * Description: Used to gather all NFS mounts and there associated
1052  *              mount information.
1053  *
1054  * Parameters:
1055  * int *errp - error pointer - If an error occurs this will be non-zero upon
1056  *                             return from the function
1057  *
1058  * Return:
1059  * nfs_mntlist_t * - Returns a list of all nfs mounts.
1060  */
1061 nfs_mntlist_t *nfs_get_mount_list(int *);
1062 
1063 /*
1064  * Netconfig (/etc/netconfig) interface method declarations
1065  */
1066 /*
1067  * Method: netcfg_free_networkid_list
1068  *
1069  * Description: Used to free the network id list, which is an array of strings.
1070  *
1071  * Parameters:
1072  * char **netlist - The array of strings containing the network id list
1073  * int  num_elements - The number of elements in the network id list
1074  *
1075  */
1076 void	netcfg_free_networkid_list(char **netlist, int num_elements);
1077 
1078 /*
1079  * NOTE: the caller of this function is responsible for freeing any
1080  * memory allocated by calling netcfg_free_networkid_list()
1081  *
1082  * Method: netcfg_get_networkid_list
1083  *
1084  * Description: Used to create the network id list.
1085  *
1086  * Parameters:
1087  * int *num_elements - The number of elements in the network id list.
1088  * int *errp - error pointer - If an error occurs this will be non-zero upon
1089  *                             return from the function
1090  *
1091  * Return:
1092  * char    ** - Returns the netowk id list.
1093  */
1094 char	**netcfg_get_networkid_list(int *num_elements, int *errp);
1095 
1096 /*
1097  * nfssec (/etc/nfssec.conf) interface method declarations
1098  */
1099 /*
1100  * Method: nfssec_free_secmode_list
1101  *
1102  * Description: Used to free the NFS security mode list.
1103  *
1104  * Parameters:
1105  * char **seclist - The array of strings containing the security mode list
1106  * int num_elements - The number of elements in the list
1107  *
1108  */
1109 void	nfssec_free_secmode_list(char **seclist, int num_elements);
1110 
1111 /*
1112  * Method: nfssec_get_default_secmode
1113  *
1114  * Description: Used to retrieve the default security mode
1115  *
1116  * Parameters:
1117  * int *errp - error pointer - If an error occurs this will be non-zero upon
1118  *                             return from the function
1119  *
1120  * Return:
1121  * char * - Returns the name of the default security mode
1122  */
1123 char	*nfssec_get_default_secmode(int *errp);
1124 
1125 /*
1126  * NOTE: the caller of this function is responsible for freeing any
1127  * memory allocated by calling nfssec_free_secmode_list()
1128  *
1129  * Method: nfssec_get_nfs_secmode_list
1130  *
1131  * Description: Used to create the NFS security mode list.
1132  *
1133  * Parameters:
1134  * int *num_elements - The number of elements in the security mode list
1135  * int *errp - error pointer - If an error occurs this will be non-zero upon
1136  *                             return from the function
1137  *
1138  * Return:
1139  * char ** - Returns the NFS security mode list
1140  *
1141  */
1142 char	**nfssec_get_nfs_secmode_list(int *num_elements, int *errp);
1143 
1144 /*
1145  * System information interface method declarations
1146  */
1147 /*
1148  * Method: sys_get_hostname
1149  *
1150  * Description: Used to retrieve the name of the host
1151  *
1152  * Parameters:
1153  * int *errp - error pointer - If an error occurs this will be non-zero upon
1154  *                             return from the function
1155  *
1156  * Return:
1157  * char * - Returns the name of the host system
1158  */
1159 char *sys_get_hostname(int *errp);
1160 
1161 
1162 #ifdef __cplusplus
1163 }
1164 #endif
1165 
1166 #endif /* _LIBFSMGT_H */
1167