The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help required with using system() call ramkrix High Level Programming 9 03-24-2008 01:05 AM
c system call rangaswamy High Level Programming 1 02-19-2008 01:53 PM
how to differentiate system call from library call muru UNIX for Advanced & Expert Users 2 07-19-2007 11:20 PM
Making a system call hardwickj High Level Programming 5 07-06-2006 09:28 PM
read system call Madhu Babu High Level Programming 1 11-16-2002 07:11 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 09-18-2006
nathan nathan is offline VIP Member  
Supporter
  
 

Join Date: Jul 2006
Posts: 156
mknod system call to clone /dev/null

I'm trying to use the "mknod" call in C to create a clone of /dev/null. I am stumped as to the final parameter I should provide to "mknod()". I am supposed to give it a type dev_t, which specifies a major & minor number. I want to specify major 3, minor 1, but how can I do this?

dev_t seems to be a long long. It takes up 8 bytes, but I can't find anything about it. I've searched through quite a few /usr/include files, but I still can't find anything (nor on google).

If I 'stat()' /dev/null and then print the value of st_dev as an int (%d), I get '16'. But when I try and create a file called 'mynull', a clone of /dev/null, I get a major number of 0 and minor number of 16 , as shown below ( mknod() fails unless I call it as root ).
Code:
c---------  1 root root 0, 16 Sep 18 21:20 mynull
From my man page:
Code:
       If the file type is S_IFCHR or S_IFBLK then dev specifies the major and minor  numbers of the newly created device special file; otherwise it is ignored.
Does anyone have any ideas as to how I can create a character special file with major number 1 and minor number 3?

Code:
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <strings.h>
#include <errno.h>

/* int mknod(const char *pathname, mode_t mode, dev_t dev); */

main( argc, argv )
  int   argc;
  char  *argv[];
{
  int rc;
  char path[256];
  char errstr[1024];

  strcpy( path, "mynull" );

  rc = mknod( path, S_IFCHR, 16 );

  if ( rc < 0 )
    perror( "mknod" );

  return(rc);
}
Here's what I get when I stat /dev/null:
Code:
  rc = stat( "/dev/null" , &fstatus );
  printf("dev_t for /dev/null = %d\n", fstatus.st_dev);
$ a.out
dev_t for /dev/null = 16
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:08 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0