@@ -73,45 +73,6 @@ static int fsdev_cmp(const void *a, const void *b)
73
73
return memcmp (a , b , sizeof (dev_t ));
74
74
}
75
75
76
- /**
77
- * Compare two strings.
78
- */
79
- static int fsname_cmp (const void * a , const void * b )
80
- {
81
- return strcmp (a , b );
82
- }
83
-
84
- /**
85
- * Search for a filesystem name in a sorted array using binary search.
86
- * @param fsname name
87
- * @param fs_arr sorted array of filesystem names
88
- * @param fs_cnt number of names in the array
89
- * @retval 1 if found
90
- * @retval 0 otherwise
91
- */
92
- static int match_fs (const char * fsname , const char * * fs_arr , size_t fs_cnt )
93
- {
94
- size_t w , s ;
95
- int cmp ;
96
-
97
- w = fs_cnt ;
98
- s = 0 ;
99
-
100
- while (w > 0 ) {
101
- cmp = fsname_cmp (fsname , fs_arr [s + w / 2 ]);
102
- if (cmp > 0 ) {
103
- s += w / 2 + 1 ;
104
- w = w - w / 2 - 1 ;
105
- } else if (cmp < 0 ) {
106
- w = w / 2 ;
107
- } else {
108
- return (1 );
109
- }
110
- }
111
-
112
- return (0 );
113
- }
114
-
115
76
#if defined(__linux__ ) || defined(_AIX )
116
77
117
78
#define DEVID_ARRAY_SIZE 16
@@ -197,7 +158,7 @@ int is_local_fs(struct mntent *ment)
197
158
198
159
#endif /* _AIX */
199
160
200
- static fsdev_t * __fsdev_init (fsdev_t * lfs , const char * * fs , size_t fs_cnt )
161
+ static fsdev_t * __fsdev_init (fsdev_t * lfs )
201
162
{
202
163
int e ;
203
164
FILE * fp ;
@@ -228,12 +189,8 @@ static fsdev_t *__fsdev_init(fsdev_t * lfs, const char **fs, size_t fs_cnt)
228
189
i = 0 ;
229
190
230
191
while ((ment = getmntent (fp )) != NULL ) {
231
- if (fs == NULL ) {
232
- if (!is_local_fs (ment ))
233
- continue ;
234
- } else if (!match_fs (ment -> mnt_type , fs , fs_cnt )) {
235
- continue ;
236
- }
192
+ if (!is_local_fs (ment ))
193
+ continue ;
237
194
if (stat (ment -> mnt_dir , & st ) != 0 )
238
195
continue ;
239
196
if (i >= lfs -> cnt ) {
@@ -251,7 +208,7 @@ static fsdev_t *__fsdev_init(fsdev_t * lfs, const char **fs, size_t fs_cnt)
251
208
return (lfs );
252
209
}
253
210
#elif defined(__FreeBSD__ ) || defined(__FreeBSD_kernel__ )
254
- static fsdev_t * __fsdev_init (fsdev_t * lfs , const char * * fs , size_t fs_cnt )
211
+ static fsdev_t * __fsdev_init (fsdev_t * lfs )
255
212
{
256
213
struct statfs * mntbuf = NULL ;
257
214
struct stat st ;
@@ -260,20 +217,11 @@ static fsdev_t *__fsdev_init(fsdev_t * lfs, const char **fs, size_t fs_cnt)
260
217
lfs -> cnt = getmntinfo (& mntbuf , (fs == NULL ? MNT_LOCAL : 0 ) | MNT_NOWAIT );
261
218
lfs -> ids = malloc (sizeof (dev_t ) * lfs -> cnt );
262
219
263
- if (fs == NULL ) {
264
- for (i = 0 ; i < lfs -> cnt ; ++ i ) {
265
- if (stat (mntbuf [i ].f_mntonname , & st ) != 0 )
266
- continue ;
267
-
268
- memcpy (& (lfs -> ids [i ]), & st .st_dev , sizeof (dev_t ));
269
- }
270
- } else {
271
- for (i = 0 ; i < lfs -> cnt ; ++ i ) {
272
- if (!match_fs (mntbuf [i ].f_fstypename , fs , fs_cnt ))
273
- continue ;
220
+ for (i = 0 ; i < lfs -> cnt ; ++ i ) {
221
+ if (stat (mntbuf [i ].f_mntonname , & st ) != 0 )
222
+ continue ;
274
223
275
- memcpy (& (lfs -> ids [i ]), & st .st_dev , sizeof (dev_t ));
276
- }
224
+ memcpy (& (lfs -> ids [i ]), & st .st_dev , sizeof (dev_t ));
277
225
}
278
226
279
227
if (i != lfs -> cnt ) {
@@ -288,7 +236,7 @@ static fsdev_t *__fsdev_init(fsdev_t * lfs, const char **fs, size_t fs_cnt)
288
236
#define DEVID_ARRAY_SIZE 16
289
237
#define DEVID_ARRAY_ADD 8
290
238
291
- static fsdev_t * __fsdev_init (fsdev_t * lfs , const char * * fs , size_t fs_cnt )
239
+ static fsdev_t * __fsdev_init (fsdev_t * lfs )
292
240
{
293
241
int e ;
294
242
FILE * fp ;
@@ -318,31 +266,16 @@ static fsdev_t *__fsdev_init(fsdev_t * lfs, const char **fs, size_t fs_cnt)
318
266
lfs -> cnt = DEVID_ARRAY_SIZE ;
319
267
i = 0 ;
320
268
321
- if (fs == NULL ) {
322
- while ((getmntent (fp , & mentbuf )) == 0 ) {
323
- /* TODO: Is this check reliable? */
324
- if (stat (mentbuf .mnt_special , & st ) == 0 && (st .st_mode & S_IFCHR )) {
325
-
326
- if (i >= lfs -> cnt ) {
327
- lfs -> cnt += DEVID_ARRAY_ADD ;
328
- lfs -> ids = realloc (lfs -> ids , sizeof (dev_t ) * lfs -> cnt );
329
- }
269
+ while ((getmntent (fp , & mentbuf )) == 0 ) {
270
+ /* TODO: Is this check reliable? */
271
+ if (stat (mentbuf .mnt_special , & st ) == 0 && (st .st_mode & S_IFCHR )) {
330
272
331
- memcpy (& (lfs -> ids [i ++ ]), & st .st_dev , sizeof (dev_t ));
273
+ if (i >= lfs -> cnt ) {
274
+ lfs -> cnt += DEVID_ARRAY_ADD ;
275
+ lfs -> ids = realloc (lfs -> ids , sizeof (dev_t ) * lfs -> cnt );
332
276
}
333
- }
334
- } else {
335
- while ((getmntent (fp , & mentbuf )) == 0 ) {
336
-
337
- if (match_fs (mentbuf .mnt_fstype , fs , fs_cnt )) {
338
-
339
- if (i >= lfs -> cnt ) {
340
- lfs -> cnt += DEVID_ARRAY_ADD ;
341
- lfs -> ids = realloc (lfs -> ids , sizeof (dev_t ) * lfs -> cnt );
342
- }
343
277
344
- memcpy (& (lfs -> ids [i ++ ]), & st .st_dev , sizeof (dev_t ));
345
- }
278
+ memcpy (& (lfs -> ids [i ++ ]), & st .st_dev , sizeof (dev_t ));
346
279
}
347
280
}
348
281
@@ -355,7 +288,7 @@ static fsdev_t *__fsdev_init(fsdev_t * lfs, const char **fs, size_t fs_cnt)
355
288
}
356
289
#endif
357
290
358
- fsdev_t * fsdev_init (const char * * fs , size_t fs_cnt )
291
+ fsdev_t * fsdev_init ()
359
292
{
360
293
fsdev_t * lfs ;
361
294
@@ -364,7 +297,7 @@ fsdev_t *fsdev_init(const char **fs, size_t fs_cnt)
364
297
if (lfs == NULL )
365
298
return (NULL );
366
299
367
- if (__fsdev_init (lfs , fs , fs_cnt ) == NULL )
300
+ if (__fsdev_init (lfs ) == NULL )
368
301
return (NULL );
369
302
370
303
if (lfs -> ids != NULL && lfs -> cnt > 1 )
@@ -378,53 +311,6 @@ static inline int isfschar(int c)
378
311
return (isalpha (c ) || isdigit (c ) || c == '-' || c == '_' );
379
312
}
380
313
381
- fsdev_t * fsdev_strinit (const char * fs_names )
382
- {
383
- fsdev_t * lfs ;
384
- char * pstr , * * fs_arr ;
385
- size_t fs_cnt ;
386
- int state , e ;
387
-
388
- pstr = strdup (fs_names );
389
- state = 0 ;
390
- fs_arr = NULL ;
391
- fs_cnt = 0 ;
392
-
393
- while (* pstr != '\0' ) {
394
- switch (state ) {
395
- case 0 :
396
- if (isfschar (* pstr )) {
397
- state = 1 ;
398
- ++ fs_cnt ;
399
- fs_arr = realloc (fs_arr , sizeof (char * ) * fs_cnt );
400
- fs_arr [fs_cnt - 1 ] = pstr ;
401
- }
402
-
403
- ++ pstr ;
404
-
405
- break ;
406
- case 1 :
407
- if (!isfschar (* pstr ) && * pstr != '\0' ) {
408
- state = 0 ;
409
- * pstr = '\0' ;
410
- ++ pstr ;
411
- }
412
- break ;
413
- }
414
- }
415
-
416
- if (fs_arr != NULL && fs_cnt > 0 )
417
- qsort (fs_arr , fs_cnt , sizeof (char * ), fsname_cmp );
418
-
419
- lfs = fsdev_init ((const char * * )fs_arr , fs_cnt );
420
- e = errno ;
421
- free (fs_arr );
422
- errno = e ;
423
- free (pstr );
424
-
425
- return (lfs );
426
- }
427
-
428
314
void fsdev_free (fsdev_t * lfs )
429
315
{
430
316
if (lfs != NULL ) {
0 commit comments