-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVolumeStatus.m
77 lines (70 loc) · 1.66 KB
/
VolumeStatus.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
// VolumeStatus.m
// test
//
// Created by Scott Jann on 5/3/09.
// Copyright (c) 2009 Scott Jann
//
#import "VolumeStatus.h"
#include <stdio.h>
#include <string.h>
@implementation VolumeStatus
- (id) init {
processList = nil;
[self refresh];
return self;
}
- (int)numberOfProcesses {
if(processList == nil)
return 0;
else
return [processList count];
}
- (void)refresh {
if(processList != nil)
[processList release];
processList = [NSMutableArray arrayWithCapacity:8];
char buf[255], server[255], volume[255];
char *p;
FILE *f = popen("ps -ef", "r");
if(f == NULL)
return;
while(fgets(buf, sizeof(buf), f)) {
server[0] = volume[0] = 0;
if(strstr(buf, "glusterfs") == 0)
continue;
p = strstr(buf, SERVER_PARAM);
if(p != 0)
{
strcpy(server, p + strlen(SERVER_PARAM));
p = strchr(server, ' ');
if(p != 0)
*p = 0;
}
p = strstr(buf, VOLUME_PARAM);
if(p != 0)
{
strcpy(volume, p + strlen(VOLUME_PARAM));
p = strchr(volume, ' ');
if(p != 0)
*p = 0;
}
if(server[0] != 0)
{
NSMutableDictionary *item = [NSMutableDictionary dictionaryWithCapacity:2];
[item setObject:[NSString stringWithUTF8String:volume] forKey:@"volume"];
[item setObject:[NSString stringWithUTF8String:server] forKey:@"server"];
[processList insertObject:item atIndex:[processList count]];
}
}
pclose(f);
}
- (BOOL)isMounted:(NSString *)volume onServer:(NSString *)server {
for(int i = 0; i < [processList count]; i++) {
NSMutableDictionary *item = [processList objectAtIndex:i];
if([[item objectForKey:@"volume"] isEqualToString:volume] && [[item objectForKey:@"server"] isEqualToString:server])
return YES;
}
return NO;
}
@end