Andrea Francia wrote:
There are a lot of filesystems out there and it seems futile to
keep track of every single one. One possibility is writing a
parser in C
that compares the filesystems in /proc/filesystems (I assume "nodev"
means it's a virtual filesystem?) against /etc/mtab and returns the
mount points that have the correct type.
Are you sure that all filesystems with nodev are fake filesystems?
Pretty sure... Again, there are probably weird exceptions out there. I
don't know about FUSE though. Is it relevant for trash purposes? I
really don't know... I see that gvfs-fuse-daemon uses the type
"fuse.gvfs-fuse-daemon" in /etc/mtab and that doesn't match any entry in
/proc/filesystems.
If you rely on /proc/filesystems your program will work only on those
system that have the /proc filesystem available.
But it should still work on all Unix-like systems. It's not so different
than depending on /etc/mtab.
I think that the blacklist alternative is better.
At the present trash-cli doesn't have yet a black-list, simply checks
if the .Trash directory exists. This works for me.
If you don't have a /net fileststem the blacklist will only speed up
the list-trash operation of few milliseconds, I'll implement that only
after other things.
I have to disagree there. You're hard coding something that can be
provided dynamically by the kernel. I wrote some basic proof of concept
type code and it seems to work well. It prints to stdout all the mount
points associated with device nodes. Even as a command line tool maybe
it could fill a legitimate need if improved. I'm attaching it in case
anyone is interested, I hope that's OK.
Regards,
João Valverde
/*
* mountpath.c
*
* Copyright 2008 João Valverde <[EMAIL PROTECTED]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <mntent.h>
#include <string.h>
#include <assert.h>
#define STRSIZ 30
#define _STRSIZ_ "30"
/* these call exit() on malloc errors */
char **argv_add(char ***argvp, const char *str);
int argv_find(char **argv, const char *str);
int main(int argc, char** argv)
{
char **fs_dev = NULL, **fs_nodev = NULL;
char line[BUFSIZ];
char str1[STRSIZ], str2[STRSIZ];
FILE *fp = NULL;
struct mntent *mp = NULL;
int n;
fp = fopen("/proc/filesystems", "r");
if (fp == NULL) {
fprintf(stderr, "Error opening '/proc/filesystems' for reading.\n");
exit(EXIT_FAILURE);
}
memset(line, 0, BUFSIZ);
memset(str1, 0, STRSIZ);
memset(str2, 0, STRSIZ);
/* parse /proc/filesystems */
while (fgets(line, BUFSIZ, fp) != NULL) {
n = sscanf(line, "%"_STRSIZ_"s %"_STRSIZ_"s", str1, str2);
str1[STRSIZ - 1] = str2[STRSIZ - 1] = '\0';
if (n == 1) {
argv_add(&fs_dev, str1);
}
else if (n == 2 && strcmp(str1, "nodev") == 0) {
argv_add(&fs_nodev, str2);
}
else {
fprintf(stderr, "Ignoring unrecognized '/proc/filesystems' line:\n%s\n", line);
}
}
fclose(fp);
fp = setmntent("/etc/mtab", "r");
if (fp == NULL) {
fprintf(stderr, "Error opening '/etc/mtab' for reading.\n");
exit(EXIT_FAILURE);
}
/* parse mtab for known dev filesystems and print the mount points */
while ((mp = getmntent(fp)) != NULL) {
if (argv_find(fs_dev, mp->mnt_type) == 0)
printf("%s\n", mp->mnt_dir);
}
endmntent(fp);
return EXIT_SUCCESS;
}
void *xmalloc(size_t s)
{
void *p = malloc(s);
if (!p) {
fprintf(stderr, "Out of memory error.\n");
exit(EXIT_FAILURE);
}
return p;
}
char **argv_add(char ***ap, const char *s)
{
char **a;
int n = 1;
assert(ap != NULL);
assert(s != NULL);
a = *ap;
if (a == NULL) {
a = xmalloc(2*sizeof(char *));
a[0] = xmalloc((strlen(s) + 1) * sizeof(char *));
strcpy(a[0], s);
a[1] = NULL;
return *ap = a;
}
while (*a++)
n++;
a = *ap;
a = realloc(a, (n + 1) * sizeof(char *));
if (a == NULL) {
fprintf(stderr, "Out of memory error.\n");
exit(EXIT_FAILURE);
}
a[n-1] = xmalloc((strlen(s) + 1) * sizeof(char));
strcpy(a[n-1], s);
a[n] = NULL;
return *ap = a;
}
int argv_find(char **argv, const char *str)
{
int i;
for (i = 0; argv[i] != NULL; i++) {
if(strcmp(argv[i], str) == 0)
return 0;
}
return 1;
}
_______________________________________________
xdg mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/xdg