Tuesday, March 09, 2004

Re: Mount ( Extended )

just as you can mount devices onto the file system heirarchy after boot-up, during booting the partitions containing the basic heirarchy (/) are also mounted.

at some stage after the kernel is started at boot time, the /etc/fstab is read. this file contains information on which partition is to be mounted on which mount point. a mount point is simply the directory in the entire file system. the listing on my setup is like

LABEL=/ < space> / < space> ext3 < space> defaults < space> 1 < space> 1
LABEL=/boot < space> /boot < space> ext3 < space> defaults < space> 1 < space> 2
/dev/hda6 < space> /tmp/d < space> vfat < space> defaults < space> 1 < space> 2

#replace < space> with actual spaces

the explanation from the man pages...
<<
The first field, (fs_spec), describes the block special device or remote filesystem to be mounted.

The second field, (fs_file), describes the mount point for the filesystem.

The third field, (fs_vfstype), describes the type of the filesystem. Linux supports lots of filesystem types, such as ext2, ext3, hfs, hpfs, iso9660, jfs, minix, msdos, ntfs, proc, reiserfs, vfat, xenix, xfs, and possibly others.

The fourth field, (fs_mntops), describes the mount options associated with the filesystem.
It is formatted as a comma separated list of options. It contains at least the type of mount plus any additional options appropriate to the filesystem type.

The fifth field, (fs_freq), is used for these filesystems by the dump command to determine which filesystems need to be dumped. If the fifth field is not present, a value of zero is returned and dump will assume that the filesystem does not need to be dumped.

The sixth field, (fs_passno), is used by the fsck program to determine the order in which filesystem checks are done at reboot time. The root filesystem should be specified with a fs_passno of 1, and other filesystems should have a fs_passno of 2.
>>

the label / and /boot i think are defined in the boot loader config file. if you notice the third line in my config, /dev/hda6 type vfat, its my common windows fat32 partition where i store all my data / articles etc.

Re: C++ Generics

thanks for the great explanation and quick response..

could you give some places where templates, both class and function would be used. other than containers.

should the 'size_t n' variable you created in the class template example be 'int n'??

how is the generics implementation in .net?

i am basically trying to gear up for java 1.5. the examples i saw were using generics for containers. so other than casting, i did not notice any great advantages. what else do you guys think are the advantages?

Sunday, March 07, 2004

C++ Generics II

Besides class templates, you can also have function templates. Here you leave the type of the arguments to the function unspecified.

Ex...

template <typename T>
T max( T x, T y )
{
    if ( x > y )
    {
        return x;
    }
    else
    {
        return y;
    }
}


Again, similar to class templates, when you call the function with a particular type, the compiler will create a function with your specified type.

Ex...

int bigger = max( 2, 4 );

double bigger2 = max( 2.2, 4.6 );


Here, two separate functions will be generated. One for ints, one for doubles.

Function max, uses the ">" operator to compare values. So the compiler makes sure that whatever type you specify has overloaded this operator. If not, it will generate an error message. This is where the type safety comes into play.

One thing to notice is that function templates infer the type automatically, whereas class templates don't. With class templates, you HAVE to explicitly mention the type. But there are situations where it might be necessary to explicitly mention the types for functions also. In that case the syntax is similar... max<int>( 2, 4 );

C++ Generics

Generics in C++ are actually implemented with templates. There is some difference in the way it is implemented in C++ vs Java vs C#. I'm not very sure of the differences, but it involves the amount of work done at runtime. In C++ everything is done at compile time whereas in Java and C# it's done both at compile as well as runtime.

Anyway, templates provide a way to paramatize types. Templates allow us to NOT specify the type and program generically. This is most useful in collections like vector, deque, map etc.. since you don't need to create a class for every kind of type that could be held in the collection. C++ does not have a unified type system like Java and C#, so if you did NOT have templates, you would have the tedious job of creating something like an intVector that will hold only integers, stringVector for only strings etc...

