Add file properties dialog.
[guestfs-browser.git] / utils.ml
index 4ec1531..57faf38 100644 (file)
--- a/utils.ml
+++ b/utils.ml
@@ -25,6 +25,7 @@ let (+^) = Int64.add
 let (-^) = Int64.sub
 let ( *^ ) = Int64.mul
 let (/^) = Int64.div
+let (&^) = Int64.logand
 
 type ('a, 'b) either = Left of 'a | Right of 'b
 
@@ -178,6 +179,35 @@ and is_xo mode =           test_bit 0o001L mode
 
 and test_bit mask mode = Int64.logand mode mask = mask
 
+let file_permissions_string mode =
+  let c =
+    if is_socket mode then 's'
+    else if is_symlink mode then 'l'
+    else if is_regular_file mode then '-'
+    else if is_block mode then 'b'
+    else if is_directory mode then 'd'
+    else if is_char mode then 'c'
+    else if is_fifo mode then 'p' else '?' in
+  let ru = if is_ru mode then 'r' else '-' in
+  let wu = if is_wu mode then 'w' else '-' in
+  let xu = if is_xu mode then 'x' else '-' in
+  let rg = if is_rg mode then 'r' else '-' in
+  let wg = if is_wg mode then 'w' else '-' in
+  let xg = if is_xg mode then 'x' else '-' in
+  let ro = if is_ro mode then 'r' else '-' in
+  let wo = if is_wo mode then 'w' else '-' in
+  let xo = if is_xo mode then 'x' else '-' in
+  let str = sprintf "%c%c%c%c%c%c%c%c%c%c" c ru wu xu rg wg xg ro wo xo in
+
+  let suid = is_suid mode in
+  let sgid = is_sgid mode in
+  let svtx = is_svtx mode in
+  if suid then str.[3] <- 's';
+  if sgid then str.[6] <- 's';
+  if svtx then str.[9] <- 't';
+
+  str
+
 let tmpdir () =
   let chan = open_in "/dev/urandom" in
   let data = String.create 16 in