@@ -71,58 +71,32 @@ static int fsdev_cmp(const void *a, const void *b)
71
71
return memcmp (a , b , sizeof (dev_t ));
72
72
}
73
73
74
- /**
75
- * Compare two strings.
76
- */
77
- static int fsname_cmp (const void * a , const void * b )
78
- {
79
- return strcmp (a , b );
80
- }
81
-
82
- /**
83
- * Search for a filesystem name in a sorted array using binary search.
84
- * @param fsname name
85
- * @param fs_arr sorted array of filesystem names
86
- * @param fs_cnt number of names in the array
87
- * @retval 1 if found
88
- * @retval 0 otherwise
89
- */
90
- static int match_fs (const char * fsname , const char * * fs_arr , size_t fs_cnt )
91
- {
92
- size_t w , s ;
93
- int cmp ;
94
-
95
- w = fs_cnt ;
96
- s = 0 ;
97
-
98
- while (w > 0 ) {
99
- cmp = fsname_cmp (fsname , fs_arr [s + w / 2 ]);
100
- if (cmp > 0 ) {
101
- s += w / 2 + 1 ;
102
- w = w - w / 2 - 1 ;
103
- } else if (cmp < 0 ) {
104
- w = w / 2 ;
105
- } else {
106
- return (1 );
107
- }
108
- }
109
-
110
- return (0 );
111
- }
112
-
113
74
#if defined(OS_LINUX ) || defined(OS_AIX )
114
75
115
76
#define DEVID_ARRAY_SIZE 16
116
77
#define DEVID_ARRAY_ADD 8
117
78
118
79
#if defined(OS_LINUX )
119
- static int
120
- is_local_fs (struct mntent * ment )
80
+ int is_local_fs (struct mntent * ment )
121
81
{
122
82
// todo: would it be usefull to provide the choice during build-time?
123
83
#if 1
124
84
char * s ;
125
85
86
+ /*
87
+ * When type of the filesystem is autofs, it means the mtab entry
88
+ * describes the autofs configuration, which means ment->mnt_fsname
89
+ * is a path to the relevant autofs map, eg. /etc/auto.misc. In this
90
+ * situation, the following code which analyses ment->mnt_type would
91
+ * not work. When the filesystem handled by autofs is mounted, there
92
+ * is another different entry in mtab which contains the real block
93
+ * special device or remote filesystem in ment->mnt_fsname, and that
94
+ * will be parsed in a different call of this function.
95
+ */
96
+ if (!strcmp (ment -> mnt_type , "autofs" )) {
97
+ return 0 ;
98
+ }
99
+
126
100
s = ment -> mnt_fsname ;
127
101
/* If the fsname begins with "//", it is probably CIFS. */
128
102
if (s [0 ] == '/' && s [1 ] == '/' )
@@ -153,8 +127,7 @@ is_local_fs(struct mntent *ment)
153
127
}
154
128
155
129
#elif defined(OS_AIX )
156
- static int
157
- is_local_fs (struct mntent * ment )
130
+ int is_local_fs (struct mntent * ment )
158
131
{
159
132
int i ;
160
133
struct vfs_ent * e ;
@@ -183,7 +156,7 @@ is_local_fs(struct mntent *ment)
183
156
184
157
#endif /* OS_AIX */
185
158
186
- static fsdev_t * __fsdev_init (fsdev_t * lfs , const char * * fs , size_t fs_cnt )
159
+ static fsdev_t * __fsdev_init (fsdev_t * lfs )
187
160
{
188
161
int e ;
189
162
FILE * fp ;
@@ -214,12 +187,8 @@ static fsdev_t *__fsdev_init(fsdev_t * lfs, const char **fs, size_t fs_cnt)
214
187
i = 0 ;
215
188
216
189
while ((ment = getmntent (fp )) != NULL ) {
217
- if (fs == NULL ) {
218
- if (!is_local_fs (ment ))
219
- continue ;
220
- } else if (!match_fs (ment -> mnt_type , fs , fs_cnt )) {
221
- continue ;
222
- }
190
+ if (!is_local_fs (ment ))
191
+ continue ;
223
192
if (stat (ment -> mnt_dir , & st ) != 0 )
224
193
continue ;
225
194
if (i >= lfs -> cnt ) {
@@ -237,7 +206,7 @@ static fsdev_t *__fsdev_init(fsdev_t * lfs, const char **fs, size_t fs_cnt)
237
206
return (lfs );
238
207
}
239
208
#elif defined(OS_FREEBSD ) || defined(OS_APPLE )
240
- static fsdev_t * __fsdev_init (fsdev_t * lfs , const char * * fs , size_t fs_cnt )
209
+ static fsdev_t * __fsdev_init (fsdev_t * lfs )
241
210
{
242
211
struct statfs * mntbuf = NULL ;
243
212
struct stat st ;
@@ -246,20 +215,11 @@ static fsdev_t *__fsdev_init(fsdev_t * lfs, const char **fs, size_t fs_cnt)
246
215
lfs -> cnt = getmntinfo (& mntbuf , (fs == NULL ? MNT_LOCAL : 0 ) | MNT_NOWAIT );
247
216
lfs -> ids = malloc (sizeof (dev_t ) * lfs -> cnt );
248
217
249
- if (fs == NULL ) {
250
- for (i = 0 ; i < lfs -> cnt ; ++ i ) {
251
- if (stat (mntbuf [i ].f_mntonname , & st ) != 0 )
252
- continue ;
253
-
254
- memcpy (& (lfs -> ids [i ]), & st .st_dev , sizeof (dev_t ));
255
- }
256
- } else {
257
- for (i = 0 ; i < lfs -> cnt ; ++ i ) {
258
- if (!match_fs (mntbuf [i ].f_fstypename , fs , fs_cnt ))
259
- continue ;
218
+ for (i = 0 ; i < lfs -> cnt ; ++ i ) {
219
+ if (stat (mntbuf [i ].f_mntonname , & st ) != 0 )
220
+ continue ;
260
221
261
- memcpy (& (lfs -> ids [i ]), & st .st_dev , sizeof (dev_t ));
262
- }
222
+ memcpy (& (lfs -> ids [i ]), & st .st_dev , sizeof (dev_t ));
263
223
}
264
224
265
225
if (i != lfs -> cnt ) {
@@ -274,7 +234,7 @@ static fsdev_t *__fsdev_init(fsdev_t * lfs, const char **fs, size_t fs_cnt)
274
234
#define DEVID_ARRAY_SIZE 16
275
235
#define DEVID_ARRAY_ADD 8
276
236
277
- static fsdev_t * __fsdev_init (fsdev_t * lfs , const char * * fs , size_t fs_cnt )
237
+ static fsdev_t * __fsdev_init (fsdev_t * lfs )
278
238
{
279
239
int e ;
280
240
FILE * fp ;
@@ -304,31 +264,16 @@ static fsdev_t *__fsdev_init(fsdev_t * lfs, const char **fs, size_t fs_cnt)
304
264
lfs -> cnt = DEVID_ARRAY_SIZE ;
305
265
i = 0 ;
306
266
307
- if (fs == NULL ) {
308
- while ((getmntent (fp , & mentbuf )) == 0 ) {
309
- /* TODO: Is this check reliable? */
310
- if (stat (mentbuf .mnt_special , & st ) == 0 && (st .st_mode & S_IFCHR )) {
311
-
312
- if (i >= lfs -> cnt ) {
313
- lfs -> cnt += DEVID_ARRAY_ADD ;
314
- lfs -> ids = realloc (lfs -> ids , sizeof (dev_t ) * lfs -> cnt );
315
- }
267
+ while ((getmntent (fp , & mentbuf )) == 0 ) {
268
+ /* TODO: Is this check reliable? */
269
+ if (stat (mentbuf .mnt_special , & st ) == 0 && (st .st_mode & S_IFCHR )) {
316
270
317
- memcpy (& (lfs -> ids [i ++ ]), & st .st_dev , sizeof (dev_t ));
271
+ if (i >= lfs -> cnt ) {
272
+ lfs -> cnt += DEVID_ARRAY_ADD ;
273
+ lfs -> ids = realloc (lfs -> ids , sizeof (dev_t ) * lfs -> cnt );
318
274
}
319
- }
320
- } else {
321
- while ((getmntent (fp , & mentbuf )) == 0 ) {
322
-
323
- if (match_fs (mentbuf .mnt_fstype , fs , fs_cnt )) {
324
275
325
- if (i >= lfs -> cnt ) {
326
- lfs -> cnt += DEVID_ARRAY_ADD ;
327
- lfs -> ids = realloc (lfs -> ids , sizeof (dev_t ) * lfs -> cnt );
328
- }
329
-
330
- memcpy (& (lfs -> ids [i ++ ]), & st .st_dev , sizeof (dev_t ));
331
- }
276
+ memcpy (& (lfs -> ids [i ++ ]), & st .st_dev , sizeof (dev_t ));
332
277
}
333
278
}
334
279
@@ -341,7 +286,7 @@ static fsdev_t *__fsdev_init(fsdev_t * lfs, const char **fs, size_t fs_cnt)
341
286
}
342
287
#endif
343
288
344
- fsdev_t * fsdev_init (const char * * fs , size_t fs_cnt )
289
+ fsdev_t * fsdev_init ()
345
290
{
346
291
fsdev_t * lfs ;
347
292
@@ -350,7 +295,7 @@ fsdev_t *fsdev_init(const char **fs, size_t fs_cnt)
350
295
if (lfs == NULL )
351
296
return (NULL );
352
297
353
- if (__fsdev_init (lfs , fs , fs_cnt ) == NULL )
298
+ if (__fsdev_init (lfs ) == NULL )
354
299
return (NULL );
355
300
356
301
if (lfs -> ids != NULL && lfs -> cnt > 1 )
@@ -364,53 +309,6 @@ static inline int isfschar(int c)
364
309
return (isalpha (c ) || isdigit (c ) || c == '-' || c == '_' );
365
310
}
366
311
367
- fsdev_t * fsdev_strinit (const char * fs_names )
368
- {
369
- fsdev_t * lfs ;
370
- char * pstr , * * fs_arr ;
371
- size_t fs_cnt ;
372
- int state , e ;
373
-
374
- pstr = strdup (fs_names );
375
- state = 0 ;
376
- fs_arr = NULL ;
377
- fs_cnt = 0 ;
378
-
379
- while (* pstr != '\0' ) {
380
- switch (state ) {
381
- case 0 :
382
- if (isfschar (* pstr )) {
383
- state = 1 ;
384
- ++ fs_cnt ;
385
- fs_arr = realloc (fs_arr , sizeof (char * ) * fs_cnt );
386
- fs_arr [fs_cnt - 1 ] = pstr ;
387
- }
388
-
389
- ++ pstr ;
390
-
391
- break ;
392
- case 1 :
393
- if (!isfschar (* pstr ) && * pstr != '\0' ) {
394
- state = 0 ;
395
- * pstr = '\0' ;
396
- ++ pstr ;
397
- }
398
- break ;
399
- }
400
- }
401
-
402
- if (fs_arr != NULL && fs_cnt > 0 )
403
- qsort (fs_arr , fs_cnt , sizeof (char * ), fsname_cmp );
404
-
405
- lfs = fsdev_init ((const char * * )fs_arr , fs_cnt );
406
- e = errno ;
407
- free (fs_arr );
408
- errno = e ;
409
- free (pstr );
410
-
411
- return (lfs );
412
- }
413
-
414
312
void fsdev_free (fsdev_t * lfs )
415
313
{
416
314
if (lfs != NULL ) {
0 commit comments