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 2 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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "vfs_posix.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, NOTIFY_ACTION_REMOVED,
117 delete a file - the dirtype specifies the file types to include in the search.
118 The name can contain CIFS wildcards, but rarely does (except with OS/2 clients)
120 NTSTATUS pvfs_unlink(struct ntvfs_module_context *ntvfs,
121 struct ntvfs_request *req,
122 union smb_unlink *unl)
124 struct pvfs_state *pvfs = ntvfs->private_data;
125 struct pvfs_dir *dir;
127 uint32_t total_deleted=0;
128 struct pvfs_filename *name;
132 /* resolve the cifs name to a posix name */
133 status = pvfs_resolve_name(pvfs, req, unl->unlink.in.pattern,
134 PVFS_RESOLVE_WILDCARD | PVFS_RESOLVE_STREAMS, &name);
135 if (!NT_STATUS_IS_OK(status)) {
139 if (!name->exists && !name->has_wildcard) {
140 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
144 (name->dos.attrib & FILE_ATTRIBUTE_DIRECTORY)) {
145 return NT_STATUS_FILE_IS_A_DIRECTORY;
148 if (name->stream_name) {
149 return pvfs_unlink_stream(pvfs, req, name, unl->unlink.in.attrib);
152 /* get list of matching files */
153 status = pvfs_list_start(pvfs, name, req, &dir);
154 if (!NT_STATUS_IS_OK(status)) {
158 status = NT_STATUS_NO_SUCH_FILE;
162 while ((fname = pvfs_list_next(dir, &ofs))) {
163 /* this seems to be a special case */
164 if ((unl->unlink.in.attrib & FILE_ATTRIBUTE_DIRECTORY) &&
165 (strcmp(fname, ".") == 0 ||
166 strcmp(fname, "..") == 0)) {
167 return NT_STATUS_OBJECT_NAME_INVALID;
170 status = pvfs_unlink_one(pvfs, req, pvfs_list_unix_path(dir), fname, unl->unlink.in.attrib);
171 if (NT_STATUS_IS_OK(status)) {
176 if (total_deleted > 0) {
177 status = NT_STATUS_OK;