open.itworld.com
  Search  
Security Home Page Security Webcasts Security White Papers Security Newsletters Security News Open Topics Careers ITworld Voices ITwhirled The Security site of ITworld.com

Unix Tip: The directory that wasn't

ITworld.com 10/11/2006

Sandra Henry-Stocker, ITworld.com

Digg!

Send in your Unix questions today! | See additional Unix tips and tricks

I'm not exactly sure how this came about, but I recently found myself with a directory that didn't contain the standard "." and ".." directories that would have properly tied it into the file system. To fix the immediate problem, I moved the troublesome directory (using mv) and created a new one. When I tried to remove the (then renamed) directory, I found that I couldn't.

First, I tried the obvious. I tried removing the directory with rm, rmdir, rm -f and rm -rf. None of these commands worked for me.

# rm huh
rm: huh is a directory
# rmdir huh
rmdir: directory "huh": Directory not empty
# rm -f huh
rm: huh is a directory
# rm -rf huh
rm: Unable to remove directory huh: File exists
Except for the absence of "." and "..", the directory looked normal in a directory listing:
drwxr-xr-x   4 root     root        1024 Sep 20 12:52 huh
Would I be able to remove it by referring to its inode number? I didn't think so, but I tried anyway.
# find . -inum 19640 -exec rm {} \;
rm: ./huh is a directory
# find . -inum 19640 -exec rm -rf {} \;
rm: ./huh is a directory
Clearly, I was running into the same underlying issue.

I could cd into the directory, though I clearly could not back out of it with "cd .." directory since .. didn't exist.
# cd huh
# ls -a
# touch junk
# ls
junk
# ls -l
total 0
-rw-r--r--   1 root     root           0 Sep 20 12:57 junk
# cd ..
..: does not exist
After creating an empty file, a subsequent rm -rf command removed the new file, but left the directory intact.
# rm -rf huh
rm: Unable to remove directory huh: File exists
# cd huh
# ls -al
total 0
# ls
# pwd
/var/huh
I began to wonder if I'd have to live with this anomaly, but then came up with an idea. If I moved the directory to another file system, the system would likely create it in its new location with all the proper attributes and maybe even remove all evidence of the odd directory from its initial location.

However, when I "moved" the directory, the botched original remained, even though the directory copy was normal in every way.
# mv huh /tmp
# ls
adm         crash       inet        lp          opt         statmon
apache      cron        krb5        mail        preserve    tmp
apache2     dmi         ld          mysql       run
appserver   dt          ldap        news        sadm
audit       fm          lib         nfs         saf
cache       huh <==     log         nis         sma_snmp
cc-ccr      imq         lost+found  ntp         spool
Of course, fsck will be able to repair this, I finally thought, and it certainly did, but it was more trouble than I anticipated. Notice in the output below that it noticed the missing files (e.g., MISSING '.').
# fsck -y /dev/md/dsk/d20
/dev/md/dsk/d20 IS CURRENTLY MOUNTED READ/WRITE.
CONTINUE?  yes

** /dev/md/dsk/d20
** Currently Mounted on /var
** Phase 1 - Check Blocks and Sizes
** Phase 2 - Check Pathnames
DIRECTORY CORRUPTED  I=19640  OWNER=root MODE=40777
SIZE=1024 MTIME=Sep 20 12:58 2006
DIR=/huh

SALVAGE?  yes

MISSING '.'  I=19640  OWNER=root MODE=40777
SIZE=1024 MTIME=Sep 20 12:58 2006
DIR=/huh

FIX?  yes

MISSING '..'  I=19640  OWNER=root MODE=40777
SIZE=1024 MTIME=Sep 20 12:58 2006
DIR=/huh

FIX?  yes

** Phase 3a - Check Connectivity
UNREF DIR  I=19653  OWNER=root MODE=40755
SIZE=512 MTIME=Sep 19 18:15 2006
RECONNECT?  yes

DIR I=19653 CONNECTED. PARENT WAS I=19640

UNREF DIR  I=19649  OWNER=root MODE=40755
SIZE=512 MTIME=Sep 19 18:14 2006
RECONNECT?  yes

DIR I=19649 CONNECTED. PARENT WAS I=19640

** Phase 3b - Verify Shadows/ACLs
** Phase 4 - Check Reference Counts
LINK COUNT lost+found I=3  OWNER=root MODE=40700
SIZE=8192 MTIME=Sep 15 15:21 2006  COUNT 2 SHOULD BE 4
ADJUST?  yes

** Phase 5 - Check Cylinder Groups

CORRECT BAD CG SUMMARIES?  yes