With templates, you can keep the type unspecified. When you actually want to use the class with an integer, you just specify the type to be int. Before compiling, the compiler will go through the code, find the unspecified type in the class and replace it with the one you specified. This is, I guess, pre-processing... similar to macro's. But the difference is that it is type safe since after replacing with the specific type, the compiler will check to see if it supports the operation (like +... integral types support this operation, but bool doesnt). If it doesn't suport the op, the compiler will generate (sometimes amazingly cryptic) error messages.

I guess a simple ex may help...

template <typename T>
class myVector
{
    private:
        T* m_elements;

    public:

        myVector( size_t n )
        {
            this->m_elements = new T[ n ];
        }

        ~myVector()
        {
            delete[] this->m_elements;
        }

        void set( size_t i, T v )
        {
            this->m_elements[ i ] = v;
        }

        T get( size_t i )
        {
            return this->m_elements[ i ];
        }
};


Here, T is the unspecified type. myVector is a collection that holds on to T's. When you want to retreive an element at a specific location, get returns a T. And similarly, to add values to the collection you use set.

To actually use this class you'd need to specifiy a type...

int main()
{
    myVector<int> intVector( 2 );

    intVector.set( 0, 11111 );
    intVector.set( 1, 22222 );

    int val1 = intVector.get( 0 );
    int val2 = intVector.get( 1 );
}


So here you specify the type you want myVector to store as int. When the compiler sees myVector<int>, it will create a copy of your template class, with the T's replaced with ints. It will do the same for every type you specify. So if you have myVector<string>, it will have a separate copy of the code with the T's replaced with string. So the idea is to let the compiler do the work.

So hope this gave you some idea. Dinesh/Hrishi correct any mistakes I might have made.

Saturday, March 06, 2004

Re: mount

Dyou mean System V? The kernel is standardized, but what about the commands/programs?

i think there are some POSIX standards as well. i do not have a book right now so cannot confirm. also a basic set of commands / utilities are also always present. basic directory structure, services etc and a few other things are also standardised.


Microsoft had a version of Unix called Xenix! And more surprising... it was developed in a partnership with SCO!

SCO was previously a distro company called Caldera. but they never made much money or something. then they became SCO. also MS does have a stake in SCO. all the reason why linuxers feel this entire SCO issue is just FUD.


Interesting. But dyou think this is such a great idea? It seems this might be a nightmare scenario when it comes to managing different versions. Is there something similar to DLLs? Basically components, which enables reuse.

i have never built apps in linux so i cannot say. all library files ie == dll's go in the /lib or /usr/lib folder. they generally have extensions *.so. also i noticed some lib files with extensions like *.so.2.6 .. so i guess they do manage versions pretty well. some distro's like debian, gentoo have advanced dependency checking mechanisms for apps.


So I have a folder called /u/mrao. So, this is my home directory?
that should be yur home folder. try $ ls -a . yu'll see a bunch of hidden directories and files. most are application settings files.


I didn't try to access them, but I'm sure if I did, it would ask for login data. Anyway, does this mean that all these folders are actually stored in some server and the machine I used to log in is just a thin client (terminal)?

you will get an access denied error. in linux permission model, there are three roles. user == guy who made the file, group == group of which the user is part of and others == everyone else. there are three access levels, read write and execute. execute is when i create an app (suppose cpp or shell script) i can set whether it is executable or not. so calculate the permutations.

the setup definitely seems distributed. but cannot say much. yu might be using dumb terminals, with only processor and ram, no hdd. basically boot over the network. or some other config might be possible.


Another question was regarding daemons.

the stuff you mentioned about daemons, actually services is correct. try
$ ps -ax
this gives a list of all processes.or goto sys settings>>server settings>>services under rh gui mode.
another interesting command is
$ top
discover for yourself. remember h for help. you'll get some idea of how wonderful/powerful the shell is.!!

Re: mount

mohn, i really suggest you read the pike book hrishi got

