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>
17 #include <afs/afsint.h>
19 #ifdef AFS_PTHREAD_ENV
21 #else /* AFS_PTHREAD_ENV */
22 #include <afs/assert.h>
23 #endif /* AFS_PTHREAD_ENV */
27 #if defined(AFS_SUN5_ENV) || defined(AFS_NT40_ENV)
33 #include <afs/assert.h>
37 #include <afs/afssyscalls.h>
41 #include "partition.h"
42 #include "viceinode.h"
47 #define afs_stat stat64
48 #else /* !O_LARGEFILE */
50 #endif /* !O_LARGEFILE */
52 /*@printflike@*/ extern void Log(const char *format, ...);
55 struct Lock localLock;
59 /* structure containing neatly packed set of inodes and the # of times we'll have
60 * to idec them in order to reclaim their storage. NukeProc, called by ListViceInodes,
61 * builds this list for us.
65 afs_int32 freePtr; /* first free index in this table */
66 Inode inode[MAXATONCE]; /* inode # */
67 afs_int32 count[MAXATONCE]; /* link count */
70 /* called with a structure specifying info about the inode, and our rock (which
71 * is the volume ID. Returns true if we should keep this inode, otherwise false.
72 * Note that ainfo->u.param[0] is always the volume ID, for any vice inode.
75 NukeProc(struct ViceInodeInfo *ainfo, afs_int32 avolid)
80 #ifndef AFS_PTHREAD_ENV
81 IOMGR_Poll(); /* poll so we don't kill the RPC connection */
82 #endif /* !AFS_PTHREAD_ENV */
84 /* check if this is the volume we're looking for */
85 if (ainfo->u.param[0] != avolid)
86 return 0; /* don't want this one */
88 if (!allInodes || allInodes->freePtr >= MAXATONCE) {
89 ti = (struct ilist *)malloc(sizeof(struct ilist));
90 memset(ti, 0, sizeof(*ti));
94 ti = allInodes; /* use the one with space */
95 i = ti->freePtr++; /* find our slot in this mess */
96 ti->inode[i] = ainfo->inodeNumber;
97 ti->count[i] = ainfo->linkCount;
98 return 0; /* don't care if anything's written out, actually */
101 /* function called with partition name and volid ID, and which removes all
102 * inodes marked with the specified volume ID. If the volume is a read-only
103 * clone, we'll only remove the header inodes, since they're the only inodes
104 * marked with that volume ID. If you want to reclaim all the data, you should
105 * nuke the read-write volume ID.
107 * Note also that nuking a read-write volume effectively nukes all RO volumes
108 * cloned from that RW volume ID, too, since everything except for their
109 * indices will be gone.
112 nuke(char *aname, afs_int32 avolid)
114 /* first process the partition containing this junk */
115 struct afs_stat tstat;
116 struct ilist *ti, *ni;
117 register afs_int32 code;
119 char devName[64], wpath[100];
128 #endif /* AFS_NAMEI_ENV */
133 code = afs_stat(aname, &tstat);
135 printf("volnuke: partition %s does not exist.\n", aname);
138 /* get the device name for the partition */
139 #if defined(AFS_NAMEI_ENV) && !defined(AFS_NT40_ENV)
143 lastDevComp = &aname[strlen(aname) - 1];
144 *lastDevComp = toupper(*lastDevComp);
147 char *tfile = vol_DevName(tstat.st_dev, wpath);
149 printf("volnuke: can't find %s's device.\n", aname);
152 strcpy(devName, tfile); /* save this from the static buffer */
154 /* aim lastDevComp at the 'foo' of '/dev/foo' */
155 lastDevComp = strrchr(devName, '/');
156 /* either points at slash, or there is no slash; adjust appropriately */
160 lastDevComp = devName;
161 #endif /* AFS_NT40_ENV */
162 #endif /* AFS_NAMEI_ENV && !AFS_NT40_ENV */
164 ObtainWriteLock(&localLock);
165 /* OK, we have the mounted on place, aname, the device name (in devName).
166 * all we need to do to call ListViceInodes is find the inodes for the
167 * volume we're nuking.
171 ListViceInodes(lastDevComp, aname, NULL, NukeProc, avolid, &forceSal,
175 ListViceInodes(lastDevComp, aname, "/tmp/vNukeXX", NukeProc, avolid,
176 &forceSal, 0, wpath);
177 unlink("/tmp/vNukeXX"); /* clean it up now */
180 /* actually do the idecs now */
181 for (ti = allInodes; ti; ti = ti->next) {
182 for (i = 0; i < ti->freePtr; i++) {
183 #ifndef AFS_PTHREAD_ENV
184 IOMGR_Poll(); /* keep RPC running */
185 #endif /* !AFS_PTHREAD_ENV */
186 /* idec this inode into oblivion */
189 IH_INIT(fileH, (int)(*lastDevComp - 'A'), avolid,
191 nt_HandleToName(path, fileH);
193 IH_INIT(fileH, (int)volutil_GetPartitionID(aname), avolid,
195 namei_HandleToName(&ufs_name, fileH);
196 path = ufs_name.n_path;
197 #endif /* AFS_NT40_ENV */
199 if (unlink(path) < 0) {
200 Log("Nuke: Failed to remove %s\n", path);
202 #else /* AFS_NAMEI_ENV */
203 IH_INIT(fileH, (int)tstat.st_dev, avolid, ti->inode[i]);
206 for (j = 0; j < ti->count[i]; j++) {
207 code = IH_DEC(fileH, ti->inode[i], avolid);
211 #endif /* AFS_NAMEI_ENV */
216 code = 0; /* we really don't care about it except for debugging */
219 /* at this point, we should try to remove the volume header file itself.
220 * the volume header file is the file named VNNNNN.vol in the UFS file
221 * system, and is a normal file. As such, it is not stamped with the
222 * volume's ID in its inode, and has to be removed explicitly.
224 /* reuse devName buffer now */
226 afs_snprintf(devName, sizeof devName, "%c:\\%s", *lastDevComp,
227 VolumeExternalName(avolid));
229 afs_snprintf(devName, sizeof devName, "%s/%s", aname,
230 VolumeExternalName(avolid));
231 #endif /* AFS_NT40_ENV */
232 code = unlink(devName);
236 /* just free things */
237 for (ti = allInodes; ti; ti = ni) {
243 ReleaseWriteLock(&localLock);