[pacman-dev] [PATCH] Check mountpoint read-only status when checking space

Dan McGee dpmcgee at gmail.com
Fri Feb 11 11:31:21 EST 2011


On Wed, Feb 9, 2011 at 7:47 PM, Allan McRae <allan at archlinux.org> wrote:
> On 09/02/11 13:23, Dan McGee wrote:
>>
>> This is a bit of a stopgap solution for the problem, but an easier one
>> than
>> revamping the file conflict checking code to support the same stuff. Using
>> some more gross autoconf magic, figure out which struct field we need to
>> look at to determine read-only status and store that on our mountpoint
>> struct. If we find out we needed this partition after calculating size
>> requirements, then toss an error.
>>
>> Signed-off-by: Dan McGee<dan at archlinux.org>
>> ---
>> Note: there are two definite areas for improvement here- we would fail on
>> a
>> package uninstall due to us not setting the ->used flag there. We may want
>> two
>> flags for this purpose- used, and "getting installed to" or something.
>> Second
>> is we don't do anything with directories and symlinks, so this would still
>> fail
>> if /boot was read-only:
>>
>> /var/lib/myfile
>> /boot/youlose
>> /boot/youloseagain ->  /var/lib/myfile
>>
>> -Dan
>>
>>  configure.ac            |    4 ++++
>>  lib/libalpm/diskspace.c |   30 +++++++++++++++++++++++-------
>>  lib/libalpm/diskspace.h |    1 +
>>  3 files changed, 28 insertions(+), 7 deletions(-)
>>
>> diff --git a/configure.ac b/configure.ac
>> index 47d6093..1039bba 100644
>> --- a/configure.ac
>> +++ b/configure.ac
>> @@ -194,6 +194,10 @@ AC_CHECK_FUNCS([geteuid getmntinfo realpath regcomp
>> strcasecmp \
>>                  wcwidth uname])
>>  # For the diskspace code
>>  FS_STATS_TYPE
>> +AC_CHECK_MEMBERS([struct statvfs.f_flag],,,[[#include<sys/statvfs.h>]])
>> +AC_CHECK_MEMBERS([struct statfs.f_flags],,,[[#include<sys/param.h>
>> +                  #include<sys/mount.h>]])
>> +
>>  # Enable large file support if available
>>  AC_SYS_LARGEFILE
>>
>> diff --git a/lib/libalpm/diskspace.c b/lib/libalpm/diskspace.c
>> index ae2edf7..d47f9be 100644
>> --- a/lib/libalpm/diskspace.c
>> +++ b/lib/libalpm/diskspace.c
>> @@ -19,6 +19,7 @@
>>
>>  #include "config.h"
>>
>> +#include<errno.h>
>>  #if defined(HAVE_MNTENT_H)
>>  #include<mntent.h>
>>  #endif
>> @@ -66,7 +67,7 @@ static alpm_list_t *mount_point_list(void)
>>  #if defined HAVE_GETMNTENT
>>        struct mntent *mnt;
>>        FILE *fp;
>> -       FSSTATSTYPE fsp;
>> +       struct statvfs fsp;
>>
>
> I am missing why this change (and the similar one later in the patch) are
> made.
>
> Was it for clarity?  And if so, why not do it everywhere?
This one was for clarity. In the GETMNTENT section, we explicitly call
statvfs, so assuming fsp can be any other type is pretty silly. It
also helps make clearer why we don't have to do the #ifdef shuffle for
the read-only flags bit in the ENT section, only in the INFO section.

>
>
> e.g. two very similar memcpy lines:
>
> Changed FSSTATSTYPE:
>
>> -             mp->mount_dir_len = strlen(mnt->mnt_dir);
>> -             memcpy(&(mp->fsp),&fsp, sizeof(FSSTATSTYPE));
>> +             mp->mount_dir_len = strlen(mp->mount_dir);
>> +             memcpy(&(mp->fsp),&fsp, sizeof(struct statvfs));
>> +             mp->read_only = fsp.f_flag&  ST_RDONLY;
>
>
> Not changed FSSTATSTYPE:
>
>>               mp->mount_dir = strdup(fsp->f_mntonname);
>> -             mp->mount_dir_len = strlen(mnt->mnt_dir);
>> +             mp->mount_dir_len = strlen(mp->mount_dir);
>>               memcpy(&(mp->fsp), fsp, sizeof(FSSTATSTYPE));

So in a previous patch I actually slipped a compile-error into the
GETMNTINFO section; I tried to refer to mnt->mnt_dir which doesn't
exist at all. mnt isn't even a local variable there. That might
explain some of the oddness when looking at the diff itself.

If I split this patch into a cleanup one first, I think it might make
things a bit clearer.

-Dan


More information about the pacman-dev mailing list