CORRECTED SUMMARY FOR CG 0
CORRECTED SUMMARY FOR CG 1
FILE BITMAP WRONG
FIX?  yes

FRAG BITMAP WRONG (CORRECTED)
CORRECTED SUMMARY FOR CG 5
FILESYSTEM MAY STILL BE INCONSISTENT.
18933 files, 99084 used, 1859431 free (11983 frags, 230931 blocks, 0.6% fragmentation)

***** FILE SYSTEM WAS MODIFIED *****
ORPHANED DIRECTORIES REATTACHED; DIR LINK COUNTS MAY NOT BE CORRECT.
***** FILE SYSTEM IS BAD *****

***** PLEASE RERUN FSCK *****

***** REBOOT NOW *****
As soon as the fsck was done, I rebooted and the file system was as it should have been, except for one small problem -- I still could not remove the directory, even though it now looked proper. Oops! Did that "REBOOT NOW" message mean after rerunning fsck?
# rmdir huh
rmdir: directory "huh": Directory not empty
# rm -rf huh
rm: Unable to remove directory huh: File exists
I then ran fsck again and rebooted:
# fsck -y /dev/md/dsk/d20
/dev/md/dsk/d20 IS CURRENTLY MOUNTED READ/WRITE.
CONTINUE?  yes

** /dev/md/dsk/d20
** Currently Mounted on /var
** Phase 1 - Check Blocks and Sizes
** Phase 2 - Check Pathnames
** Phase 3a - Check Connectivity
** Phase 3b - Verify Shadows/ACLs
** Phase 4 - Check Reference Counts
LINK COUNT DIR I=19640  OWNER=root MODE=40777
SIZE=1024 MTIME=Sep 20 12:58 2006  COUNT 4 SHOULD BE 2
ADJUST?  yes

** Phase 5 - Check Cylinder Groups

CORRECT BAD CG SUMMARIES?  yes

CORRECTED SUMMARY FOR CG 0
CORRECTED SUMMARY FOR CG 1
CORRECTED SUMMARY FOR CG 5
FILESYSTEM MAY STILL BE INCONSISTENT.
18933 files, 99109 used, 1859406 free (11990 frags, 230927 blocks, 0.6% fragmen
ation)

***** FILE SYSTEM WAS MODIFIED *****
***** FILE SYSTEM IS BAD *****
After another fsck -y and a reboot, the file system was intact and I was able to remove the strange directory without a problem. Interesting, this was a problem that I hadn't encountered before.

On this topic

 

Sandra Henry-Stocker has been administering Unix systems for more than 18 years. She describes herself as "USL" (Unix as a second language) but remembers enough English to write books and buy groceries. She currently works for TeleCommunication Systems, a wireless communications company, in Annapolis, Maryland, where no one else necessarily shares any of her opinions. She lives with her second family on a small farm on Maryland's Eastern Shore. Send comments and suggestions to bugfarm@gmail.com.




Sponsored Links

Sign up for a Microsoft Dynamics® CRM WEBCAST
Hear globally recognized leaders in customer strategy discuss the importance and evolution of CRM.
TRY NEW SUN SERVERS FREE for 60 Days!
Test The Latest Sun Servers In Your Environment BEFORE YOU BUY. Pay Nothing, Not Even Shipping.
Workflow Enabled Help Desk & IT Service Management
Automate service desk activities and integrate processes across IT. Learn more here.
Sign up for a FREE NETWORK RISK ASSESSMENT!
MORE THAN 70% OF NETWORKS ARE INFECTED by hidden Malware. Find out if your network is infected now!
Enterprise IP Goes Mobile
To maximize full productivity, companies must integrate their mobile applications with the IP network.
» Buy a link now

Advertisements
Sponsored links
Top 5 Reasons to Combine App Performance and Security
Locate Hidden Software on business PCs with this free tool
KODAK i1400 Series Scanners stand up to the challenge
Bring harmony to your mix of UNIX-Linux-Windows computing environments
 Home   Open source  Operating systems  Unix
www.itworld.com    open.itworld.com     security.itworld.com     smallbusiness.itworld.com
storage.itworld.com     utilitycomputing.itworld.com     wireless.itworld.com

 
Contact Us   About Us   Privacy Policy    Terms of Service   Reprints  

CIO   Computerworld   CSO   GamePro   Games.net   IDG Connect   IDG World Expo   Infoworld   ITworld   JavaWorld   LinuxWorld  MacUser   Macworld   Network World   PC World   Playlist  

Copyright © Computerworld, Inc. All rights reserved

Reproduction in whole or in part in any form or medium without express written permission of Computerworld Inc. is prohibited. Computerworld and Computerworld.com and the respective logos are trademarks of International Data Group Inc.