📄 vfs_cifs.c
字号:
struct smbcli_request *c_req; SETUP_PID; if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) { return smb_raw_rmdir(private->tree, rd); } c_req = smb_raw_rmdir_send(private->tree, rd); SIMPLE_ASYNC_TAIL;}/* rename a set of files*/static NTSTATUS cvfs_rename(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, union smb_rename *ren){ struct cvfs_private *private = ntvfs->private_data; struct smbcli_request *c_req; SETUP_PID; if (ren->nttrans.level == RAW_RENAME_NTTRANS) { struct cvfs_file *f; f = ntvfs_handle_get_backend_data(ren->nttrans.in.file.ntvfs, ntvfs); if (!f) return NT_STATUS_INVALID_HANDLE; ren->nttrans.in.file.fnum = f->fnum; } if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) { return smb_raw_rename(private->tree, ren); } c_req = smb_raw_rename_send(private->tree, ren); SIMPLE_ASYNC_TAIL;}/* copy a set of files*/static NTSTATUS cvfs_copy(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, struct smb_copy *cp){ return NT_STATUS_NOT_SUPPORTED;}/* a handler for async read replies */static void async_read(struct smbcli_request *c_req){ struct async_info *async = c_req->async.private; struct ntvfs_request *req = async->req; req->async_states->status = smb_raw_read_recv(c_req, async->parms); talloc_free(async); req->async_states->send_fn(req);}/* read from a file*/static NTSTATUS cvfs_read(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, union smb_read *io){ struct cvfs_private *private = ntvfs->private_data; struct smbcli_request *c_req; SETUP_PID; if (io->generic.level != RAW_READ_GENERIC && private->map_generic) { return ntvfs_map_read(ntvfs, req, io); } SETUP_FILE; if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) { return smb_raw_read(private->tree, io); } c_req = smb_raw_read_send(private->tree, io); ASYNC_RECV_TAIL(io, async_read);}/* a handler for async write replies */static void async_write(struct smbcli_request *c_req){ struct async_info *async = c_req->async.private; struct ntvfs_request *req = async->req; req->async_states->status = smb_raw_write_recv(c_req, async->parms); talloc_free(async); req->async_states->send_fn(req);}/* write to a file*/static NTSTATUS cvfs_write(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, union smb_write *io){ struct cvfs_private *private = ntvfs->private_data; struct smbcli_request *c_req; SETUP_PID; if (io->generic.level != RAW_WRITE_GENERIC && private->map_generic) { return ntvfs_map_write(ntvfs, req, io); } SETUP_FILE; if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) { return smb_raw_write(private->tree, io); } c_req = smb_raw_write_send(private->tree, io); ASYNC_RECV_TAIL(io, async_write);}/* a handler for async seek replies */static void async_seek(struct smbcli_request *c_req){ struct async_info *async = c_req->async.private; struct ntvfs_request *req = async->req; req->async_states->status = smb_raw_seek_recv(c_req, async->parms); talloc_free(async); req->async_states->send_fn(req);}/* seek in a file*/static NTSTATUS cvfs_seek(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, union smb_seek *io){ struct cvfs_private *private = ntvfs->private_data; struct smbcli_request *c_req; SETUP_PID_AND_FILE; if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) { return smb_raw_seek(private->tree, io); } c_req = smb_raw_seek_send(private->tree, io); ASYNC_RECV_TAIL(io, async_seek);}/* flush a file*/static NTSTATUS cvfs_flush(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, union smb_flush *io){ struct cvfs_private *private = ntvfs->private_data; struct smbcli_request *c_req; SETUP_PID; switch (io->generic.level) { case RAW_FLUSH_FLUSH: SETUP_FILE; break; case RAW_FLUSH_ALL: io->generic.in.file.fnum = 0xFFFF; break; case RAW_FLUSH_SMB2: return NT_STATUS_INVALID_LEVEL; } if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) { return smb_raw_flush(private->tree, io); } c_req = smb_raw_flush_send(private->tree, io); SIMPLE_ASYNC_TAIL;}/* close a file*/static NTSTATUS cvfs_close(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, union smb_close *io){ struct cvfs_private *private = ntvfs->private_data; struct smbcli_request *c_req; struct cvfs_file *f; union smb_close io2; SETUP_PID; if (io->generic.level != RAW_CLOSE_GENERIC && private->map_generic) { return ntvfs_map_close(ntvfs, req, io); } if (io->generic.level == RAW_CLOSE_GENERIC) { ZERO_STRUCT(io2); io2.close.level = RAW_CLOSE_CLOSE; io2.close.in.file = io->generic.in.file; io2.close.in.write_time = io->generic.in.write_time; io = &io2; } SETUP_FILE_HERE(f); /* Note, we aren't free-ing f, or it's h here. Should we? even if file-close fails, we'll remove it from the list, what else would we do? Maybe we should not remove until after the proxied call completes? */ DLIST_REMOVE(private->files, f); if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) { return smb_raw_close(private->tree, io); } c_req = smb_raw_close_send(private->tree, io); SIMPLE_ASYNC_TAIL;}/* exit - closing files open by the pid*/static NTSTATUS cvfs_exit(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req){ struct cvfs_private *private = ntvfs->private_data; struct smbcli_request *c_req; SETUP_PID; if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) { return smb_raw_exit(private->tree->session); } c_req = smb_raw_exit_send(private->tree->session); SIMPLE_ASYNC_TAIL;}/* logoff - closing files open by the user*/static NTSTATUS cvfs_logoff(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req){ /* we can't do this right in the cifs backend .... */ return NT_STATUS_OK;}/* setup for an async call - nothing to do yet*/static NTSTATUS cvfs_async_setup(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, void *private){ return NT_STATUS_OK;}/* cancel an async call*/static NTSTATUS cvfs_cancel(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req){ struct cvfs_private *private = ntvfs->private_data; struct async_info *a; /* find the matching request */ for (a=private->pending;a;a=a->next) { if (a->req == req) { break; } } if (a == NULL) { return NT_STATUS_INVALID_PARAMETER; } return smb_raw_ntcancel(a->c_req);}/* lock a byte range*/static NTSTATUS cvfs_lock(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, union smb_lock *io){ struct cvfs_private *private = ntvfs->private_data; struct smbcli_request *c_req; SETUP_PID; if (io->generic.level != RAW_LOCK_GENERIC && private->map_generic) { return ntvfs_map_lock(ntvfs, req, io); } SETUP_FILE; if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) { return smb_raw_lock(private->tree, io); } c_req = smb_raw_lock_send(private->tree, io); SIMPLE_ASYNC_TAIL;}/* set info on a open file*/static NTSTATUS cvfs_setfileinfo(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, union smb_setfileinfo *io){ struct cvfs_private *private = ntvfs->private_data; struct smbcli_request *c_req; SETUP_PID_AND_FILE; if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) { return smb_raw_setfileinfo(private->tree, io); } c_req = smb_raw_setfileinfo_send(private->tree, io); SIMPLE_ASYNC_TAIL;}/* a handler for async fsinfo replies */static void async_fsinfo(struct smbcli_request *c_req){ struct async_info *async = c_req->async.private; struct ntvfs_request *req = async->req; req->async_states->status = smb_raw_fsinfo_recv(c_req, req, async->parms); talloc_free(async); req->async_states->send_fn(req);}/* return filesystem space info*/static NTSTATUS cvfs_fsinfo(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, union smb_fsinfo *fs){ struct cvfs_private *private = ntvfs->private_data; struct smbcli_request *c_req; SETUP_PID; if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) { return smb_raw_fsinfo(private->tree, req, fs); } c_req = smb_raw_fsinfo_send(private->tree, req, fs); ASYNC_RECV_TAIL(fs, async_fsinfo);}/* return print queue info*/static NTSTATUS cvfs_lpq(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, union smb_lpq *lpq){ return NT_STATUS_NOT_SUPPORTED;}/* list files in a directory matching a wildcard pattern*/static NTSTATUS cvfs_search_first(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, union smb_search_first *io, void *search_private, bool (*callback)(void *, const union smb_search_data *)){ struct cvfs_private *private = ntvfs->private_data; SETUP_PID; return smb_raw_search_first(private->tree, req, io, search_private, callback);}/* continue a search */static NTSTATUS cvfs_search_next(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, union smb_search_next *io, void *search_private, bool (*callback)(void *, const union smb_search_data *)){ struct cvfs_private *private = ntvfs->private_data; SETUP_PID; return smb_raw_search_next(private->tree, req, io, search_private, callback);}/* close a search */static NTSTATUS cvfs_search_close(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, union smb_search_close *io){ struct cvfs_private *private = ntvfs->private_data; SETUP_PID; return smb_raw_search_close(private->tree, io);}/* a handler for async trans2 replies */static void async_trans2(struct smbcli_request *c_req){ struct async_info *async = c_req->async.private; struct ntvfs_request *req = async->req; req->async_states->status = smb_raw_trans2_recv(c_req, req, async->parms); talloc_free(async); req->async_states->send_fn(req);}/* raw trans2 */static NTSTATUS cvfs_trans2(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, struct smb_trans2 *trans2){ struct cvfs_private *private = ntvfs->private_data; struct smbcli_request *c_req; if (private->map_trans2) { return NT_STATUS_NOT_IMPLEMENTED; } SETUP_PID; if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) { return smb_raw_trans2(private->tree, req, trans2); } c_req = smb_raw_trans2_send(private->tree, trans2); ASYNC_RECV_TAIL(trans2, async_trans2);}/* SMBtrans - not used on file shares */static NTSTATUS cvfs_trans(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, struct smb_trans2 *trans2){ return NT_STATUS_ACCESS_DENIED;}/* a handler for async change notify replies */static void async_changenotify(struct smbcli_request *c_req){ struct async_info *async = c_req->async.private; struct ntvfs_request *req = async->req; req->async_states->status = smb_raw_changenotify_recv(c_req, req, async->parms); talloc_free(async); req->async_states->send_fn(req);}/* change notify request - always async */static NTSTATUS cvfs_notify(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, union smb_notify *io){ struct cvfs_private *private = ntvfs->private_data; struct smbcli_request *c_req; int saved_timeout = private->transport->options.request_timeout; struct cvfs_file *f; if (io->nttrans.level != RAW_NOTIFY_NTTRANS) { return NT_STATUS_NOT_IMPLEMENTED; } SETUP_PID; f = ntvfs_handle_get_backend_data(io->nttrans.in.file.ntvfs, ntvfs); if (!f) return NT_STATUS_INVALID_HANDLE; io->nttrans.in.file.fnum = f->fnum; /* this request doesn't make sense unless its async */ if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) { return NT_STATUS_INVALID_PARAMETER; } /* we must not timeout on notify requests - they wait forever */ private->transport->options.request_timeout = 0; c_req = smb_raw_changenotify_send(private->tree, io); private->transport->options.request_timeout = saved_timeout; ASYNC_RECV_TAIL(io, async_changenotify);}/* initialise the CIFS->CIFS backend, registering ourselves with the ntvfs subsystem */NTSTATUS ntvfs_cifs_init(void){ NTSTATUS ret; struct ntvfs_ops ops; NTVFS_CURRENT_CRITICAL_SIZES(vers); ZERO_STRUCT(ops); /* fill in the name and type */ ops.name = "cifs"; ops.type = NTVFS_DISK; /* fill in all the operations */ ops.connect = cvfs_connect; ops.disconnect = cvfs_disconnect; ops.unlink = cvfs_unlink; ops.chkpath = cvfs_chkpath; ops.qpathinfo = cvfs_qpathinfo; ops.setpathinfo = cvfs_setpathinfo; ops.open = cvfs_open; ops.mkdir = cvfs_mkdir; ops.rmdir = cvfs_rmdir; ops.rename = cvfs_rename; ops.copy = cvfs_copy; ops.ioctl = cvfs_ioctl; ops.read = cvfs_read; ops.write = cvfs_write; ops.seek = cvfs_seek; ops.flush = cvfs_flush; ops.close = cvfs_close; ops.exit = cvfs_exit; ops.lock = cvfs_lock; ops.setfileinfo = cvfs_setfileinfo; ops.qfileinfo = cvfs_qfileinfo; ops.fsinfo = cvfs_fsinfo; ops.lpq = cvfs_lpq; ops.search_first = cvfs_search_first; ops.search_next = cvfs_search_next; ops.search_close = cvfs_search_close; ops.trans = cvfs_trans; ops.logoff = cvfs_logoff; ops.async_setup = cvfs_async_setup; ops.cancel = cvfs_cancel; ops.notify = cvfs_notify; ops.trans2 = cvfs_trans2; /* register ourselves with the NTVFS subsystem. We register under the name 'cifs'. */ ret = ntvfs_register(&ops, &vers); if (!NT_STATUS_IS_OK(ret)) { DEBUG(0,("Failed to register CIFS backend!\n")); } return ret;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -