fsck: code shrink, improve code comments on resolve_mount_spec() alloc

function                                             old     new   delta
create_fs_device                                     155     140     -15

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko committed 2026-10-18 16:31:49 +02:00
1 parent 6fb8efcd6c
commit bad78f5e96
3 files changed
+13 -9

No files matched your search

+7 -5
View File
@@ -332,7 +332,7 @@ static struct fs_info *create_fs_device(const char *device, const char *mntpnt,
if (strchr(type, ','))
type = (char *)"auto";
fs->type = xstrdup(type);
fs->opts = xstrdup(opts ? opts : "");
fs->opts = xstrdup(opts); /* can be NULL */
fs->passno = passno < 0 ? 1 : passno;
/*fs->flags = 0; */
/*fs->next = NULL; */
@@ -372,7 +372,7 @@ static void load_fs_info(const char *filename)
}
/* Lookup filesys in /etc/fstab and return the corresponding entry. */
static struct fs_info *lookup(char *filesys)
static struct fs_info *lookup_in_fs_info(const char *filesys)
{
struct fs_info *fs;
@@ -556,7 +556,9 @@ static void execute(const char *type, char *device,
}
#endif
resolve_mount_spec(&device);
/* int free_the_pointer = */ resolve_mount_spec(&device);
/* NB: the possible new pointer is malloced, we leak it */
G.args[G.num_args - 2] = device;
/* G.args[G.num_args - 1] = NULL; - already is */
@@ -645,7 +647,7 @@ static void fsck_device(struct fs_info *fs /*, int interactive */)
* Returns TRUE if a partition on the same disk is already being
* checked.
*/
static int device_already_active(char *device)
static int device_already_active(const char *device)
{
struct fsck_instance *inst;
char *base;
@@ -1105,7 +1107,7 @@ int fsck_main(int argc UNUSED_PARAM, char **argv)
break;
}
fs = lookup(devices[i]);
fs = lookup_in_fs_info(devices[i]);
if (!fs)
fs = create_fs_device(devices[i], "", "auto", NULL, -1);
fsck_device(fs /*, interactive */);
+2 -1
View File
@@ -25,7 +25,8 @@ void display_uuid_cache(int scan_devices);
/* Returns:
* 0: no UUID= or LABEL= prefix found
* 1: UUID= or LABEL= prefix found. In this case,
* *fsname is replaced if device with such UUID or LABEL is found
* *fsname is replaced if device with such UUID or LABEL is found.
* The new string is malloced. The old string is NOT freed!
*/
int resolve_mount_spec(char **fsname);
int add_to_uuid_cache(const char *device);
+4 -3
View File
@@ -151,7 +151,8 @@ static int swap_enable_disable(char *device)
int err = 0;
int quiet = 0;
resolve_mount_spec(&device);
/* int free_the_pointer = */ resolve_mount_spec(&device);
/* NB: the possible new pointer is malloced, we leak it */
if (do_swapoff) {
err = swapoff(device);
@@ -232,7 +233,7 @@ static int do_em_all_in_fstab(void)
{
struct mntent *m;
int err = 0;
FILE *f = xfopen_for_read("/etc/fstab");
FILE *f = xfopen_for_read("/etc/fstab"); /* poor man's setmntent */
while ((m = getmntent(f)) != NULL) {
if (strcmp(m->mnt_type, MNTTYPE_SWAP) == 0) {
@@ -264,7 +265,7 @@ static int do_em_all_in_fstab(void)
}
if (ENABLE_FEATURE_CLEAN_UP)
endmntent(f);
fclose(f);
return err;
}