Wednesday, December 30, 2015

D-Bus main loop programming

Over internet, there are many D-Bus examples like the following

1
2
3
4
5
6
7
8
9
10
11
12
13
while(true)
{
    dbus_connection_read_write();
    …
    pMessage = dbus_connection_pop_message();

    if (pMessage)
    {
        …
        dbus_message_unref(pMessage);
    }

}

This is incorrect.
  • dbus_connection_read_write() is a low level function bringing in raw data from lower transport layer.  It does not parse data and not aware of how many messages have been brought up.
  • dbus_message_pop_message() is a function popping 1 message from incoming queue/buffer. 
Overall, each dbus_connection_read_write() can effectively bring in more than 1 message.  Consequently, only popping 1 message after each dbus_connection_read_write() will potentially leave a large number of data in the incoming queue/buffer.

The correct loop is following

1
2
3
4
5
6
7
8
9
10
11
12
13
while(true)
{
    dbus_connection_read_write();
    …
    pMessage = dbus_connection_pop_message();

    while (pMessage)
    {
        …
        dbus_message_unref(pMessage);
    }

}

Friday, December 18, 2015

Build Ubuntu Package from Source

TBC...

root# apt-get source dbus
Reading package lists... Done
Building dependency tree    
Reading state information... Done
NOTICE: 'dbus' packaging is maintained in the 'Git' version control system at:
git://anonscm.debian.org/pkg-utopia/dbus.git
Need to get 1,961 kB of source archives.
Get:1 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main dbus 1.4.18-1ubuntu1.7 (dsc) [2,614 B]
Get:2 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main dbus 1.4.18-1ubuntu1.7 (tar) [1,893 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main dbus 1.4.18-1ubuntu1.7 (diff) [64.8 kB]
Fetched 1,961 kB in 1s (1,304 kB/s)
gpgv: Signature made Tue 25 Nov 2014 03:24:17 PM EST using RSA key ID A744BE93
gpgv: Can't check signature: public key not found
dpkg-source: warning: failed to verify signature on ./dbus_1.4.18-1ubuntu1.7.dsc
dpkg-source: info: extracting dbus in dbus-1.4.18
dpkg-source: info: unpacking dbus_1.4.18.orig.tar.gz
dpkg-source: info: unpacking dbus_1.4.18-1ubuntu1.7.debian.tar.gz
dpkg-source: info: applying 01_no-fatal-warnings.patch
dpkg-source: info: applying 02_obsolete_g_thread_api.patch
dpkg-source: info: applying 20_system_conf_limit.patch
dpkg-source: info: applying 81-session.conf-timeout.patch
dpkg-source: info: applying 0001-activation-allow-for-more-variation-than-just-system.patch
dpkg-source: info: applying 0002-bus-change-systemd-activation-to-activation-systemd.patch
dpkg-source: info: applying 0003-upstart-add-upstart-as-a-possible-activation-type.patch
dpkg-source: info: applying 0004-upstart-add-UpstartJob-to-service-desktop-files.patch
dpkg-source: info: applying 0005-activation-implement-upstart-activation.patch
dpkg-source: info: applying CVE-2012-3524-dbus.patch
dpkg-source: info: applying CVE-2012-3524-regression-fix.patch
dpkg-source: info: applying CVE-2013-2168.patch
dpkg-source: info: applying CVE-2014-3477.patch
dpkg-source: info: applying CVE-2014-3532.patch
dpkg-source: info: applying CVE-2014-3533.patch
dpkg-source: info: applying CVE-2014-3635.patch
dpkg-source: info: applying CVE-2014-3636.patch
dpkg-source: info: applying CVE-2014-3637.patch
dpkg-source: info: applying CVE-2014-3638.patch
dpkg-source: info: applying CVE-2014-3639.patch
dpkg-source: info: applying CVE-2014-7824.patch
dpkg-source: info: applying CVE-2014-3639-regression.patch

# cd dbus-1.4.18
# ./configure --prefix=
# make

Files:
mkdir -p ~/dbus/bin
cp bus/dbus-daemon ~/dbus/bin
cp tools/dbus-cleanup-sockets ~/dbus/bin
cp tools/dbus-uuidgen ~/dbus/bin

mkdir -p ~/dbus/usr/bin
cp tools/dbus-monitor ~/dbus/usr/bin
cp tools/dbus-send ~/dbus/usr/bin

mkdir -p ~/dbus/lib/i386-linux-gnu
cp dbus/.libs/libdbus-1.so.3.5.8 ~/dbus/lib/i386-linux-gnu

mkdir -p ~/dbus/usr/lib/dbus-1.0
cp bus/dbus-daemon-launch-helper ~/dbus/lib/dbus-1.0/

Thursday, December 17, 2015

Mac OS X can not sign in App Store / iTunes / iCloud

Validated on Mac OS X El Capitan


Run the following commands:
sudo pkill -9 -f Account
sudo rm $HOME/Library/Accounts/*
sudo pkill -9 -f Store
sudo pkill -9 -f iTunes

Restart App Store and log on

D-Bus memory leak

My goodness.  This whole week, the whole team have been scrambling around memory leak related to D-Bus.

Some basic references:
http://dbus.freedesktop.org/doc/dbus-tutorial.html
http://sy198704.is-programmer.com/posts/33060.html
http://www.cnblogs.com/chenbin7/archive/2013/03/05/2944895.html

We have a Ubuntu 12.04 LTS.  The D-Bus version is 1.4.18.  There are a good number of leak issues.  What should we do?

Well, desirably, we should go to 1.7.10.


Here is the list of leak issues.

might leak memory in dbus_message_iter_get_args_valist:
report date: 4/17/2009
fixed 1.7.8
https://bugs.freedesktop.org/show_bug.cgi?id=21259


file dicriptor leak in _dbus_connect_tcp_socket_with_nonce
report on 5/16/2011
fixed in 1.5.6
https://bugzilla.freedesktop.org/show_bug.cgi?id=37258


a small memory leak, and a failure to report errors, when updating a service file entry for activation
report on 7/21/2011
fixed in 1.5.8
https://bugzilla.freedesktop.org/show_bug.cgi?id=39230


can crash on failed realloc; cannot be forced to crash on all failed mallocs
report on 9/20/2011
fixed in 1.5.10
https://bugzilla.freedesktop.org/show_bug.cgi?id=41048


Dbus is leaking some fd to /dev/null when it demonize.
report on 11/9/2012
fixed in 1.7.0
https://bugzilla.freedesktop.org/show_bug.cgi?id=56927


File descriptor leak in _dbus_command_for_pid():
report on 9/10/2013
fixed in 1.6.16, 1.7.6
https://bugs.freedesktop.org/show_bug.cgi?id=69182


Memory leak in dbus-daemon:
report on 11/12/2013
fixed in 1.6.20, 1.7.10
https://bugs.freedesktop.org/show_bug.cgi?id=71526


D-Bus 1.8.0 release note (1/20/2014)
• fixed long-standing fd and array leaks when failing to parse a message
• fixed referenced-but-never-freed parent nodes (effectively memory
  leaks) when using certain object-path allocation patterns, notably in
  Avahi

dbus-monitor leak file descriptor
report on 6/27/2014
fixed in 1.9.0
https://bugs.freedesktop.org/show_bug.cgi?id=80603


Missing varargs cleanup
report on 1/6/2015
fixed in 1.9.8
https://bugs.freedesktop.org/show_bug.cgi?id=88087


Memleak when GetConnectionCredentials is successful
report on 6/17/2015
fixed in 1.8.20, 1.9.18
https://bugs.freedesktop.org/show_bug.cgi?id=91008


libcap-ng < 0.7.7 leaks one non-close-on-exec fd during initialization
report on 8/19/2015
fixed in 1.10
https://bugs.freedesktop.org/show_bug.cgi?id=91684

Thursday, December 3, 2015

grub.cfg windows entry

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
### BEGIN /etc/grub.d/30_os-prober ###
menuentry 'Windows 8 (loader) (on /dev/sda1)' --class windows --class os $menuentry_id_option 'osprober-chain-A8A8863CA88608D0' {
 insmod part_msdos
 insmod ntfs
 set root='hd0,msdos1'
 if [ x$feature_platform_search_hint = xy ]; then
   search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1  A8A8863CA88608D0
 else
   search --no-floppy --fs-uuid --set=root A8A8863CA88608D0
 fi
 parttool ${root} hidden-
 drivemap -s (hd0) ${root}
 chainloader +1
}
menuentry 'Windows Recovery Environment (loader) (on /dev/sdb3)' --class windows --class os $menuentry_id_option 'osprober-chain-1ACA-FBDA' {
 insmod part_gpt
 insmod fat
 set root='hd1,gpt3'
 if [ x$feature_platform_search_hint = xy ]; then
   search --no-floppy --fs-uuid --set=root --hint-bios=hd1,gpt3 --hint-efi=hd1,gpt3 --hint-baremetal=ahci1,gpt3  1ACA-FBDA
 else
   search --no-floppy --fs-uuid --set=root 1ACA-FBDA
 fi
 drivemap -s (hd0) ${root}
 chainloader +1
}
menuentry 'Windows 8 (loader) (on /dev/sdb5)' --class windows --class os $menuentry_id_option 'osprober-chain-6A18CDFA18CDC573' {
 insmod part_gpt
 insmod ntfs
 set root='hd1,gpt5'
 if [ x$feature_platform_search_hint = xy ]; then
   search --no-floppy --fs-uuid --set=root --hint-bios=hd1,gpt5 --hint-efi=hd1,gpt5 --hint-baremetal=ahci1,gpt5  6A18CDFA18CDC573
 else
   search --no-floppy --fs-uuid --set=root 6A18CDFA18CDC573
 fi
 drivemap -s (hd0) ${root}
 chainloader +1
}

Wednesday, December 2, 2015

Linux Memory Management

32 bit : http://tldp.org/HOWTO/KernelAnalysis-HOWTO-7.html
64 bit : https://www.kernel.org/doc/gorman/html/understand/understand012.html

Check Memory Utilization
cat /proc/meminfo
free -m

Configuration
/proc/sys/vm/*

Dirty Page
/proc/sys/vm/dirty_background_ratio: disk write buffer flushing threshold as percentage of system memory
/proc/sys/vm/dirty_ratio: disk write buffer size as percentage of system memory

Handle out of memory
/proc/sys/vm/vfs_cache_pressure
/proc/sys/vm/min_free_kbytes
/proc/sys/vm/drop_cache

Thursday, November 19, 2015

Issue SATA commands directly through IOCTL

Directly write to SATA interface to perform simple read and write operation on a storage device.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <scsi/sg.h>
#include <scsi/scsi.h>
main()
{
 int fd;
 unsigned char buffer[512];

 fd=open("/dev/sda", O_RDWR );

 ReadSector(fd, 0, 1, buffer);
 WriteSector(fd, 0, 1, buffer);
}


// return 0 on fail
// return 1 on success
int ReadSector(int fd, int sector, int nsec, unsigned char *pbuffer)
{
 int res;
 int t_length;
 sg_io_hdr_t io_hdr;
 unsigned char sense_b[SG_MAX_SENSE];
 unsigned char rdCmdBlk6[6];

 t_length = 512;              // 512 bytes transferred per sec

// Prepare SCSI READ (6) command
 rdCmdBlk6[0]  = READ_6;           // COMMAND
 rdCmdBlk6[1]  = (sector & 0xFF0000 ) >> 16;           // LBA
 rdCmdBlk6[2]  = (sector & 0xff00) >> 8;         // LBA
 rdCmdBlk6[3]  = sector & 0xff;  // LBA
 rdCmdBlk6[4]  = nsec;
 rdCmdBlk6[5]  = 0x00;

// Prepare the sg_io_hdr_t structure
 memset(&io_hdr, 0, sizeof(sg_io_hdr_t));
 io_hdr.interface_id = 'S';                  // Always set to 'S' for sg driver
 io_hdr.cmd_len = sizeof(rdCmdBlk6);         // Size of SCSI command
 io_hdr.mx_sb_len  = sizeof(sense_b);        // Max sense buffer size(for error)
 io_hdr.dxfer_direction = SG_DXFER_FROM_DEV; // Data transfer direction(no data)
 io_hdr.dxfer_len = nsec*t_length;                // Data transfer length(512)
 io_hdr.dxferp = pbuffer;                       // Data transfer buffer(none)
 io_hdr.cmdp = rdCmdBlk6;                    // SCSI command buffer
 io_hdr.sbp = sense_b;                       // Sense buffer
 io_hdr.timeout = 5000;                      // Timeout(5s)

// Sends the command to device
 if ((res = ioctl(fd, SG_IO, &io_hdr)) < 0) {
   return 0;
 }

// Error processing
 if ( ((io_hdr.info & SG_INFO_OK_MASK) != SG_INFO_OK) || // check info
      (io_hdr.masked_status != 0x00) ||                  // check status(0 if ioctl success)
      (io_hdr.msg_status != 0x00) ||                     // check message status
      (io_hdr.host_status != 0x00) ||                    // check host status
      (io_hdr.driver_status != 0x00) )                   // check driver status
 {
   return 0;
 } else {
   return 1;
 }
}

int WriteSector(int fd, int sector, int nsec, unsigned char *pbuffer)
{
 int res;
 int t_length;
 sg_io_hdr_t io_hdr;
 unsigned char sense_b[SG_MAX_SENSE];
 unsigned char rdCmdBlk6[6] ;
 t_length = 512;              // 512 bytes transferred per sec

// Prepare SCSI WRITE (6) command
 rdCmdBlk6[0]  = WRITE_6;           // COMMAND
 rdCmdBlk6[1]  = (sector & 0xFF0000 ) >> 16;           // LBA
 rdCmdBlk6[2]  = (sector & 0xff00) >> 8;         // LBA
 rdCmdBlk6[3]  = sector & 0xff;  // LBA
 rdCmdBlk6[4]  = nsec;
 rdCmdBlk6[5]  = 0x00;

// Prepare the sg_io_hdr_t structure
 memset(&io_hdr, 0, sizeof(sg_io_hdr_t));
 io_hdr.interface_id = 'S';                  // Always set to 'S' for sg driver
 io_hdr.cmd_len = sizeof(rdCmdBlk6);         // Size of SCSI command
 io_hdr.mx_sb_len  = sizeof(sense_b);        // Max sense buffer size(for error)
 io_hdr.dxfer_direction = SG_DXFER_TO_DEV; // Data transfer direction(no data)
 io_hdr.dxfer_len = nsec*t_length;                // Data transfer length(512)
 io_hdr.dxferp = pbuffer;                       // Data transfer buffer(none)
 io_hdr.cmdp = rdCmdBlk6;                    // SCSI command buffer
 io_hdr.sbp = sense_b;                       // Sense buffer
 io_hdr.timeout = 5000;                      // Timeout(5s)

// Sends the command to device
 if ((res = ioctl(fd, SG_IO, &io_hdr)) < 0) {
   return 0;
 }

// Error processing
 if ( ((io_hdr.info & SG_INFO_OK_MASK) != SG_INFO_OK) || // check info
      (io_hdr.masked_status != 0x00) ||                  // check status(0 if ioctl success)
      (io_hdr.msg_status != 0x00) ||                     // check message status
      (io_hdr.host_status != 0x00) ||                    // check host status
      (io_hdr.driver_status != 0x00) )                   // check driver status
 {
   return 0;
 } else {
   return 1;
 }
}

Tuesday, November 17, 2015

Intel xHCI drivers

xHCI

https://downloadcenter.intel.com/download/21129/USB-3-0-Driver-Intel-USB-3-0-eXtensible-Host-Controller-Driver-for-Intel-7-Series-C216-Chipset-Family

https://downloadcenter.intel.com/download/22824/USB-3-0-Driver-Intel-USB-3-0-eXtensible-Host-Controller-Driver-for-Intel-8-9-100-Series-and-C220-C610-Chipset-Family

CentOS 7 32 bit VirtualBox client

Officially, CentOS 7 only has x86_64.  The first version 7.0 was released in 2014.

Not until 10/13/2015, AltArch SIG released a CentOS 7 32 bit for IOT x86 boards.
Release note: https://wiki.centos.org/SpecialInterestGroup/AltArch/i386
Release images: http://mirror.centos.org/altarch/7/isos/i386/

Not like the x86_64 version, the 32 bit version is not typically available on CentOS mirror sites.

At this moment, AltArch CentOS 7 32 bit version meets our need of creating USB token now with a catch.
- The two required RPM packages are from CentOS 6.7.  Luckily, they are working.

So far, I believe that it would be in the best interests of normal institution to consider taking CentOS 7 x86_64 instead of 32bit (i386/i686) version.  With x86_64, there is definitely less worry for future.


Note for getting the task done.

2 VirtualBox
2.1 Required VirtualBox components
Both VirtualBox installer and extension pack are required.  They can be found on the URL
http://www.oracle.com/technetwork/server-storage/virtualbox/downloads/index.html

2.2 Virtual Machine Creation
2.2.1 VirtualBox options
System->Motherboard->Base Memory must be >= 512MB
System->Processor->Extended Features check Enable PAE/NX
Network->Adapter 1 -> Advanced ->Adapter Type Intel PRO/1000 MT Desktop (8254OEM)
USB -> Enable USB Controller -> USB 3.0 (xHCI) Controller

Note that xHCI driver should be from vendors, Intel etc.

3 Install CentOS
3.1 Required CentOS 7 components
CentOS 7 ISO image
http://mirror.centos.org/altarch/7/isos/i386/CentOS-7-i386-Minimal-1503.iso
vim filesystem RPM package
ftp://fr2.rpmfind.net/linux/centos/6.7/os/i386/Packages/vim-filesystem-7.4.629-5.el6.i686.rpm
vim common RPM package
ftp://fr2.rpmfind.net/linux/centos/6.7/os/i386/Packages/vim-common-7.4.629-5.el6.i686.rpm

Friday, November 13, 2015

CentOS 7 32 bit virtualbox client

32bit CentOS 7 was released on 10/15/2015

The download is available here
http://mirror.centos.org/altarch/7/isos/i386/

When creating virtualbox client, the default configurations are not sufficient.

Create Virtual Machine:
- Linex and Other Linux(32-bit)

Settings
- System->Processor->Enable PAE/NX
- Network->Advanced->Adapter Type: Intel PRO/1000 MT Desktop (8254OEM)

CentOS 7 i386 by default won't recognize the default virtualbox network device.  This is from the 3.10 kernel taken by CentOS 7
https://www.centos.org/forums/viewtopic.php?f=47&t=47724

For development on CentOS, the following line will install compiler/linker packages.
yum groupinstall 'Development Tools'

Friday, October 30, 2015

Ubuntu 12.04 random crash and Intel i915 DRM video driver + Sandy Bridge

12/15/2012:
http://ubuntuforums.org/showthread.php?t=2094859

Investigation:

12/28/2011: Intel disable RC6 for Linux 3.2
http://www.phoronix.com/scan.php?page=news_item&px=MTAzNDg

Ubuntu official messages on the issue.
02/18/2012: Official notice of testing new kernel fix for RC6 related hang.
https://lists.ubuntu.com/archives/ubuntu-devel/2012-February/034782.html

04/11/2012: Official announcement of disabling RC6 and updated testing results of testing
https://wiki.ubuntu.com/Kernel/PowerManagementRC6

10/02/2015: Official announcement of reenabling RC6
https://wiki.ubuntu.com/Kernel/PowerManagement/PowerSavingTweaks
NOTE: If you are running 12.04 LTS ("Precise"), this is already enabled by default.

The Intel i915 RC6 feature allows the Graphics Processing Unit (GPU) to enter a lower power state during GPU idle. The i915 RC6 feature applies to Intel Sandybridge and later processors. RC6 was switched between enabled and disabled earlier in the Ubuntu 12.04 Precise LTS development cycle, but eventually all problems were fixed and it is now enabled by default.

Source code (Kernel 3.14):

/drivers/gpu/drm/i915/intel_pm.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
static void intel_print_rc6_info(struct drm_device *dev, u32 mode)
{
        if (IS_GEN6(dev))
                DRM_DEBUG_DRIVER("Sandybridge: deep RC6 disabled\n");

        if (IS_HASWELL(dev))
                DRM_DEBUG_DRIVER("Haswell: only RC6 available\n");

        DRM_INFO("Enabling RC6 states: RC6 %s, RC6p %s, RC6pp %s\n",
                        (mode & GEN6_RC_CTL_RC6_ENABLE) ? "on" : "off",
                        (mode & GEN6_RC_CTL_RC6p_ENABLE) ? "on" : "off",
                        (mode & GEN6_RC_CTL_RC6pp_ENABLE) ? "on" : "off");
}

int intel_enable_rc6(const struct drm_device *dev)
{
        /* No RC6 before Ironlake */
        if (INTEL_INFO(dev)->gen < 5)
                return 0;

        /* Respect the kernel parameter if it is set */
        if (i915_enable_rc6 >= 0)
                return i915_enable_rc6;

        /* Disable RC6 on Ironlake */
        if (INTEL_INFO(dev)->gen == 5)
                return 0;

        if (IS_HASWELL(dev))
                return INTEL_RC6_ENABLE;

        /* snb/ivb have more than one rc6 state. */
        if (INTEL_INFO(dev)->gen == 6)
                return INTEL_RC6_ENABLE;

        return (INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE);
}


Since kernel version 3.6, Intel disabled their i915 driver pushing “deep sleep” on all Sandy Bridge devices.  However, the corresponding source code files are varying in different versions.

The video device on ATOM E6xx is GMA 600, a PowerVR SGX 535 based device.  Consequently, Ubuntu 12.04 running on E6xx is immune to the issue by nature.

Monday, October 26, 2015

View, Change, and Repack initrd

View
1
2
3
4
cp /boot/initrd.img /tmp
mv initrd.img initrd.gz
gunzip initrd.gz
cpio -id < initrd

Change
Repack
1
find . | cpio -o --format='newc' > ../initrd_new.img

Sunday, October 18, 2015

不从Win7/Win8.1升级,直接全新安装并激活Win10方法

http://www.mitbbs.com/article/Hardware/31885857_0.html

发信人: cym (纯爷们), 信区: Hardware
标  题: 不从Win7/Win8.1升级,直接全新安装并激活Win10方法
发信站: BBS 未名空间站 (Mon Aug 31 01:12:47 2015, 美东)

本文针对那些还没有升级Win10但是想升级的Win7/Win8.1用户。

关于Windows10系统激活,大多数用户还是想好好利用一下微软提供的免费升级途径的
。根据微软公布的升级方案以及实测,Windows7/Windows 8.1用户需要在当前系统基础
上执行升级安装才能够保证Win10安装后自动激活。也就是说, (首次激活Win10)升
级是必经之路。

但肯定有人想跳过升级,直接全新安装或安装双系统。那有没有方法在这种情况下也能
自动激活呢?

有!方法如下:

1、在你正在使用的Win7/Win8.1系统中(注意,要确保系统已经激活)打开下载的
Win10 ISO镜像,在Sources文件夹中找到gatherosstate.exe程序,把它复制到桌面。

提示:Win7系统下可使用 ultraISO / winRAR / 7Zip 软件打开ISO镜像。

2、双击gatherosstate.exe,稍后会在桌面生成名为GenuineTicket.xml的文件(名字
翻译过来就是“正版通行证”),这份文件至关重要,把它保存好。

3、然后用你熟悉的安装方法安装Win10吧。U盘法、硬盘法、光盘法,随你选。但要注
意一定要确保安装前后系统版本相对应。安装过程中跳过一切密钥输入步骤。

4、安装完成后,打开C:\ProgramData\Microsoft\Windows\ClipSVC\GenuineTicket文
件夹(注意ProgramData为隐藏文件夹),然后把保存的GenuineTicket.xml文件复制到
这个目录中。

5、重启电脑,确保系统已联网,稍后就会自动激活了。你也可以在系统属性中手动点
击“立即激活”。

以上过程执行一次即可,激活后微软服务器会记录信息,再次重装后只需联网即可自动
激活。

此方法对于升级总是失败的人会更有帮助,你可以直接选择全新安装,不用再去升级了。

Friday, October 9, 2015

EXT4: crtime, ctime, atime, mtime

EXT4 enables administrators to track file creation / access / modification.

What are they?
ctime: last file/inode change time
atime: last access time
mtime: last file modification time
crtime: creation time

How to get them?
First, get inode number
1
2
# ls -i /var/log/syslog
359 syslog

Then, with an inode number, debugfs can feedback ctime, atime, mtime, crtime
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# debugfs -R 'stat <359>' /dev/mmcblk0p1
debugfs 1.42 (29-Nov-2011)
Inode: 359   Type: regular    Mode:  0640   Flags: 0x80000
Generation: 2296437698    Version: 0x00000000:00000001
User:   101   Group:     4   Size: 8130
File ACL: 0    Directory ACL: 0
Links: 1   Blockcount: 16
Fragment:  Address: 0    Number: 0    Size: 0
 ctime: 0x5609d80e:e110b1d4 -- Tue Sep 29 00:15:10 2015
 atime: 0x5609ca6d:db4095b4 -- Mon Sep 28 23:17:01 2015
 mtime: 0x5609d80e:e110b1d4 -- Tue Sep 29 00:15:10 2015
crtime: 0x5609ca6d:db4095b4 -- Mon Sep 28 23:17:01 2015
Size of extra inode fields: 28
EXTENTS:
(0):146512, (1):146004
(END)

