-
- if (cp->c_flag & C_HARDLINK) {
- lockflags = hfs_systemfile_lock(hfsmp, SFL_CATALOG, HFS_EXCLUSIVE_LOCK);
-
- /* Delete the link record */
- error = cat_delete(hfsmp, &desc, &cp->c_attr);
- if (error == 0) {
- /* Update the parent directory */
- if (dcp->c_entries > 0)
- dcp->c_entries--;
- if (dcp->c_nlink > 0)
- dcp->c_nlink--;
- dcp->c_ctime = tv.tv_sec;
- dcp->c_mtime = tv.tv_sec;
- (void ) cat_update(hfsmp, &dcp->c_desc, &dcp->c_attr, NULL, NULL);
-
- if (--cp->c_nlink < 1) {
- char inodename[32];
- char delname[32];
- struct cat_desc to_desc;
- struct cat_desc from_desc;
-
- /*
- * This is now esentially an open deleted file.
- * Rename it to reflect this state which makes
- * orphan file cleanup easier (see hfs_remove_orphans).
- * Note: a rename failure here is not fatal.
- */
- MAKE_INODE_NAME(inodename, cp->c_rdev);
- bzero(&from_desc, sizeof(from_desc));
- from_desc.cd_nameptr = inodename;
- from_desc.cd_namelen = strlen(inodename);
- from_desc.cd_parentcnid = hfsmp->hfs_privdir_desc.cd_cnid;
- from_desc.cd_flags = 0;
- from_desc.cd_cnid = cp->c_fileid;
-
- MAKE_DELETED_NAME(delname, cp->c_fileid);
- bzero(&to_desc, sizeof(to_desc));
- to_desc.cd_nameptr = delname;
- to_desc.cd_namelen = strlen(delname);
- to_desc.cd_parentcnid = hfsmp->hfs_privdir_desc.cd_cnid;
- to_desc.cd_flags = 0;
- to_desc.cd_cnid = cp->c_fileid;
-
- error = cat_rename(hfsmp, &from_desc, &hfsmp->hfs_privdir_desc,
- &to_desc, (struct cat_desc *)NULL);
- if (error != 0) {
- panic("hfs_removefile: error %d from cat_rename(%s %s) cp 0x%x\n",
- inodename, delname, cp);
- }
- if (error == 0) {
- /* Update the file's state */
- cp->c_flag |= C_DELETED;
- cp->c_ctime = tv.tv_sec;
- (void) cat_update(hfsmp, &to_desc, &cp->c_attr, NULL, NULL);
- }
- } else {
- /* Update the file's state */
- cp->c_ctime = tv.tv_sec;
- (void) cat_update(hfsmp, &cp->c_desc, &cp->c_attr, NULL, NULL);
- }
- }
- hfs_systemfile_unlock(hfsmp, lockflags);
- if (error != 0)
- goto out;
-
- hfs_volupdate(hfsmp, VOL_RMFILE, (dcp->c_cnid == kHFSRootFolderID));
-
- } else if (dataforkbusy || rsrcforkbusy || isbigfile) {