+diff -urN coreutils-5.0.org/src/stat.c coreutils-5.0/src/stat.c
+--- coreutils-5.0.org/src/stat.c 2003-12-27 12:26:28.951091752 +0100
++++ coreutils-5.0/src/stat.c 2003-12-27 12:26:52.961441624 +0100
+@@ -32,6 +32,13 @@
+ # include <sys/vfs.h>
+ #endif
+
++#ifdef WITH_SELINUX
++#include <selinux/selinux.h>
++#define SECURITY_ID_T security_context_t
++#else
++#define SECURITY_ID_T char *
++#endif
++
+ /* NetBSD 1.5.2 needs these, for the declaration of struct statfs. */
+ #if !HAVE_SYS_STATVFS_H && !HAVE_SYS_VFS_H
+ # if HAVE_SYS_MOUNT_H && HAVE_SYS_PARAM_H
+@@ -93,6 +100,7 @@
+ {"dereference", no_argument, 0, 'L'},
+ {"format", required_argument, 0, 'c'},
+ {"filesystem", no_argument, 0, 'f'},
++ {"context", no_argument, 0, 'Z'},
+ {"terse", no_argument, 0, 't'},
+ {GETOPT_HELP_OPTION_DECL},
+ {GETOPT_VERSION_OPTION_DECL},
+@@ -332,7 +340,7 @@
+ /* print statfs info */
+ static void
+ print_statfs (char *pformat, char m, char const *filename,
+- void const *data)
++ void const *data,SECURITY_ID_T scontext)
+ {
+ STRUCT_STATVFS const *statfsbuf = data;
+
+@@ -394,7 +402,10 @@
+ strcat (pformat, PRIdMAX);
+ printf (pformat, (intmax_t) (statfsbuf->f_ffree));
+ break;
+-
++ case 'C':
++ strcat (pformat, "s");
++ printf(scontext);
++ break;
+ default:
+ strcat (pformat, "c");
+ printf (pformat, m);
+@@ -404,7 +415,7 @@
+
+ /* print stat info */
+ static void
+-print_stat (char *pformat, char m, char const *filename, void const *data)
++print_stat (char *pformat, char m, char const *filename, void const *data, SECURITY_ID_T scontext)
+ {
+ struct stat *statbuf = (struct stat *) data;
+ struct passwd *pw_ent;
+@@ -537,6 +548,10 @@
+ strcat (pformat, "d");
+ printf (pformat, (int) statbuf->st_ctime);
+ break;
++ case 'C':
++ strcat (pformat, "s");
++ printf(pformat,scontext);
++ break;
+ default:
+ strcat (pformat, "c");
+ printf (pformat, m);
+@@ -546,8 +561,8 @@
+
+ static void
+ print_it (char const *masterformat, char const *filename,
+- void (*print_func) (char *, char, char const *, void const *),
+- void const *data)
++ void (*print_func) (char *, char, char const *, void const *,SECURITY_ID_T ),
++ void const *data, SECURITY_ID_T scontext)
+ {
+ char *b;
+
+@@ -580,7 +595,7 @@
+ putchar ('%');
+ break;
+ default:
+- print_func (dest, *p, filename, data);
++ print_func (dest, *p, filename, data,scontext);
+ break;
+ }
+ b = p + 1;
+@@ -598,9 +613,17 @@
+
+ /* stat the filesystem and print what we find */
+ static void
+-do_statfs (char const *filename, int terse, char const *format)
++do_statfs (char const *filename, int terse, int secure, char const *format)
+ {
+ STRUCT_STATVFS statfsbuf;
++ SECURITY_ID_T scontext = NULL;
++#ifdef WITH_SELINUX
++ if(secure)
++ if (getfilecon(filename,&scontext)<0) {
++ perror (filename);
++ return;
++ }
++#endif
+ int i = statfs (filename, &statfsbuf);
+
+ if (i == -1)
+@@ -612,23 +635,40 @@
+
+ if (format == NULL)
+ {
+- format = (terse
+- ? "%n %i %l %t %b %f %a %s %c %d"
+- : " File: \"%n\"\n"
+- " ID: %-8i Namelen: %-7l Type: %T\n"
+- "Blocks: Total: %-10b Free: %-10f Available: %-10a Size: %s\n"
+- "Inodes: Total: %-10c Free: %-10d");
+- }
+-
+- print_it (format, filename, print_statfs, &statfsbuf);
++ if (terse) {
++ if(secure)
++ format = "%n %i %l %t %b %f %a %s %c %d %C";
++ else
++ format = "%n %i %l %t %b %f %a %s %c %d";
++ }
++ else
++ {
++ if(secure)
++ format = " File: \"%n\"\n"
++ " ID: %-8i Namelen: %-7l Type: %T\n"
++ "Blocks: Total: %-10b Free: %-10f Available: %-10a Size: %s\n"
++ "Inodes: Total: %-10c Free: %-10d\n"
++ " S_Context: %C\n";
++ else
++ format= " File: \"%n\"\n"
++ " ID: %-8i Namelen: %-7l Type: %T\n"
++ "Blocks: Total: %-10b Free: %-10f Available: %-10a Size: %s\n"
++ "Inodes: Total: %-10c Free: %-10d";
++ }
++ }
++ print_it (format, filename, print_statfs, &statfsbuf,scontext);
++#ifdef WITH_SELINUX
++ if (scontext != NULL)
++ freecon(scontext);
++#endif
+ }
+-
+ /* stat the file and print what we find */
+ static void
+-do_stat (char const *filename, int follow_links, int terse,
++ do_stat (char const *filename, int follow_links, int terse,int secure,
+ char const *format)
+ {
+ struct stat statbuf;
++ SECURITY_ID_T scontext = NULL;
+ int i = ((follow_links == 1)
+ ? stat (filename, &statbuf)
+ : lstat (filename, &statbuf));
+@@ -639,11 +679,28 @@
+ return;
+ }
+
++#ifdef WITH_SELINUX
++ if(secure) {
++ if (link)
++ i=lgetfilecon(filename, &scontext);
++ else
++ i=getfilecon(filename, &scontext);
++ if (i == -1)
++ {
++ perror (filename);
++ return;
++ }
++ }
++#endif
++
+ if (format == NULL)
+ {
+ if (terse != 0)
+ {
+- format = "%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %o";
++ if (secure)
++ format = "%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %o %C";
++ else
++ format = "%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %o";
+ }
+ else
+ {
+@@ -651,7 +708,17 @@
+ i = statbuf.st_mode & S_IFMT;
+ if (i == S_IFCHR || i == S_IFBLK)
+ {
+- format =
++ if (secure)
++ format =
++ " File: %N\n"
++ " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
++ "Device: %Dh/%dd\tInode: %-10i Links: %-5h"
++ " Device type: %t,%T\n"
++ "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
++ " S_Context: %C\n"
++ "Access: %x\n" "Modify: %y\n" "Change: %z\n";
++ else
++ format =
+ " File: %N\n"
+ " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
+ "Device: %Dh/%dd\tInode: %-10i Links: %-5h"
+@@ -661,6 +728,15 @@
+ }
+ else
+ {
++ if (secure)
++ format =
++ " File: %N\n"
++ " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
++ "Device: %Dh/%dd\tInode: %-10i Links: %-5h\n"
++ "Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
++ "S_Context: %C\n"
++ "Access: %x\n" "Modify: %y\n" "Change: %z\n";
++ else
+ format =
+ " File: %N\n"
+ " Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
+@@ -670,7 +746,11 @@
+ }
+ }
+ }
+- print_it (format, filename, print_stat, &statbuf);
++ print_it (format, filename, print_stat, &statbuf,scontext);
++#ifdef WITH_SELINUX
++ if (scontext)
++ freecon(scontext);
++#endif
+ }
+
+ void
+@@ -688,6 +768,7 @@
+ -f, --filesystem display filesystem status instead of file status\n\
+ -c --format=FORMAT use the specified FORMAT instead of the default\n\
+ -L, --dereference follow links\n\
++ -Z, --context print the security context \n\
+ -t, --terse print the information in terse form\n\
+ "), stdout);
+ fputs (HELP_OPTION_DESCRIPTION, stdout);
+@@ -739,6 +820,7 @@
+ %c Total file nodes in file system\n\
+ %d Free file nodes in file system\n\
+ %f Free blocks in file system\n\
++ %C - Security context in SELinux\n\
+ "), stdout);
+ fputs (_("\
+ %i File System id in hex\n\
+@@ -761,6 +843,7 @@
+ int follow_links = 0;
+ int fs = 0;
+ int terse = 0;
++ int secure = 0;
+ char *format = NULL;
+
+ program_name = argv[0];
+@@ -770,7 +853,7 @@
+
+ atexit (close_stdout);
+
+- while ((c = getopt_long (argc, argv, "c:fLlt", long_options, NULL)) != -1)
++ while ((c = getopt_long (argc, argv, "c:fLltZ", long_options, NULL)) != -1)
+ {
+ switch (c)
+ {
+@@ -787,6 +870,14 @@
+ case 't':
+ terse = 1;
+ break;
++ case 'Z':
++ if(is_selinux_enabled())
++ secure = 1;
++ else {
++ error (0, 0, _("Kernel is not SELinux enabled"));
++ usage (EXIT_FAILURE);
++ }
++ break;
+
+ case_GETOPT_HELP_CHAR;
+
+@@ -806,9 +897,9 @@
+ for (i = optind; i < argc; i++)
+ {
+ if (fs == 0)
+- do_stat (argv[i], follow_links, terse, format);
++ do_stat (argv[i], follow_links, terse, secure, format);
+ else
+- do_statfs (argv[i], terse, format);
++ do_statfs (argv[i], terse, secure, format);
+ }
+
+ exit (G_fail ? EXIT_FAILURE : EXIT_SUCCESS);