Skip to content

Commit

Permalink
Improved mountedFileSystems method in FSUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
sveinbjornt committed Oct 13, 2023
1 parent 18c410e commit 87165b6
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions source/Util/FSUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,18 @@ + (NSDictionary *)mountedFileSystems {
return @{};
}
if (fs_count > MAX_FILESYSTEMS) {
// We set a maximum number of filesystems to prevent
// a stack overflow.
// TODO: Manually allocate memory from heap instead of using stack
// to handle an arbitrary number of filesystems.
fprintf(stderr, "Too many filesystems, bailing");
return @{};
}

struct statfs buf[fs_count];
getfsstat(buf, fs_count * sizeof(buf[0]), MNT_NOWAIT);

NSMutableDictionary *fsdict = [NSMutableDictionary dictionary];
NSMutableDictionary *fsdict = [NSMutableDictionary new];

for (int i = 0; i < fs_count; ++i) {
dev_t fsid = buf[i].f_fsid.val[0];
Expand All @@ -68,7 +72,7 @@ + (NSDictionary *)mountedFileSystems {
};
}

return [fsdict copy];
return [fsdict copy]; // Return immutable copy
}

@end

0 comments on commit 87165b6

Please sign in to comment.