NFS: various checks added if malloc succeeded. (also coding style fix).
This commit is contained in:
@@ -209,22 +209,21 @@ postoffice_func(fs_nspace *ns)
|
|||||||
{
|
{
|
||||||
uint8 *buffer=(uint8 *)malloc(B_UDP_MAX_SIZE);
|
uint8 *buffer=(uint8 *)malloc(B_UDP_MAX_SIZE);
|
||||||
|
|
||||||
while (!ns->quit)
|
while (!ns->quit) {
|
||||||
{
|
|
||||||
struct sockaddr_in from;
|
struct sockaddr_in from;
|
||||||
socklen_t fromLen=sizeof(from);
|
socklen_t fromLen=sizeof(from);
|
||||||
|
|
||||||
ssize_t bytes=recvfrom (ns->s,buffer,B_UDP_MAX_SIZE,0,(struct sockaddr *)&from,&fromLen);
|
ssize_t bytes = recvfrom(ns->s, buffer, B_UDP_MAX_SIZE, 0,
|
||||||
|
(struct sockaddr *)&from, &fromLen);
|
||||||
|
|
||||||
if (bytes>=4)
|
if (bytes >= 4) {
|
||||||
{
|
|
||||||
struct PendingCall *call;
|
struct PendingCall *call;
|
||||||
int32 xid=B_BENDIAN_TO_HOST_INT32(*((int32 *)buffer));
|
int32 xid=B_BENDIAN_TO_HOST_INT32(*((int32 *)buffer));
|
||||||
|
|
||||||
call=RPCPendingCallsFindAndRemovePendingCall(&ns->pendingCalls,xid,&from);
|
call=RPCPendingCallsFindAndRemovePendingCall(&ns->pendingCalls, xid,
|
||||||
|
&from);
|
||||||
|
|
||||||
if (call)
|
if (call) {
|
||||||
{
|
|
||||||
call->buffer=(uint8 *)malloc(bytes);
|
call->buffer=(uint8 *)malloc(bytes);
|
||||||
memcpy(call->buffer, buffer, bytes);
|
memcpy(call->buffer, buffer, bytes);
|
||||||
|
|
||||||
@@ -301,7 +300,8 @@ send_rpc_call(fs_nspace *ns, const struct sockaddr_in *addr, int32 prog,
|
|||||||
while (bytes < 0 && errno == EINTR);
|
while (bytes < 0 && errno == EINTR);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
result = acquire_sem_etc (pending->sem,1,B_TIMEOUT,(retries)?(conf_call_timeout):(2*conf_call_timeout));
|
result = acquire_sem_etc (pending->sem, 1, B_TIMEOUT,
|
||||||
|
(retries) ? (conf_call_timeout) : (2*conf_call_timeout));
|
||||||
}
|
}
|
||||||
while (result == B_INTERRUPTED);
|
while (result == B_INTERRUPTED);
|
||||||
|
|
||||||
@@ -424,17 +424,16 @@ get_remote_address(fs_nspace *ns, int32 prog, int32 vers, int32 prot,
|
|||||||
XDROutPacketAddInt32(&call, prot);
|
XDROutPacketAddInt32(&call, prot);
|
||||||
XDROutPacketAddInt32(&call, 0);
|
XDROutPacketAddInt32(&call, 0);
|
||||||
|
|
||||||
replyBuf=send_rpc_call (ns,addr,PMAP_PROGRAM,PMAP_VERSION,PMAPPROC_GETPORT,&call);
|
replyBuf = send_rpc_call(ns, addr, PMAP_PROGRAM, PMAP_VERSION,
|
||||||
|
PMAPPROC_GETPORT, &call);
|
||||||
|
|
||||||
if (replyBuf)
|
if (replyBuf) {
|
||||||
{
|
|
||||||
struct XDRInPacket reply;
|
struct XDRInPacket reply;
|
||||||
XDRInPacketInit(&reply);
|
XDRInPacketInit(&reply);
|
||||||
|
|
||||||
XDRInPacketSetTo(&reply,replyBuf,0);
|
XDRInPacketSetTo(&reply,replyBuf,0);
|
||||||
|
|
||||||
if (is_successful_reply(&reply))
|
if (is_successful_reply(&reply)) {
|
||||||
{
|
|
||||||
addr->sin_port = htons(XDRInPacketGetInt32(&reply));
|
addr->sin_port = htons(XDRInPacketGetInt32(&reply));
|
||||||
memset(addr->sin_zero, 0, sizeof(addr->sin_zero));
|
memset(addr->sin_zero, 0, sizeof(addr->sin_zero));
|
||||||
|
|
||||||
@@ -450,7 +449,8 @@ get_remote_address(fs_nspace *ns, int32 prog, int32 vers, int32 prot,
|
|||||||
return EHOSTUNREACH;
|
return EHOSTUNREACH;
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t nfs_mount (fs_nspace *ns, const char *path, nfs_fhandle *fhandle)
|
status_t
|
||||||
|
nfs_mount(fs_nspace *ns, const char *path, nfs_fhandle *fhandle)
|
||||||
{
|
{
|
||||||
struct XDROutPacket call;
|
struct XDROutPacket call;
|
||||||
struct XDRInPacket reply;
|
struct XDRInPacket reply;
|
||||||
@@ -462,10 +462,10 @@ status_t nfs_mount (fs_nspace *ns, const char *path, nfs_fhandle *fhandle)
|
|||||||
|
|
||||||
XDROutPacketAddString(&call,path);
|
XDROutPacketAddString(&call,path);
|
||||||
|
|
||||||
replyBuf=send_rpc_call (ns,&ns->mountAddr,MOUNT_PROGRAM,MOUNT_VERSION,MOUNTPROC_MNT,&call);
|
replyBuf = send_rpc_call(ns, &ns->mountAddr, MOUNT_PROGRAM, MOUNT_VERSION,
|
||||||
|
MOUNTPROC_MNT, &call);
|
||||||
|
|
||||||
if (!replyBuf)
|
if (!replyBuf) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return EHOSTUNREACH;
|
return EHOSTUNREACH;
|
||||||
@@ -473,8 +473,7 @@ status_t nfs_mount (fs_nspace *ns, const char *path, nfs_fhandle *fhandle)
|
|||||||
|
|
||||||
XDRInPacketSetTo(&reply, replyBuf, 0);
|
XDRInPacketSetTo(&reply, replyBuf, 0);
|
||||||
|
|
||||||
if (!is_successful_reply(&reply))
|
if (!is_successful_reply(&reply)) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
@@ -482,8 +481,7 @@ status_t nfs_mount (fs_nspace *ns, const char *path, nfs_fhandle *fhandle)
|
|||||||
|
|
||||||
fhstatus = XDRInPacketGetInt32(&reply);
|
fhstatus = XDRInPacketGetInt32(&reply);
|
||||||
|
|
||||||
if (fhstatus!=0)
|
if (fhstatus != 0) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return map_nfs_to_system_error(fhstatus);
|
return map_nfs_to_system_error(fhstatus);
|
||||||
@@ -496,8 +494,10 @@ status_t nfs_mount (fs_nspace *ns, const char *path, nfs_fhandle *fhandle)
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t nfs_lookup (fs_nspace *ns, const nfs_fhandle *dir, const char *filename, nfs_fhandle *fhandle,
|
|
||||||
struct stat *st)
|
status_t
|
||||||
|
nfs_lookup (fs_nspace *ns, const nfs_fhandle *dir, const char *filename,
|
||||||
|
nfs_fhandle *fhandle, struct stat *st)
|
||||||
{
|
{
|
||||||
struct XDROutPacket call;
|
struct XDROutPacket call;
|
||||||
struct XDRInPacket reply;
|
struct XDRInPacket reply;
|
||||||
@@ -510,10 +510,10 @@ status_t nfs_lookup (fs_nspace *ns, const nfs_fhandle *dir, const char *filename
|
|||||||
XDROutPacketAddFixed(&call, dir->opaque, NFS_FHSIZE);
|
XDROutPacketAddFixed(&call, dir->opaque, NFS_FHSIZE);
|
||||||
XDROutPacketAddString(&call, filename);
|
XDROutPacketAddString(&call, filename);
|
||||||
|
|
||||||
replyBuf=send_rpc_call (ns,&ns->nfsAddr,NFS_PROGRAM,NFS_VERSION,NFSPROC_LOOKUP,&call);
|
replyBuf = send_rpc_call(ns, &ns->nfsAddr, NFS_PROGRAM, NFS_VERSION,
|
||||||
|
NFSPROC_LOOKUP, &call);
|
||||||
|
|
||||||
if (!replyBuf)
|
if (!replyBuf) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return EHOSTUNREACH;
|
return EHOSTUNREACH;
|
||||||
@@ -521,8 +521,7 @@ status_t nfs_lookup (fs_nspace *ns, const nfs_fhandle *dir, const char *filename
|
|||||||
|
|
||||||
XDRInPacketSetTo(&reply, replyBuf, 0);
|
XDRInPacketSetTo(&reply, replyBuf, 0);
|
||||||
|
|
||||||
if (!is_successful_reply(&reply))
|
if (!is_successful_reply(&reply)) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
@@ -530,8 +529,7 @@ status_t nfs_lookup (fs_nspace *ns, const nfs_fhandle *dir, const char *filename
|
|||||||
|
|
||||||
status = XDRInPacketGetInt32(&reply);
|
status = XDRInPacketGetInt32(&reply);
|
||||||
|
|
||||||
if (status!=NFS_OK)
|
if (status != NFS_OK) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return map_nfs_to_system_error(status);
|
return map_nfs_to_system_error(status);
|
||||||
@@ -762,11 +760,10 @@ insert_node(fs_nspace *ns, fs_node *node)
|
|||||||
|
|
||||||
current = ns->first;
|
current = ns->first;
|
||||||
|
|
||||||
while ((current)&&(current->vnid!=node->vnid))
|
while (current != NULL && current->vnid != node->vnid)
|
||||||
current = current->next;
|
current = current->next;
|
||||||
|
|
||||||
if (current)
|
if (current) {
|
||||||
{
|
|
||||||
free(node);
|
free(node);
|
||||||
while (release_sem(ns->sem) == B_INTERRUPTED);
|
while (release_sem(ns->sem) == B_INTERRUPTED);
|
||||||
return;
|
return;
|
||||||
@@ -814,21 +811,19 @@ remove_node(fs_nspace *ns, ino_t vnid)
|
|||||||
static status_t
|
static status_t
|
||||||
fs_read_vnode(fs_volume *_volume, ino_t vnid, fs_vnode *_node, int *_type,
|
fs_read_vnode(fs_volume *_volume, ino_t vnid, fs_vnode *_node, int *_type,
|
||||||
uint32 *_flags, bool r)
|
uint32 *_flags, bool r)
|
||||||
|
|
||||||
{
|
{
|
||||||
fs_nspace *ns;
|
fs_nspace *ns;
|
||||||
fs_node *current;
|
fs_node *current;
|
||||||
|
|
||||||
ns = _volume->private_volume;
|
ns = _volume->private_volume;
|
||||||
|
|
||||||
if (!r)
|
if (!r) {
|
||||||
{
|
|
||||||
while (acquire_sem(ns->sem) == B_INTERRUPTED);
|
while (acquire_sem(ns->sem) == B_INTERRUPTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
current = ns->first;
|
current = ns->first;
|
||||||
|
|
||||||
while ((current)&&(current->vnid!=vnid))
|
while (current != NULL && current->vnid != vnid)
|
||||||
current = current->next;
|
current = current->next;
|
||||||
|
|
||||||
if (!current)
|
if (!current)
|
||||||
@@ -840,8 +835,7 @@ fs_read_vnode(fs_volume *_volume, ino_t vnid, fs_vnode *_node, int *_type,
|
|||||||
*_type = current->mode;
|
*_type = current->mode;
|
||||||
*_flags = 0;
|
*_flags = 0;
|
||||||
|
|
||||||
if (!r)
|
if (!r) {
|
||||||
{
|
|
||||||
while (release_sem(ns->sem) == B_INTERRUPTED);
|
while (release_sem(ns->sem) == B_INTERRUPTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -872,18 +866,15 @@ fs_walk(fs_volume *_volume, fs_vnode *_base, const char *file, ino_t *vnid)
|
|||||||
ns = _volume->private_volume;
|
ns = _volume->private_volume;
|
||||||
base = _base->private_node;
|
base = _base->private_node;
|
||||||
|
|
||||||
if (!strcmp(".",file))
|
if (!strcmp(".", file)) {
|
||||||
{
|
|
||||||
*vnid = base->vnid;
|
*vnid = base->vnid;
|
||||||
isLink = false;
|
isLink = false;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
fs_node *newNode = (fs_node *)malloc(sizeof(fs_node));
|
fs_node *newNode = (fs_node *)malloc(sizeof(fs_node));
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
if ((result=nfs_lookup(ns,&base->fhandle,file,&newNode->fhandle,&st))<B_OK)
|
if ((result = nfs_lookup(ns, &base->fhandle, file, &newNode->fhandle,
|
||||||
{
|
&st)) < B_OK) {
|
||||||
free(newNode);
|
free(newNode);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -971,8 +962,7 @@ fs_readdir(fs_volume *_volume, fs_vnode *_node, void *_cookie,
|
|||||||
ns = _volume->private_volume;
|
ns = _volume->private_volume;
|
||||||
node = _node->private_node;
|
node = _node->private_node;
|
||||||
|
|
||||||
do
|
do {
|
||||||
{
|
|
||||||
ino_t vnid;
|
ino_t vnid;
|
||||||
char *filename;
|
char *filename;
|
||||||
uint8 *replyBuf;
|
uint8 *replyBuf;
|
||||||
@@ -987,10 +977,10 @@ fs_readdir(fs_volume *_volume, fs_vnode *_node, void *_cookie,
|
|||||||
XDROutPacketAddFixed(&call, cookie->opaque, NFS_COOKIESIZE);
|
XDROutPacketAddFixed(&call, cookie->opaque, NFS_COOKIESIZE);
|
||||||
XDROutPacketAddInt32(&call, count);
|
XDROutPacketAddInt32(&call, count);
|
||||||
|
|
||||||
replyBuf=send_rpc_call (ns,&ns->nfsAddr,NFS_PROGRAM,NFS_VERSION,NFSPROC_READDIR,&call);
|
replyBuf = send_rpc_call (ns, &ns->nfsAddr, NFS_PROGRAM, NFS_VERSION,
|
||||||
|
NFSPROC_READDIR, &call);
|
||||||
|
|
||||||
if (!replyBuf)
|
if (!replyBuf) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
@@ -998,8 +988,7 @@ fs_readdir(fs_volume *_volume, fs_vnode *_node, void *_cookie,
|
|||||||
|
|
||||||
XDRInPacketSetTo(&reply, replyBuf, 0);
|
XDRInPacketSetTo(&reply, replyBuf, 0);
|
||||||
|
|
||||||
if (!is_successful_reply(&reply))
|
if (!is_successful_reply(&reply)) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
@@ -1007,15 +996,13 @@ fs_readdir(fs_volume *_volume, fs_vnode *_node, void *_cookie,
|
|||||||
|
|
||||||
status = XDRInPacketGetInt32(&reply);
|
status = XDRInPacketGetInt32(&reply);
|
||||||
|
|
||||||
if (status!=NFS_OK)
|
if (status != NFS_OK) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return map_nfs_to_system_error(status);
|
return map_nfs_to_system_error(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (XDRInPacketGetInt32(&reply)==1)
|
while (XDRInPacketGetInt32(&reply) == 1) {
|
||||||
{
|
|
||||||
nfs_cookie newCookie;
|
nfs_cookie newCookie;
|
||||||
|
|
||||||
vnid=XDRInPacketGetInt32(&reply);
|
vnid=XDRInPacketGetInt32(&reply);
|
||||||
@@ -1025,16 +1012,16 @@ fs_readdir(fs_volume *_volume, fs_vnode *_node, void *_cookie,
|
|||||||
|
|
||||||
//if (strcmp(".",filename)&&strcmp("..",filename))
|
//if (strcmp(".",filename)&&strcmp("..",filename))
|
||||||
//if ((ns->rootid != node->vnid) || (strcmp(".",filename)&&strcmp("..",filename)))
|
//if ((ns->rootid != node->vnid) || (strcmp(".",filename)&&strcmp("..",filename)))
|
||||||
if (conf_ls_root_parent || ((ns->rootid != node->vnid) || strcmp("..",filename)))
|
if (conf_ls_root_parent
|
||||||
{
|
|| ((ns->rootid != node->vnid) || strcmp("..", filename))) {
|
||||||
status_t result;
|
status_t result;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
fs_node *newNode = (fs_node *)malloc(sizeof(fs_node));
|
fs_node *newNode = (fs_node *)malloc(sizeof(fs_node));
|
||||||
newNode->vnid = vnid;
|
newNode->vnid = vnid;
|
||||||
|
|
||||||
if ((result=nfs_lookup(ns,&node->fhandle,filename,&newNode->fhandle,&st))<B_OK)
|
if ((result = nfs_lookup(ns, &node->fhandle, filename,
|
||||||
{
|
&newNode->fhandle, &st)) < B_OK) {
|
||||||
free (filename);
|
free (filename);
|
||||||
free(newNode);
|
free(newNode);
|
||||||
XDRInPacketDestroy (&reply);
|
XDRInPacketDestroy (&reply);
|
||||||
@@ -1045,8 +1032,8 @@ fs_readdir(fs_volume *_volume, fs_vnode *_node, void *_cookie,
|
|||||||
newNode->mode = st.st_mode;
|
newNode->mode = st.st_mode;
|
||||||
insert_node(ns,newNode);
|
insert_node(ns,newNode);
|
||||||
|
|
||||||
if (bufsize<2*(sizeof(dev_t)+sizeof(ino_t))+sizeof(unsigned short)+strlen(filename)+1)
|
if (bufsize < 2 * (sizeof(dev_t) + sizeof(ino_t))
|
||||||
{
|
+ sizeof(unsigned short) + strlen(filename) + 1) {
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -1056,7 +1043,8 @@ fs_readdir(fs_volume *_volume, fs_vnode *_node, void *_cookie,
|
|||||||
buf->d_pdev = ns->nsid;
|
buf->d_pdev = ns->nsid;
|
||||||
buf->d_ino = vnid;
|
buf->d_ino = vnid;
|
||||||
buf->d_pino = node->vnid;
|
buf->d_pino = node->vnid;
|
||||||
buf->d_reclen=2*(sizeof(dev_t)+sizeof(ino_t))+sizeof(unsigned short)+strlen(filename)+1;
|
buf->d_reclen = 2 * (sizeof(dev_t) + sizeof(ino_t))
|
||||||
|
+ sizeof(unsigned short) + strlen(filename) + 1;
|
||||||
strcpy (buf->d_name,filename);
|
strcpy (buf->d_name,filename);
|
||||||
// if ((ns->rootid == node->vnid))//XXX:mmu_man:test
|
// if ((ns->rootid == node->vnid))//XXX:mmu_man:test
|
||||||
// dprintf("nfs: dirent %d {d:%ld pd:%ld i:%lld pi:%lld '%s'}\n", *num, buf->d_dev, buf->d_pdev, buf->d_ino, buf->d_pino, buf->d_name);
|
// dprintf("nfs: dirent %d {d:%ld pd:%ld i:%lld pi:%lld '%s'}\n", *num, buf->d_dev, buf->d_pdev, buf->d_ino, buf->d_pino, buf->d_name);
|
||||||
@@ -1067,15 +1055,13 @@ fs_readdir(fs_volume *_volume, fs_vnode *_node, void *_cookie,
|
|||||||
memcpy(cookie->opaque, newCookie.opaque, NFS_COOKIESIZE);
|
memcpy(cookie->opaque, newCookie.opaque, NFS_COOKIESIZE);
|
||||||
|
|
||||||
(*num)++;
|
(*num)++;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
memcpy(cookie->opaque, newCookie.opaque, NFS_COOKIESIZE);
|
memcpy(cookie->opaque, newCookie.opaque, NFS_COOKIESIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
free (filename);
|
free (filename);
|
||||||
|
|
||||||
if ((*num)==max)
|
if ((*num) == max) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -1261,21 +1247,18 @@ fs_mount(fs_volume *_vol, const char *devname, uint32 flags, const char *_parms,
|
|||||||
ns->mountAddr.sin_addr.s_addr = htonl(ns->params.serverIP);
|
ns->mountAddr.sin_addr.s_addr = htonl(ns->params.serverIP);
|
||||||
memset(ns->mountAddr.sin_zero, 0, sizeof(ns->mountAddr.sin_zero));
|
memset(ns->mountAddr.sin_zero, 0, sizeof(ns->mountAddr.sin_zero));
|
||||||
|
|
||||||
if ((result = create_socket(ns)) < B_OK)
|
if ((result = create_socket(ns)) < B_OK) {
|
||||||
{
|
|
||||||
dprintf( "nfs: could not create socket (%d)\n", (int)result );
|
dprintf( "nfs: could not create socket (%d)\n", (int)result );
|
||||||
goto err_socket;
|
goto err_socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((result = init_postoffice(ns)) < B_OK)
|
if ((result = init_postoffice(ns)) < B_OK) {
|
||||||
{
|
|
||||||
dprintf( "nfs: could not init_postoffice() (%d)\n", (int)result );
|
dprintf( "nfs: could not init_postoffice() (%d)\n", (int)result );
|
||||||
goto err_postoffice;
|
goto err_postoffice;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((result = get_remote_address(ns, MOUNT_PROGRAM, MOUNT_VERSION,
|
if ((result = get_remote_address(ns, MOUNT_PROGRAM, MOUNT_VERSION,
|
||||||
PMAP_IPPROTO_UDP, &ns->mountAddr)) < B_OK)
|
PMAP_IPPROTO_UDP, &ns->mountAddr)) < B_OK) {
|
||||||
{
|
|
||||||
dprintf( "could not get_remote_address() (%d)\n", (int)result );
|
dprintf( "could not get_remote_address() (%d)\n", (int)result );
|
||||||
goto err_sem;
|
goto err_sem;
|
||||||
}
|
}
|
||||||
@@ -1619,10 +1602,10 @@ fs_write(fs_volume *_volume, fs_vnode *_node, void *_cookie, off_t pos,
|
|||||||
XDROutPacketAddInt32(&call, 0);
|
XDROutPacketAddInt32(&call, 0);
|
||||||
XDROutPacketAddDynamic(&call, (const char *)buf + bytesWritten, count);
|
XDROutPacketAddDynamic(&call, (const char *)buf + bytesWritten, count);
|
||||||
|
|
||||||
replyBuf=send_rpc_call (ns,&ns->nfsAddr,NFS_PROGRAM,NFS_VERSION,NFSPROC_WRITE,&call);
|
replyBuf = send_rpc_call(ns, &ns->nfsAddr, NFS_PROGRAM, NFS_VERSION,
|
||||||
|
NFSPROC_WRITE, &call);
|
||||||
|
|
||||||
if (!replyBuf)
|
if (!replyBuf) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
@@ -1630,8 +1613,7 @@ fs_write(fs_volume *_volume, fs_vnode *_node, void *_cookie, off_t pos,
|
|||||||
|
|
||||||
XDRInPacketSetTo(&reply, replyBuf, 0);
|
XDRInPacketSetTo(&reply, replyBuf, 0);
|
||||||
|
|
||||||
if (!is_successful_reply(&reply))
|
if (!is_successful_reply(&reply)) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
@@ -1639,8 +1621,7 @@ fs_write(fs_volume *_volume, fs_vnode *_node, void *_cookie, off_t pos,
|
|||||||
|
|
||||||
status = XDRInPacketGetInt32(&reply);
|
status = XDRInPacketGetInt32(&reply);
|
||||||
|
|
||||||
if (status!=NFS_OK)
|
if (status != NFS_OK) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return map_nfs_to_system_error(status);
|
return map_nfs_to_system_error(status);
|
||||||
@@ -1659,6 +1640,7 @@ fs_write(fs_volume *_volume, fs_vnode *_node, void *_cookie, off_t pos,
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
fs_wstat(fs_volume *_volume, fs_vnode *_node, const struct stat *st, uint32 mask)
|
fs_wstat(fs_volume *_volume, fs_vnode *_node, const struct stat *st, uint32 mask)
|
||||||
{
|
{
|
||||||
@@ -1687,10 +1669,10 @@ fs_wstat(fs_volume *_volume, fs_vnode *_node, const struct stat *st, uint32 mask
|
|||||||
XDROutPacketAddInt32(&call, (mask & WSTAT_MTIME) ? st->st_mtime : -1);
|
XDROutPacketAddInt32(&call, (mask & WSTAT_MTIME) ? st->st_mtime : -1);
|
||||||
XDROutPacketAddInt32(&call, (mask & WSTAT_MTIME) ? 0 : -1);
|
XDROutPacketAddInt32(&call, (mask & WSTAT_MTIME) ? 0 : -1);
|
||||||
|
|
||||||
replyBuf=send_rpc_call (ns,&ns->nfsAddr,NFS_PROGRAM,NFS_VERSION,NFSPROC_SETATTR,&call);
|
replyBuf = send_rpc_call(ns, &ns->nfsAddr, NFS_PROGRAM, NFS_VERSION,
|
||||||
|
NFSPROC_SETATTR, &call);
|
||||||
|
|
||||||
if (!replyBuf)
|
if (!replyBuf) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return EHOSTUNREACH;
|
return EHOSTUNREACH;
|
||||||
@@ -1698,8 +1680,7 @@ fs_wstat(fs_volume *_volume, fs_vnode *_node, const struct stat *st, uint32 mask
|
|||||||
|
|
||||||
XDRInPacketSetTo(&reply, replyBuf, 0);
|
XDRInPacketSetTo(&reply, replyBuf, 0);
|
||||||
|
|
||||||
if (!is_successful_reply(&reply))
|
if (!is_successful_reply(&reply)) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
@@ -1726,7 +1707,8 @@ fs_wfsstat(fs_volume *_volume, const struct fs_info *info, uint32 mask)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
fs_create(fs_volume *_volume, fs_vnode *_dir, const char *name, int omode, int perms, void **_cookie, ino_t *vnid)
|
fs_create(fs_volume *_volume, fs_vnode *_dir, const char *name, int omode,
|
||||||
|
int perms, void **_cookie, ino_t *vnid)
|
||||||
{
|
{
|
||||||
nfs_fhandle fhandle;
|
nfs_fhandle fhandle;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
@@ -1743,10 +1725,12 @@ fs_create(fs_volume *_volume, fs_vnode *_dir, const char *name, int omode, int p
|
|||||||
|
|
||||||
result = nfs_lookup(ns,&dir->fhandle,name,&fhandle,&st);
|
result = nfs_lookup(ns,&dir->fhandle,name,&fhandle,&st);
|
||||||
|
|
||||||
if (result==B_OK)
|
if (result == B_OK) {
|
||||||
{
|
|
||||||
void *dummy;
|
void *dummy;
|
||||||
fs_node *newNode = (fs_node *)malloc(sizeof(fs_node));
|
fs_node *newNode = (fs_node *)malloc(sizeof(fs_node));
|
||||||
|
if (newNode == NULL)
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
newNode->fhandle = fhandle;
|
newNode->fhandle = fhandle;
|
||||||
newNode->vnid = st.st_ino;
|
newNode->vnid = st.st_ino;
|
||||||
newNode->mode = st.st_mode;
|
newNode->mode = st.st_mode;
|
||||||
@@ -1770,16 +1754,17 @@ fs_create(fs_volume *_volume, fs_vnode *_dir, const char *name, int omode, int p
|
|||||||
}
|
}
|
||||||
|
|
||||||
*cookie=(fs_file_cookie *)malloc(sizeof(fs_file_cookie));
|
*cookie=(fs_file_cookie *)malloc(sizeof(fs_file_cookie));
|
||||||
|
if (*cookie == NULL)
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
(*cookie)->omode=omode;
|
(*cookie)->omode=omode;
|
||||||
(*cookie)->original_size=st.st_size;
|
(*cookie)->original_size=st.st_size;
|
||||||
(*cookie)->st=st;
|
(*cookie)->st=st;
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
} else if (result != ENOENT) {
|
||||||
else if (result!=ENOENT)
|
|
||||||
return result;
|
return result;
|
||||||
else
|
} else {
|
||||||
{
|
|
||||||
struct XDROutPacket call;
|
struct XDROutPacket call;
|
||||||
struct XDRInPacket reply;
|
struct XDRInPacket reply;
|
||||||
|
|
||||||
@@ -1805,10 +1790,10 @@ fs_create(fs_volume *_volume, fs_vnode *_dir, const char *name, int omode, int p
|
|||||||
XDROutPacketAddInt32(&call, time(NULL));
|
XDROutPacketAddInt32(&call, time(NULL));
|
||||||
XDROutPacketAddInt32(&call, 0);
|
XDROutPacketAddInt32(&call, 0);
|
||||||
|
|
||||||
replyBuf=send_rpc_call (ns,&ns->nfsAddr,NFS_PROGRAM,NFS_VERSION,NFSPROC_CREATE,&call);
|
replyBuf = send_rpc_call(ns, &ns->nfsAddr, NFS_PROGRAM, NFS_VERSION,
|
||||||
|
NFSPROC_CREATE, &call);
|
||||||
|
|
||||||
if (!replyBuf)
|
if (!replyBuf) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
@@ -1816,8 +1801,7 @@ fs_create(fs_volume *_volume, fs_vnode *_dir, const char *name, int omode, int p
|
|||||||
|
|
||||||
XDRInPacketSetTo(&reply, replyBuf, 0);
|
XDRInPacketSetTo(&reply, replyBuf, 0);
|
||||||
|
|
||||||
if (!is_successful_reply(&reply))
|
if (!is_successful_reply(&reply)) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
@@ -1825,8 +1809,7 @@ fs_create(fs_volume *_volume, fs_vnode *_dir, const char *name, int omode, int p
|
|||||||
|
|
||||||
status = XDRInPacketGetInt32(&reply);
|
status = XDRInPacketGetInt32(&reply);
|
||||||
|
|
||||||
if (status!=NFS_OK)
|
if (status != NFS_OK) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return map_nfs_to_system_error(status);
|
return map_nfs_to_system_error(status);
|
||||||
@@ -1837,6 +1820,11 @@ fs_create(fs_volume *_volume, fs_vnode *_dir, const char *name, int omode, int p
|
|||||||
get_nfs_attr(&reply,&st);
|
get_nfs_attr(&reply,&st);
|
||||||
|
|
||||||
newNode = (fs_node *)malloc(sizeof(fs_node));
|
newNode = (fs_node *)malloc(sizeof(fs_node));
|
||||||
|
if (newNode == NULL) {
|
||||||
|
XDRInPacketDestroy(&reply);
|
||||||
|
XDROutPacketDestroy(&call);
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
}
|
||||||
newNode->fhandle = fhandle;
|
newNode->fhandle = fhandle;
|
||||||
newNode->vnid = st.st_ino;
|
newNode->vnid = st.st_ino;
|
||||||
newNode->mode = st.st_mode;
|
newNode->mode = st.st_mode;
|
||||||
@@ -1845,14 +1833,18 @@ fs_create(fs_volume *_volume, fs_vnode *_dir, const char *name, int omode, int p
|
|||||||
|
|
||||||
*vnid = st.st_ino;
|
*vnid = st.st_ino;
|
||||||
*cookie = (fs_file_cookie *)malloc(sizeof(fs_file_cookie));
|
*cookie = (fs_file_cookie *)malloc(sizeof(fs_file_cookie));
|
||||||
|
if (*cookie == NULL) {
|
||||||
|
XDRInPacketDestroy(&reply);
|
||||||
|
XDROutPacketDestroy(&call);
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
}
|
||||||
(*cookie)->omode = omode;
|
(*cookie)->omode = omode;
|
||||||
(*cookie)->original_size = st.st_size;
|
(*cookie)->original_size = st.st_size;
|
||||||
(*cookie)->st = st;
|
(*cookie)->st = st;
|
||||||
|
|
||||||
result = new_vnode(_volume, *vnid, newNode, &sNFSVnodeOps);
|
result = new_vnode(_volume, *vnid, newNode, &sNFSVnodeOps);
|
||||||
|
|
||||||
if (result<B_OK)
|
if (result < B_OK) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return result;
|
return result;
|
||||||
@@ -1864,6 +1856,7 @@ fs_create(fs_volume *_volume, fs_vnode *_dir, const char *name, int omode, int p
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
fs_unlink(fs_volume *_volume, fs_vnode *_dir, const char *name)
|
fs_unlink(fs_volume *_volume, fs_vnode *_dir, const char *name)
|
||||||
{
|
{
|
||||||
@@ -1888,43 +1881,43 @@ fs_unlink(fs_volume *_volume, fs_vnode *_dir, const char *name)
|
|||||||
XDROutPacketInit(&call);
|
XDROutPacketInit(&call);
|
||||||
XDRInPacketInit(&reply);
|
XDRInPacketInit(&reply);
|
||||||
|
|
||||||
if ((result=nfs_lookup(ns,&dir->fhandle,name,&fhandle,&st))<B_OK)
|
if ((result = nfs_lookup(ns, &dir->fhandle, name, &fhandle, &st)) < B_OK) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
newNode = (fs_node *)malloc(sizeof(fs_node));
|
newNode = (fs_node *)malloc(sizeof(fs_node));
|
||||||
|
if (newNode == NULL) {
|
||||||
|
XDRInPacketDestroy(&reply);
|
||||||
|
XDROutPacketDestroy(&call);
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
}
|
||||||
newNode->fhandle = fhandle;
|
newNode->fhandle = fhandle;
|
||||||
newNode->vnid = st.st_ino;
|
newNode->vnid = st.st_ino;
|
||||||
newNode->mode = st.st_mode;
|
newNode->mode = st.st_mode;
|
||||||
|
|
||||||
insert_node(ns, newNode);
|
insert_node(ns, newNode);
|
||||||
|
|
||||||
if ((result=get_vnode(_volume,st.st_ino,(void **)&dummy))<B_OK)
|
if ((result = get_vnode(_volume, st.st_ino, (void **)&dummy)) < B_OK) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!S_ISREG(st.st_mode)&&!S_ISLNK(st.st_mode))
|
if (!S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode)) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return EISDIR;
|
return EISDIR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((result=remove_vnode(_volume,st.st_ino))<B_OK)
|
if ((result=remove_vnode(_volume,st.st_ino)) < B_OK) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((result=put_vnode(_volume,st.st_ino))<B_OK)
|
if ((result=put_vnode(_volume, st.st_ino)) < B_OK) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return result;
|
return result;
|
||||||
@@ -1935,8 +1928,7 @@ fs_unlink(fs_volume *_volume, fs_vnode *_dir, const char *name)
|
|||||||
|
|
||||||
replyBuf=send_rpc_call (ns,&ns->nfsAddr,NFS_PROGRAM,NFS_VERSION,NFSPROC_REMOVE,&call);
|
replyBuf=send_rpc_call (ns,&ns->nfsAddr,NFS_PROGRAM,NFS_VERSION,NFSPROC_REMOVE,&call);
|
||||||
|
|
||||||
if (!replyBuf)
|
if (!replyBuf) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return EHOSTUNREACH;
|
return EHOSTUNREACH;
|
||||||
@@ -1944,8 +1936,7 @@ fs_unlink(fs_volume *_volume, fs_vnode *_dir, const char *name)
|
|||||||
|
|
||||||
XDRInPacketSetTo(&reply, replyBuf, 0);
|
XDRInPacketSetTo(&reply, replyBuf, 0);
|
||||||
|
|
||||||
if (!is_successful_reply(&reply))
|
if (!is_successful_reply(&reply)) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
@@ -1953,8 +1944,7 @@ fs_unlink(fs_volume *_volume, fs_vnode *_dir, const char *name)
|
|||||||
|
|
||||||
status = XDRInPacketGetInt32(&reply);
|
status = XDRInPacketGetInt32(&reply);
|
||||||
|
|
||||||
if (status!=NFS_OK)
|
if (status != NFS_OK) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return map_nfs_to_system_error(status);
|
return map_nfs_to_system_error(status);
|
||||||
@@ -1966,6 +1956,7 @@ fs_unlink(fs_volume *_volume, fs_vnode *_dir, const char *name)
|
|||||||
return notify_entry_removed(_volume->id, dir->vnid, name, st.st_ino);
|
return notify_entry_removed(_volume->id, dir->vnid, name, st.st_ino);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
fs_remove_vnode(fs_volume *_volume, fs_vnode *_node, bool r)
|
fs_remove_vnode(fs_volume *_volume, fs_vnode *_node, bool r)
|
||||||
{
|
{
|
||||||
@@ -1979,6 +1970,7 @@ fs_remove_vnode(fs_volume *_volume, fs_vnode *_node, bool r)
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
fs_mkdir(fs_volume *_volume, fs_vnode *_dir, const char *name, int perms)
|
fs_mkdir(fs_volume *_volume, fs_vnode *_dir, const char *name, int perms)
|
||||||
{
|
{
|
||||||
@@ -2004,8 +1996,7 @@ fs_mkdir(fs_volume *_volume, fs_vnode *_dir, const char *name, int perms)
|
|||||||
|
|
||||||
result = nfs_lookup(ns, &dir->fhandle, name, &fhandle, &st);
|
result = nfs_lookup(ns, &dir->fhandle, name, &fhandle, &st);
|
||||||
|
|
||||||
if (result==B_OK)
|
if (result == B_OK) {
|
||||||
{
|
|
||||||
//void *dummy;
|
//void *dummy;
|
||||||
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
@@ -2014,9 +2005,7 @@ fs_mkdir(fs_volume *_volume, fs_vnode *_dir, const char *name, int perms)
|
|||||||
//if ((result=get_vnode(_volume,st.st_ino,&dummy))<B_OK)
|
//if ((result=get_vnode(_volume,st.st_ino,&dummy))<B_OK)
|
||||||
// return result;
|
// return result;
|
||||||
return EEXIST;
|
return EEXIST;
|
||||||
}
|
} else if (result != ENOENT) {
|
||||||
else if (result!=ENOENT)
|
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return result;
|
return result;
|
||||||
@@ -2033,10 +2022,10 @@ fs_mkdir(fs_volume *_volume, fs_vnode *_dir, const char *name, int perms)
|
|||||||
XDROutPacketAddInt32(&call, time(NULL));
|
XDROutPacketAddInt32(&call, time(NULL));
|
||||||
XDROutPacketAddInt32(&call, 0);
|
XDROutPacketAddInt32(&call, 0);
|
||||||
|
|
||||||
replyBuf=send_rpc_call (ns,&ns->nfsAddr,NFS_PROGRAM,NFS_VERSION,NFSPROC_MKDIR,&call);
|
replyBuf = send_rpc_call(ns, &ns->nfsAddr, NFS_PROGRAM, NFS_VERSION,
|
||||||
|
NFSPROC_MKDIR, &call);
|
||||||
|
|
||||||
if (!replyBuf)
|
if (!replyBuf) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
@@ -2044,8 +2033,7 @@ fs_mkdir(fs_volume *_volume, fs_vnode *_dir, const char *name, int perms)
|
|||||||
|
|
||||||
XDRInPacketSetTo(&reply, replyBuf, 0);
|
XDRInPacketSetTo(&reply, replyBuf, 0);
|
||||||
|
|
||||||
if (!is_successful_reply(&reply))
|
if (!is_successful_reply(&reply)) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
@@ -2053,8 +2041,7 @@ fs_mkdir(fs_volume *_volume, fs_vnode *_dir, const char *name, int perms)
|
|||||||
|
|
||||||
status = XDRInPacketGetInt32(&reply);
|
status = XDRInPacketGetInt32(&reply);
|
||||||
|
|
||||||
if (status!=NFS_OK)
|
if (status != NFS_OK) {
|
||||||
{
|
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return map_nfs_to_system_error(status);
|
return map_nfs_to_system_error(status);
|
||||||
}
|
}
|
||||||
@@ -2064,6 +2051,11 @@ fs_mkdir(fs_volume *_volume, fs_vnode *_dir, const char *name, int perms)
|
|||||||
get_nfs_attr(&reply, &st);
|
get_nfs_attr(&reply, &st);
|
||||||
|
|
||||||
newNode=(fs_node *)malloc(sizeof(fs_node));
|
newNode=(fs_node *)malloc(sizeof(fs_node));
|
||||||
|
if (newNode == NULL) {
|
||||||
|
XDRInPacketDestroy(&reply);
|
||||||
|
XDROutPacketDestroy(&call);
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
}
|
||||||
newNode->fhandle = fhandle;
|
newNode->fhandle = fhandle;
|
||||||
newNode->vnid = st.st_ino;
|
newNode->vnid = st.st_ino;
|
||||||
newNode->mode = st.st_mode;
|
newNode->mode = st.st_mode;
|
||||||
@@ -2098,23 +2090,22 @@ fs_rename(fs_volume *_volume, fs_vnode *_olddir, const char *oldname,
|
|||||||
XDROutPacketInit(&call);
|
XDROutPacketInit(&call);
|
||||||
XDRInPacketInit(&reply);
|
XDRInPacketInit(&reply);
|
||||||
|
|
||||||
if ((result=nfs_lookup(ns,&newdir->fhandle,newname,&fhandle,&st))==B_OK)
|
if ((result = nfs_lookup(ns, &newdir->fhandle, newname, &fhandle, &st))
|
||||||
{
|
== B_OK) {
|
||||||
if (S_ISREG(st.st_mode))
|
if (S_ISREG(st.st_mode))
|
||||||
result = fs_unlink (_volume,_newdir,newname);
|
result = fs_unlink (_volume,_newdir,newname);
|
||||||
else
|
else
|
||||||
result = fs_rmdir (_volume,_newdir,newname);
|
result = fs_rmdir (_volume,_newdir,newname);
|
||||||
|
|
||||||
if (result<B_OK)
|
if (result < B_OK) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy (&reply);
|
XDRInPacketDestroy (&reply);
|
||||||
XDROutPacketDestroy (&call);
|
XDROutPacketDestroy (&call);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((result=nfs_lookup(ns,&olddir->fhandle,oldname,&fhandle,&st))<B_OK)
|
if ((result = nfs_lookup(ns, &olddir->fhandle, oldname, &fhandle, &st))
|
||||||
{
|
< B_OK) {
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return result;
|
return result;
|
||||||
@@ -2125,10 +2116,10 @@ fs_rename(fs_volume *_volume, fs_vnode *_olddir, const char *oldname,
|
|||||||
XDROutPacketAddFixed(&call, newdir->fhandle.opaque, NFS_FHSIZE);
|
XDROutPacketAddFixed(&call, newdir->fhandle.opaque, NFS_FHSIZE);
|
||||||
XDROutPacketAddString(&call, newname);
|
XDROutPacketAddString(&call, newname);
|
||||||
|
|
||||||
replyBuf=send_rpc_call (ns,&ns->nfsAddr,NFS_PROGRAM,NFS_VERSION,NFSPROC_RENAME,&call);
|
replyBuf = send_rpc_call(ns, &ns->nfsAddr, NFS_PROGRAM, NFS_VERSION,
|
||||||
|
NFSPROC_RENAME, &call);
|
||||||
|
|
||||||
if (!replyBuf)
|
if (!replyBuf) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return EHOSTUNREACH;
|
return EHOSTUNREACH;
|
||||||
@@ -2136,8 +2127,7 @@ fs_rename(fs_volume *_volume, fs_vnode *_olddir, const char *oldname,
|
|||||||
|
|
||||||
XDRInPacketSetTo(&reply, replyBuf, 0);
|
XDRInPacketSetTo(&reply, replyBuf, 0);
|
||||||
|
|
||||||
if (!is_successful_reply(&reply))
|
if (!is_successful_reply(&reply)) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
@@ -2145,8 +2135,7 @@ fs_rename(fs_volume *_volume, fs_vnode *_olddir, const char *oldname,
|
|||||||
|
|
||||||
status = XDRInPacketGetInt32(&reply);
|
status = XDRInPacketGetInt32(&reply);
|
||||||
|
|
||||||
if (status!=NFS_OK)
|
if (status != NFS_OK) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return map_nfs_to_system_error(status);
|
return map_nfs_to_system_error(status);
|
||||||
@@ -2155,7 +2144,8 @@ fs_rename(fs_volume *_volume, fs_vnode *_olddir, const char *oldname,
|
|||||||
XDRInPacketDestroy (&reply);
|
XDRInPacketDestroy (&reply);
|
||||||
XDROutPacketDestroy (&call);
|
XDROutPacketDestroy (&call);
|
||||||
|
|
||||||
return notify_entry_moved (_volume->id, olddir->vnid, oldname, newdir->vnid, newname, st.st_ino);
|
return notify_entry_moved(_volume->id, olddir->vnid, oldname, newdir->vnid,
|
||||||
|
newname, st.st_ino);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -2182,43 +2172,43 @@ fs_rmdir(fs_volume *_volume, fs_vnode *_dir, const char *name)
|
|||||||
XDROutPacketInit(&call);
|
XDROutPacketInit(&call);
|
||||||
XDRInPacketInit(&reply);
|
XDRInPacketInit(&reply);
|
||||||
|
|
||||||
if ((result=nfs_lookup(ns,&dir->fhandle,name,&fhandle,&st))<B_OK)
|
if ((result = nfs_lookup(ns, &dir->fhandle, name, &fhandle, &st)) < B_OK) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
newNode = (fs_node *)malloc(sizeof(fs_node));
|
newNode = (fs_node *)malloc(sizeof(fs_node));
|
||||||
|
if (newNode == NULL) {
|
||||||
|
XDRInPacketDestroy(&reply);
|
||||||
|
XDROutPacketDestroy(&call);
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
}
|
||||||
newNode->fhandle = fhandle;
|
newNode->fhandle = fhandle;
|
||||||
newNode->vnid = st.st_ino;
|
newNode->vnid = st.st_ino;
|
||||||
newNode->mode = st.st_mode;
|
newNode->mode = st.st_mode;
|
||||||
|
|
||||||
insert_node(ns, newNode);
|
insert_node(ns, newNode);
|
||||||
|
|
||||||
if ((result=get_vnode(_volume,st.st_ino,(void **)&dummy))<B_OK)
|
if ((result = get_vnode(_volume, st.st_ino, (void **)&dummy)) < B_OK) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!S_ISDIR(st.st_mode))
|
if (!S_ISDIR(st.st_mode)) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return ENOTDIR;
|
return ENOTDIR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((result=remove_vnode(_volume,st.st_ino))<B_OK)
|
if ((result = remove_vnode(_volume, st.st_ino)) < B_OK) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((result=put_vnode(_volume,st.st_ino))<B_OK)
|
if ((result = put_vnode(_volume, st.st_ino)) < B_OK) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return result;
|
return result;
|
||||||
@@ -2227,10 +2217,10 @@ fs_rmdir(fs_volume *_volume, fs_vnode *_dir, const char *name)
|
|||||||
XDROutPacketAddFixed (&call, dir->fhandle.opaque, NFS_FHSIZE);
|
XDROutPacketAddFixed (&call, dir->fhandle.opaque, NFS_FHSIZE);
|
||||||
XDROutPacketAddString(&call, name);
|
XDROutPacketAddString(&call, name);
|
||||||
|
|
||||||
replyBuf=send_rpc_call (ns,&ns->nfsAddr,NFS_PROGRAM,NFS_VERSION,NFSPROC_RMDIR,&call);
|
replyBuf = send_rpc_call(ns, &ns->nfsAddr, NFS_PROGRAM, NFS_VERSION,
|
||||||
|
NFSPROC_RMDIR, &call);
|
||||||
|
|
||||||
if (!replyBuf)
|
if (!replyBuf) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return EHOSTUNREACH;
|
return EHOSTUNREACH;
|
||||||
@@ -2238,8 +2228,7 @@ fs_rmdir(fs_volume *_volume, fs_vnode *_dir, const char *name)
|
|||||||
|
|
||||||
XDRInPacketSetTo (&reply,replyBuf,0);
|
XDRInPacketSetTo (&reply,replyBuf,0);
|
||||||
|
|
||||||
if (!is_successful_reply(&reply))
|
if (!is_successful_reply(&reply)) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
@@ -2247,8 +2236,7 @@ fs_rmdir(fs_volume *_volume, fs_vnode *_dir, const char *name)
|
|||||||
|
|
||||||
status = XDRInPacketGetInt32(&reply);
|
status = XDRInPacketGetInt32(&reply);
|
||||||
|
|
||||||
if (status!=NFS_OK)
|
if (status != NFS_OK) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return map_nfs_to_system_error(status);
|
return map_nfs_to_system_error(status);
|
||||||
@@ -2259,6 +2247,7 @@ fs_rmdir(fs_volume *_volume, fs_vnode *_dir, const char *name)
|
|||||||
return notify_entry_removed(_volume->id, dir->vnid, name, st.st_ino);
|
return notify_entry_removed(_volume->id, dir->vnid, name, st.st_ino);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
fs_readlink(fs_volume *_volume, fs_vnode *_node, char *buf, size_t *bufsize)
|
fs_readlink(fs_volume *_volume, fs_vnode *_node, char *buf, size_t *bufsize)
|
||||||
{
|
{
|
||||||
@@ -2279,10 +2268,10 @@ fs_readlink(fs_volume *_volume, fs_vnode *_node, char *buf, size_t *bufsize)
|
|||||||
|
|
||||||
XDROutPacketAddFixed(&call, node->fhandle.opaque, NFS_FHSIZE);
|
XDROutPacketAddFixed(&call, node->fhandle.opaque, NFS_FHSIZE);
|
||||||
|
|
||||||
replyBuf=send_rpc_call (ns,&ns->nfsAddr,NFS_PROGRAM,NFS_VERSION,NFSPROC_READLINK,&call);
|
replyBuf = send_rpc_call(ns, &ns->nfsAddr, NFS_PROGRAM, NFS_VERSION,
|
||||||
|
NFSPROC_READLINK, &call);
|
||||||
|
|
||||||
if (!replyBuf)
|
if (!replyBuf) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return EHOSTUNREACH;
|
return EHOSTUNREACH;
|
||||||
@@ -2290,8 +2279,7 @@ fs_readlink(fs_volume *_volume, fs_vnode *_node, char *buf, size_t *bufsize)
|
|||||||
|
|
||||||
XDRInPacketSetTo (&reply, replyBuf, 0);
|
XDRInPacketSetTo (&reply, replyBuf, 0);
|
||||||
|
|
||||||
if (!is_successful_reply(&reply))
|
if (!is_successful_reply(&reply)) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
@@ -2299,8 +2287,7 @@ fs_readlink(fs_volume *_volume, fs_vnode *_node, char *buf, size_t *bufsize)
|
|||||||
|
|
||||||
status = XDRInPacketGetInt32(&reply);
|
status = XDRInPacketGetInt32(&reply);
|
||||||
|
|
||||||
if (status!=NFS_OK)
|
if (status != NFS_OK) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy (&call);
|
XDROutPacketDestroy (&call);
|
||||||
return map_nfs_to_system_error(status);
|
return map_nfs_to_system_error(status);
|
||||||
@@ -2318,7 +2305,8 @@ fs_readlink(fs_volume *_volume, fs_vnode *_node, char *buf, size_t *bufsize)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
fs_symlink(fs_volume *_volume, fs_vnode *_dir, const char *name, const char *path, int mode)
|
fs_symlink(fs_volume *_volume, fs_vnode *_dir, const char *name,
|
||||||
|
const char *path, int mode)
|
||||||
{
|
{
|
||||||
fs_nspace *ns;
|
fs_nspace *ns;
|
||||||
fs_node *dir;
|
fs_node *dir;
|
||||||
@@ -2339,8 +2327,7 @@ fs_symlink(fs_volume *_volume, fs_vnode *_dir, const char *name, const char *pat
|
|||||||
|
|
||||||
result = nfs_lookup(ns, &dir->fhandle, name, &fhandle, &st);
|
result = nfs_lookup(ns, &dir->fhandle, name, &fhandle, &st);
|
||||||
|
|
||||||
if (result==B_OK)
|
if (result == B_OK) {
|
||||||
{
|
|
||||||
void *dummy;
|
void *dummy;
|
||||||
if ((result = get_vnode(_volume, st.st_ino, &dummy)) < B_OK)
|
if ((result = get_vnode(_volume, st.st_ino, &dummy)) < B_OK)
|
||||||
return result;
|
return result;
|
||||||
@@ -2348,9 +2335,7 @@ fs_symlink(fs_volume *_volume, fs_vnode *_dir, const char *name, const char *pat
|
|||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return EEXIST;
|
return EEXIST;
|
||||||
}
|
} else if (result != ENOENT) {
|
||||||
else if (result!=ENOENT)
|
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return result;
|
return result;
|
||||||
@@ -2368,10 +2353,10 @@ fs_symlink(fs_volume *_volume, fs_vnode *_dir, const char *name, const char *pat
|
|||||||
XDROutPacketAddInt32(&call, time(NULL));
|
XDROutPacketAddInt32(&call, time(NULL));
|
||||||
XDROutPacketAddInt32(&call, 0);
|
XDROutPacketAddInt32(&call, 0);
|
||||||
|
|
||||||
replyBuf=send_rpc_call (ns,&ns->nfsAddr,NFS_PROGRAM,NFS_VERSION,NFSPROC_SYMLINK,&call);
|
replyBuf = send_rpc_call (ns, &ns->nfsAddr, NFS_PROGRAM, NFS_VERSION,
|
||||||
|
NFSPROC_SYMLINK, &call);
|
||||||
|
|
||||||
if (!replyBuf)
|
if (!replyBuf) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
@@ -2379,8 +2364,7 @@ fs_symlink(fs_volume *_volume, fs_vnode *_dir, const char *name, const char *pat
|
|||||||
|
|
||||||
XDRInPacketSetTo(&reply, replyBuf, 0);
|
XDRInPacketSetTo(&reply, replyBuf, 0);
|
||||||
|
|
||||||
if (!is_successful_reply(&reply))
|
if (!is_successful_reply(&reply)) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
@@ -2396,14 +2380,18 @@ fs_symlink(fs_volume *_volume, fs_vnode *_dir, const char *name, const char *pat
|
|||||||
|
|
||||||
result = nfs_lookup(ns, &dir->fhandle, name, &fhandle, &st);
|
result = nfs_lookup(ns, &dir->fhandle, name, &fhandle, &st);
|
||||||
|
|
||||||
if (result<B_OK)
|
if (result < B_OK) {
|
||||||
{
|
|
||||||
XDRInPacketDestroy(&reply);
|
XDRInPacketDestroy(&reply);
|
||||||
XDROutPacketDestroy(&call);
|
XDROutPacketDestroy(&call);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
newNode = (fs_node *)malloc(sizeof(fs_node));
|
newNode = (fs_node *)malloc(sizeof(fs_node));
|
||||||
|
if (newNode == NULL) {
|
||||||
|
XDRInPacketDestroy(&reply);
|
||||||
|
XDROutPacketDestroy(&call);
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
}
|
||||||
newNode->fhandle = fhandle;
|
newNode->fhandle = fhandle;
|
||||||
newNode->vnid = st.st_ino;
|
newNode->vnid = st.st_ino;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user