~ubuntu-branches/ubuntu/maverick/di/maverick

« back to all changes in this revision

Viewing changes to didiskutil.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Ablassmeier
  • Date: 2009-12-06 19:03:54 UTC
  • mfrom: (1.1.10 upstream) (3.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20091206190354-whfqb83521hg9jf8
Tags: 4.18-1
* New upstream release
* iffe has been replaced with new build environment, no need to make
  our own dfsg free tarball anymore, remove debian/README.debian-source
* raise compat level to 5
* Bump standards version
* add ${misc:Depends} to debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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
 
5
 */
 
6
 
 
7
#include "config.h"
 
8
#include "di.h"
 
9
#include "dimntopt.h"
 
10
 
 
11
#include <stdio.h>
 
12
#if _hdr_stdlib
 
13
# include <stdlib.h>
 
14
#endif
 
15
#if _hdr_string
 
16
# include <string.h>
 
17
#endif
 
18
#if _hdr_strings && ((! defined (_hdr_string)) || (_include_string))
 
19
# include <strings.h>
 
20
#endif
 
21
#if _hdr_memory
 
22
# include <memory.h>
 
23
#endif
 
24
#if _include_malloc && _hdr_malloc
 
25
# include <malloc.h>
 
26
#endif
 
27
 
 
28
 
 
29
/********************************************************/
 
30
/*
 
31
    This module contains utility routines for conversion
 
32
    and checking the data.
 
33
 
 
34
    di_initDiskInfo ()
 
35
        initialize disk info structure
 
36
    di_saveBlockSizes ()
 
37
        save the block sizes in the diskinfo structure.
 
38
    di_saveInodeSizes ()
 
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.
 
44
    chkMountOptions ()
 
45
        Checks to see if the mount option is set.
 
46
        Used if hasmntopt() is not present.
 
47
    di_testRemoteDisk ()
 
48
        test a disk to see if it is remote (nfs, nfs3).
 
49
 
 
50
*/
 
51
 
 
52
void
 
53
#if _proto_stdc
 
54
di_initDiskInfo (diDiskInfo_t *diptr)
 
55
#else
 
56
di_initDiskInfo (diptr)
 
57
    diDiskInfo_t        *diptr;
 
58
#endif
 
59
{
 
60
    memset ((char *) diptr, '\0', sizeof (diDiskInfo_t));
 
61
    diptr->printFlag = DI_PRNT_OK;
 
62
    diptr->isLocal = TRUE;
 
63
    diptr->isReadOnly = FALSE;
 
64
}
 
65
 
 
66
void
 
67
#if _proto_stdc
 
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)
 
71
#else
 
72
di_saveBlockSizes (diptr, block_size, total_blocks, free_blocks, avail_blocks)
 
73
    diDiskInfo_t *diptr;
 
74
    _fs_size_t block_size;
 
75
    _fs_size_t total_blocks;
 
76
    _fs_size_t free_blocks;
 
77
    _fs_size_t avail_blocks;
 
78
#endif
 
79
{
 
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;
 
84
}
 
85
 
 
86
void
 
87
#if _proto_stdc
 
88
di_saveInodeSizes (diDiskInfo_t *diptr,
 
89
        _fs_size_t total_nodes, _fs_size_t free_nodes,
 
90
        _fs_size_t avail_nodes)
 
91
#else
 
92
di_saveInodeSizes (diptr, total_nodes, free_nodes, avail_nodes)
 
93
    diDiskInfo_t *diptr;
 
94
    _fs_size_t total_nodes;
 
95
    _fs_size_t free_nodes;
 
96
    _fs_size_t avail_nodes;
 
97
#endif
 
98
{
 
99
    diptr->totalInodes = total_nodes;
 
100
    diptr->freeInodes = free_nodes;
 
101
    diptr->availInodes = avail_nodes;
 
102
}
 
103
 
 
104
void
 
105
#if _proto_stdc
 
106
convertMountOptions (long flags, diDiskInfo_t *diptr)
 
107
#else
 
108
convertMountOptions (flags, diptr)
 
109
    long          flags;
 
110
    diDiskInfo_t   *diptr;
 
111
#endif
 
