From: "gux.fnst" <gux.fnst@cn.fujitsu.com>
To: Jan Stancek <jstancek@redhat.com>
Cc: ltp-list <ltp-list@lists.sourceforge.net>
Subject: Re: [LTP] [PATCH v3] lib/tst_path_has_mnt_flags.c: create a function tst_path_has_mnt_flags()
Date: Fri, 11 Apr 2014 14:22:34 +0800 [thread overview]
Message-ID: <53478A2A.7070506@cn.fujitsu.com> (raw)
In-Reply-To: <472091851.2162463.1397039648410.JavaMail.zimbra@redhat.com>
[-- Attachment #1.1: Type: text/plain, Size: 3524 bytes --]
On 04/09/2014 06:34 PM, Jan Stancek wrote:
>
>
>
> ----- Original Message -----
>> From: "gux fnst" <gux.fnst@cn.fujitsu.com>
>> To: ltp-list@lists.sourceforge.net
>> Sent: Wednesday, 9 April, 2014 5:46:34 AM
>> Subject: [LTP] [PATCH v3] lib/tst_path_has_mnt_flags.c: create a function tst_path_has_mnt_flags()
>>
>> Create a function tst_path_has_mnt_flags() for checking whether
>> a path is on a system that is mounted with specified flags.
>>
>> Signed-off-by: Xing Gu <gux.fnst@cn.fujitsu.com>
>> ---
>> include/test.h | 9 +++++
>> lib/tst_path_has_mnt_flags.c | 79
>> ++++++++++++++++++++++++++++++++++++++++++++
>> 2 files changed, 88 insertions(+)
>>
>> +
>> + prefix_len = strlen(mnt->mnt_dir);
>> +
>> + if (strncmp(path, mnt->mnt_dir, prefix_len) == 0
>> + && prefix_len > prefix_max) {
>> + prefix_max = prefix_len;
>> + has_opt = 0;
>> + i = 0;
>> + while ((has_opt == 0) && (flags[i] != NULL)) {
>> + has_opt = hasmntopt(mnt, flags[i]) != NULL;
>> + i++;
>> + }
>> + has_flags = has_opt;
>> + }
>> + }
>> +
>> + endmntent(f);
>> +
>> + return has_flags;
>> +}
> This function looks OK for one testcase that needs to check for
> OR logic between flags. I was thinking, whether we should change
> this function to return number matched flags. That way we could
> also check easily for AND logic (matches all flags) if we need
> that in future.
>
>
> * Returns:
> * -1 - an error has occurred
> * 0 - the filesystem does not have any specified flags
> - * 1 - the filesystem has at least one flag matched
> + * 1..n - number of flags matched
> */
> int tst_path_has_mnt_flags(const char *path, const char *flags[])
> {
> struct mntent *mnt;
> size_t prefix_max = 0, prefix_len;
> - int has_flags = 0, has_opt;
> + int flags_matched = 0;
> FILE *f;
> int i;
>
> @@ -63,17 +65,24 @@ int tst_path_has_mnt_flags(const char *path, const char *flags[])
> if (strncmp(path, mnt->mnt_dir, prefix_len) == 0
> && prefix_len > prefix_max) {
> prefix_max = prefix_len;
> - has_opt = 0;
> + flags_matched = 0;
> i = 0;
> - while ((has_opt == 0) && (flags[i] != NULL)) {
> - has_opt = hasmntopt(mnt, flags[i]) != NULL;
> + while (flags[i] != NULL) {
> + if (hasmntopt(mnt, flags[i]) != NULL)
> + flags_matched++;
> i++;
> }
> - has_flags = has_opt;
> }
> }
>
> endmntent(f);
>
> - return has_flags;
> + return flags_matched;
> +}
>
> What do you think?
Thanks for your suggestion. It is very helpfull.
I will send a new version today.
Regards,
Xing Gu
>
> Regards,
> Jan
>
>> --
>> 1.8.3.1
>> ------------------------------------------------------------------------------
>> Put Bad Developers to Shame
>> Dominate Development with Jenkins Continuous Integration
>> Continuously Automate Build, Test & Deployment
>> Start a new project now. Try Jenkins in the cloud.
>> http://p.sf.net/sfu/13600_Cloudbees
>> _______________________________________________
>> Ltp-list mailing list
>> Ltp-list@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/ltp-list
>>
> .
>
[-- Attachment #1.2: Type: text/html, Size: 4672 bytes --]
[-- Attachment #2: Type: text/plain, Size: 298 bytes --]
------------------------------------------------------------------------------
Put Bad Developers to Shame
Dominate Development with Jenkins Continuous Integration
Continuously Automate Build, Test & Deployment
Start a new project now. Try Jenkins in the cloud.
http://p.sf.net/sfu/13600_Cloudbees
[-- Attachment #3: Type: text/plain, Size: 155 bytes --]
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
next prev parent reply other threads:[~2014-04-11 6:23 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-03 12:00 [LTP] [PATCH v2 1/2] lib/tst_path_has_mnt_flags.c: create a function tst_path_has_mnt_flags() gux.fnst
2014-04-03 12:00 ` [LTP] [PATCH v2 2/2] openat/openat02.c: add a new case to test flags gux.fnst
2014-04-04 10:01 ` [LTP] [PATCH v2 1/2] lib/tst_path_has_mnt_flags.c: create a function tst_path_has_mnt_flags() Jan Stancek
2014-04-09 2:26 ` gux.fnst
2014-04-09 3:46 ` [LTP] [PATCH v3] " gux.fnst
2014-04-09 10:34 ` Jan Stancek
2014-04-09 12:52 ` chrubis
2014-04-11 6:22 ` gux.fnst [this message]
2014-04-11 7:54 ` [LTP] [PATCH v4 1/2] " gux.fnst
2014-04-11 7:54 ` [LTP] [PATCH v4 2/2] openat/openat02.c: add a new case to test flags gux.fnst
2014-05-14 15:40 ` chrubis
2014-05-06 17:26 ` [LTP] [PATCH v4 1/2] lib/tst_path_has_mnt_flags.c: create a function tst_path_has_mnt_flags() chrubis
2014-05-08 9:50 ` [LTP] [PATCH v5 " Xing Gu
2014-05-08 9:50 ` [LTP] [PATCH v5 2/2] openat/openat02.c: add a new case to test flags Xing Gu
2014-05-14 13:15 ` [LTP] [PATCH v5 1/2] lib/tst_path_has_mnt_flags.c: create a function tst_path_has_mnt_flags() chrubis
2014-05-14 13:35 ` chrubis
2014-05-14 13:46 ` chrubis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=53478A2A.7070506@cn.fujitsu.com \
--to=gux.fnst@cn.fujitsu.com \
--cc=jstancek@redhat.com \
--cc=ltp-list@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.