Solved

change file to directories and vice versa

Posted on 2004-08-12
7
234 Views
Last Modified: 2010-04-22
Hi,
It's funny to think or say but i have a question in my mind,
is there any way to change the files to directories or vice versa by some way.like changing the in its property of
drwxr--r-- to -rwxr--r--
if it could be please suggest
0
Comment
Question by:decentswati
7 Comments
 
LVL 4

Accepted Solution

by:
alikoank earned 68 total points
ID: 11782400
on some systems you can see their contents by cat command.

try typing

cat mydir > test.bin

that may or may not work on your filesystem.
0
 
LVL 23

Assisted Solution

by:brettmjohnson
brettmjohnson earned 66 total points
ID: 11784010
In most filesystems directories ARE files.  Some OS's even allow you to use
open(), read(), write(), etc to access the data.  However the directory's file
contents is highly structured and specific to the file system implementation.
So using write() to modify a directory file runs a very high risk of rendering
the filesystem unusable if you don't know what you are doing.

To aid the programmer in managing that structured information, the OS
provides abstracted access using opendir(), readdir(), etc.

0
 
LVL 6

Assisted Solution

by:de2Zotjes
de2Zotjes earned 66 total points
ID: 11787493
On unix systems the main difference between a regular file and a directory file is that you cannot use the write-systemcall on a directory file :-)

But to get back to the question: you might be able to change the properties of the directory file so it becomes a regular file, but you would destroy a large chunk of your filesystem in the process.

I can see no good reason to do this other than satisfying you curiosity (which is a good enough reason for me :-) But before you even try, make sure the filesystem you kill holds no unique data..
0
 
LVL 1

Author Comment

by:decentswati
ID: 11799591
Hi de2Zotjes,
really I think the way is to change the property of directory file to make it a regular file.give me the suggestion so that I can try it.OfCourse there is no reason or need to do that but knowing the thing will make concepts clear.Help me.

bye
decentswati
0
 
LVL 6

Expert Comment

by:de2Zotjes
ID: 11800085
Make sure you have libext2fs on your system (ldconfig -p|grep ext2fs) It is part of the e2fsprogs collection.

After that it would be something like:
(this is pseudo-code!)

#include <ext2fs.h>

main () {
err_code = ext2fs_read_inode(fs,inode_num,&inode)
inode.i_mode = inode.i_mode | LINUX_S_IFDIR
ext2fs_write_inode(fs,inode_num, &inode)
}

Not even close to a working program but these are the funtions you would need to use.

Again: you most likely WILL f*ck up your complete file system! dump before you try this.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now