168
print_device_attributes(string devpath, string subdir)
171
var attr_dir = Path.build_filename(devpath, subdir);
173
d = Dir.open(attr_dir);
176
exit_error("Cannot open directory %s: %s", attr_dir, e.message);
178
// we ignore this on subdirs, some might be transient or
180
debug("Cannot open directory %s: %s", attr_dir, e.message);
185
var attributes = new List<string>();
187
// filter out the uninteresting attributes, sort the others
188
while ((entry = d.read_name()) != null)
189
if (entry != "subsystem" && entry != "firmware_node" && entry != "uevent")
190
attributes.append(entry);
192
// don't look into subdirs which are devices by themselves
196
attributes.sort(strcmp);
198
foreach (var attr in attributes) {
199
string attr_path = Path.build_filename(attr_dir, attr);
200
string attr_name = Path.build_filename(subdir, attr);
201
if (FileUtils.test(attr_path, FileTest.IS_SYMLINK)) {
203
stdout.printf("L: %s=%s\n", attr_name, FileUtils.read_link(attr_path));
205
exit_error("Cannot read link %s: %s", attr_path, e.message);
207
} else if (FileUtils.test(attr_path, FileTest.IS_REGULAR)) {
210
FileUtils.get_data(attr_path, out contents);
211
write_attr(attr_name, contents);
212
} catch (FileError e) {} // some attributes are EACCES, or "no such device", etc.
213
} else if (FileUtils.test(attr_path, FileTest.IS_DIR)) {
214
print_device_attributes(devpath, attr);
168
220
record_device(string dev)
170
222
debug("recording device %s", dev);
210
262
// now append all attributes
215
exit_error("Cannot open directory %s: %s", dev, e.message);
216
return; /* not reached, just to avoid warnings */
218
var attributes = new List<string>();
220
// filter out the uninteresting attributes, sort the others
221
while ((entry = d.read_name()) != null)
222
if (entry != "subsystem" && entry != "firmware_node" && entry != "uevent")
223
attributes.append(entry);
224
attributes.sort(strcmp);
226
foreach (var attr in attributes) {
227
string attr_path = Path.build_filename(dev, attr);
228
// only look at files or symlinks
229
if (FileUtils.test(attr_path, FileTest.IS_SYMLINK)) {
231
stdout.printf("L: %s=%s\n", attr, FileUtils.read_link(attr_path));
233
exit_error("Cannot read link %s: %s", attr, e.message);
235
} else if (FileUtils.test(attr_path, FileTest.IS_REGULAR)) {
238
FileUtils.get_data(attr_path, out contents);
239
write_attr(attr, contents);
240
} catch (FileError e) {} // some attributes are EACCES, or "no such device", etc.
263
print_device_attributes(dev, "");
244
264
stdout.putc('\n');