2 Unix SMB/CIFS implementation.
4 POSIX NTVFS backend - unlink
6 Copyright (C) Andrew Tridgell 2004
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "vfs_posix.h"
24 #include "system/dir.h"
30 static NTSTATUS pvfs_unlink_file(struct pvfs_state *pvfs,
31 struct pvfs_filename *name)
35 if (name->dos.attrib & FILE_ATTRIBUTE_DIRECTORY) {
36 return NT_STATUS_FILE_IS_A_DIRECTORY;
39 if (name->st.st_nlink == 1) {
40 status = pvfs_xattr_unlink_hook(pvfs, name->full_name);
41 if (!NT_STATUS_IS_OK(status)) {
46 /* finally try the actual unlink */
47 if (unlink(name->full_name) == -1) {
48 status = pvfs_map_errno(pvfs, errno);
51 if (NT_STATUS_IS_OK(status)) {
52 notify_trigger(pvfs->notify_context,
53 NOTIFY_ACTION_REMOVED,
54 FILE_NOTIFY_CHANGE_FILE_NAME,
64 static NTSTATUS pvfs_unlink_one(struct pvfs_state *pvfs,
65 struct ntvfs_request *req,
66 union smb_unlink *unl,
67 struct pvfs_filename *name)
71 /* make sure its matches the given attributes */
72 status = pvfs_match_attrib(pvfs, name,
73 unl->unlink.in.attrib, 0);
74 if (!NT_STATUS_IS_OK(status)) {
78 status = pvfs_can_delete(pvfs, req, name, NULL);
79 if (!NT_STATUS_IS_OK(status)) {
83 if (name->stream_name) {
84 if (!name->stream_exists) {
85 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
88 return pvfs_stream_delete(pvfs, name, -1);
91 return pvfs_unlink_file(pvfs, name);
95 delete a file - the dirtype specifies the file types to include in the search.
96 The name can contain CIFS wildcards, but rarely does (except with OS/2 clients)
98 NTSTATUS pvfs_unlink(struct ntvfs_module_context *ntvfs,
99 struct ntvfs_request *req,
100 union smb_unlink *unl)
102 struct pvfs_state *pvfs = ntvfs->private_data;
103 struct pvfs_dir *dir;
105 uint32_t total_deleted=0;
106 struct pvfs_filename *name;
110 /* resolve the cifs name to a posix name */
111 status = pvfs_resolve_name(pvfs, req, unl->unlink.in.pattern,
112 PVFS_RESOLVE_WILDCARD | PVFS_RESOLVE_STREAMS, &name);
113 if (!NT_STATUS_IS_OK(status)) {
117 if (!name->exists && !name->has_wildcard) {
118 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
122 (name->dos.attrib & FILE_ATTRIBUTE_DIRECTORY)) {
123 return NT_STATUS_FILE_IS_A_DIRECTORY;
126 if (!name->has_wildcard) {
127 return pvfs_unlink_one(pvfs, req, unl, name);
130 /* get list of matching files */
131 status = pvfs_list_start(pvfs, name, req, &dir);
132 if (!NT_STATUS_IS_OK(status)) {
136 status = NT_STATUS_NO_SUCH_FILE;
141 while ((fname = pvfs_list_next(dir, &ofs))) {
142 /* this seems to be a special case */
143 if ((unl->unlink.in.attrib & FILE_ATTRIBUTE_DIRECTORY) &&
144 (ISDOT(fname) || ISDOTDOT(fname))) {
145 return NT_STATUS_OBJECT_NAME_INVALID;
148 /* get a pvfs_filename object */
149 status = pvfs_resolve_partial(pvfs, req,
150 pvfs_list_unix_path(dir),
152 if (!NT_STATUS_IS_OK(status)) {
156 status = pvfs_unlink_one(pvfs, req, unl, name);
157 if (NT_STATUS_IS_OK(status)) {
164 if (total_deleted > 0) {
165 status = NT_STATUS_OK;