void mdev_main(void) { // Handle -s if (toys.optflags) { dirtree_read("/sys/class", callback); dirtree_read("/sys/block", callback); } else { // hotplug support make_device(NULL); } }
void mdev_main(void) { // Handle -s if (toys.optflags) { dirtree_read("/sys/class", callback); dirtree_read("/sys/block", callback); } // hotplug support goes here }
void lsattr_main(void) { if (!*toys.optargs) dirtree_read(".", retell_dir); else for (; *toys.optargs; toys.optargs++) { struct stat sb; if (lstat(*toys.optargs, &sb)) perror_msg("stat '%s'", *toys.optargs); else if (S_ISDIR(sb.st_mode) && !(toys.optflags & FLAG_d)) dirtree_read(*toys.optargs, retell_dir); else print_file_attr(*toys.optargs);// to handle "./Filename" or "./Dir" } }
void i2cdetect_main(void) { if (toys.optflags & FLAG_l) { if (toys.optc) error_exit("-l doesn't take arguments"); dirtree_read("/sys/class/i2c-dev", i2cdetect_dash_l); } else if (toys.optflags & FLAG_F) { if (toys.optc != 1) error_exit("-F BUS"); i2cdetect_dash_F(atolx_range(*toys.optargs, 0, INT_MAX)); } else { int bus, first = 0x03, last = 0x77, fd, row, addr, byte; if (toys.optflags & FLAG_a) { first = 0x00; last = 0x7f; } if (toys.optc != 1 && toys.optc != 3) error_exit("bad args"); bus = atolx_range(*toys.optargs, 0, INT_MAX); if (toys.optc == 3) { first = atolx_range(toys.optargs[1], 0, 0x7f); last = atolx_range(toys.optargs[1], 0, 0x7f); if (first > last) error_exit("first > last"); } confirm("Probe chips 0x%02x-0x%02x on bus %d?", first, last, bus); fd = i2c_open(bus, 0, 0); printf(" 0 1 2 3 4 5 6 7 8 9 a b c d e f\n"); for (row = 0; row <= 0x70; row += 16) { xprintf("%02x:", row & 0xf0); for (addr = row; addr < row + 16; ++addr) { if (addr < first || addr > last) printf(" "); else { if (ioctl(fd, I2C_SLAVE, addr) == -1) { if (errno == EBUSY) { xprintf(" UU"); continue; } perror_exit("ioctl(I2C_SLAVE)"); } if (i2c_read_byte(fd, addr, &byte) == -1) xprintf(" --"); else xprintf(" %02x", addr); } } putchar('\n'); } close(fd); } }
void chattr_main(void) { char **argv = toys.optargs; memset(&chattr, 0, sizeof(struct _chattr)); parse_cmdline_arg(&argv); if (!*argv) help_exit("no file"); if (chattr.set && (chattr.add || chattr.rm)) error_exit("no '=' with '-' or '+'"); if (chattr.rm & chattr.add) error_exit("set/unset same flag"); if (!(chattr.add || chattr.rm || chattr.set || chattr.vflag)) error_exit("need '-v', '=', '-' or '+'"); for (; *argv; argv++) dirtree_read(*argv, update_attr); toys.exitval = 0; //always set success at this point. }
void chattr_main(void) { char **argv = toys.optargs; memset(&chattr, 0, sizeof(struct _chattr)); parse_cmdline_arg(&argv); if (!*argv) chattr_help(); if (chattr.set && (chattr.add || chattr.rm)) error_exit("'=' is incompatible with '-' and '+'"); if (chattr.rm & chattr.add) error_exit("Can't set and unset same flag."); if (!(chattr.add || chattr.rm || chattr.set || chattr.vflag)) error_exit(("Must use '-v', '=', '-' or '+'")); for (; *argv; argv++) dirtree_read(*argv, update_attr); toys.exitval = 0; //always set success at this point. }