What is tilde (~) in Mac/Linux?

The tilde(~) expansion in Mac/Linux has several pathnames.

  • It could be ${HOME} if you do not specify the username.
    If you specify the user, it will expend the home directory of the user.
    For example,

    $ echo ~
    /Users/yourusername
    $ echo ~otheruser
    /Users/otheruser
  • It contains the working directory by +/-
    For example,

    $ echo ~+
    /Users/current_directory
    $ echo ~-
    /Users/old/previous_directory

In shell, if you want to expand it,

EXPAND_PATH=`eval echo ~otheruse/bin/`

VMware Tool Patch for Linux Kernel 2.6.37/38

This post is not longer maintained since VMWare has announced the latest version of 3.1.3 (416484) which is able to work with the linux 2.6.38 (which is being used in Ubuntu 11.04). I’ve tested the latest version, and I’ve updated my virtual ubuntu as 11.04, and verified it works fine in everything. Thank you for all nice and wonderful comments and suggestions on this post.

This is a note for patching VMware tool for linux kernel 2.6.37/38 guest OS while using VMware Fusion.

Here is my environment for your reference.

  • Host OS: Mac OS 10.6.6
  • Guest OS: Ubuntu 10.10 + Kernel Updated (2.6.38)
  • VMware Fusion: 3.1.2 (332101)

Since the vmware-tool in vmware fusion is not aware of the changes of the latest kernel structure, it needs to be patched in order to get correct kernel module for vmware tool such like file sharing, clipboard sharing, etc.

Here is the walk-through steps:

  1. Install VMware Tool
  2. Copy vmware-tools-distrib directory into a local directory (say, ~/tmp/vmware-tools-distrib) by
     mkdir -p ~/tmp/ && tar -C ~/tmp -xvzf /media/VMware\ Tools/VMwareTools-8.4.5-332101.tar.gz
  3.  cd ~/tmp/vmware-tools-distrib/lib/modules/source
  4. tar -xvf vmci.tar && tar -xvf vmhgfs.tar && tar -xvf vsock.tar
  5. copy patch files (0001-vmwaretool-vmci-Linux-2.6.37.patch, 0001-vmwaretool-vmhgfs-Linux-2.6.37.patch, 0001-vmwaretool-vsock-Linux-2.6.37.patch) into ~/tmp/vmware-tools-distrib/lib/modules/source
  6.  cd vmci-only && git apply --ignore-whitespace ../0001-vmwaretool-vmci-Linux-2.6.37.patch && cd ..
  7.  cd vmhgfs-only && git apply --ignore-whitespace ../0001-vmwaretool-vmhgfs-Linux-2.6.37.patch && cd ..
    • Caution: For now (05/07/2011), this will pass the compile error, but a segment fault error is caused while creating/removing a file on the filesystem. If I find a resolution, I will update it. (Thanks, Chris.)
  8.  cd vsock-only && git apply --ignore-whitespace ../0001-vmwaretool-vsock-Linux-2.6.37.patch && cd ..
  9.  rm -rf vmci.tar vmhgfs.tar vsock.tar
  10.  tar -cvf vmci.tar vmci-only && tar -cvf vmhgfs.tar vmhgfs-only && tar -cvf vsock.tar vsock-only
  11.  rm -rf vmci-only vmhgfs-only vsock-only
  12. Install the vmware tool by
     cd ~/tmp/vmware-tools-distrib && ./vmware-install.pl

