Re: [PATCH] losetup: canonicalize loopfile name

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Karel Zak <kzak@xxxxxxxxxx> writes:

> On Tue, Sep 11, 2007 at 02:35:33PM +0200, Matthias Koenig wrote:
>
>> -	xstrncpy(loopinfo64.lo_file_name, file, LO_NAME_SIZE);
>> + 	myrealpath(file, res_file, PATH_MAX);
>> + 	xstrncpy(loopinfo64.lo_file_name, res_file, LO_NAME_SIZE);
>
>  The LO_NAME_SIZE is terribly small (64 bytes). 

Too bad.

>Matthias, what do you think about:
>
>  -       xstrncpy(loopinfo64.lo_file_name, file, LO_NAME_SIZE);
>  +       lo_filename = filename = canonicalize(file);
>  +       if (strlen(filename) > LO_NAME_SIZE)
>  +               lo_filename = basename(filename);
>  +       xstrncpy(loopinfo64.lo_file_name, lo_filename, LO_NAME_SIZE);
>

Hmm, I don't like the two convention approach, using full path and
basename mixed.
What about truncating the name in the middle and adding a continuation
marker if it is too long? Like:
"/path/to/very_very_long_name" --> "/path/to...name"

Doing something like:

#define MID ((LO_NAME_SIZE-1)/2)

        if (strlen(res_file) > LO_NAME_SIZE-1) {
                memset(loopinfo64.lo_file_name+MID-1, '.', 3);
                strncpy(loopinfo64.lo_file_name, res_file, MID-1);
                strncpy(loopinfo64.lo_file_name+MID+2,
                         res_file+strlen(res_file)-MID+2, MID-1);


>  plus relevant description to losetup and mount man pages.
>
>  (Well, in the final patch we should call the canonicalize(file)
>  outside set_loop(), because mount(8) code is already using
>  canonicalized paths. That's detail (for now...))

Ok.

>  I'd like to a little clean up mount/* code, because now there is more
>  than one version of error(), ...etc. So please, be patient with your
>  lomount patches. I'll inform you...

Yes, good idea. I also noticed some need for cleanup, when trying to use
the canonicalize function.
But the actual reason for prefering myrealpath() is that the
canonicalize function has exceptions for none, proc, devpts. So if you
have a file which is named like this (which is unlikely but perfectly
valid) and don't use the full path, the name will not be canonicalized.
This might be useful for device paths, but for general pathnames this is
not really reasonable.

Matthias
-
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux