Archive

Archive for August, 2011

FreeBsd System Calls

August 31, 2011 Leave a comment
Below is the list of system calls in freebsd. Total 467 entries.

abort2                    463
accept                    30
accept(old)               99
access                    33
acct                      51
acl_aclcheck_fd           354
acl_aclcheck_file         353
__acl_aclcheck_link       428
__acl_delete_fd           352
__acl_delete_file         351
__acl_delete_link         427
__acl_get_fd              349
__acl_get_file            347
__acl_get_link            425
__acl_set_fd              350
__acl_set_file            348
__acl_set_link            426
adjtime                   140
afs3_syscall              377
aio_cancel                316
aio_error                 317
aio_fsync                 465
aio_read                  255
aio_return                314
aio_suspend               315
aio_waitcomplete          359
aio_write                 256
asyncdaemon               153
audit                     445
auditctl                  453
auditon                   446
bind                      104
break                     17
cap_enter                 516
__cap_get_fd              366
__cap_get_file            367
cap_getmode               517
__cap_get_proc            364
cap_getrights             515
cap_new                   514
__cap_set_fd              368
__cap_set_file            369
__cap_set_proc            365
chdir                     12
chflags                   34
chmod                     15
chown                     16
chroot                    61
clock_getres              234
clock_gettime             232
clock_settime             233
close                     6
closefrom                 509
connect                   98
cpuset                    484
cpuset_getaffinity        487
cpuset_getid              486
cpuset_setaffinity        488
cpuset_setid              485
creat(old)                8
dup                       41
dup2                      90
eaccess                   376
execve                    59
execv(obsolete)           11
exit                      1
extattrctl                355
extattr_delete_fd         373
extattr_delete_file       358
extattr_delete_link       414
extattr_get_fd            372
extattr_get_file          357
extattr_get_link          413
extattr_list_fd           437
extattr_list_file         438
extattr_list_link         439
extattr_set_fd            371
extattr_set_file          356
extattr_set_link          412
faccessat                 489
fchdir                    13
fchflags                  35
fchmod                    124
fchmodat                  490
fchown                    123
fchownat                  491
fcntl                     92
fexecve                   492
fhopen                    298
fhstat                    299
fhstatfs                  398
fhstatfs(freebsd4)        297
flock                     131
fork                      2
fpathconf                 192
fstat                     189
fstatat                   493
fstatfs                   397
fstatfs(freebsd4)         158
fstat(old)                62
fsync                     95
ftruncate                 480
ftruncate(freebsd6)       201
ftruncate(old)            130
futimes                   206
futimesat                 494
getaudit                  449
getaudit_addr             451
getauid                   447
getcontext                421
__getcwd                  326
getdents                  272
getdescriptor             178
getdirentries             196
getdirentries(old)        156
getdomainname(freebsd4)   162
getdopt                   91
getdtablesize             89
getegid                   43
geteuid                   25
getfh                     161
getfsstat                 395
getfsstat(freebsd4)       18
getgid                    47
getgroups                 79
gethostid(old)            142
gethostname(old)          87
getitimer                 86
getkerninfo(old)          63
getlogin                  49
getpagesize(old)          64
__getpath_fromaddr        470
__getpath_fromfd          469
getpeername               31
getpeername(old)          141
getpgid                   207
getpgrp                   81
getpid                    20
getppid                   39
getpriority               100
getresgid                 361
getresuid                 360
getrlimit                 194
getrlimit(old)            144
getrusage                 117
getsid                    310
getsockname               32
getsockname(old)          150
getsockopt                118
gettimeofday              116
getuid                    24
gssd_syscall              505
ioctl                     54
issetugid                 253
jail                      338
jail_attach               436
jail_get                  506
jail_remove               508
jail_set                  507
kenv                      390
kevent                    363
kill                      37
killpg(old)               146
kldfind                   306
kldfirstmod               309
kldload                   304
kldnext                   307
kldstat                   308
kldsym                    337
kldunload                 305
kldunloadf                444
kmq_notify                461
kmq_open                  457
kmq_setattr               458
kmq_timedreceive          459
kmq_timedsend             460
kmq_unlink                462
kqueue                    362
kse_create                381
kse_exit                  379
kse_release               383
kse_switchin              440
kse_thr_interrupt         382
kse_wakeup                380
ksem_close                400
ksem_destroy              408
ksem_getvalue             407
ksem_init                 404
ksem_open                 405
ksem_post                 401
ksem_timedwait            441
ksem_trywait              403
ksem_unlink               406
ksem_wait                 402
ktimer_create             235
ktimer_delete             236
ktimer_getoverrun         239
ktimer_gettime            238
ktimer_settime            237
ktrace                    45
lchflags                  391
lchmod                    274
lchown                    254
lchown(netbsd)            275
lfs_bmapv                 184
lfs_markv                 185
lfs_segclean              186
lfs_segwait               187
lgetfh                    160
link                      9
linkat                    495
lio_listio                257
listen                    106
lkmnosys                  210-219
lpathconf                 513
lseek                     478
lseek(freebsd6)           199
lseek(old)                19
lstat                     190
lstat(old)                40
lutimes                   276
__mac_execve              415
__mac_get_fd              386
__mac_get_file            387
__mac_get_link            410
__mac_get_pid             409
__mac_get_proc            384
__mac_set_fd              388
__mac_set_file            389
__mac_set_link            411
__mac_set_proc            385
mac_syscall               394
madvise                   75
mincore                   78
minherit                  250
mkdir                     136
mkdirat                   496
mkfifo                    132
mkfifoat                  497
mknod                     14
mknodat                   498
mlock                     203
mlockall                  324
mmap                      477
mmap(freebsd6)            197
mmap(old)                 71
modfind                   303
modfnext                  302
modnext                   300
modstat                   301
mount                     21
mprotect                  74
msgctl                    511
msgctl(freebsd7)          224
msgget                    225
msgrcv                    227
msgsnd                    226
msgsys                    170
msync                     65
msync(netbsd)             277
munlock                   204
munlockall                325
munmap                    73
nanosleep                 240
nfsclnt                   375
nfssvc                    155
nfstat                    279
nlm_syscall               154
nlstat                    280
nmount                    378
nnpfs_syscall             339
nstat                     278
ntp_adjtime               176
ntp_gettime               248
oaio_read                 318
oaio_write                319
olio_listio               320
open                      5
openat                    499
openpt(posix)             504
pathconf                  191
pdfork                    518
pdgetpid                  520
pdkill                    519
pdwait                    521
pipe                      42
poll                      209
poll(openbsd)             252
pread                     475
pread(freebsd6)           173
preadv                    289
profil                    44
pselect                   522
ptrace                    26
pwrite                    476
pwrite(freebsd6)          174
pwritev                   290
quotactl                  148
quota(old)                149
read                      3
readlink                  58
readlinkat                500
readv                     120
reboot                    55
reboot(new)               208
recvfrom                  29
recvfrom(old)             125
recvmsg                   27
recvmsg(old)              113
recv(old)                 102
rename                    128
renameat                  501
resuba                    119
revoke                    56
rfork                     251
rmdir                     137
rtprio                    166
rtprio_thread             466
sbrk                      69
sched_getparam            328
sched_get_priority_max    332
sched_get_priority_min    333
sched_getscheduler        330
sched_rr_get_interval     334
sched_setparam            327
sched_setscheduler        329
sched_yield               331
sctp_generic_recvmsg      474
sctp_generic_sendmsg      472
sctp_generic_sendmsg_iov  473
sctp_peeloff              471
select                    93
semconfig                 223
__semctl                  510
__semctl(freebsd7)        220
semget                    221
sem_lock                  151
semop                     222
semsys                    169
sem_wakeup                152
sendfile                  393
sendfile(freebsd4)        336
sendmsg                   28
sendmsg(old)              114
send(old)                 101
sendto                    133
setaudit                  450
setaudit_addr             452
setauid                   448
setcontext                422
setdescriptor             179
setdomainname(freebsd4)   163
setdopt                   94
setegid                   182
seteuid                   183
setfib                    175
setgid                    181
setgroups                 80
sethostid(old)            143
sethostname(old)          88
setitimer                 83
setlogin                  50
setpgid                   82
setpriority               96
setregid                  127
setresgid                 312
setresuid                 311
setreuid                  126
setrlimit                 195
setrlimit(old)            145
setsid                    147
setsockopt                105
settimeofday              122
__setugid                 374
setuid                    23
sfork                     177
shmat                     228
shmctl                    512
shmctl(freebsd7)          229
shmdt                     230
shmget                    231
shm_open                  482
shmsys                    171
shm_unlink                483
shutdown                  134
sigaction                 416
sigaction(freebsd4)       342
sigaction(old)            46
sigaltstack               53
sigblock(old)             109
signanosleep(obsolete)    313
sigpending                343
sigpending(old)           52
sigprocmask               340
sigprocmask(old)          48
sigqueue                  456
sigreturn                 417
sigreturn(freebsd4)       344
sigreturn(obsolete)       139
sigreturn(old)            103
sigsetmask(old)           110
sigstack(old)             112
sigsuspend                341
sigsuspend(old)           111
sigtimedwait              345
sigvec(old)               108
sigwait                   429
sigwaitinfo               346
socket                    97
socketpair                135
sstk                      70
stat                      188
statfs                    396
statfs(freebsd4)          157
stat(old)                 38
swapcontext               423
swapoff                   424
swapon                    85
symlink                   57
symlinkat                 502
sync                      36
sysarch                   165
syscall                   0
__syscall                 198
__sysctl                  202
thr_create                430
thr_exit                  431
thr_kill2                 481
thr_kill                  433
thr_new                   455
thr_self                  432
thr_set_name              464
thr_sleep(obsolete)       322
thr_suspend               442
thr_wake                  443
thr_wakeup(obsolete)      323
truncate                  479
truncate(freebsd6)        200
truncate(old)             129
umask                     60
_umtx_lock                434
_umtx_op                  454
_umtx_unlock              435
uname(freebsd4)           164
undelete                  205
unlink                    10
unlinkat                  503
unmount                   22
utimes                    138
utrace                    335
uuidgen                   392
vadvise                   72
vfork                     66
vhangup(obsolete)         76
vlimit(obsolete)          77
vread(obsolete)           67
vtimes(obsolete)          107
vtrace(obsolete)          115
vwrite(obsolete)          68
wait4                     7
wait(old)                 84
write                     4
writev                    121
__xfstat                  419
__xlstat                  420
__xstat                   418
yield                     321