Where are they?
In /include/linux/fs.h, atime, ctime, and mtime within inode structure.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
struct inode {
        umode_t                 i_mode;
        unsigned short          i_opflags;
        kuid_t                  i_uid;
        kgid_t                  i_gid;
        unsigned int            i_flags;

#ifdef CONFIG_FS_POSIX_ACL
        struct posix_acl        *i_acl;
        struct posix_acl        *i_default_acl;
#endif

        const struct inode_operations   *i_op;
        struct super_block      *i_sb;
        struct address_space    *i_mapping;

#ifdef CONFIG_SECURITY
        void                    *i_security;
#endif

        /* Stat data, not accessed from path walking */
        unsigned long           i_ino;
        /*
         * Filesystems may only read i_nlink directly.  They shall use the
         * following functions for modification:
         *
         *    (set|clear|inc|drop)_nlink
         *    inode_(inc|dec)_link_count
         */
        union {
                const unsigned int i_nlink;
                unsigned int __i_nlink;
        };
        dev_t                   i_rdev;
        loff_t                  i_size;
        struct timespec         i_atime;
        struct timespec         i_mtime;
        struct timespec         i_ctime;
        spinlock_t              i_lock; /* i_blocks, i_bytes, maybe i_size */
        unsigned short          i_bytes;
        unsigned int            i_blkbits;
        blkcnt_t                i_blocks;

#ifdef __NEED_I_SIZE_ORDERED
        seqcount_t              i_size_seqcount;
#endif

        /* Misc */
        unsigned long           i_state;
        struct mutex            i_mutex;

        unsigned long           dirtied_when;   /* jiffies of first dirtying */
        unsigned long           dirtied_time_when;

        struct hlist_node       i_hash;
        struct list_head        i_wb_list;      /* backing dev IO list */
#ifdef CONFIG_CGROUP_WRITEBACK
        struct bdi_writeback    *i_wb;          /* the associated cgroup wb */

        /* foreign inode detection, see wbc_detach_inode() */
        int                     i_wb_frn_winner;
        u16                     i_wb_frn_avg_time;
        u16                     i_wb_frn_history;
#endif
        struct list_head        i_lru;          /* inode LRU list */
        struct list_head        i_sb_list;
        union {
                struct hlist_head       i_dentry;
                struct rcu_head         i_rcu;
        };
        u64                     i_version;
        atomic_t                i_count;
        atomic_t                i_dio_count;
        atomic_t                i_writecount;
#ifdef CONFIG_IMA
        atomic_t                i_readcount; /* struct files open RO */
#endif
        const struct file_operations    *i_fop; /* former ->i_op->default_file_ops */
        struct file_lock_context        *i_flctx;
        struct address_space    i_data;
        struct list_head        i_devices;
        union {
                struct pipe_inode_info  *i_pipe;
                struct block_device     *i_bdev;
                struct cdev             *i_cdev;
                char                    *i_link;
        };

        __u32                   i_generation;

#ifdef CONFIG_FSNOTIFY
        __u32                   i_fsnotify_mask; /* all events this inode cares about */
        struct hlist_head       i_fsnotify_marks;
#endif

        void                    *i_private; /* fs or device private pointer */
};

For crtime, it is in the /fs/ext4/ext4.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
struct ext4_inode_info {
        __le32  i_data[15];     /* unconverted */
        __u32   i_dtime;
        ext4_fsblk_t    i_file_acl;

        /*
         * i_block_group is the number of the block group which contains
         * this file's inode.  Constant across the lifetime of the inode,
         * it is ued for making block allocation decisions - we try to
         * place a file's data blocks near its inode block, and new inodes
         * near to their parent directory's inode.
         */
        ext4_group_t    i_block_group;
        ext4_lblk_t     i_dir_start_lookup;
#if (BITS_PER_LONG < 64)
        unsigned long   i_state_flags;          /* Dynamic state flags */
#endif
        unsigned long   i_flags;

        /*
         * Extended attributes can be read independently of the main file
         * data. Taking i_mutex even when reading would cause contention
         * between readers of EAs and writers of regular file data, so
         * instead we synchronize on xattr_sem when reading or changing
         * EAs.
         */
        struct rw_semaphore xattr_sem;

        struct list_head i_orphan;      /* unlinked but open inodes */

        /*
         * i_disksize keeps track of what the inode size is ON DISK, not
         * in memory.  During truncate, i_size is set to the new size by
         * the VFS prior to calling ext4_truncate(), but the filesystem won't
         * set i_disksize to 0 until the truncate is actually under way.
         *
         * The intent is that i_disksize always represents the blocks which
         * are used by this file.  This allows recovery to restart truncate
         * on orphans if we crash during truncate.  We actually write i_disksize
         * into the on-disk inode when writing inodes out, instead of i_size.
         *
         * The only time when i_disksize and i_size may be different is when
         * a truncate is in progress.  The only things which change i_disksize
         * are ext4_get_block (growth) and ext4_truncate (shrinkth).
         */
        loff_t  i_disksize;

        /*
         * i_data_sem is for serialising ext4_truncate() against
         * ext4_getblock().  In the 2.4 ext2 design, great chunks of inode's
         * data tree are chopped off during truncate. We can't do that in
         * ext4 because whenever we perform intermediate commits during
         * truncate, the inode and all the metadata blocks *must* be in a
         * consistent state which allows truncation of the orphans to restart
         * during recovery.  Hence we must fix the get_block-vs-truncate race
         * by other means, so we have i_data_sem.
         */
        struct rw_semaphore i_data_sem;
        struct inode vfs_inode;
        struct jbd2_inode *jinode;

        spinlock_t i_raw_lock;  /* protects updates to the raw inode */

        /*
         * File creation time. Its function is same as that of
         * struct timespec i_{a,c,m}time in the generic inode.
         */
        struct timespec i_crtime;

        /* mballoc */
        struct list_head i_prealloc_list;
        spinlock_t i_prealloc_lock;

        /* extents status tree */
        struct ext4_es_tree i_es_tree;
        rwlock_t i_es_lock;
        struct list_head i_es_list;
        unsigned int i_es_all_nr;       /* protected by i_es_lock */
        unsigned int i_es_shk_nr;       /* protected by i_es_lock */
        ext4_lblk_t i_es_shrink_lblk;   /* Offset where we start searching for
                                           extents to shrink. Protected by
                                           i_es_lock  */