112
{
 
113
#if defined (MNT_RDONLY)
 
114
    if ((flags & MNT_RDONLY) == MNT_RDONLY)
 
115
    {
 
116
        strncat (diptr->options, "ro,",
 
117
                DI_OPT_LEN - strlen (diptr->options) - 1);
 
118
    }
 
119
    else
 
120
    {
 
121
        strncat (diptr->options, "rw,",
 
122
                DI_OPT_LEN - strlen (diptr->options) - 1);
 
123
    }
 
124
#endif
 
125
#if defined (MNT_FORCE)
 
126
    if ((flags & MNT_FORCE) == MNT_FORCE)
 
127
    {
 
128
        strncat (diptr->options, "force,",
 
129
                DI_OPT_LEN - strlen (diptr->options) - 1);
 
130
    }
 
131
#endif
 
132
#if defined (MNT_GRPID)
 
133
    if ((flags & MNT_GRPID) == MNT_GRPID)
 
134
    {
 
135
        strncat (diptr->options, "grpid,",
 
136
                DI_OPT_LEN - strlen (diptr->options) - 1);
 
137
    }
 
138
#endif
 
139
#if defined (MNT_MAGICLINKS)
 
140
    if ((flags & MNT_MAGICLINKS) == MNT_MAGICLINKS)
 
141
    {
 
142
        strncat (diptr->options, "magiclinks,",
 
143
                DI_OPT_LEN - strlen (diptr->options) - 1);
 
144
    }
 
145
#endif
 
146
#if defined (MNT_MLSD)
 
147
    if ((flags & MNT_MLSD) == MNT_MLSD)
 
148
    {
 
149
        strncat (diptr->options, "mlsd,",
 
150
                DI_OPT_LEN - strlen (diptr->options) - 1);
 
151
    }
 
152
#endif
 
153
#if defined (MNT_NOATIMES)
 
154
    if ((flags & MNT_NOATIMES) == MNT_NOATIMES)
 
155
    {
 
156
        strncat (diptr->options, "noatime,",
 
157
                DI_OPT_LEN - strlen (diptr->options) - 1);
 
158
    }
 
159
#endif
 
160
#if defined (MNT_NOCACHE)
 
161
    if ((flags & MNT_NOCACHE) == MNT_NOCACHE)
 
162
    {
 
163
        strncat (diptr->options, "nocache,",
 
164
                DI_OPT_LEN - strlen (diptr->options) - 1);
 
165
    }
 
166
#endif
 
167
#if defined (MNT_NOCOREDUMP)
 
168
    if ((flags & MNT_NOCOREDUMP) == MNT_NOCOREDUMP)
 
169
    {
 
170
        strncat (diptr->options, "nocoredump,",
 
171
                DI_OPT_LEN - strlen (diptr->options) - 1);
 
172
    }
 
173
#endif
 
174
#if defined (MNT_NODEV)
 
175
    if ((flags & MNT_NODEV) == MNT_NODEV)
 
176
    {
 
177
        strncat (diptr->options, "nodev,",
 
178
                DI_OPT_LEN - strlen (diptr->options) - 1);
 
179
    }
 
180
#endif
 
181
#if defined (MNT_NODEVMTIME)
 
182
    if ((flags & MNT_NODEVMTIME) == MNT_NODEVMTIME)
 
183
    {
 
184
        strncat (diptr->options, "nodevmtime,",
 
185
                DI_OPT_LEN - strlen (diptr->options) - 1);
 
186
    }
 
187
#endif
 
188
#if defined (MNT_NOEXEC)
 
189
    if ((flags & MNT_NOEXEC) == MNT_NOEXEC)
 
190
    {
 
191
        strncat (diptr->options, "noexec,",
 
192
                DI_OPT_LEN - strlen (diptr->options) - 1);
 
193
    }
 
194
#endif
 
195
#if defined (MNT_NOSUID)
 
196
    if ((flags & MNT_NOSUID) == MNT_NOSUID)
 
197
    {
 
198
        strncat (diptr->options, "nosuid,",
 
199
                DI_OPT_LEN - strlen (diptr->options) - 1);
 
200
    }
 
201
#endif
 
202
#if defined (MNT_QUOTA)
 
203
    if ((flags & MNT_QUOTA) == MNT_QUOTA)
 
204
    {
 
205
        strncat (diptr->options, "quota,",
 
206
                DI_OPT_LEN - strlen (diptr->options) - 1);
 
207
    }
 
208
#endif
 
209
#if defined (MNT_SECURE)
 
210
    if ((flags & MNT_SECURE) == MNT_SECURE)
 
211
    {
 
212
        strncat (diptr->options, "secure,",
 
213
                DI_OPT_LEN - strlen (diptr->options) - 1);
 
214
    }
 
215
#endif
 
216
#if defined (MNT_SMSYNC2)
 
217
    if ((flags & MNT_SMSYNC2) == MNT_SMSYNC2)
 
218
    {
 
219
        strncat (diptr->options, "smsync2,",
 
220
                DI_OPT_LEN - strlen (diptr->options) - 1);
 
221
    }
 
222
#endif
 
223
#if defined (MNT_SOFTDEP)
 
224
    if ((flags & MNT_SOFTDEP) == MNT_SOFTDEP)
 
225
    {
 
226
        strncat (diptr->options, "softdep,",
 
227
                DI_OPT_LEN - strlen (diptr->options) - 1);
 
228
    }
 
229
#endif
 
230
#if defined (MNT_SYMPERM)
 
231
    if ((flags & MNT_SYMPERM) == MNT_SYMPERM)
 
232
    {
 
233
        strncat (diptr->options, "symperm,",
 
234
                DI_OPT_LEN - strlen (diptr->options) - 1);
 
235
    }
 
236
#endif
 
237
#if defined (MNT_SYNC)
 
238
    if ((flags & MNT_SYNC) == MNT_SYNC)
 
239
    {
 
240
        strncat (diptr->options, "sync,",
 
241
                DI_OPT_LEN - strlen (diptr->options) - 1);
 
242
    }
 
243
#endif
 
244
#if defined (MNT_SYNCHRONOUS)
 
245
    if ((flags & MNT_SYNCHRONOUS) == MNT_SYNCHRONOUS)
 
246
    {
 
247
        strncat (diptr->options, "sync,",
 
248
                DI_OPT_LEN - strlen (diptr->options) - 1);
 
249
    }
 
250
#endif
 
251
#if defined (MNT_THROTTLE)
 
252
    if ((flags & MNT_THROTTLE) == MNT_THROTTLE)
 
253
    {
 
254
        strncat (diptr->options, "throttle,",
 
255
                DI_OPT_LEN - strlen (diptr->options) - 1);
 
256
    }
 
257
#endif
 
258
#if defined (MNT_UNION)
 
259
    if ((flags & MNT_UNION) == MNT_UNION)
 
260
    {
 
261
        strncat (diptr->options, "union,",
 
262
                DI_OPT_LEN - strlen (diptr->options) - 1);
 
263
    }
 
264
#endif
 
265
#if defined (MNT_UNION)
 
266
    if ((flags & MNT_UNION) == MNT_UNION)
 
267
    {
 
268
        strncat (diptr->options, "union,",
 
269
                DI_OPT_LEN - strlen (diptr->options) - 1);
 
270
    }
 
271
#endif
 
272
#if defined (MNT_REMOVABLE)
 
273
    if ((flags & MNT_REMOVABLE) == MNT_REMOVABLE)
 
274
    {
 
275
        strncat (diptr->options, "removable,",
 
276
                DI_OPT_LEN - strlen (diptr->options) - 1);
 
277
    }
 
278
#endif
 
279
#if defined (MNT_PERSISTENT)
 
280
    if ((flags & MNT_PERSISTENT) == MNT_PERSISTENT)
 
281
    {
 
282
        strncat (diptr->options, "persistent,",
 
283
                DI_OPT_LEN - strlen (diptr->options) - 1);
 
284
    }
 
285
#endif
 
286
#if defined (MNT_SHARED)
 
287
    if ((flags & MNT_SHARED) == MNT_SHARED)
 
288
    {
 
289
        strncat (diptr->options, "shared,",
 
290
                DI_OPT_LEN - strlen (diptr->options) - 1);
 
291
    }
 
292
#endif
 
293
#if defined (MNT_BLOCKBASED)
 
294
    if ((flags & MNT_BLOCKBASED) == MNT_BLOCKBASED)
 
295
    {
 
296
        strncat (diptr->options, "blockbased,",
 
297
                DI_OPT_LEN - strlen (diptr->options) - 1);
 
298
    }
 
299
#endif
 
300
#if defined (MNT_HAS_MIME)
 
301
    if ((flags & MNT_HAS_MIME) == MNT_HAS_MIME)
 
302
    {
 
303
        strncat (diptr->options, "mime,",
 
304
                DI_OPT_LEN - strlen (diptr->options) - 1);
 
305
    }
 
306
#endif
 
307
#if defined (MNT_HAS_QUERY)
 
308
    if ((flags & MNT_HAS_QUERY) == MNT_HAS_QUERY)
 
309
    {
 
310
        strncat (diptr->options, "query,",
 
311
                DI_OPT_LEN - strlen (diptr->options) - 1);
 
312
    }
 
313
#endif
 
314
#if defined (MNT_HAS_ATTR)
 
315
    if ((flags & MNT_HAS_ATTR) == MNT_HAS_ATTR)
 
316
    {
 
317
        strncat (diptr->options, "attr,",
 
318
                DI_OPT_LEN - strlen (diptr->options) - 1);
 
319
    }
 
320
#endif
 
321
    return;
 
322
}
 
