2
* $Id: didiskutil.c,v 1.2 2009-11-23 14:30:56-08 bll Exp $
3
* $Source: /home/bll/DI/RCS/didiskutil.c,v $
4
* Copyright 1994-2009 Brad Lanam, Walnut Creek, CA
18
#if _hdr_strings && ((! defined (_hdr_string)) || (_include_string))
24
#if _include_malloc && _hdr_malloc
29
/********************************************************/
31
This module contains utility routines for conversion
32
and checking the data.
35
initialize disk info structure
37
save the block sizes in the diskinfo structure.
39
save the inode sizes in the diskinfo structure.
40
convertMountOptions ()
41
converts mount options to text format.
42
convertNFSMountOptions ()
43
converts NFS mount options to text format.
45
Checks to see if the mount option is set.
46
Used if hasmntopt() is not present.
48
test a disk to see if it is remote (nfs, nfs3).
54
di_initDiskInfo (diDiskInfo_t *diptr)
56
di_initDiskInfo (diptr)
60
memset ((char *) diptr, '\0', sizeof (diDiskInfo_t));
61
diptr->printFlag = DI_PRNT_OK;
62
diptr->isLocal = TRUE;
63
diptr->isReadOnly = FALSE;
68
di_saveBlockSizes (diDiskInfo_t *diptr, _fs_size_t block_size,
69
_fs_size_t total_blocks, _fs_size_t free_blocks,
70
_fs_size_t avail_blocks)
72
di_saveBlockSizes (diptr, block_size, total_blocks, free_blocks, avail_blocks)
74
_fs_size_t block_size;
75
_fs_size_t total_blocks;
76
_fs_size_t free_blocks;
77
_fs_size_t avail_blocks;
80
diptr->blockSize = (_fs_size_t) block_size;
81
diptr->totalBlocks = (_fs_size_t) total_blocks;
82
diptr->freeBlocks = (_fs_size_t) free_blocks;
83
diptr->availBlocks = (_fs_size_t) avail_blocks;
88
di_saveInodeSizes (diDiskInfo_t *diptr,
89
_fs_size_t total_nodes, _fs_size_t free_nodes,
90
_fs_size_t avail_nodes)
92
di_saveInodeSizes (diptr, total_nodes, free_nodes, avail_nodes)
94
_fs_size_t total_nodes;
95
_fs_size_t free_nodes;
96
_fs_size_t avail_nodes;
99
diptr->totalInodes = total_nodes;
100
diptr->freeInodes = free_nodes;
101
diptr->availInodes = avail_nodes;
106
convertMountOptions (long flags, diDiskInfo_t *diptr)
108
convertMountOptions (flags, diptr)
113
#if defined (MNT_RDONLY)
114
if ((flags & MNT_RDONLY) == MNT_RDONLY)
116
strncat (diptr->options, "ro,",
117
DI_OPT_LEN - strlen (diptr->options) - 1);
121
strncat (diptr->options, "rw,",
122
DI_OPT_LEN - strlen (diptr->options) - 1);
125
#if defined (MNT_FORCE)
126
if ((flags & MNT_FORCE) == MNT_FORCE)
128
strncat (diptr->options, "force,",
129
DI_OPT_LEN - strlen (diptr->options) - 1);
132
#if defined (MNT_GRPID)
133
if ((flags & MNT_GRPID) == MNT_GRPID)
135
strncat (diptr->options, "grpid,",
136
DI_OPT_LEN - strlen (diptr->options) - 1);
139
#if defined (MNT_MAGICLINKS)
140
if ((flags & MNT_MAGICLINKS) == MNT_MAGICLINKS)
142
strncat (diptr->options, "magiclinks,",
143
DI_OPT_LEN - strlen (diptr->options) - 1);
146
#if defined (MNT_MLSD)
147
if ((flags & MNT_MLSD) == MNT_MLSD)
149
strncat (diptr->options, "mlsd,",
150
DI_OPT_LEN - strlen (diptr->options) - 1);
153
#if defined (MNT_NOATIMES)
154
if ((flags & MNT_NOATIMES) == MNT_NOATIMES)
156
strncat (diptr->options, "noatime,",
157
DI_OPT_LEN - strlen (diptr->options) - 1);
160
#if defined (MNT_NOCACHE)
161
if ((flags & MNT_NOCACHE) == MNT_NOCACHE)
163
strncat (diptr->options, "nocache,",
164
DI_OPT_LEN - strlen (diptr->options) - 1);
167
#if defined (MNT_NOCOREDUMP)
168
if ((flags & MNT_NOCOREDUMP) == MNT_NOCOREDUMP)
170
strncat (diptr->options, "nocoredump,",
171
DI_OPT_LEN - strlen (diptr->options) - 1);
174
#if defined (MNT_NODEV)
175
if ((flags & MNT_NODEV) == MNT_NODEV)
177
strncat (diptr->options, "nodev,",
178
DI_OPT_LEN - strlen (diptr->options) - 1);
181
#if defined (MNT_NODEVMTIME)
182
if ((flags & MNT_NODEVMTIME) == MNT_NODEVMTIME)
184
strncat (diptr->options, "nodevmtime,",
185
DI_OPT_LEN - strlen (diptr->options) - 1);
188
#if defined (MNT_NOEXEC)
189
if ((flags & MNT_NOEXEC) == MNT_NOEXEC)
191
strncat (diptr->options, "noexec,",
192
DI_OPT_LEN - strlen (diptr->options) - 1);
195
#if defined (MNT_NOSUID)
196
if ((flags & MNT_NOSUID) == MNT_NOSUID)
198
strncat (diptr->options, "nosuid,",
199
DI_OPT_LEN - strlen (diptr->options) - 1);
202
#if defined (MNT_QUOTA)
203
if ((flags & MNT_QUOTA) == MNT_QUOTA)
205
strncat (diptr->options, "quota,",
206
DI_OPT_LEN - strlen (diptr->options) - 1);
209
#if defined (MNT_SECURE)
210
if ((flags & MNT_SECURE) == MNT_SECURE)
212
strncat (diptr->options, "secure,",
213
DI_OPT_LEN - strlen (diptr->options) - 1);
216
#if defined (MNT_SMSYNC2)
217
if ((flags & MNT_SMSYNC2) == MNT_SMSYNC2)
219
strncat (diptr->options, "smsync2,",
220
DI_OPT_LEN - strlen (diptr->options) - 1);
223
#if defined (MNT_SOFTDEP)
224
if ((flags & MNT_SOFTDEP) == MNT_SOFTDEP)
226
strncat (diptr->options, "softdep,",
227
DI_OPT_LEN - strlen (diptr->options) - 1);
230
#if defined (MNT_SYMPERM)
231
if ((flags & MNT_SYMPERM) == MNT_SYMPERM)
233
strncat (diptr->options, "symperm,",
234
DI_OPT_LEN - strlen (diptr->options) - 1);
237
#if defined (MNT_SYNC)
238
if ((flags & MNT_SYNC) == MNT_SYNC)
240
strncat (diptr->options, "sync,",
241
DI_OPT_LEN - strlen (diptr->options) - 1);
244
#if defined (MNT_SYNCHRONOUS)
245
if ((flags & MNT_SYNCHRONOUS) == MNT_SYNCHRONOUS)
247
strncat (diptr->options, "sync,",
248
DI_OPT_LEN - strlen (diptr->options) - 1);
251
#if defined (MNT_THROTTLE)
252
if ((flags & MNT_THROTTLE) == MNT_THROTTLE)
254
strncat (diptr->options, "throttle,",
255
DI_OPT_LEN - strlen (diptr->options) - 1);
258
#if defined (MNT_UNION)
259
if ((flags & MNT_UNION) == MNT_UNION)
261
strncat (diptr->options, "union,",
262
DI_OPT_LEN - strlen (diptr->options) - 1);
265
#if defined (MNT_UNION)
266
if ((flags & MNT_UNION) == MNT_UNION)
268
strncat (diptr->options, "union,",
269
DI_OPT_LEN - strlen (diptr->options) - 1);
272
#if defined (MNT_REMOVABLE)
273
if ((flags & MNT_REMOVABLE) == MNT_REMOVABLE)
275
strncat (diptr->options, "removable,",
276
DI_OPT_LEN - strlen (diptr->options) - 1);
279
#if defined (MNT_PERSISTENT)
280
if ((flags & MNT_PERSISTENT) == MNT_PERSISTENT)
282
strncat (diptr->options, "persistent,",
283
DI_OPT_LEN - strlen (diptr->options) - 1);
286
#if defined (MNT_SHARED)
287
if ((flags & MNT_SHARED) == MNT_SHARED)
289
strncat (diptr->options, "shared,",
290
DI_OPT_LEN - strlen (diptr->options) - 1);
293
#if defined (MNT_BLOCKBASED)
294
if ((flags & MNT_BLOCKBASED) == MNT_BLOCKBASED)
296
strncat (diptr->options, "blockbased,",
297
DI_OPT_LEN - strlen (diptr->options) - 1);
300
#if defined (MNT_HAS_MIME)
301
if ((flags & MNT_HAS_MIME) == MNT_HAS_MIME)
303
strncat (diptr->options, "mime,",
304
DI_OPT_LEN - strlen (diptr->options) - 1);
307
#if defined (MNT_HAS_QUERY)
308
if ((flags & MNT_HAS_QUERY) == MNT_HAS_QUERY)
310
strncat (diptr->options, "query,",
311
DI_OPT_LEN - strlen (diptr->options) - 1);
314
#if defined (MNT_HAS_ATTR)
315
if ((flags & MNT_HAS_ATTR) == MNT_HAS_ATTR)
317
strncat (diptr->options, "attr,",
318
DI_OPT_LEN - strlen (diptr->options) - 1);
326
convertNFSMountOptions (long flags, long wsize, long rsize, diDiskInfo_t *diptr)
328
convertNFSMountOptions (flags, wsize, rsize, diptr)
335
#if defined (NFSMNT_SOFT)
336
if ((flags & NFSMNT_SOFT) != NFSMNT_SOFT)
338
strncat (diptr->options, "hard,",
339
DI_OPT_LEN - strlen (diptr->options) - 1);
342
#if defined (NFSMNT_WSIZE)
343
if ((flags & NFSMNT_WSIZE) == NFSMNT_WSIZE)
347
Snprintf (tmp, DI_SPF(sizeof (tmp), "wsize=%ld,"), wsize);
348
strncat (diptr->options, tmp,
349
DI_OPT_LEN - strlen (diptr->options) - 1);
352
#if defined (NFSMNT_RSIZE)
353
if ((flags & NFSMNT_RSIZE) == NFSMNT_RSIZE)
357
Snprintf (tmp, DI_SPF(sizeof (tmp), "rsize=%ld,"), rsize);
358
strncat (diptr->options, tmp,
359
DI_OPT_LEN - strlen (diptr->options) - 1);
362
#if defined (NFSMNT_INT) && defined (NFSMNT_SOFT)
363
if ((flags & NFSMNT_SOFT) != NFSMNT_SOFT &&
364
(flags & NFSMNT_INT) == NFSMNT_INT)
366
strncat (diptr->options, "intr,",
367
DI_OPT_LEN - strlen (diptr->options) - 1);
370
#if defined (NFSMNT_TCP)
371
if ((flags & NFSMNT_TCP) != NFSMNT_TCP)
373
strncat (diptr->options, "udp,",
374
DI_OPT_LEN - strlen (diptr->options) - 1);
381
#if _lib_getmntent && \
382
! defined (_lib_getmntinfo) && \
383
! defined (_lib_getfsstat) && \
384
! defined (_lib_getvfsstat) && \
385
! defined (_lib_mntctl) && \
386
! defined (_class_os__Volumes)
390
chkMountOptions (char *mntopts, char *str)
392
chkMountOptions (mntopts, str)
400
tstr = strdup (mntopts);
401
ptr = strtok (tstr, ",");
402
while (ptr != (char *) NULL)
404
if (strcmp (ptr, str) == 0)
409
ptr = strtok ((char *) NULL, ",");
412
return (char *) NULL;
415
#endif /* _lib_getmntent */
419
di_testRemoteDisk (diDiskInfo_t *diskInfo)
421
di_testRemoteDisk (diskInfo)
422
diDiskInfo_t *diskInfo;
425
if (strcmp (diskInfo->fsType, "nfs") == 0 ||
426
strcmp (diskInfo->fsType, "nfs3") == 0)
428
diskInfo->isLocal = FALSE;