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_stream(struct pvfs_state *pvfs,
31 struct ntvfs_request *req,
32 struct pvfs_filename *name,
38 if (!name->stream_exists) {
39 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
42 /* make sure its matches the given attributes */
43 status = pvfs_match_attrib(pvfs, name, attrib, 0);
44 if (!NT_STATUS_IS_OK(status)) {
48 status = pvfs_can_delete(pvfs, req, name, &lck);
49 if (!NT_STATUS_IS_OK(status)) {
53 return pvfs_stream_delete(pvfs, name, -1);
60 static NTSTATUS pvfs_unlink_one(struct pvfs_state *pvfs,
61 struct ntvfs_request *req,
62 const char *unix_path,
63 const char *fname, uint32_t attrib)
65 struct pvfs_filename *name;
69 /* get a pvfs_filename object */
70 status = pvfs_resolve_partial(pvfs, req,
71 unix_path, fname, &name);
72 if (!NT_STATUS_IS_OK(status)) {
76 /* make sure its matches the given attributes */
77 status = pvfs_match_attrib(pvfs, name, attrib, 0);
78 if (!NT_STATUS_IS_OK(status)) {
83 status = pvfs_can_delete(pvfs, req, name, &lck);
84 if (!NT_STATUS_IS_OK(status)) {
89 if (name->dos.attrib & FILE_ATTRIBUTE_DIRECTORY) {
91 return NT_STATUS_FILE_IS_A_DIRECTORY;
94 if (name->st.st_nlink == 1) {
95 status = pvfs_xattr_unlink_hook(pvfs, name->full_name);
96 if (!NT_STATUS_IS_OK(status)) {
101 /* finally try the actual unlink */
102 if (unlink(name->full_name) == -1) {
103 status = pvfs_map_errno(pvfs, errno);
106 if (NT_STATUS_IS_OK(status)) {
107 notify_trigger(pvfs->notify_context,
108 NOTIFY_ACTION_REMOVED,
109 FILE_NOTIFY_CHANGE_FILE_NAME,
119 delete a file - the dirtype specifies the file types to include in the search.
120 The name can contain CIFS wildcards, but rarely does (except with OS/2 clients)
122 NTSTATUS pvfs_unlink(struct ntvfs_module_context *ntvfs,
123 struct ntvfs_request *req,
124 union smb_unlink *unl)
126 struct pvfs_state *pvfs = ntvfs->private_data;
127 struct pvfs_dir *dir;
129 uint32_t total_deleted=0;
130 struct pvfs_filename *name;
134 /* resolve the cifs name to a posix name */
135 status = pvfs_resolve_name(pvfs, req, unl->unlink.in.pattern,
136 PVFS_RESOLVE_WILDCARD | PVFS_RESOLVE_STREAMS, &name);
137 if (!NT_STATUS_IS_OK(status)) {
141 if (!name->exists && !name->has_wildcard) {
142 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
146 (name->dos.attrib & FILE_ATTRIBUTE_DIRECTORY)) {
147 return NT_STATUS_FILE_IS_A_DIRECTORY;
150 if (name->stream_name) {
151 return pvfs_unlink_stream(pvfs, req, name, unl->unlink.in.attrib);
154 /* get list of matching files */
155 status = pvfs_list_start(pvfs, name, req, &dir);
156 if (!NT_STATUS_IS_OK(status)) {
160 status = NT_STATUS_NO_SUCH_FILE;
164 while ((fname = pvfs_list_next(dir, &ofs))) {
165 /* this seems to be a special case */
166 if ((unl->unlink.in.attrib & FILE_ATTRIBUTE_DIRECTORY) &&
167 (ISDOT(fname) || ISDOTDOT(fname))) {
168 return NT_STATUS_OBJECT_NAME_INVALID;
171 status = pvfs_unlink_one(pvfs, req, pvfs_list_unix_path(dir), fname, unl->unlink.in.attrib);
172 if (NT_STATUS_IS_OK(status)) {
177 if (total_deleted > 0) {
178 status = NT_STATUS_OK;