323
 
 
324
void
 
325
#if _proto_stdc
 
326
convertNFSMountOptions (long flags, long wsize, long rsize, diDiskInfo_t *diptr)
 
327
#else
 
328
convertNFSMountOptions (flags, wsize, rsize, diptr)
 
329
    long          flags;
 
330
    long          wsize;
 
331
    long          rsize;
 
332
    diDiskInfo_t   *diptr;
 
333
#endif
 
334
{
 
335
#if defined (NFSMNT_SOFT)
 
336
    if ((flags & NFSMNT_SOFT) != NFSMNT_SOFT)
 
337
    {
 
338
        strncat (diptr->options, "hard,",
 
339
                DI_OPT_LEN - strlen (diptr->options) - 1);
 
340
    }
 
341
#endif
 
342
#if defined (NFSMNT_WSIZE)
 
343
    if ((flags & NFSMNT_WSIZE) == NFSMNT_WSIZE)
 
344
    {
 
345
        char          tmp [64];
 
346
 
 
347
        Snprintf (tmp, DI_SPF(sizeof (tmp), "wsize=%ld,"), wsize);
 
348
        strncat (diptr->options, tmp,
 
349
                DI_OPT_LEN - strlen (diptr->options) - 1);
 
350
    }
 
351
#endif
 
352
#if defined (NFSMNT_RSIZE)
 
353
    if ((flags & NFSMNT_RSIZE) == NFSMNT_RSIZE)
 
354
    {
 
355
        char          tmp [64];
 
356
 
 
357
        Snprintf (tmp, DI_SPF(sizeof (tmp), "rsize=%ld,"), rsize);
 
358
        strncat (diptr->options, tmp,
 
359
                DI_OPT_LEN - strlen (diptr->options) - 1);
 
360
    }
 
361
#endif
 
362
#if defined (NFSMNT_INT) && defined (NFSMNT_SOFT)
 
363
    if ((flags & NFSMNT_SOFT) != NFSMNT_SOFT &&
 
364
        (flags & NFSMNT_INT) == NFSMNT_INT)
 
365
    {
 
366
        strncat (diptr->options, "intr,",
 
367
                DI_OPT_LEN - strlen (diptr->options) - 1);
 
368
    }
 
369
#endif
 
370
#if defined (NFSMNT_TCP)
 
371
    if ((flags & NFSMNT_TCP) != NFSMNT_TCP)
 
372
    {
 
373
        strncat (diptr->options, "udp,",
 
374
                DI_OPT_LEN - strlen (diptr->options) - 1);
 
375
    }
 
376
#endif
 
377
    return;
 
378
}
 
