Encapsulated parts of the functionality from sys_mount/unmount() in supplementary
functions that can be used by the "mkbfs" command (and similary ones). Also added a kill_device_vnodes() function which should be called before removing the cache in the file system's "initialize volume" function - again, its use is intended for the "mkbfs" utility only. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6480 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1669,16 +1669,122 @@ error1:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
kill_device_vnodes(dev_t id)
|
||||||
|
{
|
||||||
|
fsystem *fs;
|
||||||
|
nspace *ns;
|
||||||
|
|
||||||
|
LOCK(vnlock);
|
||||||
|
|
||||||
|
ns = nstab[id % nns];
|
||||||
|
fs = ns->fs;
|
||||||
|
|
||||||
|
while (ns->vnodes.head) {
|
||||||
|
int err;
|
||||||
|
|
||||||
|
struct vnode *vn = ns->vnodes.head;
|
||||||
|
UNLOCK(vnlock);
|
||||||
|
err = (*fs->ops.write_vnode)(vn->ns->data, vn->data, FALSE);
|
||||||
|
LOCK(vnlock);
|
||||||
|
if (err)
|
||||||
|
PANIC("ERROR WRITING VNODE!!!\n");
|
||||||
|
vn->busy = FALSE;
|
||||||
|
clear_vnode(vn);
|
||||||
|
move_vnode(vn, FREE_LIST);
|
||||||
|
}
|
||||||
|
|
||||||
|
UNLOCK(vnlock);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
remove_nspace(nspace *ns)
|
||||||
|
{
|
||||||
|
fsystem *fs = ns->fs;
|
||||||
|
vnode *vn;
|
||||||
|
|
||||||
|
ns->shutdown = TRUE;
|
||||||
|
for (vn = ns->vnodes.head; vn; vn = vn->nspace.next)
|
||||||
|
vn->busy = TRUE;
|
||||||
|
|
||||||
|
while (ns->vnodes.head) {
|
||||||
|
int err;
|
||||||
|
|
||||||
|
vn = ns->vnodes.head;
|
||||||
|
UNLOCK(vnlock);
|
||||||
|
err = (*fs->ops.write_vnode)(vn->ns->data, vn->data, FALSE);
|
||||||
|
LOCK(vnlock);
|
||||||
|
if (err)
|
||||||
|
PANIC("ERROR WRITING VNODE!!!\n");
|
||||||
|
vn->busy = FALSE;
|
||||||
|
clear_vnode(vn);
|
||||||
|
move_vnode(vn, FREE_LIST);
|
||||||
|
}
|
||||||
|
|
||||||
|
nstab[ns->nsid % nns] = NULL;
|
||||||
|
|
||||||
|
if (ns->prev)
|
||||||
|
ns->prev->next = ns->next;
|
||||||
|
else
|
||||||
|
nshead = ns->next;
|
||||||
|
if (ns->next)
|
||||||
|
ns->next->prev = ns->prev;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
add_nspace(nspace *ns, fsystem *fs, const char *fileSystem, dev_t dev, ino_t ino)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (fileSystem != NULL)
|
||||||
|
fs = inc_file_system(fileSystem);
|
||||||
|
if (!fs)
|
||||||
|
return ENODEV;
|
||||||
|
|
||||||
|
for (i = 0; i < nns; i++, nxnsid++) {
|
||||||
|
if (!nstab[nxnsid % nns]) {
|
||||||
|
nstab[nxnsid % nns] = ns;
|
||||||
|
ns->nsid = nxnsid;
|
||||||
|
nxnsid++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (i == nns) {
|
||||||
|
dec_file_system(fs);
|
||||||
|
return EMFILE;
|
||||||
|
}
|
||||||
|
|
||||||
|
nstab[ns->nsid % nns] = ns;
|
||||||
|
ns->fs = fs;
|
||||||
|
ns->vnodes.head = ns->vnodes.tail = NULL;
|
||||||
|
ns->data = NULL;
|
||||||
|
ns->root = NULL;
|
||||||
|
ns->mount = NULL;
|
||||||
|
ns->prev = NULL;
|
||||||
|
ns->next = nshead;
|
||||||
|
ns->shutdown = FALSE;
|
||||||
|
ns->dev = dev;
|
||||||
|
ns->ino = ino;
|
||||||
|
|
||||||
|
if (nshead)
|
||||||
|
nshead->prev = ns;
|
||||||
|
nshead = ns;
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* sys_mount
|
* sys_mount
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void *
|
void *
|
||||||
sys_mount(bool kernel, const char *filesystem, int fd, const char *where,
|
sys_mount(bool kernel, const char *filesystem, int fd, const char *where,
|
||||||
const char *device, ulong flags, void *parms, size_t len)
|
const char *device, ulong flags, void *parms, size_t len)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
int i;
|
|
||||||
vnode_id vnid;
|
vnode_id vnid;
|
||||||
vnode *mount;
|
vnode *mount;
|
||||||
fsystem *fs;
|
fsystem *fs;
|
||||||
@@ -1711,7 +1817,7 @@ sys_mount(bool kernel, const char *filesystem, int fd, const char *where,
|
|||||||
goto error2;
|
goto error2;
|
||||||
}
|
}
|
||||||
|
|
||||||
ns = (nspace *) malloc(sizeof(nspace));
|
ns = (nspace *)malloc(sizeof(nspace));
|
||||||
if (!ns) {
|
if (!ns) {
|
||||||
err = ENOMEM;
|
err = ENOMEM;
|
||||||
goto error2;
|
goto error2;
|
||||||
@@ -1736,35 +1842,13 @@ sys_mount(bool kernel, const char *filesystem, int fd, const char *where,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i=0; i<nns; i++, nxnsid++)
|
err = add_nspace(ns, fs, NULL, dev, ino);
|
||||||
if (!nstab[nxnsid % nns]) {
|
|
||||||
nstab[nxnsid % nns] = ns;
|
|
||||||
ns->nsid = nxnsid;
|
|
||||||
nxnsid++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (i == nns) {
|
|
||||||
UNLOCK(vnlock);
|
|
||||||
err = EMFILE;
|
|
||||||
goto error4;
|
|
||||||
}
|
|
||||||
nstab[ns->nsid % nns] = ns;
|
|
||||||
ns->fs = fs;
|
|
||||||
ns->vnodes.head = ns->vnodes.tail = NULL;
|
|
||||||
ns->data = NULL;
|
|
||||||
ns->root = NULL;
|
|
||||||
ns->mount = NULL;
|
|
||||||
ns->prev = NULL;
|
|
||||||
ns->next = nshead;
|
|
||||||
ns->shutdown = FALSE;
|
|
||||||
ns->dev = dev;
|
|
||||||
ns->ino = ino;
|
|
||||||
if (nshead)
|
|
||||||
nshead->prev = ns;
|
|
||||||
nshead = ns;
|
|
||||||
|
|
||||||
UNLOCK(vnlock);
|
UNLOCK(vnlock);
|
||||||
|
|
||||||
|
if (err != B_OK)
|
||||||
|
goto error5;
|
||||||
|
|
||||||
err = (*fs->ops.mount)(ns->nsid, device, flags, parms, len, &data, &vnid);
|
err = (*fs->ops.mount)(ns->nsid, device, flags, parms, len, &data, &vnid);
|
||||||
if (err)
|
if (err)
|
||||||
goto error5;
|
goto error5;
|
||||||
@@ -1780,7 +1864,6 @@ sys_mount(bool kernel, const char *filesystem, int fd, const char *where,
|
|||||||
mount->mounted = ns;
|
mount->mounted = ns;
|
||||||
ns->mount = mount;
|
ns->mount = mount;
|
||||||
|
|
||||||
|
|
||||||
UNLOCK(vnlock);
|
UNLOCK(vnlock);
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
@@ -1790,16 +1873,9 @@ error6:
|
|||||||
(*fs->ops.unmount)(data);
|
(*fs->ops.unmount)(data);
|
||||||
error5:
|
error5:
|
||||||
LOCK(vnlock);
|
LOCK(vnlock);
|
||||||
nstab[ns->nsid % nns] = NULL;
|
remove_nspace(ns);
|
||||||
if (ns->prev)
|
|
||||||
ns->prev->next = ns->next;
|
|
||||||
else
|
|
||||||
nshead = ns->next;
|
|
||||||
if (ns->next)
|
|
||||||
ns->next->prev = ns->prev;
|
|
||||||
UNLOCK(vnlock);
|
UNLOCK(vnlock);
|
||||||
error4:
|
error4:
|
||||||
dec_file_system(fs);
|
|
||||||
error3:
|
error3:
|
||||||
free(ns);
|
free(ns);
|
||||||
error2:
|
error2:
|
||||||
@@ -1860,30 +1936,7 @@ sys_unmount(bool kernel, int fd, const char *where)
|
|||||||
mount = ns->mount;
|
mount = ns->mount;
|
||||||
mount->mounted = NULL;
|
mount->mounted = NULL;
|
||||||
|
|
||||||
ns->shutdown = TRUE;
|
remove_nspace(ns);
|
||||||
for(vn = ns->vnodes.head; vn; vn = vn->nspace.next)
|
|
||||||
vn->busy = TRUE;
|
|
||||||
|
|
||||||
while (ns->vnodes.head) {
|
|
||||||
vn = ns->vnodes.head;
|
|
||||||
UNLOCK(vnlock);
|
|
||||||
err = (*fs->ops.write_vnode)(vn->ns->data, vn->data, FALSE);
|
|
||||||
LOCK(vnlock);
|
|
||||||
if (err)
|
|
||||||
PANIC("ERROR WRITING VNODE!!!\n");
|
|
||||||
vn->busy = FALSE;
|
|
||||||
clear_vnode(vn);
|
|
||||||
move_vnode(vn, FREE_LIST);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ns->prev)
|
|
||||||
ns->prev->next = ns->next;
|
|
||||||
else
|
|
||||||
nshead = ns->next;
|
|
||||||
if (ns->next)
|
|
||||||
ns->next->prev = ns->prev;
|
|
||||||
|
|
||||||
nstab[ns->nsid % nns] = NULL;
|
|
||||||
UNLOCK(vnlock);
|
UNLOCK(vnlock);
|
||||||
|
|
||||||
(*fs->ops.unmount)(ns->data);
|
(*fs->ops.unmount)(ns->data);
|
||||||
|
|||||||
@@ -57,6 +57,14 @@ int sys_open_query(bool kernel, int fd, const char *path, const char *query, ulo
|
|||||||
int sys_close_query(bool kernel, int fd, const char *path, void *cookie);
|
int sys_close_query(bool kernel, int fd, const char *path, void *cookie);
|
||||||
int sys_read_query(bool kernel, int fd, const char *path, void *cookie,struct dirent *dent,size_t bufferSize,long num);
|
int sys_read_query(bool kernel, int fd, const char *path, void *cookie,struct dirent *dent,size_t bufferSize,long num);
|
||||||
|
|
||||||
|
struct nspace;
|
||||||
|
struct fsystem;
|
||||||
|
void kill_device_vnodes(dev_t id);
|
||||||
|
struct nspace *allocate_nspace(void);
|
||||||
|
void remove_nspace(struct nspace *);
|
||||||
|
status_t add_nspace(struct nspace *, struct fsystem *, const char *fileSystem, dev_t, ino_t);
|
||||||
|
// for initialize() hack use only :)
|
||||||
|
|
||||||
int init_vnode_layer(void);
|
int init_vnode_layer(void);
|
||||||
void *install_file_system(vnode_ops *ops, const char *name,
|
void *install_file_system(vnode_ops *ops, const char *name,
|
||||||
bool fixed, image_id aid);
|
bool fixed, image_id aid);
|
||||||
|
|||||||
Reference in New Issue
Block a user