2005-01-06 18:10:42 +00:00
|
|
|
/*-
|
2001-03-10 05:31:22 +00:00
|
|
|
* Copyright (c) 1999, 2001 Boris Popov
|
1999-10-02 04:06:24 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Boris Popov.
|
|
|
|
* 4. Neither the name of the author nor the names of any co-contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
2002-09-01 23:02:10 +00:00
|
|
|
#include <sys/lockmgr.h>
|
1999-10-02 04:06:24 +00:00
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <machine/clock.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
#include <netncp/ncp.h>
|
|
|
|
#include <netncp/ncp_conn.h>
|
|
|
|
#include <netncp/ncp_ncp.h>
|
|
|
|
#include <netncp/ncp_subr.h>
|
|
|
|
#include <netncp/ncp_rq.h>
|
|
|
|
#include <netncp/nwerror.h>
|
|
|
|
|
2001-05-26 11:57:45 +00:00
|
|
|
#include <fs/nwfs/nwfs.h>
|
|
|
|
#include <fs/nwfs/nwfs_node.h>
|
|
|
|
#include <fs/nwfs/nwfs_subr.h>
|
1999-10-02 04:06:24 +00:00
|
|
|
|
2001-03-10 05:31:22 +00:00
|
|
|
#define NCP_INFOSZ (sizeof(struct nw_entry_info) - 257)
|
|
|
|
|
2005-10-31 15:41:29 +00:00
|
|
|
MALLOC_DEFINE(M_NWFSDATA, "nwfs_data", "NWFS private data");
|
1999-10-02 04:06:24 +00:00
|
|
|
|
2001-03-10 05:31:22 +00:00
|
|
|
static int
|
|
|
|
ncp_extract_file_info(struct nwmount *nmp, struct ncp_rq *rqp,
|
|
|
|
struct nw_entry_info *target, int withname)
|
|
|
|
{
|
|
|
|
u_int8_t name_len;
|
1999-10-02 04:06:24 +00:00
|
|
|
|
2001-03-10 05:31:22 +00:00
|
|
|
md_get_mem(&rqp->rp, (caddr_t)target, NCP_INFOSZ, MB_MSYSTEM);
|
|
|
|
if (!withname)
|
|
|
|
return 0;
|
|
|
|
md_get_uint8(&rqp->rp, &name_len);
|
1999-10-02 04:06:24 +00:00
|
|
|
target->nameLen = name_len;
|
2001-03-10 05:31:22 +00:00
|
|
|
md_get_mem(&rqp->rp, (caddr_t)target->entryName, name_len, MB_MSYSTEM);
|
1999-10-02 04:06:24 +00:00
|
|
|
target->entryName[name_len] = '\0';
|
|
|
|
ncp_path2unix(target->entryName, target->entryName, name_len, &nmp->m.nls);
|
2001-03-10 05:31:22 +00:00
|
|
|
return 0;
|
1999-10-02 04:06:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
ncp_initsearch(struct vnode *dvp, struct thread *td, struct ucred *cred)
|
1999-10-02 04:06:24 +00:00
|
|
|
{
|
|
|
|
struct nwmount *nmp = VTONWFS(dvp);
|
|
|
|
struct ncp_conn *conn = NWFSTOCONN(nmp);
|
|
|
|
struct nwnode *np = VTONW(dvp);
|
2001-03-10 05:31:22 +00:00
|
|
|
struct ncp_rq *rqp;
|
1999-10-02 04:06:24 +00:00
|
|
|
u_int8_t volnum = nmp->n_volume;
|
|
|
|
u_int32_t dirent = np->n_fid.f_id;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
NCPNDEBUG("vol=%d,dir=%d\n", volnum, dirent);
|
2001-09-12 08:38:13 +00:00
|
|
|
error = ncp_rq_alloc(87, conn, td, cred, &rqp);
|
2001-03-10 05:31:22 +00:00
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
mb_put_uint8(&rqp->rq, 2); /* subfunction */
|
|
|
|
mb_put_uint8(&rqp->rq, nmp->name_space);
|
|
|
|
mb_put_uint8(&rqp->rq, 0); /* reserved */
|
1999-10-02 04:06:24 +00:00
|
|
|
ncp_rq_dbase_path(rqp, volnum, dirent, 0, NULL, NULL);
|
2001-03-10 05:31:22 +00:00
|
|
|
rqp->nr_minrplen = sizeof(np->n_seq);
|
|
|
|
error = ncp_request(rqp);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
md_get_mem(&rqp->rp, (caddr_t)&np->n_seq, sizeof(np->n_seq), MB_MSYSTEM);
|
|
|
|
ncp_rq_done(rqp);
|
|
|
|
return 0;
|
1999-10-02 04:06:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ncp_search_for_file_or_subdir(struct nwmount *nmp,
|
|
|
|
struct nw_search_seq *seq,
|
|
|
|
struct nw_entry_info *target,
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td,struct ucred *cred)
|
1999-10-02 04:06:24 +00:00
|
|
|
{
|
|
|
|
struct ncp_conn *conn = NWFSTOCONN(nmp);
|
2001-03-10 05:31:22 +00:00
|
|
|
struct ncp_rq *rqp;
|
1999-10-02 04:06:24 +00:00
|
|
|
int error;
|
2001-03-10 05:31:22 +00:00
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
error = ncp_rq_alloc(87, conn, td, cred, &rqp);
|
2001-03-10 05:31:22 +00:00
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
mb_put_uint8(&rqp->rq, 3); /* subfunction */
|
|
|
|
mb_put_uint8(&rqp->rq, nmp->name_space);
|
|
|
|
mb_put_uint8(&rqp->rq, 0); /* data stream */
|
|
|
|
mb_put_uint16le(&rqp->rq, 0xffff); /* Search attribs */
|
|
|
|
mb_put_uint32le(&rqp->rq, IM_ALL); /* return info mask */
|
|
|
|
mb_put_mem(&rqp->rq, (caddr_t)seq, 9, MB_MSYSTEM);
|
|
|
|
mb_put_uint8(&rqp->rq, 2); /* 2 byte pattern */
|
|
|
|
mb_put_uint8(&rqp->rq, 0xff); /* following is a wildcard */
|
|
|
|
mb_put_uint8(&rqp->rq, '*');
|
|
|
|
rqp->nr_minrplen = sizeof(*seq) + 1 + NCP_INFOSZ + 1;
|
|
|
|
error = ncp_request(rqp);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
md_get_mem(&rqp->rp, (caddr_t)seq, sizeof(*seq), MB_MSYSTEM);
|
|
|
|
md_get_uint8(&rqp->rp, NULL); /* skip */
|
|
|
|
error = ncp_extract_file_info(nmp, rqp, target, 1);
|
|
|
|
ncp_rq_done(rqp);
|
1999-10-02 04:06:24 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns information for a (one-component) name relative to the specified
|
|
|
|
* directory.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ncp_obtain_info(struct nwmount *nmp, u_int32_t dirent,
|
|
|
|
int namelen, char *path, struct nw_entry_info *target,
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td,struct ucred *cred)
|
1999-10-02 04:06:24 +00:00
|
|
|
{
|
|
|
|
struct ncp_conn *conn=NWFSTOCONN(nmp);
|
2001-03-10 05:31:22 +00:00
|
|
|
struct ncp_rq *rqp;
|
1999-10-02 04:06:24 +00:00
|
|
|
int error;
|
|
|
|
u_char volnum = nmp->n_volume, ns;
|
|
|
|
|
|
|
|
if (target == NULL) {
|
|
|
|
NCPFATAL("target == NULL\n");
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
ns = (path == NULL || path[0] == 0) ? NW_NS_DOS : nmp->name_space;
|
2001-09-12 08:38:13 +00:00
|
|
|
error = ncp_rq_alloc(87, conn, td, cred, &rqp);
|
2001-03-10 05:31:22 +00:00
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
mb_put_uint8(&rqp->rq, 6); /* subfunction */
|
|
|
|
mb_put_uint8(&rqp->rq, ns);
|
|
|
|
mb_put_uint8(&rqp->rq, ns); /* DestNameSpace */
|
|
|
|
mb_put_uint16le(&rqp->rq, 0xff); /* get all */
|
|
|
|
mb_put_uint32le(&rqp->rq, IM_ALL);
|
1999-10-02 04:06:24 +00:00
|
|
|
ncp_rq_dbase_path(rqp, volnum, dirent, namelen, path, &nmp->m.nls);
|
2001-03-10 05:31:22 +00:00
|
|
|
error = ncp_request(rqp);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
error = ncp_extract_file_info(nmp, rqp, target, path != NULL);
|
|
|
|
ncp_rq_done(rqp);
|
1999-10-02 04:06:24 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* lookup name pointed by cnp in directory dvp and return file info in np.
|
|
|
|
* May be I should create a little cache, but another way is to minimize
|
|
|
|
* number of calls, on other hand, in multiprocess environment ...
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ncp_lookup(struct vnode *dvp, int len, char *name, struct nw_entry_info *fap,
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td,struct ucred *cred)
|
1999-10-02 04:06:24 +00:00
|
|
|
{
|
|
|
|
struct nwmount *nmp;
|
2005-05-11 19:08:38 +00:00
|
|
|
struct nwnode *dnp;
|
1999-10-02 04:06:24 +00:00
|
|
|
struct ncp_conn *conn;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (!dvp || dvp->v_type != VDIR) {
|
|
|
|
nwfs_printf("dvp is NULL or not a directory.\n");
|
|
|
|
return (ENOENT);
|
|
|
|
}
|
2005-05-11 19:08:38 +00:00
|
|
|
dnp = VTONW(dvp);
|
1999-10-02 04:06:24 +00:00
|
|
|
nmp = VTONWFS(dvp);
|
|
|
|
conn = NWFSTOCONN(nmp);
|
|
|
|
|
|
|
|
if (len == 1 && name[0] == '.') {
|
2001-03-10 05:39:03 +00:00
|
|
|
if (dnp->n_flag & NVOLUME) {
|
1999-10-02 04:06:24 +00:00
|
|
|
error = ncp_obtain_info(nmp, dnp->n_fid.f_id, 0, NULL,
|
2001-09-12 08:38:13 +00:00
|
|
|
fap, td, cred);
|
1999-10-02 04:06:24 +00:00
|
|
|
} else {
|
|
|
|
error = ncp_obtain_info(nmp, dnp->n_fid.f_parent,
|
2001-09-12 08:38:13 +00:00
|
|
|
dnp->n_nmlen, dnp->n_name, fap, td, cred);
|
1999-10-02 04:06:24 +00:00
|
|
|
}
|
|
|
|
return error;
|
|
|
|
} else if (len == 2 && name[0] == '.' && name[1] == '.') {
|
2001-12-10 08:09:49 +00:00
|
|
|
printf("%s: knows NOTHING about '..'\n", __func__);
|
1999-10-02 04:06:24 +00:00
|
|
|
return EIO;
|
|
|
|
} else {
|
|
|
|
error = ncp_obtain_info(nmp, dnp->n_fid.f_id,
|
2001-09-12 08:38:13 +00:00
|
|
|
len, name, fap, td, cred);
|
1999-10-02 04:06:24 +00:00
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ConvertToNWfromDWORD(u_int32_t sfd, ncp_fh *fh);
|
|
|
|
static void
|
|
|
|
ConvertToNWfromDWORD(u_int32_t sfd, ncp_fh *fh) {
|
|
|
|
fh->val1 = (fh->val.val32 = sfd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If both dir and name are NULL, then in target there's already a looked-up
|
|
|
|
* entry that wants to be opened.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ncp_open_create_file_or_subdir(struct nwmount *nmp,struct vnode *dvp,int namelen,
|
|
|
|
char *name, int open_create_mode, u_int32_t create_attributes,
|
|
|
|
int desired_acc_rights, struct ncp_open_info *nop,
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td,struct ucred *cred)
|
1999-10-02 04:06:24 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
struct ncp_conn *conn=NWFSTOCONN(nmp);
|
2001-03-10 05:31:22 +00:00
|
|
|
struct ncp_rq *rqp;
|
1999-10-02 04:06:24 +00:00
|
|
|
u_int16_t search_attribs = SA_ALL & (~SA_SUBDIR_FILES);
|
|
|
|
u_int8_t volnum;
|
|
|
|
u_int32_t dirent;
|
|
|
|
int error;
|
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
error = ncp_rq_alloc(87, conn, td, cred, &rqp);
|
2001-03-10 05:31:22 +00:00
|
|
|
if (error)
|
|
|
|
return error;
|
1999-10-02 04:06:24 +00:00
|
|
|
volnum = nmp->n_volume;
|
|
|
|
dirent = VTONW(dvp)->n_fid.f_id;
|
|
|
|
if ((create_attributes & aDIR) != 0) {
|
|
|
|
search_attribs |= SA_SUBDIR_FILES;
|
|
|
|
}
|
2001-03-10 05:31:22 +00:00
|
|
|
mb_put_uint8(&rqp->rq, 1);/* subfunction */
|
|
|
|
mb_put_uint8(&rqp->rq, nmp->name_space);
|
|
|
|
mb_put_uint8(&rqp->rq, open_create_mode);
|
|
|
|
mb_put_uint16le(&rqp->rq, search_attribs);
|
|
|
|
mb_put_uint32le(&rqp->rq, IM_ALL);
|
|
|
|
mb_put_uint32le(&rqp->rq, create_attributes);
|
1999-10-02 04:06:24 +00:00
|
|
|
/*
|
|
|
|
* The desired acc rights seem to be the inherited rights mask for
|
|
|
|
* directories
|
|
|
|
*/
|
2001-03-10 05:31:22 +00:00
|
|
|
mb_put_uint16le(&rqp->rq, desired_acc_rights);
|
1999-10-02 04:06:24 +00:00
|
|
|
ncp_rq_dbase_path(rqp, volnum, dirent, namelen, name, &nmp->m.nls);
|
2001-03-10 05:31:22 +00:00
|
|
|
error = ncp_request(rqp);
|
|
|
|
if (error) {
|
|
|
|
if (error == NWE_FILE_NO_CREATE_PRIV)
|
|
|
|
error = EACCES;
|
|
|
|
return error;
|
1999-10-02 04:06:24 +00:00
|
|
|
}
|
2001-03-10 05:31:22 +00:00
|
|
|
md_get_uint32le(&rqp->rp, &nop->origfh);
|
|
|
|
md_get_uint8(&rqp->rp, &nop->action);
|
|
|
|
md_get_uint8(&rqp->rp, NULL); /* skip */
|
|
|
|
error = ncp_extract_file_info(nmp, rqp, &nop->fattr, 1);
|
|
|
|
ncp_rq_done(rqp);
|
|
|
|
ConvertToNWfromDWORD(nop->origfh, &nop->fh);
|
1999-10-02 04:06:24 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
ncp_close_file(struct ncp_conn *conn, ncp_fh *fh,struct thread *td,struct ucred *cred)
|
2001-03-10 05:31:22 +00:00
|
|
|
{
|
|
|
|
struct ncp_rq *rqp;
|
1999-10-02 04:06:24 +00:00
|
|
|
int error;
|
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
error = ncp_rq_alloc(66, conn, td, cred, &rqp);
|
2001-03-10 05:31:22 +00:00
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
mb_put_uint8(&rqp->rq, 0);
|
|
|
|
mb_put_mem(&rqp->rq, (caddr_t)fh, 6, MB_MSYSTEM);
|
|
|
|
error = ncp_request(rqp);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
ncp_rq_done(rqp);
|
1999-10-02 04:06:24 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ncp_DeleteNSEntry(struct nwmount *nmp, u_int32_t dirent,
|
2001-09-12 08:38:13 +00:00
|
|
|
int namelen,char *name,struct thread *td,struct ucred *cred)
|
1999-10-02 04:06:24 +00:00
|
|
|
{
|
2001-03-10 05:31:22 +00:00
|
|
|
struct ncp_rq *rqp;
|
1999-10-02 04:06:24 +00:00
|
|
|
int error;
|
|
|
|
struct ncp_conn *conn=NWFSTOCONN(nmp);
|
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
error = ncp_rq_alloc(87, conn, td, cred, &rqp);
|
2001-03-10 05:31:22 +00:00
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
mb_put_uint8(&rqp->rq, 8); /* subfunction */
|
|
|
|
mb_put_uint8(&rqp->rq, nmp->name_space);
|
|
|
|
mb_put_uint8(&rqp->rq, 0); /* reserved */
|
|
|
|
mb_put_uint16le(&rqp->rq, SA_ALL); /* search attribs: all */
|
1999-10-02 04:06:24 +00:00
|
|
|
ncp_rq_dbase_path(rqp, nmp->n_volume, dirent, namelen, name, &nmp->m.nls);
|
2001-03-10 05:31:22 +00:00
|
|
|
error = ncp_request(rqp);
|
|
|
|
if (!error)
|
|
|
|
ncp_rq_done(rqp);
|
1999-10-02 04:06:24 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ncp_nsrename(struct ncp_conn *conn, int volume, int ns, int oldtype,
|
|
|
|
struct ncp_nlstables *nt,
|
|
|
|
nwdirent fdir, char *old_name, int oldlen,
|
|
|
|
nwdirent tdir, char *new_name, int newlen,
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td, struct ucred *cred)
|
1999-10-02 04:06:24 +00:00
|
|
|
{
|
2001-03-10 05:31:22 +00:00
|
|
|
struct ncp_rq *rqp;
|
1999-10-02 04:06:24 +00:00
|
|
|
int error;
|
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
error = ncp_rq_alloc(87, conn, td, cred, &rqp);
|
2001-03-10 05:31:22 +00:00
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
mb_put_uint8(&rqp->rq, 4);
|
|
|
|
mb_put_uint8(&rqp->rq, ns);
|
|
|
|
mb_put_uint8(&rqp->rq, 1); /* RRenameToMySelf */
|
|
|
|
mb_put_uint16le(&rqp->rq, oldtype);
|
1999-10-02 04:06:24 +00:00
|
|
|
/* source Handle Path */
|
2001-03-10 05:31:22 +00:00
|
|
|
mb_put_uint8(&rqp->rq, volume);
|
|
|
|
mb_put_mem(&rqp->rq, (c_caddr_t)&fdir, sizeof(fdir), MB_MSYSTEM);
|
|
|
|
mb_put_uint8(&rqp->rq, 1);
|
|
|
|
mb_put_uint8(&rqp->rq, 1); /* 1 source component */
|
1999-10-02 04:06:24 +00:00
|
|
|
/* dest Handle Path */
|
2001-03-10 05:31:22 +00:00
|
|
|
mb_put_uint8(&rqp->rq, volume);
|
|
|
|
mb_put_mem(&rqp->rq, (c_caddr_t)&tdir, sizeof(tdir), MB_MSYSTEM);
|
|
|
|
mb_put_uint8(&rqp->rq, 1);
|
|
|
|
mb_put_uint8(&rqp->rq, 1); /* 1 destination component */
|
1999-10-02 04:06:24 +00:00
|
|
|
ncp_rq_pathstring(rqp, oldlen, old_name, nt);
|
|
|
|
ncp_rq_pathstring(rqp, newlen, new_name, nt);
|
2001-03-10 05:31:22 +00:00
|
|
|
error = ncp_request(rqp);
|
|
|
|
if (!error)
|
|
|
|
ncp_rq_done(rqp);
|
1999-10-02 04:06:24 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ncp_modify_file_or_subdir_dos_info(struct nwmount *nmp, struct vnode *vp,
|
|
|
|
u_int32_t info_mask,
|
|
|
|
struct nw_modify_dos_info *info,
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td,struct ucred *cred)
|
1999-10-02 04:06:24 +00:00
|
|
|
{
|
|
|
|
struct nwnode *np=VTONW(vp);
|
2001-03-10 05:31:22 +00:00
|
|
|
struct ncp_rq *rqp;
|
1999-10-02 04:06:24 +00:00
|
|
|
u_int8_t volnum = nmp->n_volume;
|
|
|
|
u_int32_t dirent = np->n_fid.f_id;
|
|
|
|
struct ncp_conn *conn=NWFSTOCONN(nmp);
|
|
|
|
int error;
|
2001-03-10 05:31:22 +00:00
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
error = ncp_rq_alloc(87, conn, td, cred, &rqp);
|
2001-03-10 05:31:22 +00:00
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
mb_put_uint8(&rqp->rq, 7); /* subfunction */
|
|
|
|
mb_put_uint8(&rqp->rq, nmp->name_space);
|
|
|
|
mb_put_uint8(&rqp->rq, 0); /* reserved */
|
|
|
|
mb_put_uint16le(&rqp->rq, SA_ALL); /* search attribs: all */
|
|
|
|
mb_put_uint32le(&rqp->rq, info_mask);
|
|
|
|
mb_put_mem(&rqp->rq, (caddr_t)info, sizeof(*info), MB_MSYSTEM);
|
1999-10-02 04:06:24 +00:00
|
|
|
ncp_rq_dbase_path(rqp, volnum, dirent, 0, NULL, NULL);
|
2001-03-10 05:31:22 +00:00
|
|
|
error = ncp_request(rqp);
|
|
|
|
if (!error)
|
|
|
|
ncp_rq_done(rqp);
|
1999-10-02 04:06:24 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
ncp_setattr(vp, vap, cred, td)
|
2000-10-02 09:29:59 +00:00
|
|
|
struct vnode *vp;
|
|
|
|
struct vattr *vap;
|
1999-10-02 04:06:24 +00:00
|
|
|
struct ucred *cred;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td;
|
1999-10-02 04:06:24 +00:00
|
|
|
{
|
|
|
|
struct nwmount *nmp=VTONWFS(vp);
|
|
|
|
struct nwnode *np=VTONW(vp);
|
|
|
|
struct ncp_open_info nwn;
|
|
|
|
struct ncp_conn *conn=NWFSTOCONN(nmp);
|
|
|
|
struct nw_modify_dos_info info;
|
2001-03-10 05:31:22 +00:00
|
|
|
struct ncp_rq *rqp;
|
1999-10-02 04:06:24 +00:00
|
|
|
int error = 0, info_mask;
|
|
|
|
|
|
|
|
if (vap->va_size != VNOVAL) {
|
|
|
|
error = ncp_open_create_file_or_subdir(nmp, vp, 0, NULL, OC_MODE_OPEN, 0,
|
2001-09-12 08:38:13 +00:00
|
|
|
AR_WRITE | AR_READ, &nwn,td,cred);
|
2001-03-10 05:31:22 +00:00
|
|
|
if (error)
|
|
|
|
return error;
|
2001-09-12 08:38:13 +00:00
|
|
|
error = ncp_rq_alloc(73, conn, td, cred, &rqp);
|
2001-03-10 05:31:22 +00:00
|
|
|
if (error) {
|
2001-09-12 08:38:13 +00:00
|
|
|
ncp_close_file(conn, &nwn.fh, td, cred);
|
2001-03-10 05:31:22 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
mb_put_uint8(&rqp->rq, 0);
|
|
|
|
mb_put_mem(&rqp->rq, (caddr_t)&nwn.fh, 6, MB_MSYSTEM);
|
|
|
|
mb_put_uint32be(&rqp->rq, vap->va_size);
|
|
|
|
mb_put_uint16be(&rqp->rq, 0);
|
|
|
|
error = ncp_request(rqp);
|
1999-10-02 04:06:24 +00:00
|
|
|
np->n_vattr.va_size = np->n_size = vap->va_size;
|
2001-03-10 05:31:22 +00:00
|
|
|
if (!error)
|
|
|
|
ncp_rq_done(rqp);
|
2001-09-12 08:38:13 +00:00
|
|
|
ncp_close_file(conn, &nwn.fh, td, cred);
|
2001-03-10 05:31:22 +00:00
|
|
|
if (error)
|
|
|
|
return error;
|
1999-10-02 04:06:24 +00:00
|
|
|
}
|
|
|
|
info_mask = 0;
|
|
|
|
bzero(&info, sizeof(info));
|
|
|
|
|
|
|
|
if (vap->va_mtime.tv_sec != VNOVAL) {
|
|
|
|
info_mask |= (DM_MODIFY_TIME | DM_MODIFY_DATE);
|
2000-04-05 10:44:04 +00:00
|
|
|
ncp_unix2dostime(&vap->va_mtime, nmp->m.tz, &info.modifyDate, &info.modifyTime, NULL);
|
1999-10-02 04:06:24 +00:00
|
|
|
}
|
|
|
|
if (vap->va_atime.tv_sec != VNOVAL) {
|
|
|
|
info_mask |= (DM_LAST_ACCESS_DATE);
|
2000-04-05 10:44:04 +00:00
|
|
|
ncp_unix2dostime(&vap->va_atime, nmp->m.tz, &info.lastAccessDate, NULL, NULL);
|
1999-10-02 04:06:24 +00:00
|
|
|
}
|
|
|
|
if (info_mask) {
|
2001-09-12 08:38:13 +00:00
|
|
|
error = ncp_modify_file_or_subdir_dos_info(nmp, vp, info_mask, &info,td,cred);
|
1999-10-02 04:06:24 +00:00
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ncp_get_volume_info_with_number(struct ncp_conn *conn,
|
2001-03-10 05:31:22 +00:00
|
|
|
int n, struct ncp_volume_info *target,
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td,struct ucred *cred)
|
2001-03-10 05:31:22 +00:00
|
|
|
{
|
|
|
|
struct ncp_rq *rqp;
|
|
|
|
u_int32_t tmp32;
|
|
|
|
u_int8_t len;
|
|
|
|
int error;
|
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
error = ncp_rq_alloc_subfn(22, 44, conn, td, cred, &rqp);
|
2001-03-10 05:31:22 +00:00
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
mb_put_uint8(&rqp->rq,n);
|
|
|
|
error = ncp_request(rqp);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
md_get_uint32le(&rqp->rp, &target->total_blocks);
|
|
|
|
md_get_uint32le(&rqp->rp, &target->free_blocks);
|
|
|
|
md_get_uint32le(&rqp->rp, &target->purgeable_blocks);
|
|
|
|
md_get_uint32le(&rqp->rp, &target->not_yet_purgeable_blocks);
|
|
|
|
md_get_uint32le(&rqp->rp, &target->total_dir_entries);
|
|
|
|
md_get_uint32le(&rqp->rp, &target->available_dir_entries);
|
|
|
|
md_get_uint32le(&rqp->rp, &tmp32);
|
|
|
|
md_get_uint8(&rqp->rp, &target->sectors_per_block);
|
1999-10-02 04:06:24 +00:00
|
|
|
bzero(&target->volume_name, sizeof(target->volume_name));
|
2001-03-10 05:31:22 +00:00
|
|
|
md_get_uint8(&rqp->rp, &len);
|
1999-10-02 04:06:24 +00:00
|
|
|
if (len > NCP_VOLNAME_LEN) {
|
|
|
|
error = ENAMETOOLONG;
|
|
|
|
} else {
|
2001-03-10 05:31:22 +00:00
|
|
|
md_get_mem(&rqp->rp, (caddr_t)&target->volume_name, len, MB_MSYSTEM);
|
1999-10-02 04:06:24 +00:00
|
|
|
}
|
2001-03-10 05:31:22 +00:00
|
|
|
ncp_rq_done(rqp);
|
1999-10-02 04:06:24 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ncp_get_namespaces(struct ncp_conn *conn, u_int32_t volume, int *nsf,
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td,struct ucred *cred)
|
2001-03-10 05:31:22 +00:00
|
|
|
{
|
|
|
|
struct ncp_rq *rqp;
|
1999-10-02 04:06:24 +00:00
|
|
|
int error;
|
|
|
|
u_int8_t ns;
|
|
|
|
u_int16_t nscnt;
|
2001-03-10 05:31:22 +00:00
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
error = ncp_rq_alloc(87, conn, td, cred, &rqp);
|
2001-03-10 05:31:22 +00:00
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
mb_put_uint8(&rqp->rq, 24); /* Subfunction: Get Loaded Name Spaces */
|
|
|
|
mb_put_uint16le(&rqp->rq, 0); /* reserved */
|
|
|
|
mb_put_uint8(&rqp->rq, volume);
|
|
|
|
error = ncp_request(rqp);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
md_get_uint16le(&rqp->rp, &nscnt);
|
1999-10-02 04:06:24 +00:00
|
|
|
*nsf = 0;
|
|
|
|
while (nscnt-- > 0) {
|
2001-03-10 05:31:22 +00:00
|
|
|
md_get_uint8(&rqp->rp, &ns);
|
1999-10-02 04:06:24 +00:00
|
|
|
*nsf |= 1 << ns;
|
|
|
|
}
|
2001-03-10 05:31:22 +00:00
|
|
|
ncp_rq_done(rqp);
|
1999-10-02 04:06:24 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ncp_lookup_volume(struct ncp_conn *conn, char *volname,
|
|
|
|
u_char *volNum, u_int32_t *dirEnt,
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td,struct ucred *cred)
|
1999-10-02 04:06:24 +00:00
|
|
|
{
|
2001-03-10 05:31:22 +00:00
|
|
|
struct ncp_rq *rqp;
|
|
|
|
u_int32_t tmp32;
|
1999-10-02 04:06:24 +00:00
|
|
|
int error;
|
|
|
|
|
|
|
|
NCPNDEBUG("looking up vol %s\n", volname);
|
2001-09-12 08:38:13 +00:00
|
|
|
error = ncp_rq_alloc(87, conn, td, cred, &rqp);
|
2001-03-10 05:31:22 +00:00
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
mb_put_uint8(&rqp->rq, 22); /* Subfunction: Generate dir handle */
|
|
|
|
mb_put_uint8(&rqp->rq, 0); /* src name space */
|
|
|
|
mb_put_uint8(&rqp->rq, 0); /* dst name space, always zero */
|
|
|
|
mb_put_uint16le(&rqp->rq, 0); /* dstNSIndicator (Jn) */
|
|
|
|
|
|
|
|
mb_put_uint8(&rqp->rq, 0); /* faked volume number */
|
|
|
|
mb_put_uint32be(&rqp->rq, 0); /* faked dir_base */
|
|
|
|
mb_put_uint8(&rqp->rq, 0xff); /* Don't have a dir_base */
|
|
|
|
mb_put_uint8(&rqp->rq, 1); /* 1 path component */
|
1999-10-02 04:06:24 +00:00
|
|
|
ncp_rq_pstring(rqp, volname);
|
2001-03-10 05:31:22 +00:00
|
|
|
error = ncp_request(rqp);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
md_get_uint32le(&rqp->rp, &tmp32);
|
|
|
|
md_get_uint32le(&rqp->rp, dirEnt);
|
|
|
|
md_get_uint8(&rqp->rp, volNum);
|
|
|
|
ncp_rq_done(rqp);
|
1999-10-02 04:06:24 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Time & date conversion routines taken from msdosfs. Although leap
|
|
|
|
* year calculation is bogus, it's sufficient before 2100 :)
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* This is the format of the contents of the deTime field in the direntry
|
|
|
|
* structure.
|
|
|
|
* We don't use bitfields because we don't know how compilers for
|
|
|
|
* arbitrary machines will lay them out.
|
|
|
|
*/
|
|
|
|
#define DT_2SECONDS_MASK 0x1F /* seconds divided by 2 */
|
|
|
|
#define DT_2SECONDS_SHIFT 0
|
|
|
|
#define DT_MINUTES_MASK 0x7E0 /* minutes */
|
|
|
|
#define DT_MINUTES_SHIFT 5
|
|
|
|
#define DT_HOURS_MASK 0xF800 /* hours */
|
|
|
|
#define DT_HOURS_SHIFT 11
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is the format of the contents of the deDate field in the direntry
|
|
|
|
* structure.
|
|
|
|
*/
|
|
|
|
#define DD_DAY_MASK 0x1F /* day of month */
|
|
|
|
#define DD_DAY_SHIFT 0
|
|
|
|
#define DD_MONTH_MASK 0x1E0 /* month */
|
|
|
|
#define DD_MONTH_SHIFT 5
|
|
|
|
#define DD_YEAR_MASK 0xFE00 /* year - 1980 */
|
|
|
|
#define DD_YEAR_SHIFT 9
|
|
|
|
/*
|
|
|
|
* Total number of days that have passed for each month in a regular year.
|
|
|
|
*/
|
|
|
|
static u_short regyear[] = {
|
|
|
|
31, 59, 90, 120, 151, 181,
|
|
|
|
212, 243, 273, 304, 334, 365
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Total number of days that have passed for each month in a leap year.
|
|
|
|
*/
|
|
|
|
static u_short leapyear[] = {
|
|
|
|
31, 60, 91, 121, 152, 182,
|
|
|
|
213, 244, 274, 305, 335, 366
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Variables used to remember parts of the last time conversion. Maybe we
|
|
|
|
* can avoid a full conversion.
|
|
|
|
*/
|
|
|
|
static u_long lasttime;
|
|
|
|
static u_long lastday;
|
|
|
|
static u_short lastddate;
|
|
|
|
static u_short lastdtime;
|
|
|
|
/*
|
|
|
|
* Convert the unix version of time to dos's idea of time to be used in
|
|
|
|
* file timestamps. The passed in unix time is assumed to be in GMT.
|
|
|
|
*/
|
|
|
|
void
|
2000-04-05 10:44:04 +00:00
|
|
|
ncp_unix2dostime(tsp, tzoff, ddp, dtp, dhp)
|
1999-10-02 04:06:24 +00:00
|
|
|
struct timespec *tsp;
|
2000-04-05 10:44:04 +00:00
|
|
|
int tzoff;
|
1999-10-02 04:06:24 +00:00
|
|
|
u_int16_t *ddp;
|
|
|
|
u_int16_t *dtp;
|
|
|
|
u_int8_t *dhp;
|
|
|
|
{
|
|
|
|
u_long t;
|
|
|
|
u_long days;
|
|
|
|
u_long inc;
|
|
|
|
u_long year;
|
|
|
|
u_long month;
|
|
|
|
u_short *months;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the time from the last conversion is the same as now, then
|
|
|
|
* skip the computations and use the saved result.
|
|
|
|
*/
|
2003-02-03 19:49:35 +00:00
|
|
|
t = tsp->tv_sec - tzoff * 60 - tz_minuteswest * 60 -
|
2000-04-05 10:44:04 +00:00
|
|
|
(wall_cmos_clock ? adjkerntz : 0);
|
1999-10-02 04:06:24 +00:00
|
|
|
t &= ~1;
|
|
|
|
if (lasttime != t) {
|
|
|
|
lasttime = t;
|
|
|
|
lastdtime = (((t / 2) % 30) << DT_2SECONDS_SHIFT)
|
|
|
|
+ (((t / 60) % 60) << DT_MINUTES_SHIFT)
|
|
|
|
+ (((t / 3600) % 24) << DT_HOURS_SHIFT);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the number of days since 1970 is the same as the last
|
|
|
|
* time we did the computation then skip all this leap year
|
|
|
|
* and month stuff.
|
|
|
|
*/
|
|
|
|
days = t / (24 * 60 * 60);
|
|
|
|
if (days != lastday) {
|
|
|
|
lastday = days;
|
|
|
|
for (year = 1970;; year++) {
|
|
|
|
inc = year & 0x03 ? 365 : 366;
|
|
|
|
if (days < inc)
|
|
|
|
break;
|
|
|
|
days -= inc;
|
|
|
|
}
|
|
|
|
months = year & 0x03 ? regyear : leapyear;
|
|
|
|
for (month = 0; days >= months[month]; month++)
|
|
|
|
;
|
|
|
|
if (month > 0)
|
|
|
|
days -= months[month - 1];
|
|
|
|
lastddate = ((days + 1) << DD_DAY_SHIFT)
|
|
|
|
+ ((month + 1) << DD_MONTH_SHIFT);
|
|
|
|
/*
|
|
|
|
* Remember dos's idea of time is relative to 1980.
|
|
|
|
* unix's is relative to 1970. If somehow we get a
|
|
|
|
* time before 1980 then don't give totally crazy
|
|
|
|
* results.
|
|
|
|
*/
|
|
|
|
if (year > 1980)
|
|
|
|
lastddate += (year - 1980) << DD_YEAR_SHIFT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dtp)
|
|
|
|
*dtp = lastdtime;
|
|
|
|
if (dhp)
|
|
|
|
*dhp = (tsp->tv_sec & 1) * 100 + tsp->tv_nsec / 10000000;
|
|
|
|
|
|
|
|
*ddp = lastddate;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The number of seconds between Jan 1, 1970 and Jan 1, 1980. In that
|
|
|
|
* interval there were 8 regular years and 2 leap years.
|
|
|
|
*/
|
|
|
|
#define SECONDSTO1980 (((8 * 365) + (2 * 366)) * (24 * 60 * 60))
|
|
|
|
|
|
|
|
static u_short lastdosdate;
|
|
|
|
static u_long lastseconds;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert from dos' idea of time to unix'. This will probably only be
|
|
|
|
* called from the stat(), and fstat() system calls and so probably need
|
|
|
|
* not be too efficient.
|
|
|
|
*/
|
|
|
|
void
|
2000-04-05 10:44:04 +00:00
|
|
|
ncp_dos2unixtime(dd, dt, dh, tzoff, tsp)
|
1999-10-02 04:06:24 +00:00
|
|
|
u_int dd;
|
|
|
|
u_int dt;
|
|
|
|
u_int dh;
|
2000-04-05 10:44:04 +00:00
|
|
|
int tzoff;
|
1999-10-02 04:06:24 +00:00
|
|
|
struct timespec *tsp;
|
|
|
|
{
|
|
|
|
u_long seconds;
|
|
|
|
u_long month;
|
|
|
|
u_long year;
|
|
|
|
u_long days;
|
|
|
|
u_short *months;
|
|
|
|
|
|
|
|
if (dd == 0) {
|
|
|
|
/*
|
|
|
|
* Uninitialized field, return the epoch.
|
|
|
|
*/
|
|
|
|
tsp->tv_sec = 0;
|
|
|
|
tsp->tv_nsec = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
seconds = (((dt & DT_2SECONDS_MASK) >> DT_2SECONDS_SHIFT) << 1)
|
|
|
|
+ ((dt & DT_MINUTES_MASK) >> DT_MINUTES_SHIFT) * 60
|
|
|
|
+ ((dt & DT_HOURS_MASK) >> DT_HOURS_SHIFT) * 3600
|
|
|
|
+ dh / 100;
|
|
|
|
/*
|
|
|
|
* If the year, month, and day from the last conversion are the
|
|
|
|
* same then use the saved value.
|
|
|
|
*/
|
|
|
|
if (lastdosdate != dd) {
|
|
|
|
lastdosdate = dd;
|
|
|
|
days = 0;
|
|
|
|
year = (dd & DD_YEAR_MASK) >> DD_YEAR_SHIFT;
|
|
|
|
days = year * 365;
|
|
|
|
days += year / 4 + 1; /* add in leap days */
|
|
|
|
if ((year & 0x03) == 0)
|
|
|
|
days--; /* if year is a leap year */
|
|
|
|
months = year & 0x03 ? regyear : leapyear;
|
|
|
|
month = (dd & DD_MONTH_MASK) >> DD_MONTH_SHIFT;
|
|
|
|
if (month < 1 || month > 12) {
|
|
|
|
month = 1;
|
|
|
|
}
|
|
|
|
if (month > 1)
|
|
|
|
days += months[month - 2];
|
|
|
|
days += ((dd & DD_DAY_MASK) >> DD_DAY_SHIFT) - 1;
|
|
|
|
lastseconds = (days * 24 * 60 * 60) + SECONDSTO1980;
|
|
|
|
}
|
2003-02-03 19:49:35 +00:00
|
|
|
tsp->tv_sec = seconds + lastseconds + tz_minuteswest * 60 +
|
2000-04-05 10:44:04 +00:00
|
|
|
tzoff * 60 + (wall_cmos_clock ? adjkerntz : 0);
|
1999-10-02 04:06:24 +00:00
|
|
|
tsp->tv_nsec = (dh % 100) * 10000000;
|
|
|
|
}
|