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 #include <afs/afs_assert.h>
21 #if defined(AFS_SUN5_ENV) || defined(AFS_NT40_ENV)
30 #include <afs/afsutil.h>
35 #include <afs/afssyscalls.h>
39 #include "partition.h"
40 #include "viceinode.h"
42 #include "daemon_com.h"
47 #define afs_stat stat64
48 #else /* !O_LARGEFILE */
50 #endif /* !O_LARGEFILE */
52 struct Lock localLock;
55 /* structure containing neatly packed set of inodes and the # of times we'll have
56 * to idec them in order to reclaim their storage. NukeProc, called by ListViceInodes,
57 * builds this list for us.
61 afs_int32 freePtr; /* first free index in this table */
62 Inode inode[MAXATONCE]; /* inode # */
63 afs_int32 count[MAXATONCE]; /* link count */
66 /* called with a structure specifying info about the inode, and our rock (which
67 * is the volume ID. Returns true if we should keep this inode, otherwise false.
68 * Note that ainfo->u.param[0] is always the volume ID, for any vice inode.
71 NukeProc(struct ViceInodeInfo *ainfo, afs_uint32 avolid, void *arock)
73 struct ilist **allInodes = (struct ilist **)arock;
77 #ifndef AFS_PTHREAD_ENV
78 IOMGR_Poll(); /* poll so we don't kill the RPC connection */
79 #endif /* !AFS_PTHREAD_ENV */
81 /* check if this is the volume we're looking for */
82 if (ainfo->u.param[0] != avolid)
83 return 0; /* don't want this one */
85 if (!*allInodes || (*allInodes)->freePtr >= MAXATONCE) {
86 ti = (struct ilist *)malloc(sizeof(struct ilist));
87 memset(ti, 0, sizeof(*ti));
88 ti->next = *allInodes;
91 ti = *allInodes; /* use the one with space */
92 i = ti->freePtr++; /* find our slot in this mess */
93 ti->inode[i] = ainfo->inodeNumber;
94 ti->count[i] = ainfo->linkCount;
95 return 0; /* don't care if anything's written out, actually */
98 /* function called with partition name and volid ID, and which removes all
99 * inodes marked with the specified volume ID. If the volume is a read-only
100 * clone, we'll only remove the header inodes, since they're the only inodes
101 * marked with that volume ID. If you want to reclaim all the data, you should
102 * nuke the read-write volume ID.
104 * Note also that nuking a read-write volume effectively nukes all RO volumes
105 * cloned from that RW volume ID, too, since everything except for their
106 * indices will be gone.
109 nuke(char *aname, afs_int32 avolid)
111 /* first process the partition containing this junk */
112 struct afs_stat tstat;
113 struct ilist *ti, *ni, *li=NULL;
118 struct DiskPartition64 *dp;
126 #endif /* AFS_NAMEI_ENV */
127 #ifndef AFS_NAMEI_ENV
129 #endif /* !AFS_NAMEI_ENV */
131 struct ilist *allInodes = 0;
135 code = afs_stat(aname, &tstat);
136 if (code || (dp = VGetPartition(aname, 0)) == NULL) {
137 printf("volnuke: partition %s does not exist.\n", aname);
143 /* get the device name for the partition */
144 #if defined(AFS_NAMEI_ENV) && !defined(AFS_NT40_ENV)
148 lastDevComp = &aname[strlen(aname) - 1];
149 *lastDevComp = toupper(*lastDevComp);
152 char *tfile = vol_DevName(tstat.st_dev, wpath);
154 printf("volnuke: can't find %s's device.\n", aname);
157 strcpy(devName, tfile); /* save this from the static buffer */
159 /* aim lastDevComp at the 'foo' of '/dev/foo' */
160 lastDevComp = strrchr(devName, '/');
161 /* either points at slash, or there is no slash; adjust appropriately */
165 lastDevComp = devName;
166 #endif /* AFS_NT40_ENV */
167 #endif /* AFS_NAMEI_ENV && !AFS_NT40_ENV */
169 ObtainWriteLock(&localLock);
170 /* OK, we have the mounted on place, aname, the device name (in devName).
171 * all we need to do to call ListViceInodes is find the inodes for the
172 * volume we're nuking.
175 ListViceInodes(lastDevComp, aname, NULL, NukeProc, avolid, &forceSal,
176 0, wpath, &allInodes);
178 /* actually do the idecs now */
179 for (ti = allInodes; ti; ti = ti->next) {
180 for (i = 0; i < ti->freePtr; i++) {
181 #ifndef AFS_PTHREAD_ENV
182 IOMGR_Poll(); /* keep RPC running */
183 #endif /* !AFS_PTHREAD_ENV */
184 /* idec this inode into oblivion */
187 IH_INIT(fileH, (int)(*lastDevComp - 'A'), avolid,
189 nt_HandleToName(path, fileH);
191 IH_INIT(fileH, (int)volutil_GetPartitionID(aname), avolid,
193 namei_HandleToName(&ufs_name, fileH);
194 path = ufs_name.n_path;
195 #endif /* AFS_NT40_ENV */
197 if (unlink(path) < 0) {
198 Log("Nuke: Failed to remove %s\n", path);
200 #else /* AFS_NAMEI_ENV */
201 IH_INIT(fileH, (int)tstat.st_dev, avolid, ti->inode[i]);
204 for (j = 0; j < ti->count[i]; j++) {
205 code = IH_DEC(fileH, ti->inode[i], avolid);
209 #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 code = VDestroyVolumeDiskHeader(dp, avolid, 0);
226 /* just free things */
227 for (ti = allInodes; ti; ti = ni) {
235 ReleaseWriteLock(&localLock);