equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
77 */ |
77 */ |
78 List<UnixMountEntry> getMountEntries(String fstab) { |
78 List<UnixMountEntry> getMountEntries(String fstab) { |
79 ArrayList<UnixMountEntry> entries = new ArrayList<>(); |
79 ArrayList<UnixMountEntry> entries = new ArrayList<>(); |
80 try { |
80 try { |
81 long fp = setmntent(Util.toBytes(fstab), Util.toBytes("r")); |
81 long fp = setmntent(Util.toBytes(fstab), Util.toBytes("r")); |
|
82 int maxLineSize = 1024; |
|
83 try { |
|
84 for (;;) { |
|
85 int lineSize = getlinelen(fp); |
|
86 if (lineSize == -1) |
|
87 break; |
|
88 if (lineSize > maxLineSize) |
|
89 maxLineSize = lineSize; |
|
90 } |
|
91 } catch (UnixException x) { |
|
92 // nothing we need to do |
|
93 } finally { |
|
94 rewind(fp); |
|
95 } |
|
96 |
82 try { |
97 try { |
83 for (;;) { |
98 for (;;) { |
84 UnixMountEntry entry = new UnixMountEntry(); |
99 UnixMountEntry entry = new UnixMountEntry(); |
85 int res = getmntent(fp, entry); |
100 // count in NUL character at the end |
|
101 int res = getmntent(fp, entry, maxLineSize + 1); |
86 if (res < 0) |
102 if (res < 0) |
87 break; |
103 break; |
88 entries.add(entry); |
104 entries.add(entry); |
89 } |
105 } |
90 } finally { |
106 } finally { |