Here is the patches for your references:

  1. 0001-vmwaretool-vmci-Linux-2.6.37.patch:
    From ad10b5458d4aa6d5df7b913174185d395943ce32 Mon Sep 17 00:00:00 2001
    From: YOUNGWHAN SONG <breadncup@gmail.com>
    Date: Fri, 25 Feb 2011 22:16:19 -0800
    Subject: [PATCH] Linux 2.6.37 Patch
    
    ---
     shared/compat_semaphore.h |    4 ++--
     vmci_drv.c                |   12 +++++++-----
     2 files changed, 9 insertions(+), 7 deletions(-)
    
    diff --git a/shared/compat_semaphore.h b/shared/compat_semaphore.h
    index c2902f0..0add974 100644
    --- a/shared/compat_semaphore.h
    +++ b/shared/compat_semaphore.h
    @@ -28,7 +28,7 @@
     #endif
     
     
    -#if defined CONFIG_PREEMPT_RT && LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31)
    +#if (defined CONFIG_PREEMPT_RT && LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31)) || LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)
        /*
         * The -rt patch series changes the name of semaphore/mutex initialization
         * routines (across the entire kernel).  Probably to identify locations that
    @@ -41,7 +41,7 @@
           #define DECLARE_MUTEX(_m)  DEFINE_SEMAPHORE(_m)
        #endif
        #ifndef init_MUTEX
    -     #define init_MUTEX(_m) semaphore_init(_m)
    +      #define init_MUTEX(_m) sema_init(_m,1)
        #endif
     #endif
     
    diff --git a/vmci_drv.c b/vmci_drv.c
    index ac64f02..14ac3b5 100644
    --- a/vmci_drv.c
    +++ b/vmci_drv.c
    @@ -73,7 +73,7 @@ static int vmci_probe_device(struct pci_dev *pdev,
     static void vmci_remove_device(struct pci_dev* pdev);
     static int vmci_open(struct inode *inode, struct file *file);
     static int vmci_close(struct inode *inode, struct file *file);
    -static int vmci_ioctl(struct inode *inode, struct file *file, 
    +static long vmci_ioctl(struct file *file, 
                           unsigned int cmd, unsigned long arg);
     static unsigned int vmci_poll(struct file *file, poll_table *wait);
     #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19)
    @@ -93,7 +93,7 @@ static struct file_operations vmci_ops = {
        .owner   = THIS_MODULE,
        .open    = vmci_open,
        .release = vmci_close,
    -   .ioctl   = vmci_ioctl,
    +   .unlocked_ioctl   = vmci_ioctl,
        .poll    = vmci_poll,
     };
     
    @@ -496,9 +496,8 @@ vmci_close(struct inode *inode,  // IN
      *-----------------------------------------------------------------------------
      */
     
    -static int
    -vmci_ioctl(struct inode *inode,  // IN
    -           struct file *file,    // IN
    +static long
    +vmci_ioctl(struct file *file,    // IN
                unsigned int cmd,     // IN
                unsigned long arg)    // IN
     {
    @@ -506,10 +505,12 @@ vmci_ioctl(struct inode *inode,  // IN
        return -ENOTTY;
     #else
        int retval;
    +   lock_kernel();
        VMCIGuestDeviceHandle *devHndl =
           (VMCIGuestDeviceHandle *) file->private_data;
     
        if (devHndl == NULL) {
    +      unlock_kernel();
           return -EINVAL;
        }
     
    @@ -669,6 +670,7 @@ vmci_ioctl(struct inode *inode,  // IN
           break;
        }
     
    +   unlock_kernel();
        return retval;
     #endif
     }
    -- 
    1.7.4.1
    
  2. 0001-vmwaretool-vmhgfs-Linux-2.6.37.patch:
    From 2d1de0f0ea3ef2fce534944431c096baed1e423b Mon Sep 17 00:00:00 2001
    From: YOUNGWHAN SONG <breadncup@gmail.com>
    Date: Fri, 25 Feb 2011 23:07:15 -0800
    Subject: [PATCH] vmware:vmhgfs: Support new linux kernel 2.6.37
    
    ---
     super.c |    2 +-
     1 files changed, 1 insertions(+), 1 deletions(-)
    
    diff --git a/super.c b/super.c
    index f6f26ff..c5627f5 100644
    --- a/super.c
    +++ b/super.c
    @@ -70,7 +70,7 @@ struct super_operations HgfsSuperOperations = {
     #ifndef VMW_USE_IGET_LOCKED
        .read_inode    = HgfsReadInode,
     #endif
    -   .clear_inode   = HgfsClearInode,
    +   .evict_inode   = HgfsClearInode,
        .put_super     = HgfsPutSuper,
        .statfs        = HgfsStatfs,
     };
    -- 
    1.7.4.1
    
    
  3. 0001-vmwaretool-vsock-Linux-2.6.37.patch:
    From dea787ae80d9a6267be21928efc164d0b4f1d4c6 Mon Sep 17 00:00:00 2001
    From: YOUNGWHAN SONG <breadncup@gmail.com>
    Date: Fri, 25 Feb 2011 23:13:28 -0800
    Subject: [PATCH] vmwaretool:vsock:Linux-2.6.37
    
    ---
     shared/compat_semaphore.h |    4 ++--
     1 files changed, 2 insertions(+), 2 deletions(-)
    
    diff --git a/shared/compat_semaphore.h b/shared/compat_semaphore.h
    index 802d174..0add974 100644
    --- a/shared/compat_semaphore.h
    +++ b/shared/compat_semaphore.h
    @@ -28,7 +28,7 @@
     #endif
     
     
    -#if defined CONFIG_PREEMPT_RT && LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31)
    +#if (defined CONFIG_PREEMPT_RT && LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31)) || LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)
        /*
         * The -rt patch series changes the name of semaphore/mutex initialization
         * routines (across the entire kernel).  Probably to identify locations that
    @@ -41,7 +41,7 @@
           #define DECLARE_MUTEX(_m)  DEFINE_SEMAPHORE(_m)
        #endif
        #ifndef init_MUTEX
    -      #define init_MUTEX(_m) semaphore_init(_m)
    +      #define init_MUTEX(_m) sema_init(_m,1)
        #endif
     #endif
     
    -- 
    1.7.4.1
    
    

p.s. Thanks to Vyacheslav, I corrected the conditional branch definition. (03/15/2011)

Mac OSX HFS is case-insensitive Filesystem by default.

I am pretty new Mac OS, but my background is from Linux (Unix), so I didn’t notice that the default filesystem in Mac is case-insensitive.

While getting a code of linux kernel through svn, I encounter this error:

A     xxxxxx/linux/netfilter_ipv4/ipt_REJECT.h
svn:  In directory  'xxxxxx/linux/netfilter_ipv4'
svn:  Can't copy  'xxxxxx/linux/netfilter_ipv4/.svn/tmp/text-base/ipt_tcpmss.h.svn-base'  to  'xxxxxx/linux/netfilter_ipv4/.svn/tmp/ipt_tcpmss.h.tmp.tmp':  No such file or directory

This problem is caused by the case-insensitive filesystem being used in MacOS. There are distinguished files, ipt_TCPMSS.h and ipt_tcpmss.h for netfilter_ipv4.

To solve the problem, there are two ways.

1. Reformat HFS entirely with case-sensitive attribute.

This is very painful, and would cause not running properly for a certain software like Photoshop. (What a mistake: case-sensitive HFS on my mac book) However, this will make faster than using dmg.

2. Create a disk image (dmg) for the specific project with case-sensitive.

Using dmg would be a little bit slower, but this makes easy. Using Disk Utility, you can create a disk volume with case-sensitive attribute.

Way not to use Cache in Linux

Here is an information not to use cache in linux while reading the kernel newbie mailing list.

Hi!
On 19:29 Fri 04 Dec     , Lal wrote:
> Dear list members,
>
> I have a question about Linux page cache. I create a 10MB file using
> following application code:
>
> int fd=open(“foo.txt”, O_CREAT|O_RDWR|O_SYNC);
> char* content=(char *)malloc(1024*1024*10);
> write(fd, content, 1024*1024*10);
> free(content); close(fd);
>
> Immediately before and after this code execution, command “free -m”
> shows free memory decreased by 10M and cache incresed by 10M.
>
> If I delete foo.txt, then free memory increases by 10M and cache
> decreases by 10M.
>
> My question is why the cache is growing even after O_SYNC flag? Even
> fsync does not help. But deleting file freeing the cache.

O_SYNC does not mean “do not cache”. It means “make sure the data is written
to disk. The data is kept in memory even after writing to speed up subsequent
reads. If you do not want this, you can pass the O_DICECT flag. But be aware
that using this can easily slow you down.
Either way, if you want to write zeros to the file, make sure the buffer is
initialised after malloc, e.g. via memset or bzero. If you only want to
allocate a file with zeros, you can also consider using fallocate or sparse
files.

-Michi

Linux에서 Cache를 통하지 않고 통신하는 방법

Linux Kernel Mailing List를 보다가 유용한 정보인 듯 싶어 여기에 저장합니다.

Hi!
On 19:29 Fri 04 Dec     , Lal wrote:
> Dear list members,
>
> I have a question about Linux page cache. I create a 10MB file using
> following application code:
>
> int fd=open(“foo.txt”, O_CREAT|O_RDWR|O_SYNC);
> char* content=(char *)malloc(1024*1024*10);
> write(fd, content, 1024*1024*10);
> free(content); close(fd);
>
> Immediately before and after this code execution, command “free -m”
> shows free memory decreased by 10M and cache incresed by 10M.
>
> If I delete foo.txt, then free memory increases by 10M and cache
> decreases by 10M.
>
> My question is why the cache is growing even after O_SYNC flag? Even
> fsync does not help. But deleting file freeing the cache.

O_SYNC does not mean “do not cache”. It means “make sure the data is written
to disk. The data is kept in memory even after writing to speed up subsequent
reads. If you do not want this, you can pass the O_DICECT flag. But be aware
that using this can easily slow you down.
Either way, if you want to write zeros to the file, make sure the buffer is
initialised after malloc, e.g. via memset or bzero. If you only want to
allocate a file with zeros, you can also consider using fallocate or sparse
files.

-Michi