Is it possible to delete a hardlink to a locked file?

4

In short, I need to do what was asked here:

One hardlink is locked. How do I remove the other?

The given solution doesn't work for me as I'm trying to create/delete a hardlink to a file that is in use by an application I can't stop and I expect to essentially run forever.

Is there truly no way to remove the link to a locked file? It seems odd to me that I can create the link but not remove it...

Morinar

Posted 2012-02-07T17:59:26.240

Reputation: 151

I don't know if hard links are affected by locks like that. They might be. You could try manually freeing the lock with something like Process Explorer, but that may make the application unstable. – Andrew Lambert – 2012-02-07T18:07:09.400

They definitely are. I have a file that is in use by an application and I can successfully create a hardlink to that file, however, I cannot delete the hardlink as the file is in use. – Morinar – 2012-02-07T18:08:24.640

possible duplicate of One hardlink is locked. How do I remove the other?

– Andrew Lambert – 2012-02-28T21:11:52.980

Answers

-1

Through combinations of "link shell extention" which messes with links. "take ownership" which messes with protections, and "unlocker" which can do deletes of locked file, and deletes at boot, You can do anything.

Disclaimer: Including destroying the whole system :-) So a full image backup (that works outside of the system, does not rely on the system, and works when the system is ruined) would be the first requirement.

Add in programs like "autoruns" , using "process explorer" and "resource monitor" , understanding cmd items "fsutil" , "net", "devcon" , and working elevated, or under the real admin, are handy things also. All usefull in further getting myself into more trouble , going to war with the new system.

No links are provided, because getting them is the easy part, just make sure you get them from source locations.

Psycogeek

Posted 2012-02-07T17:59:26.240

Reputation: 8 067

The question states that the locking application can't be stopped. So a method using Unlocker will not succeed since the lock will exist before Unlocker's driver is loaded. I don't know what you're suggesting be done with the Link Shell Extension, Autoruns, net, or fsutil; none of those can unlock a locked file. – Andrew Lambert – 2012-02-07T23:58:25.223

@Amazed There is no item that cannot be stopped, although some of them might stop the operation of the system. Then (right or wrong?) The last link cannot be removed without removing the last pointer to the data on the disk, effectivly deleting the item? So if a person is trying to remove the last link, wouldnt it be assumed they are trying to remove the file itself? I think you can come up with a better answer , I barely have my own machine under control. The reason for the other items is clear, they stop things, and can delete things that are not even visable. – Psycogeek – 2012-02-08T00:15:11.210

"In short" it was stated that morinar wanted to do what was on the link shown. The link is about breaking the link, and getting rid of the file. So if the intent is different, that is not very clear in the question. – Psycogeek – 2012-02-08T00:25:27.750

The question states that it can't be stopped. I take this to mean that the application is critical and therefore cannot be stopped because doing so would damage something, either physically or financially. Any solution which requires that the application be stopped removes the need to unlock the file in the first place. – Andrew Lambert – 2012-02-08T01:15:50.120

@Amazed if you know what the file item is or the service or driver or program that has it locked, please tell. Then i can attempt to write a step by step , by actually performing it here. (or trying to) – Psycogeek – 2012-02-08T01:50:29.140

I don't know what the file in question is. Only the asker knows at this point. – Andrew Lambert – 2012-02-08T02:06:28.373

If you want all the details: the locked file in question is the log for our database. I'm trying to write a Perl script that gathers up a bunch of files (one of which is this log) and then zips up the files so they can be brought in house for investigation. Due to limitations on our customers's systems, I'm using jar for creating the zip files. Jar on Windows is unable to resolve symbolic links properly (and Windows 2003 doesn't support them out of the box) so I wanted to use hardlinks. Regardless, it doesn't change the question: I want to delete a hardlink to a locked file programatically. – Morinar – 2012-02-08T15:32:54.127

Also, I'm using hardlink/symlinks in the first place because jar doesn't support the ability to place files into arbitrary places in an archive. I could just copy the files, but some of them have the potential to be large, thus the desire to use hard/symlinks. – Morinar – 2012-02-08T15:33:50.617

@Morinar programatically is beyond the scope of SU. Programs that want to do similar would temporarily stop the program with the lock. Or use thier own programs to write the log out. You want a log that is locked because it is open for writes? to be able to have the data in it be capturable , using script. That would be similar to pulling the systems own logs while they are locked. Where does removing the hardlink become required? At any rate it is beyond my skills, but presents a challenge of accomplishing the same thing on the systems own logs, which would be similar. – Psycogeek – 2012-02-08T19:29:55.767

Some stuff on the web suggests that a log for like SQL CAN be read by another program while it is locked by the other. http://www.geekzilla.co.uk/viewD21B312F-242A-4038-9E9B-AE6AAB53DAE0.htm including some info from MS. Although on the most part the first thing a person would see is "impossible"

– Psycogeek – 2012-02-08T20:07:34.957

Here is some pearl based backup (web find ideas) http://www.lenzg.net/mylvmbackup/mylvmbackup.1.html for databases, looks like a quick "stop and grab" method, and a "hooks" method. ??? the code itself is just a blur to me, I am trying to find backup methods for databases.

– Psycogeek – 2012-02-08T20:33:54.247

Pearl for reading event logs, which is probably easy, the nature of them is not all locked down/constant? http://oreilly.com/catalog/perlsysadm/chapter/ch09.html rotation, circular bufffer, and streaming. Looks to me like if you want an easy answer to reading locked logs with pearl scripting it would be at the programmers location, a pearl expert.

– Psycogeek – 2012-02-08T20:57:40.750