Mercurial > hg > toybox
annotate lib/getmountlist.c @ 897:849e14fecf2b
Convert getmountlist() to xgetmountlist().
author | Rob Landley <rob@landley.net> |
---|---|
date | Fri, 10 May 2013 18:57:01 -0500 |
parents | ae7a0fd5363f |
children | c44dff160d65 |
rev | line source |
---|---|
7
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
6
diff
changeset
|
1 /* getmountlist.c - Get a linked list of mount points, with stat information. |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
6
diff
changeset
|
2 * |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
6
diff
changeset
|
3 * Copyright 2006 Rob Landley <rob@landley.net> |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
6
diff
changeset
|
4 */ |
2
67b517913e56
Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents:
diff
changeset
|
5 |
67b517913e56
Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents:
diff
changeset
|
6 #include "toys.h" |
67b517913e56
Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents:
diff
changeset
|
7 |
67b517913e56
Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents:
diff
changeset
|
8 #include <mntent.h> |
67b517913e56
Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents:
diff
changeset
|
9 |
897
849e14fecf2b
Convert getmountlist() to xgetmountlist().
Rob Landley <rob@landley.net>
parents:
882
diff
changeset
|
10 // Get list of mounted filesystems, including stat and statvfs info. |
849e14fecf2b
Convert getmountlist() to xgetmountlist().
Rob Landley <rob@landley.net>
parents:
882
diff
changeset
|
11 // Returns a reversed list, which is good for finding overmounts and such. |
2
67b517913e56
Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents:
diff
changeset
|
12 |
897
849e14fecf2b
Convert getmountlist() to xgetmountlist().
Rob Landley <rob@landley.net>
parents:
882
diff
changeset
|
13 struct mtab_list *xgetmountlist(void) |
2
67b517913e56
Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents:
diff
changeset
|
14 { |
897
849e14fecf2b
Convert getmountlist() to xgetmountlist().
Rob Landley <rob@landley.net>
parents:
882
diff
changeset
|
15 struct mtab_list *mtlist, *mt; |
849e14fecf2b
Convert getmountlist() to xgetmountlist().
Rob Landley <rob@landley.net>
parents:
882
diff
changeset
|
16 struct mntent *me; |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
442
diff
changeset
|
17 FILE *fp; |
897
849e14fecf2b
Convert getmountlist() to xgetmountlist().
Rob Landley <rob@landley.net>
parents:
882
diff
changeset
|
18 |
849e14fecf2b
Convert getmountlist() to xgetmountlist().
Rob Landley <rob@landley.net>
parents:
882
diff
changeset
|
19 if (!(fp = setmntent("/proc/mounts", "r"))) perror_exit("bad /proc/mounts"); |
2
67b517913e56
Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents:
diff
changeset
|
20 |
897
849e14fecf2b
Convert getmountlist() to xgetmountlist().
Rob Landley <rob@landley.net>
parents:
882
diff
changeset
|
21 for (mtlist = 0; me = getmntent(fp); mtlist = mt) { |
849e14fecf2b
Convert getmountlist() to xgetmountlist().
Rob Landley <rob@landley.net>
parents:
882
diff
changeset
|
22 mt = xzalloc(sizeof(struct mtab_list) + strlen(me->mnt_fsname) + |
849e14fecf2b
Convert getmountlist() to xgetmountlist().
Rob Landley <rob@landley.net>
parents:
882
diff
changeset
|
23 strlen(me->mnt_dir) + strlen(me->mnt_type) + 3); |
849e14fecf2b
Convert getmountlist() to xgetmountlist().
Rob Landley <rob@landley.net>
parents:
882
diff
changeset
|
24 mt->next = mtlist; |
849e14fecf2b
Convert getmountlist() to xgetmountlist().
Rob Landley <rob@landley.net>
parents:
882
diff
changeset
|
25 |
849e14fecf2b
Convert getmountlist() to xgetmountlist().
Rob Landley <rob@landley.net>
parents:
882
diff
changeset
|
26 // Collect details about mounted filesystem (don't bother for /etc/fstab). |
849e14fecf2b
Convert getmountlist() to xgetmountlist().
Rob Landley <rob@landley.net>
parents:
882
diff
changeset
|
27 stat(me->mnt_dir, &(mt->stat)); |
849e14fecf2b
Convert getmountlist() to xgetmountlist().
Rob Landley <rob@landley.net>
parents:
882
diff
changeset
|
28 statvfs(me->mnt_dir, &(mt->statvfs)); |
849e14fecf2b
Convert getmountlist() to xgetmountlist().
Rob Landley <rob@landley.net>
parents:
882
diff
changeset
|
29 |
849e14fecf2b
Convert getmountlist() to xgetmountlist().
Rob Landley <rob@landley.net>
parents:
882
diff
changeset
|
30 // Remember information from /proc/mounts |
849e14fecf2b
Convert getmountlist() to xgetmountlist().
Rob Landley <rob@landley.net>
parents:
882
diff
changeset
|
31 mt->dir = stpcpy(mt->type, me->mnt_type) + 1; |
849e14fecf2b
Convert getmountlist() to xgetmountlist().
Rob Landley <rob@landley.net>
parents:
882
diff
changeset
|
32 mt->device = stpcpy(mt->dir, me->mnt_dir) + 1; |
849e14fecf2b
Convert getmountlist() to xgetmountlist().
Rob Landley <rob@landley.net>
parents:
882
diff
changeset
|
33 strcpy(mt->device, me->mnt_fsname); |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
442
diff
changeset
|
34 } |
703 | 35 endmntent(fp); |
897
849e14fecf2b
Convert getmountlist() to xgetmountlist().
Rob Landley <rob@landley.net>
parents:
882
diff
changeset
|
36 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
442
diff
changeset
|
37 return mtlist; |
2
67b517913e56
Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents:
diff
changeset
|
38 } |