2015年12月1日 星期二

Default cluster size for NTFS, FAT, and exFAT

Default cluster size for NTFS, FAT, and exFAT

Summary

All file systems that are used by Windows organize your hard disk based on cluster size (also known as allocation unit size). Cluster size represents the smallest amount of disk space that can be used to hold a file. When file sizes do not come out to an even multiple of the cluster size, additional space must be used to hold the file (up to the next multiple of the cluster size). On the typical hard disk partition, the average amount of space that is lost in this manner can be calculated by using the equation (cluster size)/2 * (number of files).

If no cluster size is specified when you format a partition, defaults are selected based on the size of the partition. These defaults are selected to reduce the space that is lost and to reduce the fragmentation that occurs on the partition. 
More information
A hard disk partition (also known as a volume) can be formatted to NTFS, FAT, or exFAT. The default values are used by Windows when one of the following methods is used to format the partition:
  • Using the FORMAT command from the command line without specifying a cluster size.
  • Formatting a volume from Windows Explorer when the Allocation Unit box in the Format dialog box lists Default Allocation Size.

By default, the maximum cluster size for NTFS under Windows NT 4.0 and later versions of Windows is 4 kilobytes (KB). This is because NTFS file compression is not possible on drives that have a larger cluster size. The format command won't use clusters larger than 4 KB unless the user specifically overrides the default settings. You can do this by using the /A: switch together with the Format command or by specifying a larger cluster size in the Format dialog box in Windows Explorer.

When you use the Convert.exe utility to convert a FAT partition to NTFS, Windows always uses the original FAT cluster size as the NTFS cluster size for cluster sizes up to 4 KB. If the FAT cluster size is greater than 4 KB, then the clusters are converted down to 4 KB in NTFS. This is because the FAT structures are aligned on cluster boundaries. Therefore, any larger cluster size would not allow for the conversion to function. Note also when formatting a partition under Windows NT 3.5, 3.51, and 4.0 Setup, the partition is first formatted to FAT and then converted to NTFS, so the cluster size will also always be as described earlier when a partition is formatted in Setup.

Default cluster sizes for NTFS

The following table describes the default cluster sizes for NTFS.
Volume size Windows NT 3.51Windows NT 4.0Windows 7, Windows Server 2008 R2, Windows Server 2008, Windows Vista, Windows Server 2003, Windows XP, Windows 2000
7 MB–512 MB 512 bytes4 KB4 KB
512 MB–1 GB 1 KB4 KB4 KB
1 GB–2 GB 2 KB4 KB4 KB
2 GB–2 TB 4 KB4 KB4 KB
2 TB–16 TB Not Supported*Not Supported*4 KB
16TB–32 TB Not Supported*Not Supported*8 KB
32TB–64 TBNot Supported*Not Supported*16 KB
64TB–128 TBNot Supported*Not Supported*32 KB
128TB–256 TBNot Supported*Not Supported*64 KB
> 256 TBNot SupportedNot SupportedNot Supported

Note The asterisk (*) means that it is not supported because of the limitations of the master boot record (MBR).

Default cluster sizes for FAT16

The following table describes the default cluster sizes for FAT16.
Volume size Windows NT 3.51Windows NT 4.0Windows 7, Windows Server 2008 R2, Windows Server 2008, Windows Vista, Windows Server 2003, Windows XP, Windows 2000 
7 MB–8 MB Not supported Not supportedNot supported
8 MB–32 MB 512 bytes512 bytes512 bytes
32 MB–64 MB 1 KB 1 KB 1 KB
64 MB–128 MB 2 KB2 KB2 KB
128 MB–256 MB4 KB4 KB4 KB
256 MB–512 MB8 KB8 KB8 KB
512 MB–1 GB 16 KB 16 KB 16 KB
1 GB–2 GB 32 KB32 KB32 KB
2 GB–4 GB 64 KB64 KB64 KB
4 GB–8 GB Not supported 128 KB*Not supported
8 GB–16 GB Not supported 256 KB*Not supported
> 16 GBNot supported Not supportedNot supported
Note The asterisk (*) means that it is available only on media with a sector size greater than 512 bytes.

Default cluster sizes for FAT32

The following table describes the default cluster sizes for FAT32.
Volume sizeWindows NT 3.51Windows NT 4.0Windows 7, Windows Server 2008 R2, Windows Server 2008, Windows Vista, Windows Server 2003, Windows XP, Windows 2000 
7 MB–16MB Not supported Not supportedNot supported
16 MB–32 MB 512 bytes512 bytesNot supported
32 MB–64 MB 512 bytes512 bytes512 bytes
64 MB–128 MB 1 KB1 KB1 KB
128 MB–256 MB2 KB2 KB2 KB
256 MB–8GB4 KB4 KB4 KB
8GB–16GB 8 KB8 KB8 KB
16GB–32GB 16 KB16 KB16 KB
32GB–2TB 32 KBNot supported Not supported
> 2TBNot supported Not supportedNot supported

Default cluster sizes for exFAT

The following table describes the default cluster sizes for exFAT.
Volume size Windows 7, Windows Server 2008 R2, Windows Server 2008, Windows Vista, Windows Server 2003, Windows XP
7 MB–256 MB 4 KB
256 MB–32 GB 32 KB
32 GB–256 TB 128 KB
> 256 TB Not supported

Reference:

https://support.microsoft.com/en-gb/kb/140365

2015年11月26日 星期四

C / C++ Macro Tips

Stringification

