// TODO what if you --bind mount a block device somewhere (file, dir, dev)
// TODO "touch servername; mount -t cifs servername path"
// TODO mount -o remount a user mount
+// TODO mount image.img sub (auto-loopback) then umount image.img
// Strip flags out of comma separated list of options, return flags,.
static long flag_opts(char *new, long flags, char **more)
{
FILE *fp = 0;
int rc = EINVAL;
+ char *buf = 0;
if (toys.optflags & FLAG_f) return;
toys.exitval |= xrun((char *[]){"swapon", "--", dev, 0});
for (;;) {
- char *buf = 0;
-
// If type wasn't specified, try all of them in order.
- if (fp) {
+ if (fp && !buf) {
size_t i;
if (getline(&buf, &i, fp)<0) break;
// skip nodev devices
if (!isspace(*type)) {
free(buf);
+ buf = 0;
+
continue;
}
// trim whitespace
fprintf(stderr, "'%s' is read-only", dev);
flags |= MS_RDONLY;
}
- free(buf);
-
- if (!rc) break;
// Trying to autodetect loop mounts like bind mounts above (file on dir)
// isn't good enough because "mount -t ext2 fs.img dir" is valid, but if
// Solution: try the mount, let the kernel tell us it wanted a block
// device, then do the loopback setup and retry the mount.
- if (fp && errno == EINVAL) continue;
-
- if (errno == ENOTBLK) {
+ if (rc && errno == ENOTBLK) {
char *losetup[] = {"losetup", "-fs", dev, 0};
int pipe, len;
pid_t pid;
dev = toybuf;
continue;
- } else error_msg("losetup failed %d", rc);
- } else perror_msg("'%s'->'%s'", dev, dir);
+ }
+ error_msg("losetup failed %d", rc);
+
+ break;
+ }
+
+ free(buf);
+ buf = 0;
+ if (!rc) break;
+ if (fp && (errno == EINVAL || errno == EBUSY)) continue;
+
+ perror_msg("'%s'->'%s'", dev, dir);
break;
}