Solved

change file to directories and vice versa

Posted on 2004-08-12
7
236 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

919 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

16 Experts available now in Live!

Get 1:1 Help Now