Sometimes you may want to convert a macro argument into a string constant. Parameters are not replaced inside string constants, but you can use the ‘#’ preprocessing operator instead. When a macro parameter is used with a leading ‘#’, the preprocessor replaces it with the literal text of the actual argument, converted to a string constant. Unlike normal parameter replacement, the argument is not macro-expanded first. This is called stringification.
There is no way to combine an argument with surrounding text and stringify it all together. Instead, you can write a series of adjacent string constants and stringified arguments. The preprocessor will replace the stringified arguments with string constants. The C compiler will then combine all the adjacent string constants into one long string.
Here is an example of a macro definition that uses stringification:
     #define WARN_IF(EXP) \
     do { if (EXP) \
             fprintf (stderr, "Warning: " #EXP "\n"); } \
     while (0)
     WARN_IF (x == 0);
          ==> do { if (x == 0)
                fprintf (stderr, "Warning: " "x == 0" "\n"); } while (0);
The argument for EXP is substituted once, as-is, into the if statement, and once, stringified, into the argument to fprintf. If x were a macro, it would be expanded in the if statement, but not in the string.
The do and while (0) are a kludge to make it possible to write WARN_IF (arg);, which the resemblance of WARN_IF to a function would make C programmers want to do; see Swallowing the Semicolon.
Stringification in C involves more than putting double-quote characters around the fragment. The preprocessor backslash-escapes the quotes surrounding embedded string constants, and all backslashes within string and character constants, in order to get a valid C string constant with the proper contents. Thus, stringifying p = "foo\n"; results in "p = \"foo\\n\";". However, backslashes that are not inside string or character constants are not duplicated: ‘\n’ by itself stringifies to "\n".
All leading and trailing whitespace in text being stringified is ignored. Any sequence of whitespace in the middle of the text is converted to a single space in the stringified result. Comments are replaced by whitespace long before stringification happens, so they never appear in stringified text.
There is no way to convert a macro argument into a character constant.
If you want to stringify the result of expansion of a macro argument, you have to use two levels of macros.
     #define xstr(s) str(s)
     #define str(s) #s
     #define foo 4
     str (foo)
          ==> "foo"
     xstr (foo)
          ==> xstr (4)
          ==> str (4)
          ==> "4"
s is stringified when it is used in str, so it is not macro-expanded first. But s is an ordinary argument to xstr, so it is completely macro-expanded before xstr itself is expanded (see Argument Prescan). Therefore, by the time str gets to its argument, it has already been macro-expanded.

Concatenation

It is often useful to merge two tokens into one while expanding macros. This is called token pasting or token concatenation. The ‘##’ preprocessing operator performs token pasting. When a macro is expanded, the two tokens on either side of each ‘##’ operator are combined into a single token, which then replaces the ‘##’ and the two original tokens in the macro expansion. Usually both will be identifiers, or one will be an identifier and the other a preprocessing number. When pasted, they make a longer identifier. This isn't the only valid case. It is also possible to concatenate two numbers (or a number and a name, such as 1.5 and e3) into a number. Also, multi-character operators such as += can be formed by token pasting.
However, two tokens that don't together form a valid token cannot be pasted together. For example, you cannot concatenate x with + in either order. If you try, the preprocessor issues a warning and emits the two tokens. Whether it puts white space between the tokens is undefined. It is common to find unnecessary uses of ‘##’ in complex macros. If you get this warning, it is likely that you can simply remove the ‘##’.
Both the tokens combined by ‘##’ could come from the macro body, but you could just as well write them as one token in the first place. Token pasting is most useful when one or both of the tokens comes from a macro argument. If either of the tokens next to an ‘##’ is a parameter name, it is replaced by its actual argument before ‘##’ executes. As with stringification, the actual argument is not macro-expanded first. If the argument is empty, that ‘##’ has no effect.
Keep in mind that the C preprocessor converts comments to whitespace before macros are even considered. Therefore, you cannot create a comment by concatenating ‘/’ and ‘*’. You can put as much whitespace between ‘##’ and its operands as you like, including comments, and you can put comments in arguments that will be concatenated. However, it is an error if ‘##’ appears at either end of a macro body.
Consider a C program that interprets named commands. There probably needs to be a table of commands, perhaps an array of structures declared as follows:
     struct command
     {
       char *name;
       void (*function) (void);
     };
     
     struct command commands[] =
     {
       { "quit", quit_command },
       { "help", help_command },
       ...
     };
It would be cleaner not to have to give each command name twice, once in the string constant and once in the function name. A macro which takes the name of a command as an argument can make this unnecessary. The string constant can be created with stringification, and the function name by concatenating the argument with ‘_command’. Here is how it is done:
     #define COMMAND(NAME)  { #NAME, NAME ## _command }
     
     struct command commands[] =
     {
       COMMAND (quit),
       COMMAND (help),
       ...
     };

Variadic Macros

A macro can be declared to accept a variable number of arguments much as a function can. The syntax for defining the macro is similar to that of a function. Here is an example:
#define eprintf(...) fprintf (stderr, __VA_ARGS__) This kind of macro is called variadic. When the macro is invoked, all the tokens in its argument list after the last named argument (this macro has none), including any commas, become the variable argument. This sequence of tokens replaces the identifier __VA_ARGS__ in the macro body wherever it appears. Thus, we have this expansion:
eprintf ("%s:%d: ", input_file, lineno) ==> fprintf (stderr, "%s:%d: ", input_file, lineno) The variable argument is completely macro-expanded before it is inserted into the macro expansion, just like an ordinary argument. You may use the ‘#’ and ‘##’ operators to stringify the variable argument or to paste its leading or trailing token with another token. (But see below for an important special case for ‘##’.)
If your macro is complicated, you may want a more descriptive name for the variable argument than __VA_ARGS__. CPP permits this, as an extension. You may write an argument name immediately before the ‘...’; that name is used for the variable argument. The eprintf macro above could be written
#define eprintf(args...) fprintf (stderr, args)
using this extension. You cannot use __VA_ARGS__ and this extension in the same macro.
You can have named arguments as well as variable arguments in a variadic macro. We could define eprintf like this, instead:
#define eprintf(format, ...) fprintf (stderr, format, __VA_ARGS__)
This formulation looks more descriptive, but unfortunately it is less flexible: you must now supply at least one argument after the format string. In standard C, you cannot omit the comma separating the named argument from the variable arguments. Furthermore, if you leave the variable argument empty, you will get a syntax error, because there will be an extra comma after the format string.
eprintf("success!\n", ); ==> fprintf(stderr, "success!\n", ); GNU CPP has a pair of extensions which deal with this problem. First, you are allowed to leave the variable argument out entirely:
eprintf ("success!\n") ==> fprintf(stderr, "success!\n", );
Second, the ‘##’ token paste operator has a special meaning when placed between a comma and a variable argument. If you write
#define eprintf(format, ...) fprintf (stderr, format, ##__VA_ARGS__)
and the variable argument is left out when the eprintf macro is used, then the comma before the ‘##’ will be deleted. This does not happen if you pass an empty argument, nor does it happen if the token preceding ‘##’ is anything other than a comma.
eprintf ("success!\n") ==> fprintf(stderr, "success!\n");
The above explanation is ambiguous about the case where the only macro parameter is a variable arguments parameter, as it is meaningless to try to distinguish whether no argument at all is an empty argument or a missing argument. In this case the C99 standard is clear that the comma must remain, however the existing GCC extension used to swallow the comma. So CPP retains the comma when conforming to a specific C standard, and drops it otherwise.
C99 mandates that the only place the identifier __VA_ARGS__ can appear is in the replacement list of a variadic macro. It may not be used as a macro name, macro argument name, or within a different type of macro. It may also be forbidden in open text; the standard is ambiguous. We recommend you avoid using it except for its defined purpose.
Variadic macros are a new feature in C99. GNU CPP has supported them for a long time, but only with a named variable argument (‘args...’, not ‘...’ and __VA_ARGS__). If you are concerned with portability to previous versions of GCC, you should use only named variable arguments. On the other hand, if you are concerned with portability to other conforming implementations of C99, you should use only __VA_ARGS__.
Previous versions of CPP implemented the comma-deletion extension much more generally. We have restricted it in this release to minimize the differences from C99. To get the same effect with both this and previous versions of GCC, the token preceding the special ‘##’ must be a comma, and there must be white space between that comma and whatever comes immediately before it:
#define eprintf(format, args...) fprintf (stderr, format , ##args)
See Differences from previous versions, for the gory details.


About Double Parentheses:
If you see something like "SOME_MACRO (("%s, %d, %u", arg1, arg2, arg3));", you could probably define the "SOME_MACRO" as the following to use on it functions like printf():
#define SOME_MACRO(x) \
    printf x;
Otherwise, use the "Variadic Macros" described above.

Reference:

https://gcc.gnu.org/onlinedocs/cpp/Macros.html#Macros
http://www.tutorialspoint.com/cprogramming/c_preprocessors.htm
http://stackoverflow.com/questions/5812877/why-one-needs-two-brackets-to-use-macros-in-c-c

2015年11月10日 星期二

Declaring Attributes of Functions

Declaring Attributes of Functions


In GNU C, you declare certain things about functions called in your program which help the compiler optimize function calls and check your code more carefully.
The keyword __attribute__ allows you to specify special attributes when making a declaration. This keyword is followed by an attribute specification inside double parentheses. The following attributes are currently defined for functions on all targets: noreturn, noinline, always_inline, pure, const, nothrow, format, format_arg, no_instrument_function, section, constructor, destructor, used, unused, deprecated, weak, malloc, alias, and nonnull. Several other attributes are defined for functions on particular target systems. Other attributes, including section are supported for variables declarations (see Variable Attributes) and for types (see Type Attributes).
You may also specify attributes with __ preceding and following each keyword. This allows you to use them in header files without being concerned about a possible macro of the same name. For example, you may use __noreturn__ instead of noreturn.
See Attribute Syntax, for details of the exact syntax for using attributes.
noreturn
A few standard library functions, such as abort and exit, cannot return. GCC knows this automatically. Some programs define their own functions that never return. You can declare them noreturn to tell the compiler this fact. For example,
          void fatal () __attribute__ ((noreturn));
          
          void
          fatal (/* ... */)
          {
            /* ... */ /* Print error message. */ /* ... */
            exit (1);
          }
          
The noreturn keyword tells the compiler to assume that fatal cannot return. It can then optimize without regard to what would happen if fatal ever did return. This makes slightly better code. More importantly, it helps avoid spurious warnings of uninitialized variables.
Do not assume that registers saved by the calling function are restored before calling the noreturn function.
It does not make sense for a noreturn function to have a return type other than void.
The attribute noreturn is not implemented in GCC versions earlier than 2.5. An alternative way to declare that a function does not return, which works in the current version and in some older versions, is as follows:
          typedef void voidfn ();
          
          volatile voidfn fatal;
          
noinline
This function attribute prevents a function from being considered for inlining.
always_inline
Generally, functions are not inlined unless optimization is specified. For functions declared inline, this attribute inlines the function even if no optimization level was specified.
pure
Many functions have no effects except the return value and their return value depends only on the parameters and/or global variables. Such a function can be subject to common subexpression elimination and loop optimization just as an arithmetic operator would be. These functions should be declared with the attribute pure. For example,
          int square (int) __attribute__ ((pure));
          
says that the hypothetical function square is safe to call fewer times than the program says.
Some of common examples of pure functions are strlen or memcmp. Interesting non-pure functions are functions with infinite loops or those depending on volatile memory or other system resource, that may change between two consecutive calls (such as feof in a multithreading environment).
The attribute pure is not implemented in GCC versions earlier than 2.96.
const
Many functions do not examine any values except their arguments, and have no effects except the return value. Basically this is just slightly more strict class than the pure attribute above, since function is not allowed to read global memory. Note that a function that has pointer arguments and examines the data pointed to must not be declared const. Likewise, a function that calls a non-const function usually must not be const. It does not make sense for a const function to return void.
The attribute const is not implemented in GCC versions earlier than 2.5. An alternative way to declare that a function has no side effects, which works in the current version and in some older versions, is as follows:
          typedef int intfn ();
          
          extern const intfn square;
          
This approach does not work in GNU C++ from 2.6.0 on, since the language specifies that the const must be attached to the return value.
nothrow
The nothrow attribute is used to inform the compiler that a function cannot throw an exception. For example, most functions in the standard C library can be guaranteed not to throw an exception with the notable exceptions of qsort and bsearch that take function pointer arguments. The nothrow attribute is not implemented in GCC versions earlier than 3.2.
format (archetype, string-index, first-to-check)
The format attribute specifies that a function takes printf, scanf, strftime or strfmon style arguments which should be type-checked against a format string. For example, the declaration:
          extern int
          my_printf (void *my_object, const char *my_format, ...)
                __attribute__ ((format (printf, 2, 3)));
          
causes the compiler to check the arguments in calls to my_printf for consistency with the printf style format string argument my_format.
The parameter archetype determines how the format string is interpreted, and should be printf, scanf, strftime or strfmon. (You can also use __printf__, __scanf__, __strftime__ or __strfmon__.) The parameter string-index specifies which argument is the format string argument (starting from 1), while first-to-check is the number of the first argument to check against the format string. For functions where the arguments are not available to be checked (such as vprintf), specify the third parameter as zero. In this case the compiler only checks the format string for consistency. For strftime formats, the third parameter is required to be zero.
In the example above, the format string (my_format) is the second argument of the function my_print, and the arguments to check start with the third argument, so the correct parameters for the format attribute are 2 and 3.
The format attribute allows you to identify your own functions which take format strings as arguments, so that GCC can check the calls to these functions for errors. The compiler always (unless -ffreestanding is used) checks formats for the standard library functions printf, fprintf, sprintf, scanf, fscanf, sscanf, strftime, vprintf, vfprintf and vsprintf whenever such warnings are requested (using -Wformat), so there is no need to modify the header file stdio.h. In C99 mode, the functions snprintf, vsnprintf, vscanf, vfscanf and vsscanf are also checked. Except in strictly conforming C standard modes, the X/Open function strfmon is also checked as are printf_unlocked and fprintf_unlocked. See Options Controlling C Dialect.
format_arg (string-index)
The format_arg attribute specifies that a function takes a format string for a printf, scanf, strftime or strfmon style function and modifies it (for example, to translate it into another language), so the result can be passed to a printf, scanf, strftime or strfmon style function (with the remaining arguments to the format function the same as they would have been for the unmodified string). For example, the declaration:
          extern char *
          my_dgettext (char *my_domain, const char *my_format)
                __attribute__ ((format_arg (2)));
          
causes the compiler to check the arguments in calls to a printf, scanf, strftime or strfmon type function, whose format string argument is a call to the my_dgettext function, for consistency with the format string argument my_format. If the format_arg attribute had not been specified, all the compiler could tell in such calls to format functions would be that the format string argument is not constant; this would generate a warning when -Wformat-nonliteral is used, but the calls could not be checked without the attribute.
The parameter string-index specifies which argument is the format string argument (starting from 1).
The format-arg attribute allows you to identify your own functions which modify format strings, so that GCC can check the calls to printf, scanf, strftime or strfmon type function whose operands are a call to one of your own function. The compiler always treats gettext, dgettext, and dcgettext in this manner except when strict ISO C support is requested by -ansi or an appropriate -std option, or -ffreestanding is used. See Options Controlling C Dialect.
nonnull (arg-index, ...)
The nonnull attribute specifies that some function parameters should be non-null pointers. For instance, the declaration:
          extern void *
          my_memcpy (void *dest, const void *src, size_t len)
           __attribute__((nonnull (1, 2)));
          
causes the compiler to check that, in calls to my_memcpy, arguments dest and src are non-null. If the compiler determines that a null pointer is passed in an argument slot marked as non-null, and the -Wnonnull option is enabled, a warning is issued. The compiler may also choose to make optimizations based on the knowledge that certain function arguments will not be null.
If no argument index list is given to the nonnull attribute, all pointer arguments are marked as non-null. To illustrate, the following declaration is equivalent to the previous example:
          extern void *
          my_memcpy (void *dest, const void *src, size_t len)
           __attribute__((nonnull));
          
no_instrument_function
If -finstrument-functions is given, profiling function calls will be generated at entry and exit of most user-compiled functions. Functions with this attribute will not be so instrumented.
section ("section-name")
Normally, the compiler places the code it generates in the text section. Sometimes, however, you need additional sections, or you need certain particular functions to appear in special sections. The section attribute specifies that a function lives in a particular section. For example, the declaration:
          extern void foobar (void) __attribute__ ((section ("bar")));
          
puts the function foobar in the bar section.
Some file formats do not support arbitrary sections so the section attribute is not available on all platforms. If you need to map the entire contents of a module to a particular section, consider using the facilities of the linker instead.
constructor

destructor
The constructor attribute causes the function to be called automatically before execution enters main (). Similarly, the destructor attribute causes the function to be called automatically after main () has completed or exit () has been called. Functions with these attributes are useful for initializing data that will be used implicitly during the execution of the program. These attributes are not currently implemented for Objective-C.
unused
This attribute, attached to a function, means that the function is meant to be possibly unused. GCC will not produce a warning for this function. GNU C++ does not currently support this attribute as definitions without parameters are valid in C++.
used
This attribute, attached to a function, means that code must be emitted for the function even if it appears that the function is not referenced. This is useful, for example, when the function is referenced only in inline assembly.
deprecated
The deprecated attribute results in a warning if the function is used anywhere in the source file. This is useful when identifying functions that are expected to be removed in a future version of a program. The warning also includes the location of the declaration of the deprecated function, to enable users to easily find further information about why the function is deprecated, or what they should do instead. Note that the warnings only occurs for uses:
          int old_fn () __attribute__ ((deprecated));
          int old_fn ();
          int (*fn_ptr)() = old_fn;
          
results in a warning on line 3 but not line 2.
The deprecated attribute can also be used for variables and types (see Variable Attributes, see Type Attributes.)
weak
The weak attribute causes the declaration to be emitted as a weak symbol rather than a global. This is primarily useful in defining library functions which can be overridden in user code, though it can also be used with non-function declarations. Weak symbols are supported for ELF targets, and also for a.out targets when using the GNU assembler and linker.
malloc
The malloc attribute is used to tell the compiler that a function may be treated as if it were the malloc function. The compiler assumes that calls to malloc result in a pointers that cannot alias anything. This will often improve optimization.
alias ("target")
The alias attribute causes the declaration to be emitted as an alias for another symbol, which must be specified. For instance,
          void __f () { /* Do something. */; }
          void f () __attribute__ ((weak, alias ("__f")));
          
declares f to be a weak alias for __f. In C++, the mangled name for the target must be used.
Not all target machines support this attribute.
visibility ("visibility_type")
The visibility attribute on ELF targets causes the declaration to be emitted with default, hidden, protected or internal visibility.
          void __attribute__ ((visibility ("protected")))
          f () { /* Do something. */; }
          int i __attribute__ ((visibility ("hidden")));
          
See the ELF gABI for complete details, but the short story is
default
Default visibility is the normal case for ELF. This value is available for the visibility attribute to override other options that may change the assumed visibility of symbols.
hidden
Hidden visibility indicates that the symbol will not be placed into the dynamic symbol table, so no other module (executable or shared library) can reference it directly.
protected
Protected visibility indicates that the symbol will be placed in the dynamic symbol table, but that references within the defining module will bind to the local symbol. That is, the symbol cannot be overridden by another module.
internal
Internal visibility is like hidden visibility, but with additional processor specific semantics. Unless otherwise specified by the psABI, gcc defines internal visibility to mean that the function is never called from another module. Note that hidden symbols, while then cannot be referenced directly by other modules, can be referenced indirectly via function pointers. By indicating that a symbol cannot be called from outside the module, gcc may for instance omit the load of a PIC register since it is known that the calling function loaded the correct value.
Not all ELF targets support this attribute.
tls_model ("tls_model")
The tls_model attribute sets thread-local storage model (see Thread-Local) of a particular __thread variable, overriding -ftls-model= command line switch on a per-variable basis. The tls_model argument should be one of global-dynamic, local-dynamic, initial-exec or local-exec.
regparm (number)
On the Intel 386, the regparm attribute causes the compiler to pass up to number integer arguments in registers EAX, EDX, and ECX instead of on the stack. Functions that take a variable number of arguments will continue to be passed all of their arguments on the stack.
stdcall
On the Intel 386, the stdcall attribute causes the compiler to assume that the called function will pop off the stack space used to pass arguments, unless it takes a variable number of arguments. The PowerPC compiler for Windows NT currently ignores the stdcall attribute.
cdecl
On the Intel 386, the cdecl attribute causes the compiler to assume that the calling function will pop off the stack space used to pass arguments. This is useful to override the effects of the -mrtd switch. The PowerPC compiler for Windows NT currently ignores the cdecl attribute.
longcall/shortcall
On the RS/6000 and PowerPC, the longcall attribute causes the compiler to always call this function via a pointer, just as it would if the -mlongcall option had been specified. The shortcall attribute causes the compiler not to do this. These attributes override both the -mlongcall switch and the #pragma longcall setting. See RS/6000 and PowerPC Options, for more information on when long calls are and are not necessary.
long_call/short_call
This attribute allows to specify how to call a particular function on ARM. Both attributes override the -mlong-calls (see ARM Options) command line switch and #pragma long_calls settings. The long_call attribute causes the compiler to always call the function by first loading its address into a register and then using the contents of that register. The short_call attribute always places the offset to the function from the call site into the BL instruction directly.
dllimport
On the PowerPC running Windows NT, the dllimport attribute causes the compiler to call the function via a global pointer to the function pointer that is set up by the Windows NT dll library. The pointer name is formed by combining __imp_ and the function name.
dllexport
On the PowerPC running Windows NT, the dllexport attribute causes the compiler to provide a global pointer to the function pointer, so that it can be called with the dllimport attribute. The pointer name is formed by combining __imp_ and the function name.
exception (except-func [, except-arg])
On the PowerPC running Windows NT, the exception attribute causes the compiler to modify the structured exception table entry it emits for the declared function. The string or identifier except-func is placed in the third entry of the structured exception table. It represents a function, which is called by the exception handling mechanism if an exception occurs. If it was specified, the string or identifier except-arg is placed in the fourth entry of the structured exception table.
function_vector
Use this attribute on the H8/300 and H8/300H to indicate that the specified function should be called through the function vector. Calling a function through the function vector will reduce code size, however; the function vector has a limited size (maximum 128 entries on the H8/300 and 64 entries on the H8/300H) and shares space with the interrupt vector. You must use GAS and GLD from GNU binutils version 2.7 or later for this attribute to work correctly.
interrupt
Use this attribute on the ARM, AVR, M32R/D and Xstormy16 ports to indicate that the specified function is an interrupt handler. The compiler will generate function entry and exit sequences suitable for use in an interrupt handler when this attribute is present. Note, interrupt handlers for the H8/300, H8/300H and SH processors can be specified via the interrupt_handler attribute.
Note, on the AVR interrupts will be enabled inside the function.
Note, for the ARM you can specify the kind of interrupt to be handled by adding an optional parameter to the interrupt attribute like this:
          void f () __attribute__ ((interrupt ("IRQ")));
          
Permissible values for this parameter are: IRQ, FIQ, SWI, ABORT and UNDEF.
interrupt_handler
Use this attribute on the H8/300, H8/300H and SH to indicate that the specified function is an interrupt handler. The compiler will generate function entry and exit sequences suitable for use in an interrupt handler when this attribute is present.
sp_switch
Use this attribute on the SH to indicate an interrupt_handler function should switch to an alternate stack. It expects a string argument that names a global variable holding the address of the alternate stack.
          void *alt_stack;
          void f () __attribute__ ((interrupt_handler,
                                    sp_switch ("alt_stack")));
          
trap_exit
Use this attribute on the SH for an interrupt_handle to return using trapa instead of rte. This attribute expects an integer argument specifying the trap number to be used.
eightbit_data
Use this attribute on the H8/300 and H8/300H to indicate that the specified variable should be placed into the eight bit data section. The compiler will generate more efficient code for certain operations on data in the eight bit data area. Note the eight bit data area is limited to 256 bytes of data. You must use GAS and GLD from GNU binutils version 2.7 or later for this attribute to work correctly.
tiny_data
Use this attribute on the H8/300H to indicate that the specified variable should be placed into the tiny data section. The compiler will generate more efficient code for loads and stores on data in the tiny data section. Note the tiny data area is limited to slightly under 32kbytes of data.
signal
Use this attribute on the AVR to indicate that the specified function is an signal handler. The compiler will generate function entry and exit sequences suitable for use in an signal handler when this attribute is present. Interrupts will be disabled inside function.
naked
Use this attribute on the ARM, AVR and IP2K ports to indicate that the specified function do not need prologue/epilogue sequences generated by the compiler. It is up to the programmer to provide these sequences.
model (model-name)
Use this attribute on the M32R/D to set the addressability of an object, and the code generated for a function. The identifier model-name is one of small, medium, or large, representing each of the code models. Small model objects live in the lower 16MB of memory (so that their addresses can be loaded with the ld24 instruction), and are callable with the bl instruction.
Medium model objects may live anywhere in the 32-bit address space (the compiler will generate seth/add3 instructions to load their addresses), and are callable with the bl instruction.
Large model objects may live anywhere in the 32-bit address space (the compiler will generate seth/add3 instructions to load their addresses), and may not be reachable with the bl instruction (the compiler will generate the much slower seth/add3/jl instruction sequence).
far
On 68HC11 and 68HC12 the far attribute causes the compiler to use a calling convention that takes care of switching memory banks when entering and leaving a function. This calling convention is also the default when using the -mlong-calls option. On 68HC12 the compiler will use the call and rtc instructions to call and return from a function.
On 68HC11 the compiler will generate a sequence of instructions to invoke a board-specific routine to switch the memory bank and call the real function. The board-specific routine simulates a call. At the end of a function, it will jump to a board-specific routine instead of using rts. The board-specific return routine simulates the rtc.
near
On 68HC11 and 68HC12 the near attribute causes the compiler to use the normal calling convention based on jsr and rts. This attribute can be used to cancel the effect of the -mlong-calls option.
You can specify multiple attributes in a declaration by separating them by commas within the double parentheses or by immediately following an attribute declaration with another attribute declaration.
Some people object to the __attribute__ feature, suggesting that ISO C's #pragma should be used instead. At the time __attribute__ was designed, there were two reasons for not doing this.
  1. It is impossible to generate #pragma commands from a macro.
  2. There is no telling what the same #pragma might mean in another compiler.
These two reasons applied to almost any application that might have been proposed for #pragma. It was basically a mistake to use #pragma for anything.
The ISO C99 standard includes _Pragma, which now allows pragmas to be generated from macros. In addition, a #pragma GCC namespace is now in use for GCC-specific pragmas. However, it has been found convenient to use __attribute__ to achieve a natural attachment of attributes to their corresponding declarations, whereas #pragma GCC is of use for constructs that do not naturally form part of the grammar. See Miscellaneous Preprocessing Directives.


Reference:

https://gcc.gnu.org/onlinedocs/gcc-3.3/gcc/Function-Attributes.html

Specifying Attributes of Variables

Specifying Attributes of Variables

The keyword __attribute__ allows you to specify special attributes of variables or structure fields. This keyword is followed by an attribute specification inside double parentheses. Ten attributes are currently defined for variables: aligned, mode, nocommon, packed, section, transparent_union, unused, deprecated, vector_size, and weak. Some other attributes are defined for variables on particular target systems. Other attributes are available for functions (see Function Attributes) and for types (see Type Attributes). Other front ends might define more attributes (see Extensions to the C++ Language).
You may also specify attributes with __ preceding and following each keyword. This allows you to use them in header files without being concerned about a possible macro of the same name. For example, you may use __aligned__ instead of aligned.
See Attribute Syntax, for details of the exact syntax for using attributes.
aligned (alignment)
This attribute specifies a minimum alignment for the variable or structure field, measured in bytes. For example, the declaration:
          int x __attribute__ ((aligned (16))) = 0;
          
causes the compiler to allocate the global variable x on a 16-byte boundary. On a 68040, this could be used in conjunction with an asm expression to access the move16 instruction which requires 16-byte aligned operands.
You can also specify the alignment of structure fields. For example, to create a double-word aligned int pair, you could write:
          struct foo { int x[2] __attribute__ ((aligned (8))); };
          
This is an alternative to creating a union with a double member that forces the union to be double-word aligned.
As in the preceding examples, you can explicitly specify the alignment (in bytes) that you wish the compiler to use for a given variable or structure field. Alternatively, you can leave out the alignment factor and just ask the compiler to align a variable or field to the maximum useful alignment for the target machine you are compiling for. For example, you could write:
          short array[3] __attribute__ ((aligned));
          
Whenever you leave out the alignment factor in an aligned attribute specification, the compiler automatically sets the alignment for the declared variable or field to the largest alignment which is ever used for any data type on the target machine you are compiling for. Doing this can often make copy operations more efficient, because the compiler can use whatever instructions copy the biggest chunks of memory when performing copies to or from the variables or fields that you have aligned this way.
The aligned attribute can only increase the alignment; but you can decrease it by specifying packed as well. See below.
Note that the effectiveness of aligned attributes may be limited by inherent limitations in your linker. On many systems, the linker is only able to arrange for variables to be aligned up to a certain maximum alignment. (For some linkers, the maximum supported alignment may be very very small.) If your linker is only able to align variables up to a maximum of 8 byte alignment, then specifying aligned(16) in an __attribute__ will still only provide you with 8 byte alignment. See your linker documentation for further information.
mode (mode)
This attribute specifies the data type for the declaration--whichever type corresponds to the mode mode. This in effect lets you request an integer or floating point type according to its width. You may also specify a mode of byte or __byte__ to indicate the mode corresponding to a one-byte integer, word or __word__ for the mode of a one-word integer, and pointer or __pointer__ for the mode used to represent pointers.
nocommon
This attribute specifies requests GCC not to place a variable "common" but instead to allocate space for it directly. If you specify the -fno-common flag, GCC will do this for all variables. Specifying the nocommon attribute for a variable provides an initialization of zeros. A variable may only be initialized in one source file.
packed
The packed attribute specifies that a variable or structure field should have the smallest possible alignment--one byte for a variable, and one bit for a field, unless you specify a larger value with the aligned attribute. Here is a structure in which the field x is packed, so that it immediately follows a:
          struct foo
          {
            char a;
            int x[2] __attribute__ ((packed));
          };
          
section ("section-name")
Normally, the compiler places the objects it generates in sections like data and bss. Sometimes, however, you need additional sections, or you need certain particular variables to appear in special sections, for example to map to special hardware. The section attribute specifies that a variable (or function) lives in a particular section. For example, this small program uses several specific section names:
          struct duart a __attribute__ ((section ("DUART_A"))) = { 0 };
          struct duart b __attribute__ ((section ("DUART_B"))) = { 0 };
          char stack[10000] __attribute__ ((section ("STACK"))) = { 0 };
          int init_data __attribute__ ((section ("INITDATA"))) = 0;
          
          main()
          {
            /* Initialize stack pointer */
            init_sp (stack + sizeof (stack));
          
            /* Initialize initialized data */
            memcpy (&init_data, &data, &edata - &data);
          
            /* Turn on the serial ports */
            init_duart (&a);
            init_duart (&b);
          }
          
Use the section attribute with an initialized definition of a global variable, as shown in the example. GCC issues a warning and otherwise ignores the section attribute in uninitialized variable declarations.
You may only use the section attribute with a fully initialized global definition because of the way linkers work. The linker requires each object be defined once, with the exception that uninitialized variables tentatively go in the common (or bss) section and can be multiply "defined". You can force a variable to be initialized with the -fno-common flag or the nocommon attribute.
Some file formats do not support arbitrary sections so the section attribute is not available on all platforms. If you need to map the entire contents of a module to a particular section, consider using the facilities of the linker instead.
shared
On Windows NT, in addition to putting variable definitions in a named section, the section can also be shared among all running copies of an executable or DLL. For example, this small program defines shared data by putting it in a named section shared and marking the section shareable:
          int foo __attribute__((section ("shared"), shared)) = 0;
          
          int
          main()
          {
            /* Read and write foo.  All running
               copies see the same value.  */
            return 0;
          }
          
You may only use the shared attribute along with section attribute with a fully initialized global definition because of the way linkers work. See section attribute for more information.
The shared attribute is only available on Windows NT.
transparent_union
This attribute, attached to a function parameter which is a union, means that the corresponding argument may have the type of any union member, but the argument is passed as if its type were that of the first union member. For more details see See Type Attributes. You can also use this attribute on a typedef for a union data type; then it applies to all function parameters with that type.
unused
This attribute, attached to a variable, means that the variable is meant to be possibly unused. GCC will not produce a warning for this variable.
deprecated
The deprecated attribute results in a warning if the variable is used anywhere in the source file. This is useful when identifying variables that are expected to be removed in a future version of a program. The warning also includes the location of the declaration of the deprecated variable, to enable users to easily find further information about why the variable is deprecated, or what they should do instead. Note that the warnings only occurs for uses:
          extern int old_var __attribute__ ((deprecated));
          extern int old_var;
          int new_fn () { return old_var; }
          
results in a warning on line 3 but not line 2.
The deprecated attribute can also be used for functions and types (see Function Attributes, see Type Attributes.)
vector_size (bytes)
This attribute specifies the vector size for the variable, measured in bytes. For example, the declaration:
          int foo __attribute__ ((vector_size (16)));
          
causes the compiler to set the mode for foo, to be 16 bytes, divided into int sized units. Assuming a 32-bit int (a vector of 4 units of 4 bytes), the corresponding mode of foo will be V4SI.
This attribute is only applicable to integral and float scalars, although arrays, pointers, and function return values are allowed in conjunction with this construct.
Aggregates with this attribute are invalid, even if they are of the same size as a corresponding scalar. For example, the declaration:
          struct S { int a; };
          struct S  __attribute__ ((vector_size (16))) foo;
          
is invalid even if the size of the structure is the same as the size of the int.
weak
The weak attribute is described in See Function Attributes.
model (model-name)
Use this attribute on the M32R/D to set the addressability of an object. The identifier model-name is one of small, medium, or large, representing each of the code models. Small model objects live in the lower 16MB of memory (so that their addresses can be loaded with the ld24 instruction).
Medium and large model objects may live anywhere in the 32-bit address space (the compiler will generate seth/add3 instructions to load their addresses).
To specify multiple attributes, separate them by commas within the double parentheses: for example, __attribute__ ((aligned (16), packed)).


Reference:


https://gcc.gnu.org/onlinedocs/gcc-3.3/gcc/Variable-Attributes.html#Variable%20Attributes

2015年11月7日 星期六

Outlook 2003 (或其他較舊的應用程式) 存取 Gmail

登入 Google 帳號戶後在我的帳戶裡選擇"已連結的網站與應用程式"並開啟下列選項:
[允許安全性較低的應用程式] 設定處於停用狀態
由於某些非 Google 應用程式和裝置採用的登入技術安全性較低,您的帳戶可能會因此出現安全漏洞。建議您停用這類應用程式的存取權限;當然,您也可以選擇使用這類應用程式,但請瞭解相關風險。

2015年10月21日 星期三

Windows CIFS Access Error

1. cannot access OOO: cannot allocate memory:

Restart Server: 
a. Open a command line window (with administrative privilege)
b. net stop server & net start server.
  OR
a. Open Services window (find shortcut in Start Menu->System   
    Management Tools->Services or just Win+R input "services.msc").
b. Locate the "Server", right click on it and select "Restart".

2015年10月2日 星期五

Python Packaging with setuptools

Installation


Normal installation

$ easy_install.py Package
$ easy_install.py http://sample.host/Package-X.Y.tar.gz
$ easy_install.py http://svn.sample.host/Package/trunk

Development installation

$ easy_install.py --editable --build <DIR> Package
$ # or just download and unpack the package
$ cd <DIR>/Package
$ sudo python setup.py develop

Isolated (version-specific) installation

$ easy_install.py -m Package==X.Y
$ python
>>> import pkg_resources
>>> require('Package==X.Y')

easy_install.py (General)

$ easy_install.py kid


easy_install.py (Development)

$ easy_install.py --editable \
  --build-directory ~/co \
  --find-links=http://pythonpaste.org/package_index.html \
  Paste
$ cd ~/co/paste
$ sudo python setup.py develop

* develop installs a package without moving it into site-packages/
* Paste.egg-link is the poor man's symlink to ~/co/paste
* easy-install.pth also points to ~/co/paste
* Python finds .pth files in site-packages and adds their contents to sys.path


Installing in Isolation


$ sudo python setup.py easy_install --multi-version

Creating Packages

Package layout should be like the following:
mypackage-1.0.0/
|-- README
|-- setup.py
|-- ez_setup.py
|-- mypackage/
|   |-- __init__.py
|   |-- source1.py
|   |-- source2.py
|   |-- data/ (optional)
|       |-- mydata.json
|-- tests (optional)
|-- |-- __init__.py
|-- |-- runall.py
|-- |-- test0.py
|-- docs (optional)
|-- |-- source
|-- |-- build
|-- |-- |-- html
|-- |-- |-- pdf

* Download ez_setup.py from https://bootstrap.pypa.io/ez_setup.py.

Sample for setup.py (hashcalclib):
import io
import textwrap
from distutils.util import convert_path
from ez_setup import use_setuptools
use_setuptools()
from setuptools import setup, find_packages


mainNS = {}
initPath = convert_path('hashcalclib/__init__.py')
with open(initPath, 'r') as file_:
    exec(file_.read(), mainNS)

readmeFile = io.open('README.txt', encoding='utf-8')
with readmeFile:
    longDescription = readmeFile.read()

setupParams = dict(\
    name='hashcalclib', \
    version=mainNS['__version__'], \
    description='A hash calculation and verification library.', \
    long_description=longDescription, \
    author=mainNS['__author__'], \
    author_email=mainNS['__email__'], \
    license=mainNS['__license__'], \
    keywords='', \
    url=mainNS['__url__'], \
    packages=find_packages(exclude=['*.tests']), \
    zip_safe=False, \
    classifiers=textwrap.dedent(\
        """
        Development Status :: 4 - Beta
        Environment :: Console
        Environment :: Win32 (MS Windows)
        Environment :: X11 Applications
        Intended Audience :: Developers
        Intended Audience :: End Users/Desktop
        License :: OSI Approved :: GNU General Public License v2 (GPLv2)
        License :: OSI Approved :: Python Software Foundation License
        Operating System :: OS Independent
        Programming Language :: Python :: 2.6
        Programming Language :: Python :: 2.7
        Topic :: Security :: Cryptography
        Topic :: Utilities
        """
    ).strip().splitlines(),
)
* See the references section for more classifiers.

When everything is ready, use "python setup.py --help-commands" to view the commands:
Standard commands:
  build               build everything needed to install
  build_py          "build" pure Python modules (copy to build directory)
  build_ext         build C/C++ extensions (compile/link to build directory)
  build_clib         build C/C++ libraries used by Python extensions
  build_scripts    "build" scripts (copy and fixup #! line)
  clean               clean up temporary files from 'build' command
  install              install everything from build directory
  install_lib         install all Python modules (extensions and pure Python)
  install_headers   install C/C++ header files
  install_scripts   install scripts (Python or otherwise)
  install_data      install data files
  sdist                 create a source distribution (tarball, zip file, etc.)
  register            register the distribution with the Python package index
  bdist                create a built (binary) distribution
  bdist_dumb     create a "dumb" built distribution
  bdist_rpm        create an RPM distribution
  bdist_wininst   create an executable installer for MS Windows
  upload            upload binary package to PyPI

Extra commands:
  develop           install package in 'development mode'
  saveopts          save supplied options to setup.cfg or other config file
  egg_info          create a distribution's .egg-info directory
  upload_docs    Upload documentation to PyPI
  alias                define a shortcut to invoke one or more commands
  easy_install     Find/get/install Python packages
  rotate             delete older distributions, keeping N newest files
  bdist_egg        create an "egg" distribution
  install_egg_info  Install an .egg-info directory for the package
  test                 run unit tests after in-place build
  build_sphinx    Build Sphinx documentation
  setopt             set an option in setup.cfg or another config file

usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: setup.py --help [cmd1 cmd2 ...]
   or: setup.py --help-commands
   or: setup.py cmd --help


Reference:

https://pythonhosted.org/an_example_pypi_project/index.html
https://pypi.python.org/pypi/setuptools/
https://pypi.python.org/pypi?%3Aaction=list_classifiers
http://www.ianbicking.org/docs/setuptools-presentation/
https://bashelton.com/2009/04/setuptools-tutorial/

2015年9月17日 星期四

Windows Application / Driver without a digital signature or with a expired digital signature

1. Open a command line with administrator privileges (right click on the "cmd" shortcut and select "open with administrator privileges").
2. Run the executable binary (installer or application) in the cmd window.

2015年8月12日 星期三

wxPython: Send event manually (v2.8.x)

#!/usr/bin/env python
# vim: tabstop=8 shiftwidth=4 softtabstop=4
# python version: 2.7.5 final, serial: 0

import sys
import wxversion
wxversion.select('2.8')
import wx


class DemoApp(wx.App):
    def OnInit(self):
        self._frame = DemoMainFrame(None, title='Send Event Demo')
        self.SetTopWindow(self._frame)
        self._frame.Show()
        return True
    # end of OnInit
# end of DemoApp


class DemoMainFrame(wx.Frame):
    def __init__(self, parent, id_=wx.ID_ANY, title='Main', \
                      pos=wx.DefaultPosition, size=wx.DefaultSize, \
                      style=wx.DEFAULT_FRAME_STYLE, name='Main'):
        super(DemoMainFrame, self).__init__(\
            parent, id_, title, pos, size, style, name)
        self.Centre(wx.BOTH)
        self._mainMenu = wx.MenuBar()
        self._fileMenu = wx.Menu()
        self._checkItem = self._fileMenu.AppendCheckItem(\
            wx.ID_ANY, 'Check Item')
        self.Bind(wx.EVT_MENU, self._onCheckItemClick, self._checkItem)
        self._mainMenu.Append(self._fileMenu, 'File(&F)')
        self.SetMenuBar(self._mainMenu)
        self._panel = wx.Panel(self, wx.ID_ANY)
        self._button = wx.Button(self._panel, wx.ID_ANY, 'Send Event')
        self._button.SetPosition((10, 10))
        self._button.Bind(wx.EVT_BUTTON, self._onButtonClick)
    # end of __init__

    def _onCheckItemClick(self, event):
        style = wx.OK | wx.ICON_INFORMATION | wx.STAY_ON_TOP | wx.CENTRE
        dialog = wx.MessageDialog(self, 'Check Item Clicked!', 'Check Item', style)
        dialog.ShowModal()
        if dialog:
            dialog.Destroy()
    # end of _onCheckItemClick


    def _onButtonClick(self, event):
        sendEvent(wx.wxEVT_COMMAND_MENU_SELECTED, self._checkItem.Id, \
                          self._fileMenu, self.GetEventHandler())

        self._checkItem.Check(not self._checkItem.IsChecked())
    # end of _onButtonClick

def sendEvent(eventType, targetID, eventObj, eventHandler, isSetInt=True, \
              eventClass=wx.CommandEvent):
    """Send a event manually."""
    event = eventClass(eventType, targetID)
    if isSetInt:
        event.SetInt(1)
    event.SetEventObject(eventObj)
    #wx.PostEvent(eventHandler, event)
    assert eventHandler.ProcessEvent(event), 'Send event fail!'
# end of sendEvent


def _main():
    try:
        app = DemoApp(False)
        app.SetAppName('Send Event Demo')
        app.MainLoop()
    except KeyboardInterrupt:
        sys.exit(0)
# end of _main

if __name__ == '__main__':
    _main()
# end of __main__

2015年8月3日 星期一

How To Backup / Restore Master Boot Record (MBR) in Linux

Structure of a classical generic MBR
Address Description Size
(bytes)
Hex Dec
+000h +0 Bootstrap code area 446
+1BEh +446 Partition entry #1 Partition table
(for primary partitions)
16
+1CEh +462 Partition entry #2 16
+1DEh +478 Partition entry #3 16
+1EEh +494 Partition entry #4 16
+1FEh +510 55h Boot signature[a] 2
+1FFh +511 AAh
Total size: 446 + 4×16 + 2 512

Backup / Restore Bootstrap code w/wo Partition Table

Use 446 bytes to backup / restore your /dev/s(h)dx MBR boot code.
Use 512 bytes to backup / restore your /dev/s(h)dx MBR boot code and disk partition table.

*** Use the following commands with CAUTION or it will destroy your data! ***

Clone the MBR From One Disk to Another (With Identical Sized Partitions)


Copy the MBR (first 512 bytes) from disk sda to disk sdb:
$ dd if=/dev/sda of=/dev/sdb bs=512 count=1

Clone the MBR From One Disk to Another (With different Sized Partitions)

Backup the MBR of target disk (sdb):
$ dd if=/dev/sdb of=/tmp/sdb_mbr.bak bs=512 count=1

Copy the MBR (first 446 bytes, without partition table) from disk sda to disk sdb:
$ dd if=/dev/sda of=/dev/sdb bs=446 count=1

Backup / Restore the Primary and Extended Partitions

Backup:
$ sfdisk -d /dev/sda> sda.out

Restore:
$ sfdisk /dev/sda < sda.out

Reference:

https://wiki.archlinux.org/index.php/Disk_Cloning
https://en.wikipedia.org/wiki/Master_boot_record
http://manpages.ubuntu.com/manpages/natty/man1/dd.1.html
http://manpages.ubuntu.com/manpages/hardy/man8/sfdisk.8.html

2015年7月10日 星期五

VMware Workstation 9.0.4 Installation on Ubuntu 14.04.1 LTS

After installation and configuration completed, vmware would compile its modules and the following error occurred:


Using 2.6.x kernel build system.
make: Entering directory `/tmp/modconfig-GQ2cZR/vmnet-only'
/usr/bin/make -C /lib/modules/3.13.0-39-generic/build/include/.. SUBDIRS=$PWD SRCROOT=$PWD/. \
          MODULEBUILDDIR= modules
make[1]: Entering directory `/usr/src/linux-headers-3.13.0-39-generic'
  CC [M]  /tmp/modconfig-GQ2cZR/vmnet-only/driver.o
  CC [M]  /tmp/modconfig-GQ2cZR/vmnet-only/hub.o
  CC [M]  /tmp/modconfig-GQ2cZR/vmnet-only/userif.o
  CC [M]  /tmp/modconfig-GQ2cZR/vmnet-only/netif.o
In file included from /tmp/modconfig-GQ2cZR/vmnet-only/vnet.h:28:0,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/vnetInt.h:24,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/hub.c:43:
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h: In function ‘AtomicAssertOnCompilePtr’:
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h:2397:20: warning: typedef ‘AssertOnCompileFailed’ locally defined but not used [-Wunused-local-typedefs]
       typedef char AssertOnCompileFailed[AssertOnCompileMisused];             \
                    ^
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h:2560:1: note: in expansion of macro ‘MAKE_ATOMIC_TYPE’
 MAKE_ATOMIC_TYPE(Ptr, 32, void const *, void *, uintptr_t)
 ^
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h: In function ‘AtomicAssertOnCompileInt’:
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h:2397:20: warning: typedef ‘AssertOnCompileFailed’ locally defined but not used [-Wunused-local-typedefs]
       typedef char AssertOnCompileFailed[AssertOnCompileMisused];             \
                    ^
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h:2562:1: note: in expansion of macro ‘MAKE_ATOMIC_TYPE’
 MAKE_ATOMIC_TYPE(Int, 32, int, int, int)
 ^
In file included from /tmp/modconfig-GQ2cZR/vmnet-only/vnet.h:28:0,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/vnetInt.h:24,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/driver.c:51:
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h: In function ‘AtomicAssertOnCompilePtr’:
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h:2397:20: warning: typedef ‘AssertOnCompileFailed’ locally defined but not used [-Wunused-local-typedefs]
       typedef char AssertOnCompileFailed[AssertOnCompileMisused];             \
                    ^
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h:2560:1: note: in expansion of macro ‘MAKE_ATOMIC_TYPE’
 MAKE_ATOMIC_TYPE(Ptr, 32, void const *, void *, uintptr_t)
 ^
In file included from /tmp/modconfig-GQ2cZR/vmnet-only/monitorAction_exported.h:31:0,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/vnet.h:29,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/vnetInt.h:24,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/hub.c:43:
/tmp/modconfig-GQ2cZR/vmnet-only/monitorAction_exported.h: In function ‘MonitorActionSet_AtomicInclude’:
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h: In function ‘AtomicAssertOnCompileInt’:
/tmp/modconfig-GQ2cZR/vmnet-only/vm_assert.h:320:20: warning: typedef ‘AssertOnCompileFailed’ locally defined but not used [-Wunused-local-typedefs]
       typedef char AssertOnCompileFailed[AssertOnCompileMisused]; \
                    ^
/tmp/modconfig-GQ2cZR/vmnet-only/monitorAction_exported.h:91:4: note: in expansion of macro ‘ASSERT_ON_COMPILE’
    ASSERT_ON_COMPILE((ACTION_WORD_SIZE & (ACTION_WORD_SIZE - 1)) == 0);
    ^
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h:2397:20: warning: typedef ‘AssertOnCompileFailed’ locally defined but not used [-Wunused-local-typedefs]
       typedef char AssertOnCompileFailed[AssertOnCompileMisused];             \
                    ^
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h:2562:1: note: in expansion of macro ‘MAKE_ATOMIC_TYPE’
 MAKE_ATOMIC_TYPE(Int, 32, int, int, int)
 ^
In file included from /tmp/modconfig-GQ2cZR/vmnet-only/monitorAction_exported.h:31:0,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/vnet.h:29,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/vnetInt.h:24,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/driver.c:51:
/tmp/modconfig-GQ2cZR/vmnet-only/monitorAction_exported.h: In function ‘MonitorActionSet_AtomicInclude’:
/tmp/modconfig-GQ2cZR/vmnet-only/vm_assert.h:320:20: warning: typedef ‘AssertOnCompileFailed’ locally defined but not used [-Wunused-local-typedefs]
       typedef char AssertOnCompileFailed[AssertOnCompileMisused]; \
                    ^
/tmp/modconfig-GQ2cZR/vmnet-only/monitorAction_exported.h:91:4: note: in expansion of macro ‘ASSERT_ON_COMPILE’
    ASSERT_ON_COMPILE((ACTION_WORD_SIZE & (ACTION_WORD_SIZE - 1)) == 0);
    ^
/tmp/modconfig-GQ2cZR/vmnet-only/hub.c: In function ‘VNetHubFindHubByID’:
/tmp/modconfig-GQ2cZR/vmnet-only/hub.c:132:49: warning: argument to ‘sizeof’ in ‘__builtin_memcmp’ call is the same expression as the first source; did you mean to provide an explicit length? [-Wsizeof-pointer-memaccess]
         memcmp(idNum, currHub->id.pvnID, sizeof idNum))) {
                                                 ^
In file included from /usr/src/linux-headers-3.13.0-39-generic/arch/x86/include/asm/string.h:2:0,
                 from include/linux/string.h:17,
                 from /usr/src/linux-headers-3.13.0-39-generic/arch/x86/include/asm/page_32.h:38,
                 from /usr/src/linux-headers-3.13.0-39-generic/arch/x86/include/asm/page.h:13,
                 from /usr/src/linux-headers-3.13.0-39-generic/arch/x86/include/asm/thread_info.h:11,
                 from include/linux/thread_info.h:54,
                 from /usr/src/linux-headers-3.13.0-39-generic/arch/x86/include/asm/preempt.h:6,
                 from include/linux/preempt.h:18,
                 from include/linux/spinlock.h:50,
                 from include/linux/seqlock.h:35,
                 from include/linux/time.h:5,
                 from include/uapi/linux/timex.h:56,
                 from include/linux/timex.h:56,
                 from include/linux/sched.h:17,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/hub.c:25:
/tmp/modconfig-GQ2cZR/vmnet-only/hub.c: In function ‘VNetHubAlloc’:
/tmp/modconfig-GQ2cZR/vmnet-only/hub.c:315:36: warning: argument to ‘sizeof’ in ‘__builtin_memcpy’ call is the same pointer type ‘uint8 *’ as the destination; expected ‘uint8’ or an explicit length [-Wsizeof-pointer-memaccess]
   memcpy(hub->id.pvnID, id, sizeof id);
                                    ^
/usr/src/linux-headers-3.13.0-39-generic/arch/x86/include/asm/string_32.h:182:48: note: in definition of macro ‘memcpy’
 #define memcpy(t, f, n) __builtin_memcpy(t, f, n)
                                                ^
In file included from /tmp/modconfig-GQ2cZR/vmnet-only/vnet.h:28:0,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/vnetInt.h:24,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/userif.c:45:
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h: In function ‘AtomicAssertOnCompilePtr’:
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h:2397:20: warning: typedef ‘AssertOnCompileFailed’ locally defined but not used [-Wunused-local-typedefs]
       typedef char AssertOnCompileFailed[AssertOnCompileMisused];             \
                    ^
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h:2560:1: note: in expansion of macro ‘MAKE_ATOMIC_TYPE’
 MAKE_ATOMIC_TYPE(Ptr, 32, void const *, void *, uintptr_t)
 ^
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h: In function ‘AtomicAssertOnCompileInt’:
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h:2397:20: warning: typedef ‘AssertOnCompileFailed’ locally defined but not used [-Wunused-local-typedefs]
       typedef char AssertOnCompileFailed[AssertOnCompileMisused];             \
                    ^
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h:2562:1: note: in expansion of macro ‘MAKE_ATOMIC_TYPE’
 MAKE_ATOMIC_TYPE(Int, 32, int, int, int)
 ^
In file included from /tmp/modconfig-GQ2cZR/vmnet-only/monitorAction_exported.h:31:0,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/vnet.h:29,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/vnetInt.h:24,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/userif.c:45:
/tmp/modconfig-GQ2cZR/vmnet-only/monitorAction_exported.h: In function ‘MonitorActionSet_AtomicInclude’:
/tmp/modconfig-GQ2cZR/vmnet-only/vm_assert.h:320:20: warning: typedef ‘AssertOnCompileFailed’ locally defined but not used [-Wunused-local-typedefs]
       typedef char AssertOnCompileFailed[AssertOnCompileMisused]; \
                    ^
/tmp/modconfig-GQ2cZR/vmnet-only/monitorAction_exported.h:91:4: note: in expansion of macro ‘ASSERT_ON_COMPILE’
    ASSERT_ON_COMPILE((ACTION_WORD_SIZE & (ACTION_WORD_SIZE - 1)) == 0);
    ^
/tmp/modconfig-GQ2cZR/vmnet-only/userif.c: In function ‘VNetUserIfIoctl’:
/tmp/modconfig-GQ2cZR/vmnet-only/vm_assert.h:320:20: warning: typedef ‘AssertOnCompileFailed’ locally defined but not used [-Wunused-local-typedefs]
       typedef char AssertOnCompileFailed[AssertOnCompileMisused]; \
                    ^
/tmp/modconfig-GQ2cZR/vmnet-only/userif.c:809:7: note: in expansion of macro ‘ASSERT_ON_COMPILE’
       ASSERT_ON_COMPILE(VNET_NOTIFY_VERSION == 5);
       ^
/tmp/modconfig-GQ2cZR/vmnet-only/vm_assert.h:320:20: warning: typedef ‘AssertOnCompileFailed’ locally defined but not used [-Wunused-local-typedefs]
       typedef char AssertOnCompileFailed[AssertOnCompileMisused]; \
                    ^
/tmp/modconfig-GQ2cZR/vmnet-only/userif.c:810:7: note: in expansion of macro ‘ASSERT_ON_COMPILE’
       ASSERT_ON_COMPILE(ACTION_EXPORTED_VERSION == 2);
       ^
In file included from /tmp/modconfig-GQ2cZR/vmnet-only/vnet.h:28:0,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/vnetInt.h:24,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/netif.c:42:
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h: In function ‘AtomicAssertOnCompilePtr’:
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h:2397:20: warning: typedef ‘AssertOnCompileFailed’ locally defined but not used [-Wunused-local-typedefs]
       typedef char AssertOnCompileFailed[AssertOnCompileMisused];             \
                    ^
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h:2560:1: note: in expansion of macro ‘MAKE_ATOMIC_TYPE’
 MAKE_ATOMIC_TYPE(Ptr, 32, void const *, void *, uintptr_t)
 ^
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h: In function ‘AtomicAssertOnCompileInt’:
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h:2397:20: warning: typedef ‘AssertOnCompileFailed’ locally defined but not used [-Wunused-local-typedefs]
       typedef char AssertOnCompileFailed[AssertOnCompileMisused];             \
                    ^
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h:2562:1: note: in expansion of macro ‘MAKE_ATOMIC_TYPE’
 MAKE_ATOMIC_TYPE(Int, 32, int, int, int)
 ^
In file included from /tmp/modconfig-GQ2cZR/vmnet-only/monitorAction_exported.h:31:0,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/vnet.h:29,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/vnetInt.h:24,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/netif.c:42:
/tmp/modconfig-GQ2cZR/vmnet-only/monitorAction_exported.h: In function ‘MonitorActionSet_AtomicInclude’:
/tmp/modconfig-GQ2cZR/vmnet-only/vm_assert.h:320:20: warning: typedef ‘AssertOnCompileFailed’ locally defined but not used [-Wunused-local-typedefs]
       typedef char AssertOnCompileFailed[AssertOnCompileMisused]; \
                    ^
/tmp/modconfig-GQ2cZR/vmnet-only/monitorAction_exported.h:91:4: note: in expansion of macro ‘ASSERT_ON_COMPILE’
    ASSERT_ON_COMPILE((ACTION_WORD_SIZE & (ACTION_WORD_SIZE - 1)) == 0);
    ^
  CC [M]  /tmp/modconfig-GQ2cZR/vmnet-only/bridge.o
  CC [M]  /tmp/modconfig-GQ2cZR/vmnet-only/procfs.o
  CC [M]  /tmp/modconfig-GQ2cZR/vmnet-only/filter.o
  CC [M]  /tmp/modconfig-GQ2cZR/vmnet-only/smac_compat.o
In file included from /tmp/modconfig-GQ2cZR/vmnet-only/vnet.h:28:0,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/vnetInt.h:24,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/filter.c:48:
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h: In function ‘AtomicAssertOnCompilePtr’:
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h:2397:20: warning: typedef ‘AssertOnCompileFailed’ locally defined but not used [-Wunused-local-typedefs]
       typedef char AssertOnCompileFailed[AssertOnCompileMisused];             \
                    ^
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h:2560:1: note: in expansion of macro ‘MAKE_ATOMIC_TYPE’
 MAKE_ATOMIC_TYPE(Ptr, 32, void const *, void *, uintptr_t)
 ^
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h: In function ‘AtomicAssertOnCompileInt’:
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h:2397:20: warning: typedef ‘AssertOnCompileFailed’ locally defined but not used [-Wunused-local-typedefs]
       typedef char AssertOnCompileFailed[AssertOnCompileMisused];             \
                    ^
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h:2562:1: note: in expansion of macro ‘MAKE_ATOMIC_TYPE’
 MAKE_ATOMIC_TYPE(Int, 32, int, int, int)
 ^
In file included from /tmp/modconfig-GQ2cZR/vmnet-only/monitorAction_exported.h:31:0,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/vnet.h:29,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/vnetInt.h:24,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/filter.c:48:
/tmp/modconfig-GQ2cZR/vmnet-only/monitorAction_exported.h: In function ‘MonitorActionSet_AtomicInclude’:
/tmp/modconfig-GQ2cZR/vmnet-only/vm_assert.h:320:20: warning: typedef ‘AssertOnCompileFailed’ locally defined but not used [-Wunused-local-typedefs]
       typedef char AssertOnCompileFailed[AssertOnCompileMisused]; \
                    ^
/tmp/modconfig-GQ2cZR/vmnet-only/monitorAction_exported.h:91:4: note: in expansion of macro ‘ASSERT_ON_COMPILE’
    ASSERT_ON_COMPILE((ACTION_WORD_SIZE & (ACTION_WORD_SIZE - 1)) == 0);
    ^
/tmp/modconfig-GQ2cZR/vmnet-only/filter.c: At top level:
/tmp/modconfig-GQ2cZR/vmnet-only/filter.c:206:1: error: conflicting types for ‘VNetFilterHookFn’
 VNetFilterHookFn(unsigned int hooknum,                 // IN:
 ^
/tmp/modconfig-GQ2cZR/vmnet-only/filter.c:64:18: note: previous declaration of ‘VNetFilterHookFn’ was here
 static nf_hookfn VNetFilterHookFn;
                  ^

In file included from /tmp/modconfig-GQ2cZR/vmnet-only/vnet.h:28:0,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/vnetInt.h:24,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/procfs.c:43:
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h: In function ‘AtomicAssertOnCompilePtr’:
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h:2397:20: warning: typedef ‘AssertOnCompileFailed’ locally defined but not used [-Wunused-local-typedefs]
       typedef char AssertOnCompileFailed[AssertOnCompileMisused];             \
                    ^
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h:2560:1: note: in expansion of macro ‘MAKE_ATOMIC_TYPE’
 MAKE_ATOMIC_TYPE(Ptr, 32, void const *, void *, uintptr_t)
 ^
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h: In function ‘AtomicAssertOnCompileInt’:
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h:2397:20: warning: typedef ‘AssertOnCompileFailed’ locally defined but not used [-Wunused-local-typedefs]
       typedef char AssertOnCompileFailed[AssertOnCompileMisused];             \
                    ^
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h:2562:1: note: in expansion of macro ‘MAKE_ATOMIC_TYPE’
 MAKE_ATOMIC_TYPE(Int, 32, int, int, int)
 ^
In file included from /tmp/modconfig-GQ2cZR/vmnet-only/monitorAction_exported.h:31:0,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/vnet.h:29,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/vnetInt.h:24,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/procfs.c:43:
/tmp/modconfig-GQ2cZR/vmnet-only/monitorAction_exported.h: In function ‘MonitorActionSet_AtomicInclude’:
/tmp/modconfig-GQ2cZR/vmnet-only/vm_assert.h:320:20: warning: typedef ‘AssertOnCompileFailed’ locally defined but not used [-Wunused-local-typedefs]
       typedef char AssertOnCompileFailed[AssertOnCompileMisused]; \
                    ^
/tmp/modconfig-GQ2cZR/vmnet-only/monitorAction_exported.h:91:4: note: in expansion of macro ‘ASSERT_ON_COMPILE’
    ASSERT_ON_COMPILE((ACTION_WORD_SIZE & (ACTION_WORD_SIZE - 1)) == 0);
    ^
/tmp/modconfig-GQ2cZR/vmnet-only/filter.c:64:18: warning: ‘VNetFilterHookFn’ used but never defined [enabled by default]
/tmp/modconfig-GQ2cZR/vmnet-only/filter.c:206:1: warning: ‘VNetFilterHookFn’ defined but not used [-Wunused-function]
 VNetFilterHookFn(unsigned int hooknum,                 // IN:
 ^
In file included from /tmp/modconfig-GQ2cZR/vmnet-only/vnet.h:28:0,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/vnetInt.h:24,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/bridge.c:52:
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h: In function ‘AtomicAssertOnCompilePtr’:
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h:2397:20: warning: typedef ‘AssertOnCompileFailed’ locally defined but not used [-Wunused-local-typedefs]
       typedef char AssertOnCompileFailed[AssertOnCompileMisused];             \
                    ^
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h:2560:1: note: in expansion of macro ‘MAKE_ATOMIC_TYPE’
 MAKE_ATOMIC_TYPE(Ptr, 32, void const *, void *, uintptr_t)
 ^
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h: In function ‘AtomicAssertOnCompileInt’:
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h:2397:20: warning: typedef ‘AssertOnCompileFailed’ locally defined but not used [-Wunused-local-typedefs]
       typedef char AssertOnCompileFailed[AssertOnCompileMisused];             \
                    ^
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h:2562:1: note: in expansion of macro ‘MAKE_ATOMIC_TYPE’
 MAKE_ATOMIC_TYPE(Int, 32, int, int, int)
 ^
In file included from /tmp/modconfig-GQ2cZR/vmnet-only/monitorAction_exported.h:31:0,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/vnet.h:29,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/vnetInt.h:24,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/bridge.c:52:
/tmp/modconfig-GQ2cZR/vmnet-only/monitorAction_exported.h: In function ‘MonitorActionSet_AtomicInclude’:
/tmp/modconfig-GQ2cZR/vmnet-only/vm_assert.h:320:20: warning: typedef ‘AssertOnCompileFailed’ locally defined but not used [-Wunused-local-typedefs]
       typedef char AssertOnCompileFailed[AssertOnCompileMisused]; \
                    ^
/tmp/modconfig-GQ2cZR/vmnet-only/monitorAction_exported.h:91:4: note: in expansion of macro ‘ASSERT_ON_COMPILE’
    ASSERT_ON_COMPILE((ACTION_WORD_SIZE & (ACTION_WORD_SIZE - 1)) == 0);
    ^
▽ake[2]: *** [/tmp/modconfig-GQ2cZR/vmnet-only/filter.o] Error 1
make[2]: *** Waiting for unfinished jobs....
In file included from /tmp/modconfig-GQ2cZR/vmnet-only/vnet.h:28:0,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/vnetInt.h:24,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/smac_compat.c:53:
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h: In function ‘AtomicAssertOnCompilePtr’:
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h:2397:20: warning: typedef ‘AssertOnCompileFailed’ locally defined but not used [-Wunused-local-typedefs]
       typedef char AssertOnCompileFailed[AssertOnCompileMisused];             \
                    ^
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h:2560:1: note: in expansion of macro ‘MAKE_ATOMIC_TYPE’
 MAKE_ATOMIC_TYPE(Ptr, 32, void const *, void *, uintptr_t)
 ^
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h: In function ‘AtomicAssertOnCompileInt’:
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h:2397:20: warning: typedef ‘AssertOnCompileFailed’ locally defined but not used [-Wunused-local-typedefs]
       typedef char AssertOnCompileFailed[AssertOnCompileMisused];             \
                    ^
/tmp/modconfig-GQ2cZR/vmnet-only/vm_atomic.h:2562:1: note: in expansion of macro ‘MAKE_ATOMIC_TYPE’
 MAKE_ATOMIC_TYPE(Int, 32, int, int, int)
 ^
In file included from /tmp/modconfig-GQ2cZR/vmnet-only/monitorAction_exported.h:31:0,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/vnet.h:29,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/vnetInt.h:24,
                 from /tmp/modconfig-GQ2cZR/vmnet-only/smac_compat.c:53:
/tmp/modconfig-GQ2cZR/vmnet-only/monitorAction_exported.h: In function ‘MonitorActionSet_AtomicInclude’:
/tmp/modconfig-GQ2cZR/vmnet-only/vm_assert.h:320:20: warning: typedef ‘AssertOnCompileFailed’ locally defined but not used [-Wunused-local-typedefs]
       typedef char AssertOnCompileFailed[AssertOnCompileMisused]; \
                    ^
/tmp/modconfig-GQ2cZR/vmnet-only/monitorAction_exported.h:91:4: note: in expansion of macro ‘ASSERT_ON_COMPILE’
    ASSERT_ON_COMPILE((ACTION_WORD_SIZE & (ACTION_WORD_SIZE - 1)) == 0);
    ^
make[1]: *** [_module_/tmp/modconfig-GQ2cZR/vmnet-only] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-3.13.0-39-generic'
make: *** [vmnet.ko] Error 2
make: Leaving directory `/tmp/modconfig-GQ2cZR/vmnet-only'
Failed to build vmnet.  Failed to execute the build command.
Starting VMware services:
   Virtual machine monitor                                             done
   Virtual machine communication interface                             done
   VM communication interface socket family                            done
   Blocking file system                                                done
   Virtual ethernet                                                   failed
   VMware Authentication Daemon                                        done

Root Cause:

After kernel version 3.13.x, the definition of netfilter hook function (nf_hookfn) has been changed.

 40 /* Largest hook number + 1 */
 41 #define NF_MAX_HOOKS 8
 42 
 43 struct sk_buff;
 44 
 45 struct nf_hook_ops;
 46 typedef unsigned int nf_hookfn(const struct nf_hook_ops *ops,
 47                                struct sk_buff *skb,
 48                                const struct net_device *in,
 49                                const struct net_device *out,
 50                                int (*okfn)(struct sk_buff *));
 51 
 52 struct nf_hook_ops {
 53         struct list_head list;
 54 
 55         /* User fills in from here down. */
 56         nf_hookfn       *hook;
 57         struct module   *owner;
 58         void            *priv;
 59         u_int8_t        pf;
 60         unsigned int    hooknum;
 61         /* Hooks are ordered in ascending priority. */
 62         int             priority;
 63 };
 64 

Solution:

 Use the following patch to correct this error:
--- /usr/lib/vmware/modules/source/vmnet-only/filter.c 2013-10-18 23:11:55.000000000 +0400
+++ /usr/lib/vmware/modules/source/vmnet-only/filter.c 2013-12-03 04:16:31.751352170 +0400
@@ -27,6 +27,7 @@
 #include "compat_module.h"
 #include <linux/mutex.h>
 #include <linux/netdevice.h>
+#include <linux/version.h>
 #if COMPAT_LINUX_VERSION_CHECK_LT(3, 2, 0)
 #   include <linux/module.h>
 #else
@@ -203,7 +204,11 @@
 #endif

 static unsigned int
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 13, 0)
 VNetFilterHookFn(unsigned int hooknum,                 // IN:
+#else
+VNetFilterHookFn(const struct nf_hook_ops *ops,        // IN:
+#endif
 #ifdef VMW_NFHOOK_USES_SKB
                  struct sk_buff *skb,                  // IN:
 #else
@@ -252,7 +257,12 @@

    /* When the host transmits, hooknum is VMW_NF_INET_POST_ROUTING. */
    /* When the host receives, hooknum is VMW_NF_INET_LOCAL_IN. */
-   transmit = (hooknum == VMW_NF_INET_POST_ROUTING);
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 13, 0)
+    transmit = (hooknum == VMW_NF_INET_POST_ROUTING);
+#else
+    transmit = (ops->hooknum == VMW_NF_INET_POST_ROUTING);
+#endif

    packetHeader = compat_skb_network_header(skb);
    ip = (struct iphdr*)packetHeader;

 Reference:

http://lxr.free-electrons.com/source/include/linux/netfilter.h?v=3.13
http://pastebin.com/p3bkbAMu
http://davejingtian.org/2014/03/04/hack-make-vmware-player-6-0-1-start-on-linux-kernel-3-13-x/