File System

Understanding the SOLARIS File System is very important, before we discuss anything further. Its huge topic and I suggest you really need to be patient while going through it. If you find anything difficult to understand, you can comment and I will get back to you as soon as possible.
File is the basic unit in Solaris, similar to atom for an element in chemistry. For example commands are executable files, documents are text file or file having code/script, directories are special files containing other files etc.

Blocks: A file occupies the space on disks in units. These units are called Blocks. The blocks are measured in two sizes :
1. Physical Block size: Its the size of the smallest block that the disk controller can read or write. The physical block size is usually 512B for UFS(Unix Files System). It may vary from file system to file system.
2. Logical Block size:  Its the size of the block that UNIX uses to read or write files. It is set by default to the page size of the system, which is 8KB for UFS.

Inodes: It is a data structure that contains all the file related information except the file name and data. It is 128 kb in size and is stored in cylindrical information block. The inode contains following information about a file :
1. Type of File : e.g. regular file, block special, character special, directory, symbolic link, other inode etc.
2. The file modes : e.g. read, write, execute permissions.
3. The number of hard links to the file.
4. The group id to which the file belongs
5. The user ID that owns the file.
6. The number of bytes in the file.
7. An array of addresses for 15 disk blocks
8. The date and time when the file was created, last accessed and last modified.

So, an Inode contains almost all the information about a file. But what is more important is what an inode does not contain. An inode does not contain the "file name" and data. The file name is stored inside a directory and data is saved in blocks

There is an inode associated with each file. So, the number of inodes determines the maximum number of files in the files system. The number of inodes depends upon the size of file system. For example : lets take a file system of size 2gb. The inode size will be 4kb each. So the number of inodes = 2gb /4kb = 524288. So the maximum number of files that can be created is 524288.

File System: Its the way an operating system organizes files on a medium(storage device). 
The different flavors of UNIX have different default file systems. Few of them are listed below:
Solaris UFS (Unix File System)
AIX - JFS (journal FS)
JP - HFS (high performance FS)
LINUX - ext2 ext3

Before getting into the UFS file system, lets discuss about the architecture of the file system in SOLARIS and other file systems used in SOLARIS.

SOLARIS uses VFS (Virtual File System architecture). It provides standard interface for different file system types. The VFS architecture enables kernel to perform basic file operation such as reading, writting and listing.  Its is called virtual because the user can issue same command to work regardless of the file system. SOLARIS also uses memory based file system and disk based file system.

Lets discuss some memory based file systems:
Memory based File Systems:
It use the physical memory rather than disk and hence also called Virtual File System or pseudo file system. Following are the Memory based file system supported by SOLARIS:
1. Cache File System(CacheFS): It uses the local disk to cache the data from the slow file systems like CD - ROM.
2. Loopback File System(LOFS): If we want to make a file system e.g: /example to look like /ex, we can do that by creating a new virtual file system known as Loopback File System.
3. Process File System(PROOFS): It is used to contains the list of active process in SOLARISby their process ID, in the /proc directory. It is used by the ps command.
4. Temporary File System(TEMPFS): It is the temporary file system used by SOLARIS to perform the operation on file systems. It is default file system for /tmp directory in SOLARIS.
5. FIFOFS: First in first out file system contains named pipe to give processes access to data
6. MNTFS: It contains information about all the mounted file system in SOLARIS.
7. SWAPFS: This file system is used by kernel for swapping.

Disk Based File System:
The disk based file systems resides on disks such as hard disk, cd-rom etc. Following are the disk based file system supported by SOLARIS:
1. High Sierra File System(HSFS): It is the file system for CD-ROMs. It is read only file system.
2. PC File System(PCFS): It is used to gain read/write access to the disks formatted for DOS.
3. Universal Disk Format(UDF): It is used to store information on DVDs.
4. Unix File System(UFS): It is default File system used in SOLARIS. We will discuss in details below.

Device File System (devfs)
The device file system (devfs) manages devices in Solaris 10 and is mounted to the mount point/devices.
The files in the /dev directory are symbolic links to the files in the /devices directory.

Features of UFS File System:
1. Extended Fundamental Types (EFTs). Provides a 32-bit user ID (UID), a group ID (GID), and device numbers.
2. Large file systems. This file system can be up to 1 terabyte in size, and the largest file size on a 32-bit system can be about 2 gigabytes.
3. Logging. Offers logging that is enabled by default in Solaris 10. This feature can be very useful for auditing, troubleshooting, and security purposes.
4. Multiterabyte file systemsSolaris 10 provides support for mutiterabyte file systems on machines that run a 64-bit Solaris kernel. In the previous versions, the support was limited to approximately 1 terabyte for both 32-bit and 64-bit kernels. You can create a UFS up to 16 terabytes in size with an individual file size of up to 1 terabyte.
5. State flags. Indicate the state of the file system such as active, clean, or stable. 
6. Directory contents: table
7. Max file size: 273 bytes (8 ZB)
8. Max filename length: 255 bytes
9. Max volume size: 273 bytes (8 ZB)
10. Supported operating systems: AIX, DragonFlyBSD, FreeBSD, FreeNAS, HP-UX, NetBSD, Linux, OpenBSD, Solaris, SunOS, Tru64 UNIX, UNIX System V, and others

 Now, that we have some basic idea of the SOLARIS file system, lets explore some important file systems in SOLARIS.
Windows guys must be aware of important directories in windows like sytem32, program files etc., like wise below we will discuss some important file systems in Solaris:

/    root directory
/usr     man pages information
/opt     3rd party packages
/etc     system configuration files
/dev   logical drive info
/devices   physical devices info
/home    default user home directory
/ kernel   Info abt kernel(genunix for Solaris)
lost+found unsaved data info
/proc    all active PID's running
/tmp    Temporary files system
/lib    library file information(debuggers, compilers)
/var    It contains logs for troubleshooting
/bin    Symbolic link to the /usr/bin directory (Symbolic link is same as shortcut in windows)
/export   It commonly holds user's home directory but can customized according the requirement
/mnt    Default mount point used to temporarily mount file systems
/sbin    Contains system administration commands and utilities. Used during booting when /usr/bin is not                                                mounted.
Important: / is the root directory and as the name suggests, other directories spawn from it.

File Handling
Lets us now get started with managing file i.e. creating, editing and deleting files.I have mentioned few commands below and their usage in managing/handling file & directories.

pwd Displays current working directory
touch filename Creates a file
touch file1 file2 file3   Creates multiple files(space is used as separator)
file filename Displays the type of a file/directory
cat filename Displays the content of the file
cat > filename Writes/over-writes the file(ctrl + D save and exit)
cat >> filename  Used to append the content to the file(ctrl + D save and exit)


mkdir /directoryname Creates a directory
mkdir -p /directory1/directory2  Creates a child directory under the parent directory(-p option  to  specify the parent directory)

cd  Changes the current working directory to root
cd directoryname Changes the current working directory to the directory specified
cd .. Changes the current working directory to the previous directory
cd ../.. Changes the current working directory to the previous directory of the previous  directory