Dyou mean the Unix book? Yeah, I plan on reading that. And also going through the Oreilly books he burnt for us. I'm actually reading one I got from the college library. It's quite old (he's using some disto called LST - heard of it?), but somehow I liked his approach to it. It's about getting started with Linux.

actually there were many different *nix based os'es. then they decided to standardize under a definite set of rules. not getting the name right now. something like IPC V or so. please correct. so more or less the directory structure, along with some standard commands were fixed.

Dyou mean System V? There were some three branches from the first asm based Unix... the main one - just several diff versions, BSD and SunOS. Because of differing functionality they standardized on System V which was based on the initial asm Unix. But I did not understand what the standardization involved. The kernel is standardized, but what about the commands/programs?

BTW, this came as a big surprise to me... Microsoft had a version of Unix called Xenix! And more surprising... it was developed in a partnership with SCO!

one major difference between *nix and windows is this. in linux when you install a program, it gets stored all over the file system. config files go in etc, some parts go in /lib, and the exe will go in some bin folder.

Interesting. But dyou think this is such a great idea? It seems this might be a nightmare scenario when it comes to managing different versions. Is there something similar to DLLs? Basically components, which enables reuse.

Some more questions I had... wanted to post before I forget.

As I told you before, they have Debian installed on the campus computer lab. Anyway, I have a cs unix account which allows me to log into those machines. So I have a folder called /u/mrao. So, this is my home directory?

The other day I was just playing with some cmds and entered ls -l /u. This brought back a HUGE list of folders with other peoples folders like /u/ajay, /u/dustin, /u/john etc... I didn't try to access them, but I'm sure if I did, it would ask for login data. Anyway, does this mean that all these folders are actually stored in some server and the machine I used to log in is just a thin client (terminal)? Cause sometimes I use a SSH client from home to connect and transfer my files to the Linux machines and I can connect to basically any domain on campus. Doesn't have to be one particular one.

Another question was regarding daemons. Are these just background processes? If you open up Task Manager in Windows you will see several svchost.exe's. These host several services that are always running in the background. So daemons are something similar?

i needed some info how generics work in C++.

I'll post some stuff on it soon.

Re: mount

And a request for more "beginners" linux related info.

mohn, i really suggest you read the pike book hrishi got. i had posted a blog on some fundamentals but i realised it was too long, and i was merely copying stuff. most of the fundamentals are really well explained.


So the next guy who logged in couldn't access the drive. What's the solution in that situation?

there is no solution. remember to umount. in linux, a device == file. and just as you have permissions for files, there are permissions for devices. once a user mounts a floppy, he owns it. so no one is allowed access. other than the superuser, root. also, if you do not unmount the cd, the cd will not eject from the drive even if you try ejecting. and removing a mounted floppy by force causes the system to become slightly unstable.


Can you elaborate a bit on the directory hierarchy.

/ pronounced as root is the highest level of the heirarchy. /bin contains most important system binaries like bash, kill mount etc... /boot contains the boot loader which is generally grub or lilo. /dev contains device files. /etc contains configuration files. /usr contains folders like bin, local, sbin which contain not so important binaries and other files. /var contains logs and stuff. the list i have provided is not exhaustive.


Do all linux distro's contain this exact same hierarchy? If not, how do they differ? Also what if they want to add some custom "user friendly" feature like "My Documents" or something... where would that folder be located?

actually there were many different *nix based os'es. then they decided to standardize under a definite set of rules. not getting the name right now. something like IPC V or so. please correct. so more or less the directory structure, along with some standard commands were fixed.

one major difference between *nix and windows is this. in linux when you install a program, it gets stored all over the file system. config files go in etc, some parts go in /lib, and the exe will go in some bin folder. and like you mentioned My Documents. this is the folder within /home. like say /home/rahul. all applications have different settings for different users. these are stored in the users home folder. this is yur place, yur home. try
$ cd ~
$ pwd


Also what exactly are executables in Linux called? What extensions do they have?

executables in *nix are ELF files. (Executable and Linkable Format). in linux extensions have no meaning (i would appreciate if hrishi could clarify). when you try to run a file linux reads the file and checks headers to determine file type. then takes necessary action. also you can have any length extensions. also something like file.tar.bz2 is valid.


Every new device you mount will be added under /dev? So if I mount a zip drive or whatever, it should appear there.

all devices possible on your system are already present in the /dev directory. when you mount it gets added to the filesystem. in /dev directory you cannot directly write into devices. so you mount along with filesystem type. like cd's are iso9660 or something.


What counts as secondary devices?

primary secondary depends on what bus the device is internally connected to the motherboard. there are two buses in standard x86.

master slave depends on the jumper settings you chose for the device.


This is quite cool. So I can access my music stuff on Windows which is in the main hd (hda). Does mount work "by value" or "by reference". As in, does it make a copy of the files in hda6?

cool i feel is an understaement. there i so many things in linux which are made for interoperability between systems. some stuff is really amazing. and lots lots more to discover.

refernce.. all changes will be reflected and permanent.


So, sorry for the whole bunch of stupid questions. My aim is to advance to intelligent ones after reading your posts on Linux.

hey mohn, don't embarass me. all of us are just trying to learn. we have lots to share. i needed some info how generics work in C++. probably mohn or dinesh could post some stuff.

Open Books Project

http://www.oreilly.com/openbook/

Oreilly at it again. Most are open source.

I'm personally thinking of starting with Linux Device Drivers.

Re: mount

Firstly, thnx for another great topic. And a request for more "beginners" linux related info.

Now for my dumb questions...

mount is a filesystem operation

The first time I had to use a *nix system was early last year for a cs project which HAD to run on Linux. Anyway, it was in java. So I coded it on Windows, saved it on a floppy and went to the linux box to test it. That's when someone told me about this "mounting" stuff. So it was kinda wierd and I didn't understand it. I thought it was kind of strange that the floppy drive had to be mounted and unmounted. I understand now this is an extensibility feature as Rahul said.

Anyway, one problem was that people would log into their account, mount the floppy drive, use it and then NOT unmount it before they logged off. So the next guy who logged in couldn't access the drive. What's the solution in that situation?

the directory structure in a *nix system heirarchy is of the form /(root) withinwhich there are other folders like boot, etc, dev, home etc...

Can you elaborate a bit on the directory hierarchy. I have seen a bit about the diff folders like boot, etc, usr etc... But what exactly does each contain? And are all of these first level under root? As in /boot, /etc, /usr

Do all linux distro's contain this exact same hierarchy? If not, how do they differ? Also what if they want to add some custom "user friendly" feature like "My Documents" or something... where would that folder be located?

Also there are commands that you use from the cmd line like ps, grep, set, etc... These are actualy programs (executables) right? Where are these stored in the hierarchy? Also, are they available in ALL distro's like a standard?

Also what exactly are executables in Linux called? What extensions do they have?

now the important thing here is to understand the numbering for partitions under the /dev(device) directory.

Every new device you mount will be added under /dev? So if I mount a zip drive or whatever, it should appear there.

a in hda means the primary master device on the bus. if you had a primary slave, it would be denoted as hdb.

hda == Your main hard drive.
hdb == If you have a second harddrive it will appear as that.
Similarly, if you have a thrid, fourth harddrives, will it continue as hdc, hdd etc...?
And under those if you have partitions they are numbered.

for secondary devices, they would be hdc and hdd.

What counts as secondary devices?

# mount -t vfat /dev/hda6 /tmp/d
now, wheni browse the /tmp/d directory, all my d: files are visible, with complete read/write support.


This is quite cool. So I can access my music stuff on Windows which is in the main hd (hda). Does mount work "by value" or "by reference". As in, does it make a copy of the files in hda6? What if I mount to /tmp/d and then add files to it, remove some files, edit etc... Will the changes also be made to the originals?

So, sorry for the whole bunch of stupid questions. My aim is to advance to intelligent ones after reading your posts on Linux.

Friday, March 05, 2004

mount

one of the very advanced utilities in *nix, is mount. mount is a filesystem operation.

the directory structure in a *nix system heirarchy is of the form /(root) withinwhich there are other folders like boot, etc, dev, home etc... it is not necessary to have the entire file-system on one device(for eg harddisk) or one partition. it is possible to extend the file system at any mount point for expansion, and the users will be totally unaware of the underlying implementation. let me try an exampleas things seem very cryptic right now.

on my hdd, i have d: (windows) and e: of filesystem type fat32. i store my documents etc on these partition. and need to access them through linux as well. so i just"mount" the partitions within my linux heirarchy. consider the command.

# mount -t vfat /dev/hda6 /tmp/d

here /dev/hda6 is the d: partition which is of type vfat(fat32). /tmp/d is a directory. with this command, the entired: partition is placed under /tmp/d directory. now, wheni browse the /tmp/d directory, all my d: files are visible, with complete read/write support.

now the important thing here is to understand the numbering for partitions under the /dev(device) directory. i will break up hda6. hd means harddisk. a in hda means the primary master device on the bus. if you had a primary slave, it would be denoted as hdb. for secondary devices, they would be hdc and hdd. now 6 in hda6 means the sixth partition.

Device Boot Start End Blocks Id System
/dev/hda1 * 1 1217 9775521 7 HPFS/NTFS
/dev/hda2 1218 1230 104422+ 83 Linux
/dev/hda3 1231 4734 28145880 f Win95 Ext'd (LBA)
/dev/hda4 4735 4865 1052257+ 82 Linux swap
/dev/hda5 1231 1969 5935986 b Win95 FAT32
/dev/hda6 1970 2708 5935986 b Win95 FAT32
/dev/hda7 2709 3728 8193118+ b Win95 FAT32
/dev/hda8 3729 4734 8080663+ 83 Linux

this is the print for my hda using fdisk. to view a similar partiion table for your hdd use fdisk as follows..

# fdisk /dev/hda

then use 'p' as an option to print the partion table.

mohn, you can surf on windows and save the files/tutorials and then access them in linux. now if you have only ntfs partitions, you'll have to recompile the kernel in red hat for ntfs support or get better advice from hrishi. newest mandrake might have ntfs pre-compiled.

have you ever mount-ed ntfs with total read/write hrishi? you can probably suggest some more stuff in mount.

also just a comment, this feature of mounting stuff allows to extend the file system very efficiently unlike windows where drive letters make things slightly more complicated.

Re: Burning iso

Digressing a little bit here... reiserfs is a really good option. It's more robust than the ext3 filesystem.

did you notice any performance gains using reiserfs? i tried using it once, but was a bit apprehensive as i am used to ext3 now. you tried any other fs?


also i got my iptable query solved. i had a funny red-hat default chain which allowed all packets in. so had to insert the icmp drop rule rather than add it!!


i wanted to ask you on devfs, udev, and the current /dev directory. i am a bit messed up on these concepts. any good info/links? or better still could you explain some stuff.

Re: communicating to a modem

Basically, you connect to a friend's computer using hyper terminal.
I've a question... is there a program which I can use to make / answer telephone calls?


like mohn said, it is very possible and there should be apps. but i have tried, but failed with at commands i tried at home. probably you can give me a call next time you come to vashi, and we'll try some stuff.

how come you decided to chat it up with your modem?
well this was a part of the project at barc. dinesh and i got to work on some pretty cool stuff there and these have really been great days for me.!! with respect to the project, we connect to the nokia 30 terminal and a normal data/fax modem through serial ports on the motherboard of the microcontroller. then simply open input/output streams and communicate as required. also as we are communicating to serial ports through java, we have to use the java communcation api. just to get you back down to earth, we did not write the code. just refractored the example code provided with the TINI programming api to suit our needs. if those examples would not have been there this project would simply be impossible. at least thats what i feel.

Indian Techies Answer About 'Onshore Insourcing'

http://interviews.slashdot.org/article.pl?sid=04/02/17/1654255

Wednesday, March 03, 2004

Re: Burning iso

I'm an idiot.

Thanks

Re: Burning iso

mohnish 731,797,504 bytes == 698MB (calculate it yourself if you wish :):) ), so there shouldn't be a problem.

Re: Burning iso

Thanks for the info.

If you are comfortable working on redhat, stick to redhat

Pretty much the main reason I want to switch distros is that Red Hat is not recognizing my wierd network card. So I can't connect to the net. There's not much point in booting into Linux... especially since it's so new to me without a net connection.

I'm not sure if mandrake will recognize it either, but it's worth a shot. And it seems to me (my lay opinon) that Mandrake has a pretty good community behind it. Red Hat's site sucks. Plus they've stopped the client version.

i did not understand your earlier question. the red-hat cd-s were 653mb, 661mb, 496mb.

I downloaded the ISO images for Mandrake 9.2 - just like Red Hat, it has three images. I got them from here... http://gulus.usherb.ca/pub/Mandrake/iso/. It shows all the file sizes as < 700 MB, but the biggest image (698MB) is actually 731,797,504 bytes. So how do I burn that onto a disk?

Re: Burning iso

Just a small addition to Rahul's blog. If you are comfortable working on redhat, stick to redhat. Mandrake has a pretty weird directory structure - esp with the /etc stuff. The reason I use the word 'weird' is I've become very much used to using redhat.

I haven't used Mandrake but it's quite likely that they have some other defaults set differently. From this point of view, I didn't like suse very much.

I've been using redhat all along; I stick to redhat. The point is you wouldn't want to spend much time learning these kind of minor things/defaults... so just stick to what you're comfortable with... unless you have a very specific reason for choosing a particular distribution.
Like for example, you want the reiserfs (file system) instead of the ext3. Redhat did not support it until RH9 (don't know about fedora). SuSE does. But a few minor issues bugged me and my movie player for linux (mplayer) didn't work very well on SuSE, so I ditched SuSE. :-)

Digressing a little bit here... reiserfs is a really good option. It's more robust than the ext3 filesystem. Even in cases of improper shutdowns, it hardly takes any time analyzing it the next time it boots... compare it with the significant time taken to check the ext3fs. Just do a little googling on the reiser and ext3 file systems; you'll pick up some interesting points.

Happy linuxing...

Re: Burning iso

I've downloaded the three iso images Mandrake Linux 9.2. Windows/Opera etc... give the size in MBs at around 695 mb each, but the actual size is 700mb+.How big were the red hat iso's?

i did not understand your earlier question. the red-hat cd-s were 653mb, 661mb, 496mb. if you need an app to create iso files, then i suggest winiso.


Also, apparently Mandrake 10.0 release is just around the corner.

software-wise there will be some upgrades. i expect ver 10.0 to be running on kernel 2.6.x and a few other important apps also. but again in open/free source, there are very regular updates and generally you need upgrades relatively quickly. besides for learning purposes you do not need too bleeding-edge software. but there might be some usability upgrades in mandrake 10.0. so really its all upto yur patience. i would suggest to wait. practice on red hat till then.

Burning iso

Couple questions...

I've downloaded the three iso images Mandrake Linux 9.2. Windows/Opera etc... give the size in MBs at around 695 mb each, but the actual size is 700mb+. How do you burn this on a CD? How big were the red hat iso's?

Also, apparently Mandrake 10.0 release is just around the corner. I dunno what new features it has. Do you think it might be a better idea for me to wait for a bit and then go for that? If it's like a Win2k -> WinXP type upgrade, I don't think it will make much of a diff.

Tuesday, March 02, 2004

Re: communicating to a modem

basically i'll show you how to issue commands to your modem. the modem can be programmed to perform various tasks.

That was a good blog Rahul. Quite insightful. Unfortunately, I don't have a modem, so I can't try out your stuff. But still, it was interesting. Just curious... how come you decided to chat it up with your modem? It aint something you just wake up one morning and decide to do. So something must have drove your attention there.

I've a question... is there a program which I can use to make / answer telephone calls? Something which runs in the background and tells me when the phone rings (assuming I don't have a regular phone connected) so I can answer it using the computer itself...

I'm not sure of any popular ones out there. But I'm sure they are available. A lot of ISPs over here include the software for guys using modems and having one phone line.

One a related topic... Have you guys heard of SKYPE (www.skype.com). It is program that allows you to voice chat online. The thing that makes this so amazing is the quality. The clarity is truely remarkable. It uses P2P technology based off of Kazza technology. Check it out.