open.itworld.com
  Search  
Security Home Page Security Webcasts Security White Papers Security Newsletters Security News Open Topics Careers ITworld Voices ITwhirled The Security site of ITworld.com
Creating Device and Named Pipes Entries
LINUX TIPS AND TRICKS --- 08/23/2002

Danny Kalev

Processes that access devices or communicate with other processes through named pipes create special file entries for this purpose. The mknod() syscall creates device and named pipes entries. It has the following prototype: 

On this topic

#include <fcntl.h>
#include <unistd.h> int mknod(const char * path, mode_t mode, dev_t dev);

To create a device file, you need root privileges; all users may create named pipes. The first argument contains the name of the file to be created. The second argument encodes the file type, which can be S_IFIFO, S_IFBLK or S_IFCHR, and the file's access mode, e.g. 0666. The final argument contains the major and minor numbers of the device being created. The kernel detects which device driver is responsible for handling the device file according to the file's type (i.e., character or block) and its major number. The device driver to identify the specific device uses the minor number internally.

Manipulating dev_t Variables
The <sys/sysmacros.h> header defines three macros that manipulate dev_t values. The makedev() macro takes two arguments: a major number and a minor number, and returns a dev_t value accordingly. The major() and minor() macros take a dev_t variable and extract the device's major and minor versions, respectively.

The mknod Program
Fortunately, Linux provides a mknod program that enables users to create device and named pipes entries from a command shell interface. For more information about this program, type

man 1 mknod

A Note On August 9th Newsletter
The 08/09 newsletter discussed the various prototypes of main() and their usage. Several users asked me about the validity of

void main()

Although several compilers (mostly on Windows) support this prototype, it's a non-standard form. Linux and Unix users in particular shouldn't use it because main() must always return an exit status to the kernel. Historically, this form was introduced as a DOS hack in order to suppress the (non-compliant) compiler warning issued when the programmer didn't provide an explicit return statement in main(). Note that the ANSI standard requires that when no explicit return statement is provided, main() should return 0 implicitly. Thus, not only is void main() a non-standard prototype, it's totally redundant anyway.

 

Danny Kalev is a system analyst and software engineer with more than 10 years of experience, specializing in C++ and object-oriented analysis and design on various platforms including VMS, DOS, Windows, Unix, and Linux. His technical interests involve code optimization, networking, and distributed computing. He is also a member of the ANSI C++ standardization committee and the author of ANSI/ISO C++ Professional Programmer's Handbook (Que, 1999). Danny can be reached at Danny.Kalev@itworld.com.



Advertisements
Sponsored links
Bring harmony to your mix of UNIX-Linux-Windows computing environments
Top 5 Reasons to Combine App Performance and Security
Locate Hidden Software on business PCs with this free tool
KODAK i1400 Series Scanners stand up to the challenge
 Home   Newsletters  LINUX TIPS AND TRICKS
www.itworld.com    open.itworld.com     security.itworld.com     smallbusiness.itworld.com
storage.itworld.com     utilitycomputing.itworld.com     wireless.itworld.com

 
Contact Us   About Us   Privacy Policy    Terms of Service   Reprints  

CIO   Computerworld   CSO   GamePro   Games.net   IDG Connect   IDG World Expo   Infoworld   ITworld   JavaWorld   LinuxWorld  MacUser   Macworld   Network World   PC World   Playlist  

Copyright © Computerworld, Inc. All rights reserved

Reproduction in whole or in part in any form or medium without express written permission of Computerworld Inc. is prohibited. Computerworld and Computerworld.com and the respective logos are trademarks of International Data Group Inc.