getting the full permissions of a file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers getting the full permissions of a file
# 1  
Old 02-09-2012
getting the full permissions of a file

Hi I was wondering if it would be possible to get the full octal permissions of a file by using something in the stat() system call. Can this be done without going through all of the seperate permissions (e.g. read for user, write for user .... etc.)? also how can this octal permission be changed to accomadate new permissions? (can i simply store the octal permission and then perform normal computations on it according to the permission im adding or taking away? Thanks in advance for anyone who could explain this.
# 2  
Old 02-09-2012
You don't have to "go through" them individually. stat() returns them all at once. They're all different bits of one binary integer.

You change them with chmod(). So you'd get the bits you want with stat(), alter them, then chmod() it to the new one.

To add bits, | them.
Code:
// Add read and write permissions.
// This is harmless if they're already set.
int new_perms=old_perms | 0006;

To remove bits, & their opposite. ~ is the bitwise opposite, so:

Code:
// Remove read and write permissions.  This is harmless
// if they're already missing.
int new_perms=old_perms & ~0006;

# 3  
Old 02-09-2012
so i could do something like int old_perms = stat() to set the old perms is what your saying and simply perform the operations you specified?or do i need to use st_mode and further??sorry if im kinda slow when it comes to this stuff.

Last edited by bjhum33; 02-09-2012 at 06:39 PM..
# 4  
Old 02-09-2012
No, stat() doesn't return them in that way. It reads into an entire structure with various members, only one of which contains file permissions. See man 2 stat for details.
# 5  
Old 02-09-2012
ok i figured it all out thanks alot i really appreciate your help

---------- Post updated at 07:01 PM ---------- Previous update was at 06:14 PM ----------

Hi the newPerm = oldPerm | ####; is working in my code but for some reason each case of newPerm = oldPerm & ~####; is returning an error that reads "parameter names without types in function declaration, i think when this is being called...
chmod(file, newPerm); what could be the problem?
# 6  
Old 02-10-2012
Without seeing your code I couldn't say. Please post it.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

100% Inode full with only 67% FS full.

AIX Version 6.1 and 7.1. I understand that when the OS initially creates the FS and inodes, its pretty strict, but not always tuned to a 1:1 ratio. I see the same thing when adding a whole disk LV to a separate device. It seems that when we expand a filesystem the inodes don't get tuned... (5 Replies)
Discussion started by: mrmurdock
5 Replies

2. Red Hat

List full File system permissions

I am attempting to get a baseline of deployed RHEL 6.5 servers and need to produce a full filesystem permission settings list.....but I forgot the bloody command and am racking my brain and now have a migraine. I just need a simple list starting at "/" right down the tree, listing the folder,... (3 Replies)
Discussion started by: strykergli250hp
3 Replies

3. Shell Programming and Scripting

ksh; Change file permissions, update file, change permissions back?

Hi, I am creating a ksh script to search for a string of text inside files within a directory tree. Some of these file are going to be read/execute only. I know to use chmod to change the permissions of the file, but I want to preserve the original permissions after writing to the file. How can I... (3 Replies)
Discussion started by: right_coaster
3 Replies

4. Red Hat

File system full, but not really.

Hey all, What do you think mostly happened in the following situation? I have a Red Hat 5.5 server. Someone, somehow, managed to get two .nfs000.... type files that totaled over a terabyte in size. I removed them and thought things were back to normal. Then I started getting complains from... (2 Replies)
Discussion started by: geelsu
2 Replies

5. HP-UX

To give the "unzip" permissions & "create" file permissions

Hi, I am a Unix Admin. I have to give the permissions to a user for creating new file in a directory in HP-Ux 11.11 system since he cannot able to create a new file in the directory. Thanks in advance. Mike (3 Replies)
Discussion started by: Mike1234
3 Replies

6. Solaris

file system full

I am receving following Error message in /var/adm/messages "NOTICE: alloc: /: file system full" Disk space usage is as beklow: df -k $ Filesystem kbytes used avail capacity Mounted on /dev/md/dsk/d10 76678257 56962561 18948914 76% / /proc ... (8 Replies)
Discussion started by: Asteroid
8 Replies

7. Solaris

File system full?

Hi, I just started working with UNIX on an old semi-fossilized Sun workstation which I use to process LOTS of images,however, I just started to get an error message that the file system is full and then my shell tool or/and text editor freeze up. Help? (8 Replies)
Discussion started by: Bend
8 Replies

8. UNIX for Dummies Questions & Answers

ftp file with full permissions

I am running sco openserver 5.0.6 and I was wondering if I could ftp files to one of my other servers and that file have full permissions set automatically on the new server. I have searched the internet and manned chmod chown and ftp but they only seem to talk about giving the permissions after... (7 Replies)
Discussion started by: stufine
7 Replies

9. UNIX for Advanced & Expert Users

Full File System

Hi All, There was a background process running on a Solaris 2.8 machine, and appeared to have filled all available disk-space. I done a killall, and upon re-booting found that the file system had filled up, and will not boot as normal as a result. For example, I'm getting /usr/adm/messages: No... (8 Replies)
Discussion started by: Breen
8 Replies
Login or Register to Ask a Question