        /* ialloc */
        ext4_group_t    i_last_alloc_group;

        /* allocation reservation info for delalloc */
        /* In case of bigalloc, these refer to clusters rather than blocks */
        unsigned int i_reserved_data_blocks;
        unsigned int i_reserved_meta_blocks;
        unsigned int i_allocated_meta_blocks;
        ext4_lblk_t i_da_metadata_calc_last_lblock;
        int i_da_metadata_calc_len;

        /* on-disk additional length */
        __u16 i_extra_isize;

        /* Indicate the inline data space. */
        u16 i_inline_off;
        u16 i_inline_size;

#ifdef CONFIG_QUOTA
        /* quota space reservation, managed internally by quota code */
        qsize_t i_reserved_quota;
#endif

        /* Lock protecting lists below */
        spinlock_t i_completed_io_lock;
        /*
         * Completed IOs that need unwritten extents handling and have
         * transaction reserved
         */
        struct list_head i_rsv_conversion_list;
        /*
         * Completed IOs that need unwritten extents handling and don't have
         * transaction reserved
         */
        atomic_t i_ioend_count; /* Number of outstanding io_end structs */
        atomic_t i_unwritten; /* Nr. of inflight conversions pending */
        struct work_struct i_rsv_conversion_work;

        spinlock_t i_block_reservation_lock;

        /*
         * Transactions that contain inode's metadata needed to complete
         * fsync and fdatasync, respectively.
         */
        tid_t i_sync_tid;
        tid_t i_datasync_tid;

#ifdef CONFIG_QUOTA
        struct dquot *i_dquot[MAXQUOTAS];
#endif

        /* Precomputed uuid+inum+igen checksum for seeding inode checksums */
        __u32 i_csum_seed;

#ifdef CONFIG_EXT4_FS_ENCRYPTION
        /* Encryption params */
        struct ext4_crypt_info *i_crypt_info;
#endif
};


Sunday, October 4, 2015

Set up git server on ubuntu

On server:
1
2
3
4
5
6
sudo apt-get install git
sudo adduser git
su git
cd
mkdir .ssh && chmod 700 .ssh
touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys

On workstation:
1
2
3
sudo apt-get install git
ssh-keygen -t rsa -C "yourname@mail.com"
scp .ssh/id_rsa.pub git@gitserver:/tmp

On server:
1
2
3
4
5
6
7
sudo mkdir /opt/git
cd /opt
sudo chown git git
cd git
mkdir project.git
cd project.git
git init --bare

On workstation:
1
2
3
4
5
6
cd myproject
git init
git add .
git commit -m 'initial commit'
git remote add origin git@gitserver:/opt/git/project.git
git push origin master

On server: (prevent using git to log on)
1
2
3
4
cat /etc/shells   # see if `git-shell` is already in there.  If not...
which git-shell   # make sure git-shell is installed on your system.
sudo vim /etc/shells  # and add the path to git-shell from last command
sudo chsh git  # and enter the path to git-shell, usually: /usr/bin/git-shell


Reference:
https://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server
https://help.ubuntu.com/lts/serverguide/git.html

Thursday, October 1, 2015

Ubuntu /etc/network/interfaces

mapping stanza
1
2
3
4
5
mapping <interface_name_glob>
 script <script_name>
 map <script_input1>
 map <script_input2>
 map ...

example configuration:
1
2
3
4
5
 auto eth0 eth1
 mapping eth0 eth1
     script /path/to/get-mac-address.sh
     map 11:22:33:44:55:66 lan
     map AA:BB:CC:DD:EE:FF internet

get-mac-address.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/bin/sh

set -e

export LANG=C

iface="$1"
mac=$(/sbin/ifconfig "$iface" | sed -n -e '/^.*HWaddr \([:[:xdigit:]]*\).*/{s//\1/;y/ABCDEF/abcdef/;p;q;}')
which=""

while read testmac scheme; do
        if [ "$which" ]; then continue; fi
        if [ "$mac" = "$(echo "$testmac" | sed -e 'y/ABCDEF/abcdef/')" ]; then which="$scheme"; fi
done

if [ "$which" ]; then echo $which; exit 0; fi
exit 1

The bold sections in the example configuration and the corresponding script show how the "map" inputs are handled.

Reference:
http://addisu.taddese.com/blog/mapping-in-linux-network-interfaces/
https://wiki.debian.org/NetworkConfiguration

Wednesday, September 30, 2015

Ubuntu bridge configuration

brctl in bridge-utils
1
#aptitude install bridge-utils

1
#brctl addbr br0
- creating a bridge interface

1
#ip addr show
- display the enumeration of ethernet devices

1
#brctl addif br0 eth0 eth1
- add eth0 and eth1 to bridge br0

The equivalent configuration in /etc/network/interfaces
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 # This file describes the network interfaces available on your system
 # and how to activate them. For more information, see interfaces(5).

 # The loopback network interface
 auto lo br0
 iface lo inet loopback

 # Set up interfaces manually, avoiding conflicts with, e.g., network manager
 iface eth0 inet manual

 iface eth1 inet manual

 # Bridge setup
 iface br0 inet dhcp
        bridge_ports eth0 eth1

1
#ifup br0
- bring up the bridge

It is possible to set a static IP for a bridge in /etc/network/interfaces
1
2
3
4
5
6
 iface br0 inet static
        bridge_ports eth0 eth1
        address 192.168.1.2
        broadcast 192.168.1.255
        netmask 255.255.255.0
        gateway 192.168.1.1

Bridge configuration variables are in
/etc/sysctl.conf
/etc/sysctl.d/bridge_local.conf

procps init script will loading the configurations.  For newer Debian releases, procps needs to be started in /etc/rc.local
1
2
# Load kernel variables from /etc/sysctl.d
/etc/init.d/procps restart

Setup link layer filtering rules
Need package ebtables

For supporting link aggregation (LACP), ifenslave is the required package.

references:
https://wiki.debian.org/BridgeNetworkConnections
http://wiki.libvirt.org/page/Networking
https://help.ubuntu.com/community/NetworkConnectionBridge
https://help.ubuntu.com/community/Ntop

Tuesday, September 29, 2015

Linux Kernel Source in Eclipse CDT

https://wiki.eclipse.org/HowTo_use_the_CDT_to_navigate_Linux_kernel_source
The steps are good for Eclipse Luna.

1 Download and install Eclipse plus the CDT.
2 Configure and build your kernel to define CONFIG_* and generate autoconf.h. This can be done before or after downloading and installing Eclipse.
3 Ensure that you have the right kernel source (e.g. make sure you are on the right git branch). If you check out another branch later, that's ok, but you will need to re-index the source, and that takes about 20 minutes.
4 Start up Eclipse.
5 Click File->New->C Project
6 Fill in a project name like my_kernel
7 Uncheck the Use default location box and type in the root directory of your kernel into the Location box.
8 In the Project type: pane, click the Makefile project and select Empty Project
9 On the right side, select Linux GCC
10 Click Advanced settings... and a Properties dialog will pop up.
11 Open the C/C++ General selection on the left.
12 Click on Preprocessor Include Paths
13 Select GNU C in the Languages list
14 Select CDT User Setting Entries in the Setting Entries list
15 Click on Add.... Choose Preprocessor Macros File from the top left dropdown, Project Path from the top right dropdown, and enter "include/generated/autoconf.h" into the File text box. (Note: For kernels older than 2.6.33, the location of autoconf.h is include/linux/autoconf.h)
16 Also add any other macros files you are using.
17 Click on Indexer
18 Checkmark the Enable project specific setttings box.
19 Uncheck Index source files not included in the build
20 Click on Paths and Symbols on the left.
21 Select the Includes tab and then select GNU C
22 Click Add...
23 Click Workspace... then select your kernel's include, and include/uapi directories
24 Do another Add, Workspace and add both arch/architecture/include, and arch/architecture/include/uapi directories. e.g., arch/powerpc/include and arch/powerpc/include/uapi (The UAPI directories are due to the kernel's user/kernel header split covered here in-detail)
25 Click the # Symbols tab
26 Click Add...
27 Set the name to __KERNEL__
28 Set the value to 1 and click OK
29 Click the Source Location tab
30 Click the plus sign next to your project name.
31 Select the Filter item and click Edit Filter...
32 Click Add Multiple... and then select all of the arch/* directories in your kernel source that will not be used (i.e. all the ones that are not for the architecture you are using)
33 Click OK and OK again to dismiss that dialog.
34 Under C/C++ General, select Preprocessor Include Paths, Macros etc.
35 Click the Providers tab and select CDT GCC Built-in Compiler Settings
36 Uncheck Use global provider shared between projects
37 Add -nostdinc to the Command to get compiler specs
38 Check Allocate console in the Console View so you can see that this is working
39 Click OK on the Properties dialog.
40 Click Finish on the C Project dialog.
41 The Project will index automatically.
42 On a platter drive indexing will take upwards of 20 minutes to complete, on a SSD indexing will take about 5 minutes to complete.

Notes:

1. Adding include and arch/architecture/include only gets you a couple of the common include paths. To fully index all of the kernel, you would have to add dozens of paths, unfortunately. For this reason, I advise against using PTP's remote indexing capability for the linux kernel, because what happens is that it will report thousands of errors in locating header files, and the process of reporting those errors over a possibly long-latency link, will cause the indexing to take many hours.
2 If you change any of your CONFIG_* settings, in order for Eclipse to recognize those changes, you may need to do a "build" from within Eclipse. Note, this does not mean to re-build the index; this means to build the kernel, by having Eclipse invoke make (this is normally bound to the Ctrl-B key in Eclipse). Eclipse should automatically detect changes to include/generated/autoconf.h, reread the compilation #defines it uses, and reindex.
3 The background color of "Quick Context View" will be dark if the Ambiance theme in Ubuntu is selected.
4 For some people, Eclipse may fail to index the kernel with a out of memory error. The fix seems to be to start eclipse with the arguments: eclipse -vmargs -Xmx650M

Corey Ashford cjashfor@us.ibm.com Updated by Adam Duskett Aduskett@gmail.com

Monday, September 28, 2015

Thursday, September 24, 2015

Saturday, September 19, 2015

做技术的你,如果别人找你创业,该怎么办?

作者:Bruce Dou
http://blog.eood.cn/about


由于技术背景的原因,每结交认识一位新朋友,无论是之前在国内还是先在在英国,都会跟我说:我有一个 business idea 你花时间帮我做出来,过几年我们都会成为亿万富翁。每当这时,我都笑笑,也不知道该如何回应。一般我会说我考虑一下,做一些市场调研。
直到发现这个商业计划书模板。这下好了,我可以说先给你个 BP 模板,你再仔细考虑一下。其实这不是在敷衍,假如真是不错的 BP ,会容易找到合作伙伴,也容易找到投资人。假如你也有一个 idea ,但是还处于想法阶段,这个商业计划书模板能够帮你理清思路。
这个一页 BP 模板简单实用,分几个部分:

1. 问题 (Problem)
项目解决什么问题?满足什么需求?

2. 一句话介绍 (Elevator pitch)
用一句话概括问题、受众、解决方案、创新点。

3. 解决方案 (Solution)
如何解决问题,给受众带来哪些价值。

4. 目标用户 (Audience)
用户是哪个人群?哪些人时重要用户?他们如何评价产品或者服务质量?

5. 渠道 (Channels)
如何接触目标用户?他们常常出现在哪里?他们如何找到你的产品?

6. 关键指标 (Key metrics)
如何测量决定某个用户有这个问题需要你的产品?

7. 创新点 (Differentiator)
你的解决方案的不同点和创新之处在哪?

8. 收入模式(Revenue)
你卖什么?卖多少钱?

9. 成本(Cost)
运营需要的成本和活动有哪些?除了你自身外还需要哪些资源?

10. 商业优势(Business Boosters)
你有哪些别人不具备的优势?比如社会关系、行业经验、特殊渠道。你的 idea 如何不被其他人复制?

11. 个人适合度 (Personal Fit)
这个商业模式适合你吗?你是否之后会失去兴趣?

自己想清楚如何回答这些问题,并且能够说服自己的话,估计就会是个比较靠谱的 Business Plan 了。另外,idea 其实并不是最重要,重要的是日复一日的精细执行。

Friday, September 18, 2015

Ubuntu KGDB

This is for 12.04 and I believe that this should work for 14.04.

Kernel build
Make sure .config contains
1
2
3
CONFIG_HAVE_ARCH_KGDB=y
CONFIG_KGDB=y
CONFIG_KGDB_SERIAL_CONSOLE=y

GRUB
On this line:
1
linux /boot/vmlinux-4.1.3-XXXX root=UUID=XXXXX ro consoleblank=0

append at the end
1
kgdbwait kgdboc=ttyS2,115200

Serial Port
Check which serial port is available
1
dmesg | grep ttyS

Configure serial port
Install setserial
1
sudo apt-get install setserial

Check port configuration
1
sudo setserial -g /dev/ttyS3

Install minicom
1
sudo apt-get install minicom

Configure port
1
sudo minicom -s

After configuration choose "Exit" and started session.

Ctrl-A Z and then, choose "Hang up".

GDB
Fire up gdb
1
sudo gdb vmlinux

Connect serial port
1
2
3
4
5
6
7
(gdb) set remotebaud 115200
(gdb) target remote /dev/ttyS3
Remote debugging using /dev/ttyS3
Ignoring packet error, continuing...
kgdb_breakpoint ()
    at /home/wre/work/OS/linux-4.1.3/kernel/debug/debug_core.c:1072
1072  wmb(); /* Sync point after breakpoint */

Set a break point
1
2
(gdb) b /home/nobody/work/OS/linux-4.1.3/drivers/base/core.c:1970
Breakpoint 1 at 0xc1556b68: file /home/nobody/work/OS/linux-4.1.3/drivers/base/core.c, line 1970.


Thursday, September 17, 2015

Bash File Test Operators

Copied from the following source...
http://tldp.org/LDP/abs/html/fto.html


Returns true if...
-e
file exists
-a
file exists
This is identical in effect to -e. It has been "deprecated," [1] and its use is discouraged.
-f
file is a regular file (not a directory or device file)
-s
file is not zero size
-d
file is a directory
-b
file is a block device
-c
file is a character device

device0="/dev/sda2"    # /   (root directory)
if [ -b "$device0" ]
then
  echo "$device0 is a block device."
fi

# /dev/sda2 is a block device.



device1="/dev/ttyS1"   # PCMCIA modem card.
if [ -c "$device1" ]
then
  echo "$device1 is a character device."
fi

# /dev/ttyS1 is a character device.
-p
file is a pipe

function show_input_type()
{
   [ -p /dev/fd/0 ] && echo PIPE || echo STDIN
}

show_input_type "Input"                           # STDIN
echo "Input" | show_input_type                    # PIPE

# This example courtesy of Carl Anderson.
-h
file is a symbolic link
-L
file is a symbolic link
-S
file is a socket
-t
file (descriptor) is associated with a terminal device
This test option may be used to check whether the stdin [ -t 0 ] or stdout [ -t 1 ] in a given script is a terminal.
-r
file has read permission (for the user running the test)
-w
file has write permission (for the user running the test)
-x
file has execute permission (for the user running the test)
-g
set-group-id (sgid) flag set on file or directory
If a directory has the sgid flag set, then a file created within that directory belongs to the group that owns the directory, not necessarily to the group of the user who created the file. This may be useful for a directory shared by a workgroup.
-u

set-user-id (suid) flag set on file
A binary owned by root with set-user-id flag set runs with root privileges, even when an ordinary user invokes it. [2] This is useful for executables (such as pppd and cdrecord) that need to access system hardware. Lacking the suid flag, these binaries could not be invoked by a non-root user.

       -rwsr-xr-t    1 root       178236 Oct  2  2000 /usr/sbin/pppd
       

A file with the suid flag set shows an s in its permissions.
-k
sticky bit set
Commonly known as the sticky bit, the save-text-mode flag is a special type of file permission. If a file has this flag set, that file will be kept in cache memory, for quicker access. [3] If set on a directory, it restricts write permission. Setting the sticky bit adds a t to the permissions on the file or directory listing. This restricts altering or deleting specific files in that directory to the owner of those files.

       drwxrwxrwt    7 root         1024 May 19 21:26 tmp/
       

If a user does not own a directory that has the sticky bit set, but has write permission in that directory, she can only delete those files that she owns in it. This keeps users from inadvertently overwriting or deleting each other's files in a publicly accessible directory, such as /tmp. (The owner of the directory or root can, of course, delete or rename files there.)
-O
you are owner of file
-G
group-id of file same as yours
-N
file modified since it was last read
f1 -nt f2
file f1 is newer than f2
f1 -ot f2
file f1 is older than f2
f1 -ef f2
files f1 and f2 are hard links to the same file
!
"not" -- reverses the sense of the tests above (returns true if condition absent).

Example 7-4. Testing for broken links

#!/bin/bash
# broken-link.sh
# Written by Lee bigelow <ligelowbee@yahoo.com>
# Used in ABS Guide with permission.

#  A pure shell script to find dead symlinks and output them quoted
#+ so they can be fed to xargs and dealt with :)
#+ eg. sh broken-link.sh /somedir /someotherdir|xargs rm
#
#  This, however, is a better method:
#
#  find "somedir" -type l -print0|\
#  xargs -r0 file|\
#  grep "broken symbolic"|
#  sed -e 's/^\|: *broken symbolic.*$/"/g'
#
#+ but that wouldn't be pure Bash, now would it.
#  Caution: beware the /proc file system and any circular links!
################################################################


#  If no args are passed to the script set directories-to-search 
#+ to current directory.  Otherwise set the directories-to-search 
#+ to the args passed.
######################

[ $# -eq 0 ] && directorys=`pwd` || directorys=$@


#  Setup the function linkchk to check the directory it is passed 
#+ for files that are links and don't exist, then print them quoted.
#  If one of the elements in the directory is a subdirectory then 
#+ send that subdirectory to the linkcheck function.
##########

linkchk () {
    for element in $1/*; do
      [ -h "$element" -a ! -e "$element" ] && echo \"$element\"
      [ -d "$element" ] && linkchk $element
    # Of course, '-h' tests for symbolic link, '-d' for directory.
    done
}

#  Send each arg that was passed to the script to the linkchk() function
#+ if it is a valid directoy.  If not, then print the error message
#+ and usage info.
##################
for directory in $directorys; do
    if [ -d $directory ]
 then linkchk $directory
 else 
     echo "$directory is not a directory"
     echo "Usage: $0 dir1 dir2 ..."
    fi
done

exit $?
Example 31-1, Example 11-8, Example 11-3, Example 31-3, and Example A-1 also illustrate uses of the file test operators.

Notes

[1]Per the 1913 edition of Webster's Dictionary:

Deprecate
...

To pray against, as an evil;
to seek to avert by prayer;
to desire the removal of;
to seek deliverance from;
to express deep regret for;
to disapprove of strongly.
[2]Be aware that suid binaries may open security holes. The suid flag has no effect on shell scripts.
[3]On Linux systems, the sticky bit is no longer used for files, only on directories.