Install NFS server on CentOS

Network FileSystem (NFS) is created by Sun company. It provide you a service to share files between different machine via network. It is similar with Samba which I mentioned before. But the transport speed is faster than Samba. Because it does not need user to type account and password. The server has white list to allow legal IP to login to access files directly.

Install server is very easy. We just use yum command to find necessary libraries and install automatically.
[nick1811@NAS ~]$ sudo yum install nfs-utils nfs-utils-lib
Create white list. We allows all IP in subnetwork(192.168.0.*). And all users have access right for read and write.
[nick1811@NAS ~]$ vim /etc/exports
/home/nick1811/Shared_Folder 192.168.0.1/24(rw)
Run several startup scripts for the NFS server
[nick1811@NAS ~]$ sudo service rpcbind start
[nick1811@NAS ~]$ sudo service nfs start
Finally, remember turn on the port in iptables.
[nick1811@NAS ~]$ sudo vim /etc/sysconfig/iptables
# NFS
-A INPUT -m state --state NEW -m tcp -p tcp --dport 2049 -j ACCEPT
[nick1811@NAS ~]$ sudo service iptables restart
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Unloading modules:                               [  OK  ]
iptables: Applying firewall rules:       


Although we have been set complete. But how to check all setting are correctly? To reach this purpose. I choose other CentOS and install NFS client to do it.

First, we also need to install necessary libraries.
[nick1811@Client ~]$ sudo yum install nfs-utils nfs-utils-lib
Second, we use showmount command to check we can see the shared folder.
[nick1811@Client ~]$ showmount -e 192.168.0.1
Export list for 192.168.0.1:
/home/nick1811/Shared_Folder  192.168.0.1/24
Finally, we mount shared folder to local folder which is we created.
[nick1811@Client ~]$ mount 192.168.0.1:/home/nick1811/Shared_Folder /mnt/nfs
When we can put files to /mnt/nfs and we can see files on the server side, we successfully setup NFS server.

Reference: http://linux.vbird.org/linux_server/0330nfs.php

The concept of directory structure on macOS

This article is aimed to introduce directories hierarchy for macOS. macOS is also followed by Filesystem Hierarchy Standard (FHS). But it has a little difference, that this article collects for you. The content of directories in macOS is divided to two part, standard directories and hidden directories.

Standard Directories

  • /Applications : Application’s contents
    • This directory is where you install apps intended for use by all users of a computer.
  • /Library : Shared libraries, files
    • Apps should use the Library directory to store app-specific (or system-specific) resources.
  • /Network : Network related files and libraries.
    • It contains the list of computers in the local area network.
  • /System : System related files, libraries, and preference.
    • This directory contains the system resource required by macOS to run. These resources are not modified by recommend.
  • /Users : User home directory
    • All of files involves Individual users are placed in there.
  • /Volumes : Mount point for removable media
    • This directory contains subdirectories which are used as mount point for removable media.
    • E.g. cd-rom, floppy disk, dmg mounts etc.


    Hidden Directories
    This directories are followed FHS on Linux. You can also reference “The concept of directory structure on Linux”.

  • /bin : Essential user command binaries
    • All the executable binary programs.
  • /dev : Devices files
    • It contains hardware device files.
  • /etc : Host-specific system configuration
    • It contains all configuration for system.
  • /sbin : System binaries
    • The essential binaries which only can be executed by system.
  • /tmp : Temporary files
    • The temporary files created by apps and system.
  • /usr : Secondary hierarchy
    • It contains nonessential binaries, header files and other data.
  • /var : Variable data
    • Intuitively, it contains log and other file content is variable.


    Reference: macOS File System

    Importing Swift file to Objective-C project

    I think it is very complex when I read Apple's reference. Hence, I decided to write a simple article which illustrates you how to import Swift file into Objective-C project step by step.

    First, you should create an Objective-C project.

    After project be created. We have some parameters should be set in Build Settings.

  • Find “Defines Module”, and set to “YES”. This setting let Xcode use same framework to import Swift to Objective-C project.



  • Find “Always Embed Swift Standard Libraries”, and set to “YES”.



  • The “Product Module Name” names by your project name. In there, we do not need to revise anything.


  • New or add exist Swift file into the project. Then Xcode pop-ups a dialog, follows image. We just click “Create Bridging Header” to automatically crate bridging header. After that, we can see the bridging header file which be names your product name followed by adding "-Bridging-Header.h".


    Finally, we need to import “MixDemo-Swift.h” to any Object-C .m. That header is created by Xcode, but you cannot see in the project folder. The file names your Product Module Name, which we mentioned above, followed by add “-Swift.h”. You can also search "Objective-C Generated Interface Header Name" under Build Settings.
    #import "MixDemo-Swift.h"
    

    Then, we can use swift object in the Objective-C project directly.
        BarcodeScannerViewController *barcodeViewController = [[BarcodeScannerViewController alloc] init];
        barcodeViewController.delegate = self;
        [self presentViewController:barcodeViewController animated:YES completion:nil];
    

    Reference: https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html