Original list can be found at : http://www.acsu.buffalo.edu/~charngda/freebsd_syscalls.html
Advertisements

FreeBSD Htop Installation

August 31, 2011 Leave a comment

Well i really like htop and in freebsd you’ll need linux compability layer to use htop.
Here is a short guide, i’ll be using package system if you prefer you can use ports as well.

Edit: load linux module first (kldload linux) or linux_base installation will fail

– Install linux base:

pkg_add -rv linux_base-f10

– Add fallowing line to /etc/fstab for htop:

linproc /compat/linux/proc linprocfs rw 0 0

– Install htop :

pkg_add -rv htop

– Load linux support module:

kldload linux

– To make linux support at startup as default, add fallowing line to /etc/rc.conf :

linux_enable=”YES”

– Load proc file system:

mount linproc

and start htop…..

Less Known Facts About Apple OsX

August 30, 2011 Leave a comment

Most of you out there do not know background of osx (apple operating system). Below is a email dated back to 2008 from Robert Watson (FreeBsd Core Team member) response to a member of freebsd-advocacy mailing list.

Quota from freebsd-advocacy mailing list:

“………..

I'd be a bit cautious about saying XNU is a Mach kernel.  XNU is not a 
microkernel, but it contains a lot more Mach code than FreeBSD does. 
However, XNU contains massive amounts of FreeBSD code, including countless IPC 
models, security parts, VFS, network stack, distributed file systems, etc. 
Saying that "Mac OS X is just FreeBSD with an Apple GUI" is certainly false on 
face value, but it's not correct to say that the kernel isn't in significant 
part FreeBSD-derived.  Here's what I find in my most recent XNU kernel source 
drop from Apple:

   21M of code labeled explicitly as BSD, largely from FreeBSD but heavily
   modified.

   16M of code labeled explicitly as Mach, largely from OSF Mach, but heavily
   modified.

   676K of code labeled explicitly as Security, actually the TrustedBSD MAC
   Framework from FreeBSD, with modifications.

   2.7M of device driver code in the IOKit tree, mostly from Apple.

   2M of "libkern" -- mostly Apple code (C++ parts for IOKit) and zlib.

And then some loose ends, such as libsyscall, which is really userspace code 
but stored in the kernel source tree, configuration files, GDB macros, etc.

The above is just the XNU drop, so excludes the large number of additional 
loadable kernel extensions (kexts), which include a lot of device drivers 
(largely Apple and vendor code), but also things like smbfs (pretty much 
verbatim FreeBSD code).

> If you want to brag about FreeBSD technology used in a mainstream product, 
> then by all means mention Firefox 3, because that is already quite 
> impressive.

This is true, but if you measure the proportion of Firefox code that is 
FreeBSD vs the proportion of XNU code that is FreeBSD, we definitely have more 
of a showing in XNU, making up a significant part of the product :-).  One 
shouldn't underestimate Apple's work to improve our code and produce new 
facilities, some of which has come back to FreeBSD, but likewise they gained a 
lot by using all that FreeBSD code, not to mention hiring a lot of FreeBSD 
developers to work on the product.

Robert N M Watson
Computer Laboratory
University of Cambridge ........"

Note: At the time osx kernel was around 39M-40M (might be wrong)

Original mail can be reached at :http://lists.freebsd.org/pipermail/freebsd-advocacy/2008-August/003674.html

XNU source code can be found at: http://www.opensource.apple.com/source/xnu/xnu-1456.1.26/

About XNU from wikipedia:

XNU is the computer operating system kernel that Apple Inc. acquired and
developed for use in the Mac OS X operating systemand released as free
and open source software as part of the Darwin operating system.
XNU is an acronym for X is Not Unix.

Originally developed by NeXT for the NeXTSTEP operating system, XNU was a hybrid
kernel combining version 2.5 of the Mach kernel developed at Carnegie Mellon
University with components from 4.3BSD and an object-oriented API for writing
drivers called Driver Kit.

After Apple acquired NeXT, the Mach component was upgraded to 3.0, the BSD
components were upgraded with code from the FreeBSD project and the Driver Kit
was replaced with a C++ API for writing drivers called I/O Kit.

How To Clear Memory Cache Under Linux

August 30, 2011 Leave a comment

Under linux when you use system for couple of days and process various operations system caches some content for faster access (this happens in 1 hour as well). This can lead to unnecessary used ram and buffers.

To clean up your pagecache/dentries/inodes:

First give sync command to commit the mem changes to disk

[root@kuku ~]# sync

Than give sysctl command (configure kernel parameters at runtime)

[root@kuku ~]# sysctl -w vm.drop_caches = 3

If you like you can change back to default value of 0 by:

[root@kuku ~]# sysctl -w vm.drop_caches = 0

Alternatively you can:

[root@kuku ~]# sync

[root@kuku ~]# echo 3 > /proc/sys/vm/drop_caches

Some Results:

Before sysctl:

[root@kuku ~]# free
—                  total            used            free        shared    buffers     cached
Mem:       3903392    3775516     127876          0      94972    1686960
-/+ buffers/cache:    1993584    1909808
Swap:      2047996     472640    1575356

After Sysctl:

[root@kuku ~]# free
—                   total            used          free        shared    buffers     cached
Mem:       3903392    2326952    1576440          0       6496     285436
-/+ buffers/cache:    2035020    1868372
Swap:      2047996     472548    1575448

Sysctl Modes:

0 enable cache
1 free pagecache
2 free dentries and inodes
3 free pagecache, dentries and inodes

Useful Gnu tools for programmers

August 29, 2011 Leave a comment

Global:

From gnu.org : Global Cross-environment source code tag system

…..You can locate specified objects such as functions, macros, structs, classes in your source files and move there easily. It is useful for hacking large projects which contain many sub-directories, many #ifdefand many main() functions. It is similar to ctags or etags, but is different from them at the point of independence of any editor.

Simple usage:

After you cd to your project folder invoke “gtags” command this will generate tag files so you can start searching your source files:

$ global -xg scanf

scanf              11 ctof.c               sscanf(line,”%f”,&cel);
scanf              10 read.c              sscanf(line,”%d”,&value);

Global has much more features and pretty powerful, for usage check out projects’ home page : http://www.gnu.org/software/global/

Indent:

Code reformatter (beautify C code)

http://www.gnu.org/software/indent/

Complexity:

Analyzing complexity of C functions:

Complexity measurement tools provide several pieces of information. They help to:

  1. locate suspicious areas in unfamiliar code
  2. get an idea of how much effort may be required to understand that code
  3. get an idea of the effort required to test a code base
  4. provide a reminder to yourself. You may see what you’ve written as obvious, but others may not. It is useful to have a hint about what code may seem harder to understand by others, and then decide if some rework may be in order.

http://www.gnu.org/software/complexity/manual/

Cflow:

The cflow utility analyzes a collection of source files written in C programming language and outputs a graph charting dependencies between various functions.

Simple output:

$ cflow whoami.c
main() <int main (int argc,char **argv) at whoami.c:26>:
fprintf()
who_am_i() <int who_am_i (void) at whoami.c:8>:
getpwuid()
geteuid()
getenv()
fprintf()
printf()

More complex output:

$ cflow –tree –brief –cpp wc.c
+-main() <int main (int argc,char **argv) at wc.c:127>
+-errf() <void errf (char *fmt,…) at wc.c:34>
| \-error_print()
|     <void error_print (int perr,char *fmt,va_list ap) at wc.c:22>
|   +-vfprintf()
|   +-perror()
|   +-fprintf()
|   \-exit()
+-counter() <void counter (char *file) at wc.c:108>
| +-fopen()
| +-perrf() <void perrf (char *fmt,…) at wc.c:46>
| | \-error_print()
| |    <void error_print (int perr,char *fmt,va_list ap)
| |    at wc.c:22> [see 3]
| +-getword() <int getword (FILE *fp) at wc.c:78>
| | +-feof()
| | \-isword() <int isword (unsigned char c) at wc.c:64>
| |   \-isalpha()
| +-fclose()
| \-report()
|     <void report (char *file,count_t ccount,
|       count_t wcount,count_t lcount) at wc.c:57>
|   \-printf()
\-report()
<void report (char *file,count_t ccount,count_t wcount,count_t lcount) at wc.c:57> [see 17]

Pretty useful. Homepage: http://www.gnu.org/software/cflow/

NetBsd Color ls

August 27, 2011 Leave a comment

To add colors to ls command output under netbsd:

install gnuls (pkg_add gnuls)

and add fallowing to your .profile file:  alias ls=”gls –color=always”

Freebsd has -G switch for color output such as : ls -alG

Categories: Uncategorized Tags: ,

FreeBsd/NetBsd vi/vim compatible and color mode

August 27, 2011 Leave a comment

In freebsd and netbsd vim acts same as old plain vi. To make it compatible as linux versions open your .vimrc file enter fallowing and save :

set nocompatible
set autoindent
set smartindent
set tabstop=4
set shiftwidth=4
set showmatch
set guioptions-=T
set vb t_vb=
set ruler
set nohls
set incsearch
set virtualedit=all
set bs=2
syntax on