diff --git a/disk-utils/fsck.c b/disk-utils/fsck.c index 84d2dcc..73ec9bd 100644 --- a/disk-utils/fsck.c +++ b/disk-utils/fsck.c @@ -109,6 +109,7 @@ struct fsck_instance { int lock; /* flock()ed lockpath file descriptor or -1 */ char *lockpath; /* /run/fsck/.lock or NULL */ + int lock_stacked; /* flock()ed stacked file descriptor or -1 */ int exit_status; struct timeval start_time; @@ -337,6 +338,7 @@ static int is_irrotational_disk(dev_t disk) static void lock_disk(struct fsck_instance *inst) { + char path[PATH_MAX]; dev_t disk = fs_get_disk(inst->fs, 1); char *diskpath = NULL, *diskname; @@ -365,6 +367,18 @@ static void lock_disk(struct fsck_instance *inst) if (!diskname) diskname = diskpath; + snprintf(path, sizeof(path), FSCK_RUNTIME_DIRNAME "/stacked.lock"); + + inst->lock_stacked = open(path, O_RDONLY|O_CREAT|O_CLOEXEC, + S_IWUSR|S_IRUSR|S_IRGRP|S_IROTH); + if (inst->lock_stacked >= 0) { + if (flock(inst->lock_stacked, + fs_is_stacked(inst->fs) ? LOCK_EX : LOCK_SH) != 0) { + close(inst->lock_stacked); /* failed */ + inst->lock_stacked = -1; + } + } + xasprintf(&inst->lockpath, FSCK_RUNTIME_DIRNAME "/%s.lock", diskname); if (verbose) @@ -410,10 +424,12 @@ static void unlock_disk(struct fsck_instance *inst) printf(_("Unlocking %s.\n"), inst->lockpath); close(inst->lock); /* unlock */ + close(inst->lock_stacked); /* unlock */ free(inst->lockpath); inst->lock = -1; + inst->lock_stacked = -1; inst->lockpath = NULL; }