2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
15 #include <afs/afsint.h>
17 #ifdef AFS_PTHREAD_ENV
19 #else /* AFS_PTHREAD_ENV */
20 #include <afs/assert.h>
21 #endif /* AFS_PTHREAD_ENV */
25 #if defined(AFS_SUN5_ENV) || defined(AFS_NT40_ENV)
34 #include <afs/afsutil.h>
39 #include <afs/afssyscalls.h>
43 #include "partition.h"
44 #include "viceinode.h"
46 #include "daemon_com.h"
50 #define afs_stat stat64
51 #else /* !O_LARGEFILE */
53 #endif /* !O_LARGEFILE */
55 /*@printflike@*/ extern void Log(const char *format, ...);
58 struct Lock localLock;
61 /* structure containing neatly packed set of inodes and the # of times we'll have
62 * to idec them in order to reclaim their storage. NukeProc, called by ListViceInodes,
63 * builds this list for us.
67 afs_int32 freePtr; /* first free index in this table */
68 Inode inode[MAXATONCE]; /* inode # */
69 afs_int32 count[MAXATONCE]; /* link count */
72 /* called with a structure specifying info about the inode, and our rock (which
73 * is the volume ID. Returns true if we should keep this inode, otherwise false.
74 * Note that ainfo->u.param[0] is always the volume ID, for any vice inode.
77 NukeProc(struct ViceInodeInfo *ainfo, afs_uint32 avolid, void *arock)
79 struct ilist **allInodes = (struct ilist **)arock;
83 #ifndef AFS_PTHREAD_ENV
84 IOMGR_Poll(); /* poll so we don't kill the RPC connection */
85 #endif /* !AFS_PTHREAD_ENV */
87 /* check if this is the volume we're looking for */
88 if (ainfo->u.param[0] != avolid)
89 return 0; /* don't want this one */
91 if (!*allInodes || (*allInodes)->freePtr >= MAXATONCE) {
92 ti = (struct ilist *)malloc(sizeof(struct ilist));
93 memset(ti, 0, sizeof(*ti));
94 ti->next = *allInodes;
97 ti = *allInodes; /* use the one with space */
98 i = ti->freePtr++; /* find our slot in this mess */
99 ti->inode[i] = ainfo->inodeNumber;
100 ti->count[i] = ainfo->linkCount;
101 return 0; /* don't care if anything's written out, actually */
104 /* function called with partition name and volid ID, and which removes all
105 * inodes marked with the specified volume ID. If the volume is a read-only
106 * clone, we'll only remove the header inodes, since they're the only inodes
107 * marked with that volume ID. If you want to reclaim all the data, you should
108 * nuke the read-write volume ID.
110 * Note also that nuking a read-write volume effectively nukes all RO volumes
111 * cloned from that RW volume ID, too, since everything except for their
112 * indices will be gone.
115 nuke(char *aname, afs_int32 avolid)
117 /* first process the partition containing this junk */
118 struct afs_stat tstat;
119 struct ilist *ti, *ni, *li=NULL;
120 register afs_int32 code;
124 struct DiskPartition64 *dp;
132 #endif /* AFS_NAMEI_ENV */
133 #ifndef AFS_NAMEI_ENV
135 #endif /* !AFS_NAMEI_ENV */
137 struct ilist *allInodes = 0;
141 code = afs_stat(aname, &tstat);
142 if (code || (dp = VGetPartition(aname, 0)) == NULL) {
143 printf("volnuke: partition %s does not exist.\n", aname);
149 /* get the device name for the partition */
150 #if defined(AFS_NAMEI_ENV) && !defined(AFS_NT40_ENV)
154 lastDevComp = &aname[strlen(aname) - 1];
155 *lastDevComp = toupper(*lastDevComp);
158 char *tfile = vol_DevName(tstat.st_dev, wpath);
160 printf("volnuke: can't find %s's device.\n", aname);
163 strcpy(devName, tfile); /* save this from the static buffer */
165 /* aim lastDevComp at the 'foo' of '/dev/foo' */
166 lastDevComp = strrchr(devName, '/');
167 /* either points at slash, or there is no slash; adjust appropriately */
171 lastDevComp = devName;
172 #endif /* AFS_NT40_ENV */
173 #endif /* AFS_NAMEI_ENV && !AFS_NT40_ENV */
175 ObtainWriteLock(&localLock);
176 /* OK, we have the mounted on place, aname, the device name (in devName).
177 * all we need to do to call ListViceInodes is find the inodes for the
178 * volume we're nuking.
181 ListViceInodes(lastDevComp, aname, NULL, NukeProc, avolid, &forceSal,
182 0, wpath, &allInodes);
184 /* actually do the idecs now */
185 for (ti = allInodes; ti; ti = ti->next) {
186 for (i = 0; i < ti->freePtr; i++) {
187 #ifndef AFS_PTHREAD_ENV
188 IOMGR_Poll(); /* keep RPC running */
189 #endif /* !AFS_PTHREAD_ENV */
190 /* idec this inode into oblivion */
193 IH_INIT(fileH, (int)(*lastDevComp - 'A'), avolid,
195 nt_HandleToName(path, fileH);
197 IH_INIT(fileH, (int)volutil_GetPartitionID(aname), avolid,
199 namei_HandleToName(&ufs_name, fileH);
200 path = ufs_name.n_path;
201 #endif /* AFS_NT40_ENV */
203 if (unlink(path) < 0) {
204 Log("Nuke: Failed to remove %s\n", path);
206 #else /* AFS_NAMEI_ENV */
207 IH_INIT(fileH, (int)tstat.st_dev, avolid, ti->inode[i]);
210 for (j = 0; j < ti->count[i]; j++) {
211 code = IH_DEC(fileH, ti->inode[i], avolid);
215 #endif /* AFS_NAMEI_ENV */
222 code = 0; /* we really don't care about it except for debugging */
225 /* at this point, we should try to remove the volume header file itself.
226 * the volume header file is the file named VNNNNN.vol in the UFS file
227 * system, and is a normal file. As such, it is not stamped with the
228 * volume's ID in its inode, and has to be removed explicitly.
230 code = VDestroyVolumeDiskHeader(dp, avolid, 0);
232 /* just free things */
233 for (ti = allInodes; ti; ti = ni) {
241 ReleaseWriteLock(&localLock);