I've written a couple of new toys that might well be out of scope, but might be interesting or useful "for parts".
I'll describe the commands and the use cases. 1-hwrs: This was originally intended as a SUID helper cludge for my Acer Aspire One, which has a PCI-bus based SD card reader that only shows up when the SD card is inserted. Kernel PCI hotplug does not work properly, with the card reader frequently failing to show up, dmesg getting spammed when I enable it, and the wireless card sporadically failing for reasons that seem to be related. However, it works to manually trigger a PCI bus rescan. Additionally, neither mdev nor udev (as configured in Debian Squeeze) probe for partitions on slow external media, which makes configuring a user mount in /etc/fstab pointless. I didn't want to have to log in as root every time I plugged in an SD card, so I wrote this. It simply triggers a PCI bus rescan (hwrs -p), then walks /dev opening every block device so as to make the kernel look for partitions (hwrs -b). Default behavior is the same as hwrs -pb. The sole reason I wrote it as a new toy was that was the quickest way to get it done. If you think that this isn't in scope but the probe for partitions sounds interesting for mdev, I'd be happy to write that. (Coincidentally, I've thought of a way to make mdev handle hotplugging with minimal code changes: use the environment to find the right uevent file.) 2. xfs_freeze: This is only a wrapper for the FIFREEZE/FITHAW ioctls. FIFREEZE makes all writes to a filesystem (specified as a mountpoint!) block until FITHAW is called. The point here is to allow a filesystem to be put in a state that's consistent enough for filesystem backup, checking, or repair, without preventing reads or killing/waiting for programs that had open files on the filesystem. The name is a historical artefact; this is a clone of the xfs_freeze utility from xfsprogs. These ioctls derive from and replace the XFS-specific XFS_IOC_FREEZE/XFS_IOC_THAW ioctls, which did exactly the same thing. But currently, at least xfs, ext*, jfs, gfs2, nilfs2, and reiserfs support this ioctl. I mainly wrote this because I hadn't done much with ioctls. Thanks, Isaac Dunham
/* hwrs - rescan hardware * * Copyright 2014 Isaac Dunham USE_HWRS(NEWTOY(hwrs, "bp", TOYFLAG_NEEDROOT|TOYFLAG_STAYROOT|TOYFLAG_USR|TOYFLAG_BIN)) config HWRS bool "hwrs" default n help usage: hwrs [-bp] rescan hardware -b scan block devices for partitions -p scan PCI busses for new hardware */ #define FOR_hwrs #include "toys.h" int blockopen(struct dirtree *node) { int pfd = dirtree_parentfd(node); if S_ISBLK(node->st.st_mode) { close(openat(pfd, node->name, O_RDONLY)); } return dirtree_notdotdot(node) & DIRTREE_RECURSE; } void hwrs_main(void) { if (!toys.optflags) toys.optflags = (FLAG_b|FLAG_p); if (toys.optflags & FLAG_p) { int fd = xopen("/sys/bus/pci/rescan", O_WRONLY | O_TRUNC); write(fd, "1", 2); close(fd); } if (toys.optflags & FLAG_b) { dirtree_read("/dev/", blockopen); } }
/* xfs_freeze.c - freeze or thaw filesystem * USE_XFS_FREEZE(NEWTOY(xfs_freeze, "<1>1f|u|[!fu]", TOYFLAG_USR|TOYFLAG_SBIN)) config XFS_FREEZE bool "xfs_freeze" default n help usage: xfs_freeze {-f | -u} /PATH/TO/MOUNT Freeze or unfreeze a filesystem. -f freeze -u unfreeze */ #define FOR_xfs_freeze #include "toys.h" #include <linux/fs.h> void xfs_freeze_main(void) { long p = 1; int io_call = toys.optflags & FLAG_f ? FIFREEZE : FITHAW; toys.exitval = ioctl(xopen(*toys.optargs,O_RDONLY), io_call, &p); }
_______________________________________________ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net