379
 
 
380
 
 
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)
 
387
 
 
388
extern char *
 
389
# if _proto_stdc
 
390
chkMountOptions (char *mntopts, char *str)
 
391
# else
 
392
chkMountOptions (mntopts, str)
 
393
    char          *mntopts;
 
394
    char          *str;
 
395
# endif
 
396
{
 
397
    char    *ptr;
 
398
    char    *tstr;
 
399
 
 
400
    tstr = strdup (mntopts);
 
401
    ptr = strtok (tstr, ",");
 
402
    while (ptr != (char *) NULL)
 
403
    {
 
404
        if (strcmp (ptr, str) == 0)
 
405
        {
 
406
            free (tstr);
 
407
            return ptr;
 
408
        }
 
409
        ptr = strtok ((char *) NULL, ",");
 
410
    }
 
411
    free (tstr);
 
412
    return (char *) NULL;
 
413
}
 
414
 
 
415
#endif /* _lib_getmntent */
 
416
 
 
417
void
 
418
# if _proto_stdc
 
419
di_testRemoteDisk (diDiskInfo_t *diskInfo)
 
420
# else
 
421
di_testRemoteDisk (diskInfo)
 
422
    diDiskInfo_t *diskInfo;
 
423
# endif
 
424
{
 
425
    if (strcmp (diskInfo->fsType, "nfs") == 0 ||
 
426
            strcmp (diskInfo->fsType, "nfs3") == 0)
 
427
    {
 
428
        diskInfo->isLocal = FALSE;
 
429
    }
 
430
}
 
431