From: chrubis@suse.cz
To: "gux.fnst@cn.fujitsu.com" <gux.fnst@cn.fujitsu.com>
Cc: "ltp-list@lists.sourceforge.net" <ltp-list@lists.sourceforge.net>
Subject: Re: [LTP] [PATCH v4 1/2] lib/tst_path_has_mnt_flags.c: create a function tst_path_has_mnt_flags()
Date: Tue, 6 May 2014 19:26:34 +0200 [thread overview]
Message-ID: <20140506172634.GA10697@rei> (raw)
In-Reply-To: <1397202849-5956-1-git-send-email-gux.fnst@cn.fujitsu.com>
Hi!
> +/* lib/tst_path_has_mnt_flags.c
> + *
> + * Check whether a path is on a filesystem that is mounted with
> + * specified flags.
> + * @path: path to file
> + * @flags: mount flags
You should describe that flags is NULL terminated array here.
And add a note about the return value (which is number of flags matched).
> + */
> +int tst_path_has_mnt_flags(const char *path, const char *flags[]);
Looking at the function interface, we may add the clenanup callback
parameter and do tst_brkm(TBROK, ) instead of the return -1. What do you
think?
> #ifdef TST_USE_COMPAT16_SYSCALL
> #define TCID_BIT_SUFFIX "_16"
> #elif TST_USE_NEWER64_SYSCALL
> diff --git a/lib/tst_path_has_mnt_flags.c b/lib/tst_path_has_mnt_flags.c
> new file mode 100644
> index 0000000..92c7494
> --- /dev/null
> +++ b/lib/tst_path_has_mnt_flags.c
> @@ -0,0 +1,81 @@
> +/*
> + * Copyright (c) 2014 Fujitsu Ltd.
> + * Author: Xing Gu <gux.fnst@cn.fujitsu.com>
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms of version 2 of the GNU General Public License as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it would be useful, but
> + * WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> + *
> + * You should have received a copy of the GNU General Public License along
> + * with this program; if not, write the Free Software Foundation, Inc.,
> + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
> + */
> +
> +#include <unistd.h>
> +#include <mntent.h>
> +#include <stdio.h>
> +#include <string.h>
> +#include "test.h"
> +
> +/*
> + * Check whether a path is on a filesystem that is mounted with
> + * specified flags.
> + *
> + * Returns:
> + * -1 - an error has occurred
> + * 0 - the filesystem does not have any specified flags
> + * 1..n - number of flags matched
> + */
I would omit this comment, it's more important to have this description
in the header file (which is where people look) than here.
> +int tst_path_has_mnt_flags(const char *path, const char *flags[])
> +{
> + struct mntent *mnt;
> + size_t prefix_max = 0, prefix_len;
> + int flags_matched = 0;
> + FILE *f;
> + int i;
> +
> + if (path == NULL) {
> + printf("The path is NULL.\n");
> + return -1;
> + }
> +
> + if (access(path, F_OK) == -1) {
> + printf("The path %s doesn't exist.\n", path);
> + return -1;
> + }
> +
> + f = setmntent("/proc/mounts", "r");
> +
> + if (f == NULL) {
> + printf("Couldn't mount /proc/mounts.\n");
^
open
> + return -1;
> + }
> +
> + while ((mnt = getmntent(f))) {
> + /* ignore all pseudo fs */
> + if (mnt->mnt_fsname[0] != '/')
> + continue;
> +
> + prefix_len = strlen(mnt->mnt_dir);
> +
> + if (strncmp(path, mnt->mnt_dir, prefix_len) == 0
> + && prefix_len > prefix_max) {
> + prefix_max = prefix_len;
> + flags_matched = 0;
> + i = 0;
> + while (flags[i] != NULL) {
> + if (hasmntopt(mnt, flags[i]) != NULL)
> + flags_matched++;
> + i++;
> + }
> + }
> + }
> +
> + endmntent(f);
> +
> + return flags_matched;
> +}
--
Cyril Hrubis
chrubis@suse.cz
------------------------------------------------------------------------------
Is your legacy SCM system holding you back? Join Perforce May 7 to find out:
• 3 signs your SCM is hindering your productivity
• Requirements for releasing software faster
• Expert tips and advice for migrating your SCM now
http://p.sf.net/sfu/perforce
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
next prev parent reply other threads:[~2014-05-06 17:27 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
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 ` chrubis [this message]
2014-05-08 9:50 ` [LTP] [PATCH v5 1/2] lib/tst_path_has_mnt_flags.c: create a function tst_path_has_mnt_flags() 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=20140506172634.GA10697@rei \
--to=chrubis@suse.cz \
--cc=gux.fnst@cn.fujitsu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox