1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-11-23 07:31:31 +00:00

Make umount(8) WARNS=6 clean:

- Cast delimiter width to integer [1]
 - Solve name conflicts against system header
 - Constify parameters to avoid qualifier conflict

PR:		bin/140017 [1]
Submitted by:	Ulrich Spörlein <uqs spoerlein net> [1]
MFC after:	1 month
Sponsored by:	iXsystems, Inc
This commit is contained in:
Xin LI 2009-12-28 17:57:37 +00:00
parent a411786576
commit 7f471a3289
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=201135
3 changed files with 35 additions and 35 deletions

View File

@ -4,7 +4,6 @@
PROG= umount
SRCS= umount.c vfslist.c mounttab.c
WARNS?= 0
MAN= umount.8
MOUNT= ${.CURDIR}/../mount

View File

@ -75,7 +75,7 @@ char **makevfslist (const char *);
size_t mntinfo (struct statfs **);
int namematch (struct addrinfo *);
int parsehexfsid(const char *hex, fsid_t *fsid);
int sacmp (struct sockaddr *, struct sockaddr *);
int sacmp (void *, void *);
int umountall (char **);
int checkname (char *, char **);
int umountfs(struct statfs *sfs);
@ -225,7 +225,7 @@ umountall(char **typelist)
* Do magic checks on mountpoint/device/fsid, and then call unmount(2).
*/
int
checkname(char *name, char **typelist)
checkname(char *mntname, char **typelist)
{
char buf[MAXPATHLEN];
struct statfs sfsbuf;
@ -238,25 +238,25 @@ checkname(char *name, char **typelist)
/*
* 1. Check if the name exists in the mounttable.
*/
sfs = checkmntlist(name);
sfs = checkmntlist(mntname);
/*
* 2. Remove trailing slashes if there are any. After that
* we look up the name in the mounttable again.
*/
if (sfs == NULL) {
len = strlen(name);
while (len > 1 && name[len - 1] == '/')
name[--len] = '\0';
sfs = checkmntlist(name);
len = strlen(mntname);
while (len > 1 && mntname[len - 1] == '/')
mntname[--len] = '\0';
sfs = checkmntlist(mntname);
}
/*
* 3. Check if the deprecated NFS syntax with an '@' has been used
* and translate it to the ':' syntax. Look up the name in the
* mount table again.
*/
if (sfs == NULL && (delimp = strrchr(name, '@')) != NULL) {
snprintf(buf, sizeof(buf), "%s:%.*s", delimp + 1, delimp - name,
name);
if (sfs == NULL && (delimp = strrchr(mntname, '@')) != NULL) {
snprintf(buf, sizeof(buf), "%s:%.*s", delimp + 1,
(int)(delimp - mntname), mntname);
len = strlen(buf);
while (len > 1 && buf[len - 1] == '/')
buf[--len] = '\0';
@ -271,28 +271,28 @@ checkname(char *name, char **typelist)
* mount list and reality.
* We also do this if an ambiguous mount point was specified.
*/
if (sfs == NULL || (getmntentry(NULL, name, NULL, FIND) != NULL &&
getmntentry(NULL, name, NULL, CHECKUNIQUE) == NULL)) {
if (statfs(name, &sfsbuf) != 0) {
warn("%s: statfs", name);
} else if (stat(name, &sb) != 0) {
warn("%s: stat", name);
if (sfs == NULL || (getmntentry(NULL, mntname, NULL, FIND) != NULL &&
getmntentry(NULL, mntname, NULL, CHECKUNIQUE) == NULL)) {
if (statfs(mntname, &sfsbuf) != 0) {
warn("%s: statfs", mntname);
} else if (stat(mntname, &sb) != 0) {
warn("%s: stat", mntname);
} else if (S_ISDIR(sb.st_mode)) {
/* Check that `name' is the root directory. */
/* Check that `mntname' is the root directory. */
dev = sb.st_dev;
snprintf(buf, sizeof(buf), "%s/..", name);
snprintf(buf, sizeof(buf), "%s/..", mntname);
if (stat(buf, &sb) != 0) {
warn("%s: stat", buf);
} else if (sb.st_dev == dev) {
warnx("%s: not a file system root directory",
name);
mntname);
return (1);
} else
sfs = &sfsbuf;
}
}
if (sfs == NULL) {
warnx("%s: unknown file system", name);
warnx("%s: unknown file system", mntname);
return (1);
}
if (checkvfsname(sfs->f_fstypename, typelist))
@ -469,15 +469,16 @@ getmntentry(const char *fromname, const char *onname, fsid_t *fsid, dowhat what)
}
int
sacmp(struct sockaddr *sa1, struct sockaddr *sa2)
sacmp(void *sa1, void *sa2)
{
void *p1, *p2;
int len;
if (sa1->sa_family != sa2->sa_family)
if (((struct sockaddr *)sa1)->sa_family !=
((struct sockaddr *)sa2)->sa_family)
return (1);
switch (sa1->sa_family) {
switch (((struct sockaddr *)sa1)->sa_family) {
case AF_INET:
p1 = &((struct sockaddr_in *)sa1)->sin_addr;
p2 = &((struct sockaddr_in *)sa2)->sin_addr;
@ -520,18 +521,18 @@ namematch(struct addrinfo *ai)
}
struct statfs *
checkmntlist(char *name)
checkmntlist(char *mntname)
{
struct statfs *sfs;
fsid_t fsid;
sfs = NULL;
if (parsehexfsid(name, &fsid) == 0)
if (parsehexfsid(mntname, &fsid) == 0)
sfs = getmntentry(NULL, NULL, &fsid, FIND);
if (sfs == NULL)
sfs = getmntentry(NULL, name, NULL, FIND);
sfs = getmntentry(NULL, mntname, NULL, FIND);
if (sfs == NULL)
sfs = getmntentry(name, NULL, NULL, FIND);
sfs = getmntentry(mntname, NULL, NULL, FIND);
return (sfs);
}

View File

@ -45,7 +45,7 @@ __FBSDID("$FreeBSD$");
struct mtablist *mtabhead;
static void badline(char *field, char *bad);
static void badline(const char *field, const char *bad);
/*
* Add an entry to PATH_MOUNTTAB for each mounted NFS filesystem,
@ -69,12 +69,12 @@ add_mtab(char *hostp, char *dirp) {
* Read mounttab line for line and return struct mtablist.
*/
int
read_mtab() {
read_mtab(void) {
struct mtablist **mtabpp, *mtabp;
char *hostp, *dirp, *cp;
char str[STRSIZ];
char *timep, *endp;
time_t time;
time_t actiontime;
u_long ultmp;
FILE *mtabfile;
@ -86,7 +86,7 @@ read_mtab() {
return (0);
}
}
time = 0;
actiontime = 0;
mtabpp = &mtabhead;
while (fgets(str, STRSIZ, mtabfile) != NULL) {
cp = str;
@ -113,13 +113,13 @@ read_mtab() {
badline("time", timep);
continue;
}
time = ultmp;
actiontime = ultmp;
if ((mtabp = malloc(sizeof (struct mtablist))) == NULL) {
syslog(LOG_ERR, "malloc");
fclose(mtabfile);
return (0);
}
mtabp->mtab_time = time;
mtabp->mtab_time = actiontime;
memmove(mtabp->mtab_host, hostp, MNTNAMLEN);
mtabp->mtab_host[MNTNAMLEN - 1] = '\0';
memmove(mtabp->mtab_dirp, dirp, MNTPATHLEN);
@ -218,7 +218,7 @@ free_mtab() {
* Print bad lines to syslog.
*/
static void
badline(char *field, char *bad) {
badline(const char *field, const char *bad) {
syslog(LOG_ERR, "bad mounttab %s field '%s'", field,
(bad == NULL) ? "<null>" : bad);
}