clang-format
This commit is contained in:
@@ -45,18 +45,15 @@ static struct vnode *bootfs_vnode = NULL;
|
||||
/*
|
||||
* Helper function for actually changing bootfs_vnode.
|
||||
*/
|
||||
static
|
||||
void
|
||||
change_bootfs(struct vnode *newvn)
|
||||
{
|
||||
struct vnode *oldvn;
|
||||
static void change_bootfs(struct vnode *newvn) {
|
||||
struct vnode *oldvn;
|
||||
|
||||
oldvn = bootfs_vnode;
|
||||
bootfs_vnode = newvn;
|
||||
oldvn = bootfs_vnode;
|
||||
bootfs_vnode = newvn;
|
||||
|
||||
if (oldvn != NULL) {
|
||||
VOP_DECREF(oldvn);
|
||||
}
|
||||
if (oldvn != NULL) {
|
||||
VOP_DECREF(oldvn);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -67,171 +64,161 @@ change_bootfs(struct vnode *newvn)
|
||||
*
|
||||
* It is also incidentally the system's first current directory.
|
||||
*/
|
||||
int
|
||||
vfs_setbootfs(const char *fsname)
|
||||
{
|
||||
char tmp[NAME_MAX+1];
|
||||
char *s;
|
||||
int result;
|
||||
struct vnode *newguy;
|
||||
int vfs_setbootfs(const char *fsname) {
|
||||
char tmp[NAME_MAX + 1];
|
||||
char *s;
|
||||
int result;
|
||||
struct vnode *newguy;
|
||||
|
||||
vfs_biglock_acquire();
|
||||
vfs_biglock_acquire();
|
||||
|
||||
snprintf(tmp, sizeof(tmp)-1, "%s", fsname);
|
||||
s = strchr(tmp, ':');
|
||||
if (s) {
|
||||
/* If there's a colon, it must be at the end */
|
||||
if (strlen(s)>0) {
|
||||
vfs_biglock_release();
|
||||
return EINVAL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
strcat(tmp, ":");
|
||||
}
|
||||
snprintf(tmp, sizeof(tmp) - 1, "%s", fsname);
|
||||
s = strchr(tmp, ':');
|
||||
if (s) {
|
||||
/* If there's a colon, it must be at the end */
|
||||
if (strlen(s) > 0) {
|
||||
vfs_biglock_release();
|
||||
return EINVAL;
|
||||
}
|
||||
} else {
|
||||
strcat(tmp, ":");
|
||||
}
|
||||
|
||||
result = vfs_chdir(tmp);
|
||||
if (result) {
|
||||
vfs_biglock_release();
|
||||
return result;
|
||||
}
|
||||
result = vfs_chdir(tmp);
|
||||
if (result) {
|
||||
vfs_biglock_release();
|
||||
return result;
|
||||
}
|
||||
|
||||
result = vfs_getcurdir(&newguy);
|
||||
if (result) {
|
||||
vfs_biglock_release();
|
||||
return result;
|
||||
}
|
||||
result = vfs_getcurdir(&newguy);
|
||||
if (result) {
|
||||
vfs_biglock_release();
|
||||
return result;
|
||||
}
|
||||
|
||||
change_bootfs(newguy);
|
||||
change_bootfs(newguy);
|
||||
|
||||
vfs_biglock_release();
|
||||
return 0;
|
||||
vfs_biglock_release();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Clear the bootfs vnode (preparatory to system shutdown).
|
||||
*/
|
||||
void
|
||||
vfs_clearbootfs(void)
|
||||
{
|
||||
vfs_biglock_acquire();
|
||||
change_bootfs(NULL);
|
||||
vfs_biglock_release();
|
||||
void vfs_clearbootfs(void) {
|
||||
vfs_biglock_acquire();
|
||||
change_bootfs(NULL);
|
||||
vfs_biglock_release();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Common code to pull the device name, if any, off the front of a
|
||||
* path and choose the vnode to begin the name lookup relative to.
|
||||
*/
|
||||
|
||||
static
|
||||
int
|
||||
getdevice(char *path, char **subpath, struct vnode **startvn)
|
||||
{
|
||||
int slash=-1, colon=-1, i;
|
||||
struct vnode *vn;
|
||||
int result;
|
||||
static int getdevice(char *path, char **subpath, struct vnode **startvn) {
|
||||
int slash = -1, colon = -1, i;
|
||||
struct vnode *vn;
|
||||
int result;
|
||||
|
||||
KASSERT(vfs_biglock_do_i_hold());
|
||||
KASSERT(vfs_biglock_do_i_hold());
|
||||
|
||||
/*
|
||||
* Entirely empty filenames aren't legal.
|
||||
*/
|
||||
if (path[0] == 0) {
|
||||
return EINVAL;
|
||||
}
|
||||
/*
|
||||
* Entirely empty filenames aren't legal.
|
||||
*/
|
||||
if (path[0] == 0) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Locate the first colon or slash.
|
||||
*/
|
||||
/*
|
||||
* Locate the first colon or slash.
|
||||
*/
|
||||
|
||||
for (i=0; path[i]; i++) {
|
||||
if (path[i]==':') {
|
||||
colon = i;
|
||||
break;
|
||||
}
|
||||
if (path[i]=='/') {
|
||||
slash = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (i = 0; path[i]; i++) {
|
||||
if (path[i] == ':') {
|
||||
colon = i;
|
||||
break;
|
||||
}
|
||||
if (path[i] == '/') {
|
||||
slash = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (colon < 0 && slash != 0) {
|
||||
/*
|
||||
* No colon before a slash, so no device name
|
||||
* specified, and the slash isn't leading or is also
|
||||
* absent, so this is a relative path or just a bare
|
||||
* filename. Start from the current directory, and
|
||||
* use the whole thing as the subpath.
|
||||
*/
|
||||
*subpath = path;
|
||||
return vfs_getcurdir(startvn);
|
||||
}
|
||||
if (colon < 0 && slash != 0) {
|
||||
/*
|
||||
* No colon before a slash, so no device name
|
||||
* specified, and the slash isn't leading or is also
|
||||
* absent, so this is a relative path or just a bare
|
||||
* filename. Start from the current directory, and
|
||||
* use the whole thing as the subpath.
|
||||
*/
|
||||
*subpath = path;
|
||||
return vfs_getcurdir(startvn);
|
||||
}
|
||||
|
||||
if (colon>0) {
|
||||
/* device:path - get root of device's filesystem */
|
||||
path[colon]=0;
|
||||
while (path[colon+1]=='/') {
|
||||
/* device:/path - skip slash, treat as device:path */
|
||||
colon++;
|
||||
}
|
||||
*subpath = &path[colon+1];
|
||||
if (colon > 0) {
|
||||
/* device:path - get root of device's filesystem */
|
||||
path[colon] = 0;
|
||||
while (path[colon + 1] == '/') {
|
||||
/* device:/path - skip slash, treat as device:path */
|
||||
colon++;
|
||||
}
|
||||
*subpath = &path[colon + 1];
|
||||
|
||||
result = vfs_getroot(path, startvn);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
result = vfs_getroot(path, startvn);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* We have either /path or :path.
|
||||
*
|
||||
* /path is a path relative to the root of the "boot filesystem".
|
||||
* :path is a path relative to the root of the current filesystem.
|
||||
*/
|
||||
KASSERT(colon==0 || slash==0);
|
||||
/*
|
||||
* We have either /path or :path.
|
||||
*
|
||||
* /path is a path relative to the root of the "boot filesystem".
|
||||
* :path is a path relative to the root of the current filesystem.
|
||||
*/
|
||||
KASSERT(colon == 0 || slash == 0);
|
||||
|
||||
if (path[0]=='/') {
|
||||
if (bootfs_vnode==NULL) {
|
||||
return ENOENT;
|
||||
}
|
||||
VOP_INCREF(bootfs_vnode);
|
||||
*startvn = bootfs_vnode;
|
||||
}
|
||||
else {
|
||||
KASSERT(path[0]==':');
|
||||
if (path[0] == '/') {
|
||||
if (bootfs_vnode == NULL) {
|
||||
return ENOENT;
|
||||
}
|
||||
VOP_INCREF(bootfs_vnode);
|
||||
*startvn = bootfs_vnode;
|
||||
} else {
|
||||
KASSERT(path[0] == ':');
|
||||
|
||||
result = vfs_getcurdir(&vn);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
result = vfs_getcurdir(&vn);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* The current directory may not be a device, so it
|
||||
* must have a fs.
|
||||
*/
|
||||
KASSERT(vn->vn_fs!=NULL);
|
||||
/*
|
||||
* The current directory may not be a device, so it
|
||||
* must have a fs.
|
||||
*/
|
||||
KASSERT(vn->vn_fs != NULL);
|
||||
|
||||
result = FSOP_GETROOT(vn->vn_fs, startvn);
|
||||
result = FSOP_GETROOT(vn->vn_fs, startvn);
|
||||
|
||||
VOP_DECREF(vn);
|
||||
VOP_DECREF(vn);
|
||||
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
while (path[1]=='/') {
|
||||
/* ///... or :/... */
|
||||
path++;
|
||||
}
|
||||
while (path[1] == '/') {
|
||||
/* ///... or :/... */
|
||||
path++;
|
||||
}
|
||||
|
||||
*subpath = path+1;
|
||||
*subpath = path + 1;
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -239,62 +226,57 @@ getdevice(char *path, char **subpath, struct vnode **startvn)
|
||||
* (In BSD, both of these are subsumed by namei().)
|
||||
*/
|
||||
|
||||
int
|
||||
vfs_lookparent(char *path, struct vnode **retval,
|
||||
char *buf, size_t buflen)
|
||||
{
|
||||
struct vnode *startvn;
|
||||
int result;
|
||||
int vfs_lookparent(char *path, struct vnode **retval, char *buf,
|
||||
size_t buflen) {
|
||||
struct vnode *startvn;
|
||||
int result;
|
||||
|
||||
vfs_biglock_acquire();
|
||||
vfs_biglock_acquire();
|
||||
|
||||
result = getdevice(path, &path, &startvn);
|
||||
if (result) {
|
||||
vfs_biglock_release();
|
||||
return result;
|
||||
}
|
||||
result = getdevice(path, &path, &startvn);
|
||||
if (result) {
|
||||
vfs_biglock_release();
|
||||
return result;
|
||||
}
|
||||
|
||||
if (strlen(path)==0) {
|
||||
/*
|
||||
* It does not make sense to use just a device name in
|
||||
* a context where "lookparent" is the desired
|
||||
* operation.
|
||||
*/
|
||||
result = EINVAL;
|
||||
}
|
||||
else {
|
||||
result = VOP_LOOKPARENT(startvn, path, retval, buf, buflen);
|
||||
}
|
||||
if (strlen(path) == 0) {
|
||||
/*
|
||||
* It does not make sense to use just a device name in
|
||||
* a context where "lookparent" is the desired
|
||||
* operation.
|
||||
*/
|
||||
result = EINVAL;
|
||||
} else {
|
||||
result = VOP_LOOKPARENT(startvn, path, retval, buf, buflen);
|
||||
}
|
||||
|
||||
VOP_DECREF(startvn);
|
||||
VOP_DECREF(startvn);
|
||||
|
||||
vfs_biglock_release();
|
||||
return result;
|
||||
vfs_biglock_release();
|
||||
return result;
|
||||
}
|
||||
|
||||
int
|
||||
vfs_lookup(char *path, struct vnode **retval)
|
||||
{
|
||||
struct vnode *startvn;
|
||||
int result;
|
||||
int vfs_lookup(char *path, struct vnode **retval) {
|
||||
struct vnode *startvn;
|
||||
int result;
|
||||
|
||||
vfs_biglock_acquire();
|
||||
vfs_biglock_acquire();
|
||||
|
||||
result = getdevice(path, &path, &startvn);
|
||||
if (result) {
|
||||
vfs_biglock_release();
|
||||
return result;
|
||||
}
|
||||
result = getdevice(path, &path, &startvn);
|
||||
if (result) {
|
||||
vfs_biglock_release();
|
||||
return result;
|
||||
}
|
||||
|
||||
if (strlen(path)==0) {
|
||||
*retval = startvn;
|
||||
vfs_biglock_release();
|
||||
return 0;
|
||||
}
|
||||
if (strlen(path) == 0) {
|
||||
*retval = startvn;
|
||||
vfs_biglock_release();
|
||||
return 0;
|
||||
}
|
||||
|
||||
result = VOP_LOOKUP(startvn, path, retval);
|
||||
result = VOP_LOOKUP(startvn, path, retval);
|
||||
|
||||
VOP_DECREF(startvn);
|
||||
vfs_biglock_release();
|
||||
return result;
|
||||
VOP_DECREF(startvn);
|
||||
vfs_biglock_release();
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user